Move slate code from core/libtx to wallet/libwallet (#2533)

* move slate from core to wallet crate

* rustfmt
This commit is contained in:
Yeastplume 2019-02-05 23:02:00 +00:00 committed by GitHub
parent 4eba13a207
commit e69ce5ad82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 54 additions and 77 deletions

View file

@ -16,7 +16,7 @@
use failure::{Backtrace, Context, Fail};
use std::fmt::{self, Display};
use crate::core::{committed, transaction};
use crate::core::transaction;
use crate::keychain;
use crate::util::secp;
@ -44,12 +44,6 @@ pub enum ErrorKind {
/// Rangeproof error
#[fail(display = "Rangeproof Error")]
RangeProof(String),
/// Fee error
#[fail(display = "Fee Error")]
Fee(String),
/// Error from summing commitments via committed trait.
#[fail(display = "Committed Error")]
Committed(committed::Error),
}
impl Fail for Error {
@ -97,14 +91,6 @@ impl From<secp::Error> for Error {
}
}
impl From<committed::Error> for Error {
fn from(error: committed::Error) -> Error {
Error {
inner: Context::new(ErrorKind::Committed(error)),
}
}
}
impl From<keychain::Error> for Error {
fn from(error: keychain::Error) -> Error {
Error {

View file

@ -27,7 +27,6 @@ mod error;
pub mod proof;
pub mod reward;
pub mod secp_ser;
pub mod slate;
use crate::consensus;
use crate::core::Transaction;

View file

@ -16,7 +16,7 @@
use std::fs::File;
use std::io::{Read, Write};
use crate::core::libtx::slate::Slate;
use crate::libwallet::slate::Slate;
use crate::libwallet::{Error, ErrorKind};
use crate::{WalletCommAdapter, WalletConfig};
use serde_json as json;

View file

@ -14,7 +14,7 @@
use crate::api;
use crate::controller;
use crate::core::libtx::slate::Slate;
use crate::libwallet::slate::Slate;
use crate::libwallet::{Error, ErrorKind};
use crate::{instantiate_wallet, HTTPNodeClient, WalletCommAdapter, WalletConfig};
/// HTTP Wallet 'plugin' implementation

View file

@ -15,7 +15,7 @@
// Keybase Wallet Plugin
use crate::controller;
use crate::core::libtx::slate::Slate;
use crate::libwallet::slate::Slate;
use crate::libwallet::{Error, ErrorKind};
use crate::{instantiate_wallet, HTTPNodeClient, WalletCommAdapter, WalletConfig};
use failure::ResultExt;

View file

@ -22,7 +22,7 @@ pub use self::http::HTTPWalletCommAdapter;
pub use self::keybase::KeybaseWalletCommAdapter;
pub use self::null::NullWalletCommAdapter;
use crate::core::libtx::slate::Slate;
use crate::libwallet::slate::Slate;
use crate::libwallet::Error;
use crate::WalletConfig;
use std::collections::HashMap;

View file

@ -13,7 +13,7 @@
// limitations under the License.
/// Null Output 'plugin' implementation
use crate::core::libtx::slate::Slate;
use crate::libwallet::slate::Slate;
use crate::libwallet::Error;
use crate::{WalletCommAdapter, WalletConfig};

View file

@ -19,9 +19,9 @@ use crate::adapters::{FileWalletCommAdapter, HTTPWalletCommAdapter, KeybaseWalle
use crate::api::{ApiServer, BasicAuthMiddleware, Handler, ResponseFuture, Router, TLSConfig};
use crate::core::core;
use crate::core::core::Transaction;
use crate::core::libtx::slate::Slate;
use crate::keychain::Keychain;
use crate::libwallet::api::{APIForeign, APIOwner};
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{
CbData, NodeClient, OutputData, SendTXArgs, TxLogEntry, WalletBackend, WalletInfo,
};
@ -344,8 +344,7 @@ where
match e.kind() {
// user errors, don't backtrace
ErrorKind::NotEnoughFunds { .. } => {}
ErrorKind::FeeDispute { .. } => {}
ErrorKind::FeeExceedsAmount { .. } => {}
ErrorKind::Fee { .. } => {}
_ => {
// otherwise give full dump
error!("Backtrace: {}", e.backtrace().unwrap());

View file

@ -46,6 +46,7 @@ pub use crate::adapters::{
WalletCommAdapter,
};
pub use crate::error::{Error, ErrorKind};
pub use crate::libwallet::slate::Slate;
pub use crate::libwallet::types::{
BlockFees, CbData, NodeClient, WalletBackend, WalletInfo, WalletInst,
};

View file

@ -36,10 +36,10 @@ use uuid::Uuid;
use crate::core::core::hash::Hashed;
use crate::core::core::Transaction;
use crate::core::libtx::slate::Slate;
use crate::core::ser;
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::internal::{keys, tx, updater};
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{
AcctPathMapping, BlockFees, CbData, NodeClient, OutputData, OutputLockFn, TxLogEntry,
TxLogEntryType, TxWrapper, WalletBackend, WalletInfo,

View file

@ -14,9 +14,10 @@
//! Error types for libwallet
use crate::core::core::transaction;
use crate::core::core::{committed, transaction};
use crate::core::libtx;
use crate::keychain;
use crate::util::secp;
use failure::{Backtrace, Context, Fail};
use std::env;
use std::fmt::{self, Display};
@ -47,37 +48,9 @@ pub enum ErrorKind {
needed_disp: String,
},
/// Fee dispute
#[fail(
display = "Fee dispute: sender fee {}, recipient fee {}",
sender_fee_disp, recipient_fee_disp
)]
FeeDispute {
/// sender fee
sender_fee: u64,
/// display friendly
sender_fee_disp: String,
/// recipient fee
recipient_fee: u64,
/// display friendly
recipient_fee_disp: String,
},
/// Fee Exceeds amount
#[fail(
display = "Fee exceeds amount: sender amount {}, recipient fee {}",
sender_amount_disp, recipient_fee
)]
FeeExceedsAmount {
/// sender amount
sender_amount: u64,
/// display friendly
sender_amount_disp: String,
/// recipient fee
recipient_fee: u64,
/// display friendly
recipient_fee_disp: String,
},
/// Fee error
#[fail(display = "Fee Error: {}", _0)]
Fee(String),
/// LibTX Error
#[fail(display = "LibTx Error")]
@ -97,7 +70,7 @@ pub enum ErrorKind {
/// Secp Error
#[fail(display = "Secp error")]
Secp,
Secp(secp::Error),
/// Callback implementation error conversion
#[fail(display = "Trait Implementation error")]
@ -140,8 +113,8 @@ pub enum ErrorKind {
Uri,
/// Signature error
#[fail(display = "Signature error")]
Signature(&'static str),
#[fail(display = "Signature error: {}", _0)]
Signature(String),
/// Attempt to use duplicate transaction id in separate transactions
#[fail(display = "Duplicate transaction ID error")]
@ -199,6 +172,10 @@ pub enum ErrorKind {
#[fail(display = "Unknown Account Label '{}'", _0)]
UnknownAccountLabel(String),
/// Error from summing commitments via committed trait.
#[fail(display = "Committed Error")]
Committed(committed::Error),
/// Other
#[fail(display = "Generic error: {}", _0)]
GenericError(String),
@ -305,3 +282,19 @@ impl From<crate::core::ser::Error> for Error {
}
}
}
impl From<secp::Error> for Error {
fn from(error: secp::Error) -> Error {
Error {
inner: Context::new(ErrorKind::Secp(error)),
}
}
}
impl From<committed::Error> for Error {
fn from(error: committed::Error) -> Error {
Error {
inner: Context::new(ErrorKind::Committed(error)),
}
}
}

View file

@ -15,10 +15,11 @@
//! Selection of inputs for building transactions
use crate::core::core::{amount_to_hr_string, Transaction};
use crate::core::libtx::{build, slate::Slate, tx_fee};
use crate::core::libtx::{build, tx_fee};
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::error::{Error, ErrorKind};
use crate::libwallet::internal::keys;
use crate::libwallet::slate::Slate;
use crate::libwallet::types::*;
use std::collections::HashMap;
use std::marker::PhantomData;

View file

@ -16,9 +16,9 @@
use uuid::Uuid;
use crate::core::libtx::slate::Slate;
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::internal::{selection, updater};
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{Context, NodeClient, OutputLockFn, TxLogEntryType, WalletBackend};
use crate::libwallet::{Error, ErrorKind};
@ -149,10 +149,7 @@ where
participant_id,
)?;
// Final transaction can be built by anyone at this stage
let res = slate.finalize(wallet.keychain());
if let Err(e) = res {
Err(ErrorKind::LibTX(e.kind()))?
}
slate.finalize(wallet.keychain())?;
Ok(())
}

View file

@ -25,6 +25,7 @@
pub mod api;
mod error;
pub mod internal;
pub mod slate;
pub mod types;
pub use crate::libwallet::error::{Error, ErrorKind};

View file

@ -16,17 +16,17 @@
//! around during an interactive wallet exchange
use crate::blake2::blake2b::blake2b;
use crate::core::amount_to_hr_string;
use crate::core::committed::Committed;
use crate::core::transaction::{kernel_features, kernel_sig_msg, Transaction, Weighting};
use crate::core::verifier_cache::LruVerifierCache;
use crate::keychain::{BlindSum, BlindingFactor, Keychain};
use crate::libtx::error::{Error, ErrorKind};
use crate::libtx::{aggsig, build, secp_ser, tx_fee};
use crate::libwallet::error::{Error, ErrorKind};
use crate::util::secp;
use crate::util::secp::key::{PublicKey, SecretKey};
use crate::util::secp::Signature;
use crate::util::RwLock;
use grin_core::core::amount_to_hr_string;
use grin_core::core::committed::Committed;
use grin_core::core::transaction::{kernel_features, kernel_sig_msg, Transaction, Weighting};
use grin_core::core::verifier_cache::LruVerifierCache;
use grin_core::libtx::{aggsig, build, secp_ser, tx_fee};
use rand::thread_rng;
use std::sync::Arc;
use uuid::Uuid;

View file

@ -21,11 +21,11 @@ use crate::core::libtx::aggsig;
use crate::core::ser;
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::error::{Error, ErrorKind};
use crate::libwallet::slate::ParticipantMessages;
use crate::util::secp::key::{PublicKey, SecretKey};
use crate::util::secp::{self, pedersen, Secp256k1};
use chrono::prelude::*;
use failure::ResultExt;
use grin_core::libtx::slate::ParticipantMessages;
use serde;
use serde_json;
use std::collections::HashMap;

View file

@ -21,12 +21,12 @@ use self::chain::Chain;
use self::core::core::verifier_cache::LruVerifierCache;
use self::core::core::Transaction;
use self::core::global::{set_mining_mode, ChainTypes};
use self::core::libtx::slate::Slate;
use self::core::{pow, ser};
use self::keychain::Keychain;
use self::util::secp::pedersen;
use self::util::secp::pedersen::Commitment;
use self::util::{Mutex, RwLock, StopState};
use crate::libwallet::slate::Slate;
use crate::libwallet::types::*;
use crate::{controller, libwallet, WalletCommAdapter, WalletConfig};
use failure::ResultExt;

View file

@ -17,8 +17,8 @@ extern crate log;
use self::core::global;
use self::core::global::ChainTypes;
use self::core::libtx::slate::Slate;
use self::keychain::ExtKeychain;
use self::libwallet::slate::Slate;
use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy};
use self::wallet::{libwallet, FileWalletCommAdapter};
use grin_core as core;

View file

@ -16,8 +16,8 @@
extern crate log;
use self::core::global;
use self::core::global::ChainTypes;
use self::core::libtx::slate::Slate;
use self::keychain::{ExtKeychain, Identifier, Keychain};
use self::libwallet::slate::Slate;
use self::wallet::libwallet;
use self::wallet::libwallet::types::AcctPathMapping;
use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy};

View file

@ -16,8 +16,8 @@
extern crate log;
use self::core::global;
use self::core::global::ChainTypes;
use self::core::libtx::slate::Slate;
use self::keychain::ExtKeychain;
use self::libwallet::slate::Slate;
use self::wallet::libwallet;
use self::wallet::libwallet::types::OutputStatus;
use self::wallet::test_framework::{self, LocalWalletClient, WalletProxy};