diff --git a/core/src/libtx/error.rs b/core/src/libtx/error.rs index 68810fd15..89a1ecfb5 100644 --- a/core/src/libtx/error.rs +++ b/core/src/libtx/error.rs @@ -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 for Error { } } -impl From for Error { - fn from(error: committed::Error) -> Error { - Error { - inner: Context::new(ErrorKind::Committed(error)), - } - } -} - impl From for Error { fn from(error: keychain::Error) -> Error { Error { diff --git a/core/src/libtx/mod.rs b/core/src/libtx/mod.rs index a9c802b03..e48047e67 100644 --- a/core/src/libtx/mod.rs +++ b/core/src/libtx/mod.rs @@ -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; diff --git a/wallet/src/adapters/file.rs b/wallet/src/adapters/file.rs index 41c8aaaff..0fd305cce 100644 --- a/wallet/src/adapters/file.rs +++ b/wallet/src/adapters/file.rs @@ -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; diff --git a/wallet/src/adapters/http.rs b/wallet/src/adapters/http.rs index 03e36826a..31ce97f77 100644 --- a/wallet/src/adapters/http.rs +++ b/wallet/src/adapters/http.rs @@ -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 diff --git a/wallet/src/adapters/keybase.rs b/wallet/src/adapters/keybase.rs index 2e411919d..2cac127fb 100644 --- a/wallet/src/adapters/keybase.rs +++ b/wallet/src/adapters/keybase.rs @@ -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; diff --git a/wallet/src/adapters/mod.rs b/wallet/src/adapters/mod.rs index 88f028a27..c42b09647 100644 --- a/wallet/src/adapters/mod.rs +++ b/wallet/src/adapters/mod.rs @@ -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; diff --git a/wallet/src/adapters/null.rs b/wallet/src/adapters/null.rs index 18ee73bea..9ac7500ee 100644 --- a/wallet/src/adapters/null.rs +++ b/wallet/src/adapters/null.rs @@ -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}; diff --git a/wallet/src/controller.rs b/wallet/src/controller.rs index cad0a9bdd..9bd584932 100644 --- a/wallet/src/controller.rs +++ b/wallet/src/controller.rs @@ -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()); diff --git a/wallet/src/lib.rs b/wallet/src/lib.rs index 1e5076846..1569929f2 100644 --- a/wallet/src/lib.rs +++ b/wallet/src/lib.rs @@ -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, }; diff --git a/wallet/src/libwallet/api.rs b/wallet/src/libwallet/api.rs index fbe857bfb..5302e1f19 100644 --- a/wallet/src/libwallet/api.rs +++ b/wallet/src/libwallet/api.rs @@ -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, diff --git a/wallet/src/libwallet/error.rs b/wallet/src/libwallet/error.rs index 867e7b63e..491e78e09 100644 --- a/wallet/src/libwallet/error.rs +++ b/wallet/src/libwallet/error.rs @@ -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 for Error { } } } + +impl From for Error { + fn from(error: secp::Error) -> Error { + Error { + inner: Context::new(ErrorKind::Secp(error)), + } + } +} + +impl From for Error { + fn from(error: committed::Error) -> Error { + Error { + inner: Context::new(ErrorKind::Committed(error)), + } + } +} diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index 379b133d2..c9e4b3d27 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -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; diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index cbcfb79b9..459885d4c 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -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(()) } diff --git a/wallet/src/libwallet/mod.rs b/wallet/src/libwallet/mod.rs index 3dcfc49c5..aa69b8845 100644 --- a/wallet/src/libwallet/mod.rs +++ b/wallet/src/libwallet/mod.rs @@ -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}; diff --git a/core/src/libtx/slate.rs b/wallet/src/libwallet/slate.rs similarity index 97% rename from core/src/libtx/slate.rs rename to wallet/src/libwallet/slate.rs index 85d91bef5..d06286980 100644 --- a/core/src/libtx/slate.rs +++ b/wallet/src/libwallet/slate.rs @@ -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; diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index 15e563126..81ef38f9c 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -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; diff --git a/wallet/src/test_framework/testclient.rs b/wallet/src/test_framework/testclient.rs index b6bb8fcac..5e34a2d39 100644 --- a/wallet/src/test_framework/testclient.rs +++ b/wallet/src/test_framework/testclient.rs @@ -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; diff --git a/wallet/tests/repost.rs b/wallet/tests/repost.rs index 1712245de..e24cd6f62 100644 --- a/wallet/tests/repost.rs +++ b/wallet/tests/repost.rs @@ -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; diff --git a/wallet/tests/restore.rs b/wallet/tests/restore.rs index 1b39b535d..1c1b08373 100644 --- a/wallet/tests/restore.rs +++ b/wallet/tests/restore.rs @@ -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}; diff --git a/wallet/tests/transaction.rs b/wallet/tests/transaction.rs index c9840f616..e4b8b1358 100644 --- a/wallet/tests/transaction.rs +++ b/wallet/tests/transaction.rs @@ -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};