Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions core/src/libtx/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion core/src/libtx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/adapters/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/adapters/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/adapters/keybase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/adapters/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
5 changes: 2 additions & 3 deletions wallet/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/libwallet/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 28 additions & 35 deletions wallet/src/libwallet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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")]
Expand All @@ -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")]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
}
}
}
3 changes: 2 additions & 1 deletion wallet/src/libwallet/internal/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions wallet/src/libwallet/internal/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
}

Expand Down
1 change: 1 addition & 0 deletions wallet/src/libwallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
12 changes: 6 additions & 6 deletions core/src/libtx/slate.rs → wallet/src/libwallet/slate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/libwallet/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/test_framework/testclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/tests/repost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion wallet/tests/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion wallet/tests/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down