mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 07:11:36 +02:00
Replace failure with thiserror (#654)
* updated util and libwallet with thiserror * update impl crate to thiserror * api crate converted to thiserror * update of controller crate to thiserror * update final bin + tests to thiserror * update unused import * remove failure derive * reset import of grin to master * update cargo lock * update from master
This commit is contained in:
@@ -12,8 +12,6 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
blake2-rfc = "0.2"
|
||||
failure = "0.1"
|
||||
failure_derive = "0.1"
|
||||
rand = "0.6"
|
||||
serde = "1"
|
||||
serde_derive = "1"
|
||||
@@ -24,6 +22,7 @@ chrono = { version = "0.4.11", features = ["serde"] }
|
||||
lazy_static = "1"
|
||||
strum = "0.18"
|
||||
strum_macros = "0.18"
|
||||
thiserror = "1"
|
||||
ed25519-dalek = "1.0.0-pre.4"
|
||||
x25519-dalek = "0.6"
|
||||
base64 = "0.9"
|
||||
|
||||
@@ -23,8 +23,8 @@ use crate::grin_util::secp::key::SecretKey;
|
||||
use crate::internal::{selection, tx, updater};
|
||||
use crate::slate_versions::SlateVersion;
|
||||
use crate::{
|
||||
address, BlockFees, CbData, Error, ErrorKind, NodeClient, Slate, SlateState, TxLogEntryType,
|
||||
VersionInfo, WalletBackend,
|
||||
address, BlockFees, CbData, Error, NodeClient, Slate, SlateState, TxLogEntryType, VersionInfo,
|
||||
WalletBackend,
|
||||
};
|
||||
|
||||
const FOREIGN_API_VERSION: u16 = 2;
|
||||
@@ -87,7 +87,7 @@ where
|
||||
)?;
|
||||
for t in &tx {
|
||||
if t.tx_type == TxLogEntryType::TxReceived {
|
||||
return Err(ErrorKind::TransactionAlreadyReceived(ret_slate.id.to_string()).into());
|
||||
return Err(Error::TransactionAlreadyReceived(ret_slate.id.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,12 @@ use crate::grin_keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmen
|
||||
use crate::internal::{keys, scan, selection, tx, updater};
|
||||
use crate::slate::{PaymentInfo, Slate, SlateState};
|
||||
use crate::types::{AcctPathMapping, NodeClient, TxLogEntry, WalletBackend, WalletInfo};
|
||||
use crate::Error;
|
||||
use crate::{
|
||||
address, wallet_lock, BuiltOutput, InitTxArgs, IssueInvoiceTxArgs, NodeHeightResult,
|
||||
OutputCommitMapping, PaymentProof, ScannedBlockInfo, Slatepack, SlatepackAddress, Slatepacker,
|
||||
SlatepackerArgs, TxLogEntryType, ViewWallet, WalletInitStatus, WalletInst, WalletLCProvider,
|
||||
};
|
||||
use crate::{Error, ErrorKind};
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
use ed25519_dalek::Verifier;
|
||||
@@ -211,9 +211,9 @@ where
|
||||
};
|
||||
return packer.get_slate(&slatepack);
|
||||
}
|
||||
return Err(ErrorKind::SlatepackDecryption(
|
||||
return Err(Error::SlatepackDecryption(
|
||||
"Could not decrypt slatepack with any provided index on the address derivation path"
|
||||
.into(),
|
||||
.to_owned(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
@@ -382,10 +382,9 @@ where
|
||||
K: Keychain + 'a,
|
||||
{
|
||||
if tx_id.is_none() && tx_slate_id.is_none() {
|
||||
return Err(ErrorKind::PaymentProofRetrieval(
|
||||
"Transaction ID or Slate UUID must be specified".into(),
|
||||
)
|
||||
.into());
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Transaction ID or Slate UUID must be specified".to_owned(),
|
||||
));
|
||||
}
|
||||
if refresh_from_node {
|
||||
update_wallet_state(
|
||||
@@ -406,17 +405,18 @@ where
|
||||
tx_slate_id,
|
||||
)?;
|
||||
if txs.1.len() != 1 {
|
||||
return Err(ErrorKind::PaymentProofRetrieval("Transaction doesn't exist".into()).into());
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Transaction doesn't exist".to_owned(),
|
||||
));
|
||||
}
|
||||
// Pull out all needed fields, returning an error if they're not present
|
||||
let tx = txs.1[0].clone();
|
||||
let proof = match tx.payment_proof {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProofRetrieval(
|
||||
"Transaction does not contain a payment proof".into(),
|
||||
)
|
||||
.into());
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Transaction does not contain a payment proof".to_owned(),
|
||||
));
|
||||
}
|
||||
};
|
||||
let amount = if tx.amount_credited >= tx.amount_debited {
|
||||
@@ -431,28 +431,25 @@ where
|
||||
let excess = match tx.kernel_excess {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProofRetrieval(
|
||||
"Transaction does not contain kernel excess".into(),
|
||||
)
|
||||
.into());
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Transaction does not contain kernel excess".to_owned(),
|
||||
));
|
||||
}
|
||||
};
|
||||
let r_sig = match proof.receiver_signature {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProofRetrieval(
|
||||
"Proof does not contain receiver signature ".into(),
|
||||
)
|
||||
.into());
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Proof does not contain receiver signature ".to_owned(),
|
||||
));
|
||||
}
|
||||
};
|
||||
let s_sig = match proof.sender_signature {
|
||||
Some(e) => e,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProofRetrieval(
|
||||
"Proof does not contain sender signature ".into(),
|
||||
)
|
||||
.into());
|
||||
return Err(Error::PaymentProofRetrieval(
|
||||
"Proof does not contain sender signature ".to_owned(),
|
||||
));
|
||||
}
|
||||
};
|
||||
Ok(PaymentProof {
|
||||
@@ -669,7 +666,7 @@ where
|
||||
)?;
|
||||
for t in &tx {
|
||||
if t.tx_type == TxLogEntryType::TxSent {
|
||||
return Err(ErrorKind::TransactionAlreadyReceived(ret_slate.id.to_string()).into());
|
||||
return Err(Error::TransactionAlreadyReceived(ret_slate.id.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,10 +879,9 @@ where
|
||||
status_send_channel,
|
||||
false,
|
||||
)? {
|
||||
return Err(ErrorKind::TransactionCancellationError(
|
||||
return Err(Error::TransactionCancellationError(
|
||||
"Can't contact running Grin node. Not Cancelling.",
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
wallet_lock!(wallet_inst, w);
|
||||
let parent_key_id = w.parent_key_id();
|
||||
@@ -919,10 +915,9 @@ where
|
||||
let id = match uuid {
|
||||
Some(u) => u,
|
||||
None => {
|
||||
return Err(ErrorKind::StoredTx(
|
||||
return Err(Error::StoredTx(
|
||||
"Both the provided Transaction Id and Slate UUID are invalid.".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
};
|
||||
let tx_res = w.get_stored_tx(&format!("{}", id))?;
|
||||
@@ -977,7 +972,7 @@ where
|
||||
let rewind_hash = rewind_hash.to_lowercase();
|
||||
if !(is_hex && rewind_hash.len() == 64) {
|
||||
let msg = format!("Invalid Rewind Hash");
|
||||
return Err(ErrorKind::RewindHash(msg).into());
|
||||
return Err(Error::RewindHash(msg));
|
||||
}
|
||||
|
||||
let tip = {
|
||||
@@ -1227,7 +1222,7 @@ where
|
||||
let last_confirmed_height = w.last_confirmed_height()?;
|
||||
if slate.ttl_cutoff_height != 0 {
|
||||
if last_confirmed_height >= slate.ttl_cutoff_height {
|
||||
return Err(ErrorKind::TransactionExpired.into());
|
||||
return Err(Error::TransactionExpired);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -1260,18 +1255,16 @@ where
|
||||
// Check kernel exists
|
||||
match client.get_kernel(&proof.excess, None, None) {
|
||||
Err(e) => {
|
||||
return Err(ErrorKind::PaymentProof(format!(
|
||||
return Err(Error::PaymentProof(format!(
|
||||
"Error retrieving kernel from chain: {}",
|
||||
e
|
||||
))
|
||||
.into());
|
||||
)));
|
||||
}
|
||||
Ok(None) => {
|
||||
return Err(ErrorKind::PaymentProof(format!(
|
||||
return Err(Error::PaymentProof(format!(
|
||||
"Transaction kernel with excess {:?} not found on chain",
|
||||
proof.excess
|
||||
))
|
||||
.into());
|
||||
)));
|
||||
}
|
||||
Ok(Some(_)) => {}
|
||||
};
|
||||
@@ -1279,12 +1272,14 @@ where
|
||||
// Check Sigs
|
||||
let recipient_pubkey = proof.recipient_address.pub_key;
|
||||
if recipient_pubkey.verify(&msg, &proof.recipient_sig).is_err() {
|
||||
return Err(ErrorKind::PaymentProof("Invalid recipient signature".to_owned()).into());
|
||||
return Err(Error::PaymentProof(
|
||||
"Invalid recipient signature".to_owned(),
|
||||
));
|
||||
};
|
||||
|
||||
let sender_pubkey = proof.sender_address.pub_key;
|
||||
if sender_pubkey.verify(&msg, &proof.sender_sig).is_err() {
|
||||
return Err(ErrorKind::PaymentProof("Invalid sender signature".to_owned()).into());
|
||||
return Err(Error::PaymentProof("Invalid sender signature".to_owned()));
|
||||
};
|
||||
|
||||
// for now, simple test as to whether one of the addresses belongs to this wallet
|
||||
@@ -1292,7 +1287,7 @@ where
|
||||
let d_skey = match DalekSecretKey::from_bytes(&sec_key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(ErrorKind::ED25519Key(format!("{}", e)).into());
|
||||
return Err(Error::ED25519Key(format!("{}", e)));
|
||||
}
|
||||
};
|
||||
let my_address_pubkey: DalekPublicKey = (&d_skey).into();
|
||||
@@ -1319,7 +1314,7 @@ where
|
||||
match updater::refresh_outputs(&mut **w, keychain_mask, &parent_key_id, update_all) {
|
||||
Ok(_) => Ok(true),
|
||||
Err(e) => {
|
||||
if let ErrorKind::InvalidKeychainMask = e.kind() {
|
||||
if let Error::InvalidKeychainMask = e {
|
||||
return Err(e);
|
||||
}
|
||||
Ok(false)
|
||||
|
||||
+89
-223
@@ -17,28 +17,14 @@
|
||||
use crate::grin_core::core::{committed, transaction};
|
||||
use crate::grin_core::libtx;
|
||||
use crate::grin_keychain;
|
||||
use crate::grin_store;
|
||||
use crate::grin_util::secp;
|
||||
use crate::util;
|
||||
use failure::{Backtrace, Context, Fail};
|
||||
use std::env;
|
||||
use std::fmt::{self, Display};
|
||||
use std::io;
|
||||
|
||||
/// Error definition
|
||||
#[derive(Debug, Fail)]
|
||||
pub struct Error {
|
||||
inner: Context<ErrorKind>,
|
||||
}
|
||||
use crate::util::{self, grin_store};
|
||||
|
||||
/// Wallet errors, mostly wrappers around underlying crypto or I/O errors.
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Fail, Serialize, Deserialize)]
|
||||
pub enum ErrorKind {
|
||||
#[derive(Clone, Eq, PartialEq, Debug, thiserror::Error, Serialize, Deserialize)]
|
||||
pub enum Error {
|
||||
/// Not enough funds
|
||||
#[fail(
|
||||
display = "Not enough funds. Required: {}, Available: {}",
|
||||
needed_disp, available_disp
|
||||
)]
|
||||
#[error("Not enough funds. Required: {needed_disp:?}, Available: {available_disp:?}")]
|
||||
NotEnoughFunds {
|
||||
/// available funds
|
||||
available: u64,
|
||||
@@ -51,426 +37,306 @@ pub enum ErrorKind {
|
||||
},
|
||||
|
||||
/// Fee error
|
||||
#[fail(display = "Fee Error: {}", _0)]
|
||||
#[error("Fee Error: {0}")]
|
||||
Fee(String),
|
||||
|
||||
/// LibTX Error
|
||||
#[fail(display = "LibTx Error")]
|
||||
LibTX(libtx::ErrorKind),
|
||||
#[error("LibTx Error")]
|
||||
LibTX(#[from] libtx::Error),
|
||||
|
||||
/// Keychain error
|
||||
#[fail(display = "Keychain error")]
|
||||
Keychain(grin_keychain::Error),
|
||||
#[error("Keychain error")]
|
||||
Keychain(#[from] grin_keychain::Error),
|
||||
|
||||
/// Transaction Error
|
||||
#[fail(display = "Transaction error")]
|
||||
Transaction(transaction::Error),
|
||||
#[error("Transaction error")]
|
||||
Transaction(#[from] transaction::Error),
|
||||
|
||||
/// API Error
|
||||
#[fail(display = "Client Callback Error: {}", _0)]
|
||||
#[error("Client Callback Error: {0}")]
|
||||
ClientCallback(String),
|
||||
|
||||
/// Secp Error
|
||||
#[fail(display = "Secp error")]
|
||||
Secp(secp::Error),
|
||||
/// Error from underlying secp lib
|
||||
#[error("Secp Lib Error")]
|
||||
Secp(#[from] secp::Error),
|
||||
|
||||
/// Onion V3 Address Error
|
||||
#[fail(display = "Onion V3 Address Error")]
|
||||
OnionV3Address(util::OnionV3AddressError),
|
||||
#[error("Onion V3 Address Error: {0}")]
|
||||
OnionV3Address(#[from] util::OnionV3AddressError),
|
||||
|
||||
/// Callback implementation error conversion
|
||||
#[fail(display = "Trait Implementation error")]
|
||||
#[error("Trait Implementation error")]
|
||||
CallbackImpl(&'static str),
|
||||
|
||||
/// Wallet backend error
|
||||
#[fail(display = "Wallet store error: {}", _0)]
|
||||
#[error("Wallet store error: {0}")]
|
||||
Backend(String),
|
||||
|
||||
/// Callback implementation error conversion
|
||||
#[fail(display = "Restore Error")]
|
||||
#[error("Restore Error")]
|
||||
Restore,
|
||||
|
||||
/// An error in the format of the JSON structures exchanged by the wallet
|
||||
#[fail(display = "JSON format error: {}", _0)]
|
||||
#[error("JSON format error: {0}")]
|
||||
Format(String),
|
||||
|
||||
/// Other serialization errors
|
||||
#[fail(display = "Ser/Deserialization error")]
|
||||
#[error("Ser/Deserialization error")]
|
||||
Deser(crate::grin_core::ser::Error),
|
||||
|
||||
/// IO Error
|
||||
#[fail(display = "I/O error")]
|
||||
IO,
|
||||
#[error("I/O error {0}")]
|
||||
IO(String),
|
||||
|
||||
/// Error when contacting a node through its API
|
||||
#[fail(display = "Node API error")]
|
||||
#[error("Node API error")]
|
||||
Node,
|
||||
|
||||
/// Error contacting wallet API
|
||||
#[fail(display = "Wallet Communication Error: {}", _0)]
|
||||
#[error("Wallet Communication Error: {0}")]
|
||||
WalletComms(String),
|
||||
|
||||
/// Error originating from hyper.
|
||||
#[fail(display = "Hyper error")]
|
||||
#[error("Hyper error")]
|
||||
Hyper,
|
||||
|
||||
/// Error originating from hyper uri parsing.
|
||||
#[fail(display = "Uri parsing error")]
|
||||
#[error("Uri parsing error")]
|
||||
Uri,
|
||||
|
||||
/// Signature error
|
||||
#[fail(display = "Signature error: {}", _0)]
|
||||
#[error("Signature error: {0}")]
|
||||
Signature(String),
|
||||
|
||||
/// OwnerAPIEncryption
|
||||
#[fail(display = "{}", _0)]
|
||||
#[error("{}", _0)]
|
||||
APIEncryption(String),
|
||||
|
||||
/// Attempt to use duplicate transaction id in separate transactions
|
||||
#[fail(display = "Duplicate transaction ID error")]
|
||||
#[error("Duplicate transaction ID error")]
|
||||
DuplicateTransactionId,
|
||||
|
||||
/// Wallet seed already exists
|
||||
#[fail(display = "Wallet seed exists error: {}", _0)]
|
||||
#[error("Wallet seed exists error: {0}")]
|
||||
WalletSeedExists(String),
|
||||
|
||||
/// Wallet seed doesn't exist
|
||||
#[fail(display = "Wallet seed doesn't exist error")]
|
||||
#[error("Wallet seed doesn't exist error")]
|
||||
WalletSeedDoesntExist,
|
||||
|
||||
/// Wallet seed doesn't exist
|
||||
#[fail(display = "Wallet seed decryption error")]
|
||||
#[error("Wallet seed decryption error")]
|
||||
WalletSeedDecryption,
|
||||
|
||||
/// Transaction doesn't exist
|
||||
#[fail(display = "Transaction {} doesn't exist", _0)]
|
||||
#[error("Transaction {0} doesn't exist")]
|
||||
TransactionDoesntExist(String),
|
||||
|
||||
/// Transaction already rolled back
|
||||
#[fail(display = "Transaction {} cannot be cancelled", _0)]
|
||||
#[error("Transaction {0} cannot be cancelled")]
|
||||
TransactionNotCancellable(String),
|
||||
|
||||
/// Cancellation error
|
||||
#[fail(display = "Cancellation Error: {}", _0)]
|
||||
#[error("Cancellation Error: {0}")]
|
||||
TransactionCancellationError(&'static str),
|
||||
|
||||
/// Cancellation error
|
||||
#[fail(display = "Tx dump Error: {}", _0)]
|
||||
#[error("Tx dump Error: {0}")]
|
||||
TransactionDumpError(&'static str),
|
||||
|
||||
/// Attempt to repost a transaction that's already confirmed
|
||||
#[fail(display = "Transaction already confirmed error")]
|
||||
#[error("Transaction already confirmed error")]
|
||||
TransactionAlreadyConfirmed,
|
||||
|
||||
/// Transaction has already been received
|
||||
#[fail(display = "Transaction {} has already been received", _0)]
|
||||
#[error("Transaction {0} has already been received")]
|
||||
TransactionAlreadyReceived(String),
|
||||
|
||||
/// Attempt to repost a transaction that's not completed and stored
|
||||
#[fail(display = "Transaction building not completed: {}", _0)]
|
||||
#[error("Transaction building not completed: {0}")]
|
||||
TransactionBuildingNotCompleted(u32),
|
||||
|
||||
/// Invalid BIP-32 Depth
|
||||
#[fail(display = "Invalid BIP32 Depth (must be 1 or greater)")]
|
||||
#[error("Invalid BIP32 Depth (must be 1 or greater)")]
|
||||
InvalidBIP32Depth,
|
||||
|
||||
/// Attempt to add an account that exists
|
||||
#[fail(display = "Account Label '{}' already exists", _0)]
|
||||
#[error("Account Label '{0}' already exists")]
|
||||
AccountLabelAlreadyExists(String),
|
||||
|
||||
/// Reference unknown account label
|
||||
#[fail(display = "Unknown Account Label '{}'", _0)]
|
||||
#[error("Unknown Account Label '{0}'")]
|
||||
UnknownAccountLabel(String),
|
||||
|
||||
/// Error from summing commitments via committed trait.
|
||||
#[fail(display = "Committed Error")]
|
||||
#[error("Committed Error")]
|
||||
Committed(committed::Error),
|
||||
|
||||
/// Error from summing commitments
|
||||
#[fail(display = "Committed Error: {}", _0)]
|
||||
#[error("Committed Error: {0}")]
|
||||
Commit(String),
|
||||
|
||||
/// Can't parse slate version
|
||||
#[fail(display = "Can't parse slate version")]
|
||||
#[error("Can't parse slate version")]
|
||||
SlateVersionParse,
|
||||
|
||||
/// Can't serialize slate
|
||||
#[fail(display = "Can't Serialize slate")]
|
||||
#[error("Can't Serialize slate")]
|
||||
SlateSer,
|
||||
|
||||
/// Can't deserialize slate
|
||||
#[fail(display = "Can't Deserialize slate")]
|
||||
#[error("Can't Deserialize slate")]
|
||||
SlateDeser,
|
||||
|
||||
/// Can't serialize slate pack
|
||||
#[fail(display = "Can't Serialize slatepack")]
|
||||
#[error("Can't Serialize slatepack")]
|
||||
SlatepackSer,
|
||||
|
||||
/// Can't deserialize slate
|
||||
#[fail(display = "Can't Deserialize slatepack: {}", _0)]
|
||||
#[error("Can't Deserialize slatepack: {0}")]
|
||||
SlatepackDeser(String),
|
||||
|
||||
/// Unknown slate version
|
||||
#[fail(display = "Unknown Slate Version: {}", _0)]
|
||||
#[error("Unknown Slate Version: {0}")]
|
||||
SlateVersion(u16),
|
||||
|
||||
/// Attempt to use slate transaction data that doesn't exists
|
||||
#[fail(display = "Slate transaction required in this context")]
|
||||
#[error("Slate transaction required in this context")]
|
||||
SlateTransactionRequired,
|
||||
|
||||
/// Attempt to downgrade slate that can't be downgraded
|
||||
#[fail(display = "Can't downgrade slate: {}", _0)]
|
||||
#[error("Can't downgrade slate: {0}")]
|
||||
SlateInvalidDowngrade(String),
|
||||
|
||||
/// Compatibility error between incoming slate versions and what's expected
|
||||
#[fail(display = "Compatibility Error: {}", _0)]
|
||||
#[error("Compatibility Error: {0}")]
|
||||
Compatibility(String),
|
||||
|
||||
/// Keychain doesn't exist (wallet not openend)
|
||||
#[fail(display = "Keychain doesn't exist (has wallet been opened?)")]
|
||||
#[error("Keychain doesn't exist (has wallet been opened?)")]
|
||||
KeychainDoesntExist,
|
||||
|
||||
/// Lifecycle Error
|
||||
#[fail(display = "Lifecycle Error: {}", _0)]
|
||||
#[error("Lifecycle Error: {0}")]
|
||||
Lifecycle(String),
|
||||
|
||||
/// Invalid Keychain Mask Error
|
||||
#[fail(display = "Supplied Keychain Mask Token is incorrect")]
|
||||
#[error("Supplied Keychain Mask Token is incorrect")]
|
||||
InvalidKeychainMask,
|
||||
|
||||
/// Tor Process error
|
||||
#[fail(display = "Tor Process Error: {}", _0)]
|
||||
#[error("Tor Process Error: {0}")]
|
||||
TorProcess(String),
|
||||
|
||||
/// Tor Configuration Error
|
||||
#[fail(display = "Tor Config Error: {}", _0)]
|
||||
#[error("Tor Config Error: {0}")]
|
||||
TorConfig(String),
|
||||
|
||||
/// Generating ED25519 Public Key
|
||||
#[fail(display = "Error generating ed25519 secret key: {}", _0)]
|
||||
#[error("Error generating ed25519 secret key: {0}")]
|
||||
ED25519Key(String),
|
||||
|
||||
/// Generating Payment Proof
|
||||
#[fail(display = "Payment Proof generation error: {}", _0)]
|
||||
#[error("Payment Proof generation error: {0}")]
|
||||
PaymentProof(String),
|
||||
|
||||
/// Retrieving Payment Proof
|
||||
#[fail(display = "Payment Proof retrieval error: {}", _0)]
|
||||
#[error("Payment Proof retrieval error: {0}")]
|
||||
PaymentProofRetrieval(String),
|
||||
|
||||
/// Retrieving Payment Proof
|
||||
#[fail(display = "Payment Proof parsing error: {}", _0)]
|
||||
#[error("Payment Proof parsing error: {0}")]
|
||||
PaymentProofParsing(String),
|
||||
|
||||
/// Decoding OnionV3 addresses to payment proof addresses
|
||||
#[fail(display = "Proof Address decoding: {}", _0)]
|
||||
#[error("Proof Address decoding: {0}")]
|
||||
AddressDecoding(String),
|
||||
|
||||
/// Transaction has expired it's TTL
|
||||
#[fail(display = "Transaction Expired")]
|
||||
#[error("Transaction Expired")]
|
||||
TransactionExpired,
|
||||
|
||||
/// Kernel features args don't exist
|
||||
#[fail(display = "Kernel Features Arg {} missing", _0)]
|
||||
#[error("Kernel Features Arg {0} missing")]
|
||||
KernelFeaturesMissing(String),
|
||||
|
||||
/// Unknown Kernel Feature
|
||||
#[fail(display = "Unknown Kernel Feature: {}", _0)]
|
||||
#[error("Unknown Kernel Feature: {0}")]
|
||||
UnknownKernelFeatures(u8),
|
||||
|
||||
/// Invalid Kernel Feature
|
||||
#[fail(display = "Invalid Kernel Feature: {}", _0)]
|
||||
#[error("Invalid Kernel Feature: {0}")]
|
||||
InvalidKernelFeatures(u8),
|
||||
|
||||
/// Invalid Slatepack Data
|
||||
#[fail(display = "Invalid Slatepack Data: {}", _0)]
|
||||
#[error("Invalid Slatepack Data: {0}")]
|
||||
InvalidSlatepackData(String),
|
||||
|
||||
/// Slatepack Encryption
|
||||
#[fail(display = "Couldn't encrypt Slatepack: {}", _0)]
|
||||
#[error("Couldn't encrypt Slatepack: {0}")]
|
||||
SlatepackEncryption(String),
|
||||
|
||||
/// Slatepack Decryption
|
||||
#[fail(display = "Couldn't decrypt Slatepack: {}", _0)]
|
||||
#[error("Couldn't decrypt Slatepack: {0}")]
|
||||
SlatepackDecryption(String),
|
||||
|
||||
/// age error
|
||||
#[fail(display = "Age error: {}", _0)]
|
||||
#[error("Age error: {0}")]
|
||||
Age(String),
|
||||
|
||||
/// Rewind Hash parsing error
|
||||
#[fail(display = "Rewind Hash error: {}", _0)]
|
||||
#[error("Rewind Hash error: {0}")]
|
||||
RewindHash(String),
|
||||
|
||||
/// Nonce creation error
|
||||
#[fail(display = "Nonce error: {}", _0)]
|
||||
#[error("Nonce error: {0}")]
|
||||
Nonce(String),
|
||||
|
||||
/// Slatepack address parsing error
|
||||
#[fail(display = "SlatepackAddress error: {}", _0)]
|
||||
#[error("SlatepackAddress error: {0}")]
|
||||
SlatepackAddress(String),
|
||||
|
||||
/// Retrieving Stored Tx
|
||||
#[fail(display = "Stored Tx error: {}", _0)]
|
||||
#[error("Stored Tx error: {0}")]
|
||||
StoredTx(String),
|
||||
|
||||
/// Other
|
||||
#[fail(display = "Generic error: {}", _0)]
|
||||
#[error("Generic error: {0}")]
|
||||
GenericError(String),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let show_bt = match env::var("RUST_BACKTRACE") {
|
||||
Ok(r) => r == "1",
|
||||
Err(_) => false,
|
||||
};
|
||||
let backtrace = match self.backtrace() {
|
||||
Some(b) => format!("{}", b),
|
||||
None => String::from("Unknown"),
|
||||
};
|
||||
let inner_output = format!("{}", self.inner,);
|
||||
let backtrace_output = format!("\n Backtrace: {}", backtrace);
|
||||
let mut output = inner_output;
|
||||
if show_bt {
|
||||
output.push_str(&backtrace_output);
|
||||
}
|
||||
Display::fmt(&output, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error {
|
||||
/// get kind
|
||||
pub fn kind(&self) -> ErrorKind {
|
||||
self.inner.get_context().clone()
|
||||
}
|
||||
/// get cause string
|
||||
pub fn cause_string(&self) -> String {
|
||||
match self.cause() {
|
||||
Some(k) => format!("{}", k),
|
||||
None => "Unknown".to_string(),
|
||||
}
|
||||
}
|
||||
/// get cause
|
||||
pub fn cause(&self) -> Option<&dyn Fail> {
|
||||
self.inner.cause()
|
||||
}
|
||||
/// get backtrace
|
||||
pub fn backtrace(&self) -> Option<&Backtrace> {
|
||||
self.inner.backtrace()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ErrorKind> for Error {
|
||||
fn from(kind: ErrorKind) -> Error {
|
||||
Error {
|
||||
inner: Context::new(kind),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(inner: Context<ErrorKind>) -> Error {
|
||||
Error { inner: inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(_error: io::Error) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::IO),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<grin_keychain::Error> for Error {
|
||||
fn from(error: grin_keychain::Error) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::Keychain(error)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<libtx::Error> for Error {
|
||||
fn from(error: crate::grin_core::libtx::Error) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::LibTX(error.kind())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<transaction::Error> for Error {
|
||||
fn from(error: transaction::Error) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::Transaction(error)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::grin_core::ser::Error> for Error {
|
||||
fn from(error: crate::grin_core::ser::Error) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::Deser(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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<grin_store::Error> for Error {
|
||||
fn from(error: grin_store::Error) -> Error {
|
||||
Error::from(ErrorKind::Backend(format!("{}", error)))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<util::OnionV3AddressError> for Error {
|
||||
fn from(error: util::OnionV3AddressError) -> Error {
|
||||
Error::from(ErrorKind::OnionV3Address(error))
|
||||
Error::Backend(format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<age::EncryptError> for Error {
|
||||
fn from(error: age::EncryptError) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::Age(format!("{}", error))),
|
||||
}
|
||||
Error::Age(format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<age::DecryptError> for Error {
|
||||
fn from(error: age::DecryptError) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::Age(format!("{}", error))),
|
||||
}
|
||||
Error::Age(format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(e: std::io::Error) -> Error {
|
||||
Error::IO(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Error {
|
||||
fn from(error: &str) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::Age(format!("Bech32 Key Encoding - {}", error))),
|
||||
}
|
||||
Error::Age(format!("Bech32 Key Encoding - {}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bech32::Error> for Error {
|
||||
fn from(error: bech32::Error) -> Error {
|
||||
Error {
|
||||
inner: Context::new(ErrorKind::SlatepackAddress(format!("{}", error))),
|
||||
}
|
||||
Error::SlatepackAddress(format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
//! Wallet key management functions
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::Error;
|
||||
use crate::grin_keychain::{ChildNumber, ExtKeychain, Identifier, Keychain};
|
||||
use crate::grin_util::secp::key::SecretKey;
|
||||
use crate::types::{AcctPathMapping, NodeClient, WalletBackend};
|
||||
@@ -72,7 +72,7 @@ where
|
||||
{
|
||||
let label = label.to_owned();
|
||||
if wallet.acct_path_iter().any(|l| l.label == label) {
|
||||
return Err(ErrorKind::AccountLabelAlreadyExists(label).into());
|
||||
return Err(Error::AccountLabelAlreadyExists(label));
|
||||
}
|
||||
|
||||
// We're always using paths at m/k/0 for parent keys for output derivations
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::grin_util::secp::{ContextFlag, Secp256k1};
|
||||
use crate::grin_util::Mutex;
|
||||
use crate::grin_util::{from_hex, ToHex};
|
||||
use crate::internal::{keys, updater};
|
||||
use crate::{types::*, ErrorKind};
|
||||
use crate::types::*;
|
||||
use crate::{wallet_lock, Error, OutputCommitMapping};
|
||||
use blake2_rfc::blake2b::blake2b;
|
||||
use std::cmp;
|
||||
@@ -187,12 +187,11 @@ where
|
||||
// Scanning outputs
|
||||
for output in outputs.iter() {
|
||||
let (commit, proof, is_coinbase, height, mmr_index) = output;
|
||||
let rewind_hash = from_hex(vw.rewind_hash.as_str()).map_err(|e| {
|
||||
ErrorKind::RewindHash(format!("Unable to decode rewind hash: {}", e))
|
||||
})?;
|
||||
let rewind_hash = from_hex(vw.rewind_hash.as_str())
|
||||
.map_err(|e| Error::RewindHash(format!("Unable to decode rewind hash: {}", e)))?;
|
||||
let rewind_nonce = blake2b(32, &commit.0, &rewind_hash);
|
||||
let nonce = SecretKey::from_slice(&secp, rewind_nonce.as_bytes())
|
||||
.map_err(|e| ErrorKind::Nonce(format!("Unable to create nonce: {}", e)))?;
|
||||
.map_err(|e| Error::Nonce(format!("Unable to create nonce: {}", e)))?;
|
||||
let info = secp.rewind_bullet_proof(*commit, nonce.clone(), None, *proof);
|
||||
|
||||
if info.is_err() {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//! Selection of inputs for building transactions
|
||||
|
||||
use crate::address;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::Error;
|
||||
use crate::grin_core::core::amount_to_hr_string;
|
||||
use crate::grin_core::libtx::{
|
||||
build,
|
||||
@@ -72,16 +72,15 @@ where
|
||||
false,
|
||||
)?;
|
||||
if amount_includes_fee {
|
||||
slate.amount = slate
|
||||
.amount
|
||||
.checked_sub(fee)
|
||||
.ok_or(ErrorKind::GenericError(
|
||||
format!("Transaction amount is too small to include fee").into(),
|
||||
))?;
|
||||
slate.amount = slate.amount.checked_sub(fee).ok_or(Error::GenericError(
|
||||
format!("Transaction amount is too small to include fee").into(),
|
||||
))?;
|
||||
};
|
||||
|
||||
if fixed_fee.map(|f| fee != f).unwrap_or(false) {
|
||||
return Err(ErrorKind::Fee("The initially selected fee is not sufficient".into()).into());
|
||||
return Err(Error::Fee(
|
||||
"The initially selected fee is not sufficient".into(),
|
||||
));
|
||||
}
|
||||
|
||||
// Update the fee on the slate so we account for this when building the tx.
|
||||
@@ -192,7 +191,7 @@ where
|
||||
let sender_address_path = match context.payment_proof_derivation_index {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Payment proof derivation index required".to_owned(),
|
||||
)
|
||||
.into());
|
||||
@@ -420,24 +419,22 @@ where
|
||||
};
|
||||
|
||||
if total == 0 {
|
||||
return Err(ErrorKind::NotEnoughFunds {
|
||||
return Err(Error::NotEnoughFunds {
|
||||
available: 0,
|
||||
available_disp: amount_to_hr_string(0, false),
|
||||
needed: amount_with_fee as u64,
|
||||
needed_disp: amount_to_hr_string(amount_with_fee as u64, false),
|
||||
}
|
||||
.into());
|
||||
});
|
||||
}
|
||||
|
||||
// The amount with fee is more than the total values of our max outputs
|
||||
if total < amount_with_fee && coins.len() == max_outputs {
|
||||
return Err(ErrorKind::NotEnoughFunds {
|
||||
return Err(Error::NotEnoughFunds {
|
||||
available: total,
|
||||
available_disp: amount_to_hr_string(total, false),
|
||||
needed: amount_with_fee as u64,
|
||||
needed_disp: amount_to_hr_string(amount_with_fee as u64, false),
|
||||
}
|
||||
.into());
|
||||
});
|
||||
}
|
||||
|
||||
let num_outputs = change_outputs + 1;
|
||||
@@ -455,13 +452,12 @@ where
|
||||
while total < amount_with_fee {
|
||||
// End the loop if we have selected all the outputs and still not enough funds
|
||||
if coins.len() == max_outputs {
|
||||
return Err(ErrorKind::NotEnoughFunds {
|
||||
return Err(Error::NotEnoughFunds {
|
||||
available: total as u64,
|
||||
available_disp: amount_to_hr_string(total, false),
|
||||
needed: amount_with_fee as u64,
|
||||
needed_disp: amount_to_hr_string(amount_with_fee as u64, false),
|
||||
}
|
||||
.into());
|
||||
});
|
||||
}
|
||||
|
||||
// select some spendable coins from the wallet
|
||||
@@ -486,7 +482,7 @@ where
|
||||
// If original amount includes fee, the new amount should
|
||||
// be reduced, to accommodate the fee.
|
||||
let new_amount = match amount_includes_fee {
|
||||
true => amount.checked_sub(fee).ok_or(ErrorKind::GenericError(
|
||||
true => amount.checked_sub(fee).ok_or(Error::GenericError(
|
||||
format!("Transaction amount is too small to include fee").into(),
|
||||
))?,
|
||||
false => amount,
|
||||
@@ -688,7 +684,7 @@ where
|
||||
if update_fee {
|
||||
slate.fee_fields = context
|
||||
.fee
|
||||
.ok_or_else(|| ErrorKind::Fee("Missing fee fields".into()))?;
|
||||
.ok_or_else(|| Error::Fee("Missing fee fields".into()))?;
|
||||
}
|
||||
|
||||
let keychain = wallet.keychain(keychain_mask)?;
|
||||
|
||||
@@ -29,7 +29,7 @@ use crate::slate::Slate;
|
||||
use crate::types::{Context, NodeClient, StoredProofInfo, TxLogEntryType, WalletBackend};
|
||||
use crate::util::OnionV3Address;
|
||||
use crate::InitTxArgs;
|
||||
use crate::{address, Error, ErrorKind};
|
||||
use crate::{address, Error};
|
||||
use ed25519_dalek::Keypair as DalekKeypair;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::SecretKey as DalekSecretKey;
|
||||
@@ -353,15 +353,15 @@ where
|
||||
}
|
||||
let tx_vec = updater::retrieve_txs(wallet, tx_id, tx_slate_id, Some(&parent_key_id), false)?;
|
||||
if tx_vec.len() != 1 {
|
||||
return Err(ErrorKind::TransactionDoesntExist(tx_id_string).into());
|
||||
return Err(Error::TransactionDoesntExist(tx_id_string));
|
||||
}
|
||||
let tx = tx_vec[0].clone();
|
||||
match tx.tx_type {
|
||||
TxLogEntryType::TxSent | TxLogEntryType::TxReceived | TxLogEntryType::TxReverted => {}
|
||||
_ => return Err(ErrorKind::TransactionNotCancellable(tx_id_string).into()),
|
||||
_ => return Err(Error::TransactionNotCancellable(tx_id_string)),
|
||||
}
|
||||
if tx.confirmed {
|
||||
return Err(ErrorKind::TransactionNotCancellable(tx_id_string).into());
|
||||
return Err(Error::TransactionNotCancellable(tx_id_string));
|
||||
}
|
||||
// get outputs associated with tx
|
||||
let res = updater::retrieve_outputs(
|
||||
@@ -405,7 +405,7 @@ where
|
||||
}
|
||||
let mut tx = match tx {
|
||||
Some(t) => t,
|
||||
None => return Err(ErrorKind::TransactionDoesntExist(slate.id.to_string()).into()),
|
||||
None => return Err(Error::TransactionDoesntExist(slate.id.to_string())),
|
||||
};
|
||||
let parent_key = tx.parent_key_id.clone();
|
||||
{
|
||||
@@ -487,7 +487,7 @@ pub fn create_payment_proof_signature(
|
||||
let d_skey = match DalekSecretKey::from_bytes(&sec_key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(ErrorKind::ED25519Key(format!("{}", e)).into());
|
||||
return Err(Error::ED25519Key(format!("{}", e)));
|
||||
}
|
||||
};
|
||||
let pub_key: DalekPublicKey = (&d_skey).into();
|
||||
@@ -513,56 +513,50 @@ where
|
||||
{
|
||||
let tx_vec = updater::retrieve_txs(wallet, None, Some(slate.id), Some(parent_key_id), false)?;
|
||||
if tx_vec.is_empty() {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"TxLogEntry with original proof info not found (is account correct?)".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
|
||||
let orig_proof_info = tx_vec[0].clone().payment_proof;
|
||||
|
||||
if orig_proof_info.is_some() && slate.payment_proof.is_none() {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Expected Payment Proof for this Transaction is not present".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(ref p) = slate.clone().payment_proof {
|
||||
let orig_proof_info = match orig_proof_info {
|
||||
Some(p) => p.clone(),
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Original proof info not stored in tx".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
};
|
||||
let keychain = wallet.keychain(keychain_mask)?;
|
||||
let index = match context.payment_proof_derivation_index {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Payment proof derivation index required".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
};
|
||||
let orig_sender_sk =
|
||||
address::address_from_derivation_path(&keychain, parent_key_id, index)?;
|
||||
let orig_sender_address = OnionV3Address::from_private(&orig_sender_sk.0)?;
|
||||
if p.sender_address != orig_sender_address.to_ed25519()? {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Sender address on slate does not match original sender address".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
|
||||
if orig_proof_info.receiver_address != p.receiver_address {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Recipient address on slate does not match original recipient address".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
let msg = payment_proof_message(
|
||||
slate.amount,
|
||||
@@ -572,15 +566,14 @@ where
|
||||
let sig = match p.receiver_signature {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
return Err(ErrorKind::PaymentProof(
|
||||
return Err(Error::PaymentProof(
|
||||
"Recipient did not provide requested proof signature".to_owned(),
|
||||
)
|
||||
.into());
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
if p.receiver_address.verify(&msg, &sig).is_err() {
|
||||
return Err(ErrorKind::PaymentProof("Invalid proof signature".to_owned()).into());
|
||||
return Err(Error::PaymentProof("Invalid proof signature".to_owned()));
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -25,16 +25,12 @@
|
||||
use grin_wallet_config as config;
|
||||
use grin_wallet_util::grin_core;
|
||||
use grin_wallet_util::grin_keychain;
|
||||
use grin_wallet_util::grin_store;
|
||||
use grin_wallet_util::grin_util;
|
||||
|
||||
use grin_wallet_util as util;
|
||||
|
||||
use blake2_rfc as blake2;
|
||||
|
||||
use failure;
|
||||
extern crate failure_derive;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
#[macro_use]
|
||||
@@ -55,7 +51,7 @@ pub mod slate_versions;
|
||||
pub mod slatepack;
|
||||
mod types;
|
||||
|
||||
pub use crate::error::{Error, ErrorKind};
|
||||
pub use crate::error::Error;
|
||||
pub use crate::slate::{ParticipantData, Slate, SlateState};
|
||||
pub use crate::slate_versions::v4::sig_is_blank;
|
||||
pub use crate::slate_versions::{
|
||||
|
||||
+20
-22
@@ -15,7 +15,7 @@
|
||||
//! Functions for building partial transactions to be passed
|
||||
//! around during an interactive wallet exchange
|
||||
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::Error;
|
||||
use crate::grin_core::core::amount_to_hr_string;
|
||||
use crate::grin_core::core::transaction::{
|
||||
FeeFields, Input, Inputs, KernelFeatures, NRDRelativeHeight, Output, OutputFeatures,
|
||||
@@ -196,7 +196,7 @@ impl Slate {
|
||||
pub fn tx_or_err(&self) -> Result<&Transaction, Error> {
|
||||
match &self.tx {
|
||||
Some(t) => Ok(t),
|
||||
None => Err(ErrorKind::SlateTransactionRequired.into()),
|
||||
None => Err(Error::SlateTransactionRequired),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ impl Slate {
|
||||
pub fn tx_or_err_mut(&mut self) -> Result<&mut Transaction, Error> {
|
||||
match &mut self.tx {
|
||||
Some(t) => Ok(t),
|
||||
None => Err(ErrorKind::SlateTransactionRequired.into()),
|
||||
None => Err(Error::SlateTransactionRequired),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ impl Slate {
|
||||
/// Throw error if this can't be done
|
||||
pub fn deserialize_upgrade(slate_json: &str) -> Result<Slate, Error> {
|
||||
let v_slate: VersionedSlate =
|
||||
serde_json::from_str(slate_json).map_err(|_| ErrorKind::SlateVersionParse)?;
|
||||
serde_json::from_str(slate_json).map_err(|_| Error::SlateVersionParse)?;
|
||||
Slate::upgrade(v_slate)
|
||||
}
|
||||
|
||||
@@ -352,26 +352,22 @@ impl Slate {
|
||||
0 => Ok(KernelFeatures::Plain {
|
||||
fee: self.fee_fields,
|
||||
}),
|
||||
1 => Err(ErrorKind::InvalidKernelFeatures(1).into()),
|
||||
1 => Err(Error::InvalidKernelFeatures(1)),
|
||||
2 => Ok(KernelFeatures::HeightLocked {
|
||||
fee: self.fee_fields,
|
||||
lock_height: match &self.kernel_features_args {
|
||||
Some(a) => a.lock_height,
|
||||
None => {
|
||||
return Err(ErrorKind::KernelFeaturesMissing(format!("lock_height")).into())
|
||||
}
|
||||
None => return Err(Error::KernelFeaturesMissing(format!("lock_height"))),
|
||||
},
|
||||
}),
|
||||
3 => Ok(KernelFeatures::NoRecentDuplicate {
|
||||
fee: self.fee_fields,
|
||||
relative_height: match &self.kernel_features_args {
|
||||
Some(a) => NRDRelativeHeight::new(a.lock_height)?,
|
||||
None => {
|
||||
return Err(ErrorKind::KernelFeaturesMissing(format!("lock_height")).into())
|
||||
}
|
||||
None => return Err(Error::KernelFeaturesMissing(format!("lock_height"))),
|
||||
},
|
||||
}),
|
||||
n => Err(ErrorKind::UnknownKernelFeatures(n).into()),
|
||||
n => Err(Error::UnknownKernelFeatures(n)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,11 +432,11 @@ impl Slate {
|
||||
.map(|p| &p.public_nonce)
|
||||
.collect();
|
||||
if pub_nonces.len() == 0 {
|
||||
return Err(ErrorKind::Commit(format!("Participant nonces cannot be empty")).into());
|
||||
return Err(Error::Commit(format!("Participant nonces cannot be empty")));
|
||||
}
|
||||
match PublicKey::from_combination(secp, pub_nonces) {
|
||||
Ok(k) => Ok(k),
|
||||
Err(e) => Err(ErrorKind::Secp(e).into()),
|
||||
Err(e) => Err(Error::Secp(e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,13 +448,13 @@ impl Slate {
|
||||
.map(|p| &p.public_blind_excess)
|
||||
.collect();
|
||||
if pub_blinds.len() == 0 {
|
||||
return Err(
|
||||
ErrorKind::Commit(format!("Participant Blind sums cannot be empty")).into(),
|
||||
);
|
||||
return Err(Error::Commit(format!(
|
||||
"Participant Blind sums cannot be empty"
|
||||
)));
|
||||
}
|
||||
match PublicKey::from_combination(secp, pub_blinds) {
|
||||
Ok(k) => Ok(k),
|
||||
Err(e) => Err(ErrorKind::Secp(e).into()),
|
||||
Err(e) => Err(Error::Secp(e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,9 +549,11 @@ impl Slate {
|
||||
|
||||
if fee > tx.fee() {
|
||||
// apply fee mask past HF4
|
||||
return Err(
|
||||
ErrorKind::Fee(format!("Fee Dispute Error: {}, {}", tx.fee(), fee,)).into(),
|
||||
);
|
||||
return Err(Error::Fee(format!(
|
||||
"Fee Dispute Error: {}, {}",
|
||||
tx.fee(),
|
||||
fee,
|
||||
)));
|
||||
}
|
||||
|
||||
if fee > self.amount + self.fee_fields.fee() {
|
||||
@@ -565,7 +563,7 @@ impl Slate {
|
||||
amount_to_hr_string(self.amount + self.fee_fields.fee(), false)
|
||||
);
|
||||
info!("{}", reason);
|
||||
return Err(ErrorKind::Fee(reason).into());
|
||||
return Err(Error::Fee(reason));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::grin_core::global;
|
||||
use crate::grin_core::ser::{self, Readable, Reader, Writeable, Writer};
|
||||
use crate::grin_util::secp::key::SecretKey;
|
||||
use crate::util::OnionV3Address;
|
||||
use crate::{Error, ErrorKind};
|
||||
use crate::Error;
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::{self, Display};
|
||||
@@ -91,7 +91,7 @@ impl TryFrom<&str> for SlatepackAddress {
|
||||
let pub_key = match edDalekPublicKey::from_bytes(&bytes) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(ErrorKind::ED25519Key(format!("{}", e)).into());
|
||||
return Err(Error::ED25519Key(format!("{}", e)));
|
||||
}
|
||||
};
|
||||
Ok(SlatepackAddress { hrp, pub_key })
|
||||
@@ -127,9 +127,9 @@ impl TryFrom<&SlatepackAddress> for xDalekPublicKey {
|
||||
let ep = match cep.decompress() {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(
|
||||
ErrorKind::ED25519Key("Can't decompress ed25519 Edwards Point".into()).into(),
|
||||
);
|
||||
return Err(Error::ED25519Key(
|
||||
"Can't decompress ed25519 Edwards Point".into(),
|
||||
));
|
||||
}
|
||||
};
|
||||
let res = xDalekPublicKey::from(ep.to_montgomery().to_bytes());
|
||||
@@ -143,11 +143,10 @@ impl TryFrom<&SecretKey> for SlatepackAddress {
|
||||
let d_skey = match edDalekSecretKey::from_bytes(&key.0) {
|
||||
Ok(k) => k,
|
||||
Err(e) => {
|
||||
return Err(ErrorKind::ED25519Key(format!(
|
||||
return Err(Error::ED25519Key(format!(
|
||||
"Can't create slatepack address from SecretKey: {}",
|
||||
e
|
||||
))
|
||||
.into());
|
||||
)));
|
||||
}
|
||||
};
|
||||
let d_pub_key: edDalekPublicKey = (&d_skey).into();
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// 3. Base58 encode bytes from step 2
|
||||
// Finally add armor framing and space/newline formatting as desired
|
||||
|
||||
use crate::{Error, ErrorKind};
|
||||
use crate::Error;
|
||||
use grin_wallet_util::{byte_ser, grin_core::global::max_tx_weight};
|
||||
use regex::Regex;
|
||||
use sha2::{Digest, Sha256};
|
||||
@@ -97,7 +97,7 @@ impl SlatepackArmor {
|
||||
// Decode payload from base58
|
||||
let base_decode = bs58::decode(&clean_payload)
|
||||
.into_vec()
|
||||
.map_err(|_| ErrorKind::SlatepackDeser("Bad bytes".into()))?;
|
||||
.map_err(|_| Error::SlatepackDeser("Bad bytes".into()))?;
|
||||
let error_code = &base_decode[0..4];
|
||||
let slatepack_bytes = &base_decode[4..];
|
||||
// Make sure the error check code is valid for the slate data
|
||||
@@ -109,7 +109,7 @@ impl SlatepackArmor {
|
||||
/// Encode an armored slatepack
|
||||
pub fn encode(slatepack: &Slatepack) -> Result<String, Error> {
|
||||
let slatepack_bytes = byte_ser::to_bytes(&SlatepackBin(slatepack.clone()))
|
||||
.map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
.map_err(|_| Error::SlatepackSer)?;
|
||||
let encoded_slatepack = base58check(&slatepack_bytes)?;
|
||||
let formatted_slatepack = format_slatepack(&format!("{}{}", HEADER, encoded_slatepack))?;
|
||||
Ok(format!("{}{}\n", formatted_slatepack, FOOTER))
|
||||
@@ -122,32 +122,29 @@ fn error_check(error_code: &[u8], slate_bytes: &[u8]) -> Result<(), Error> {
|
||||
if error_code.iter().eq(new_check.iter()) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ErrorKind::InvalidSlatepackData(
|
||||
Err(Error::InvalidSlatepackData(
|
||||
"Bad slate error code- some data was corrupted".to_string(),
|
||||
)
|
||||
.into())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// Checks header framing bytes and returns an error if they are invalid
|
||||
fn check_header(header: &[u8]) -> Result<(), Error> {
|
||||
let framing =
|
||||
str::from_utf8(header).map_err(|_| ErrorKind::SlatepackDeser("Bad bytes".into()))?;
|
||||
let framing = str::from_utf8(header).map_err(|_| Error::SlatepackDeser("Bad bytes".into()))?;
|
||||
if HEADER_REGEX.is_match(framing) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ErrorKind::InvalidSlatepackData("Bad armor header".to_string()).into())
|
||||
Err(Error::InvalidSlatepackData("Bad armor header".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
// Checks footer framing bytes and returns an error if they are invalid
|
||||
fn check_footer(footer: &[u8]) -> Result<(), Error> {
|
||||
let framing =
|
||||
str::from_utf8(footer).map_err(|_| ErrorKind::SlatepackDeser("Bad bytes".into()))?;
|
||||
let framing = str::from_utf8(footer).map_err(|_| Error::SlatepackDeser("Bad bytes".into()))?;
|
||||
if FOOTER_REGEX.is_match(framing) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ErrorKind::InvalidSlatepackData("Bad armor footer".to_string()).into())
|
||||
Err(Error::InvalidSlatepackData("Bad armor footer".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ use std::convert::TryFrom;
|
||||
use std::str;
|
||||
|
||||
use super::armor::HEADER;
|
||||
use crate::Error;
|
||||
use crate::{
|
||||
slatepack, Slate, SlateVersion, Slatepack, SlatepackAddress, SlatepackArmor, SlatepackBin,
|
||||
VersionedBinSlate, VersionedSlate,
|
||||
};
|
||||
use crate::{Error, ErrorKind};
|
||||
|
||||
use grin_wallet_util::byte_ser;
|
||||
|
||||
@@ -53,7 +53,7 @@ impl<'a> Slatepacker<'a> {
|
||||
let data_len = data.len() as u64;
|
||||
if data_len < slatepack::min_size() || data_len > slatepack::max_size() {
|
||||
let msg = format!("Data invalid length");
|
||||
return Err(ErrorKind::SlatepackDeser(msg).into());
|
||||
return Err(Error::SlatepackDeser(msg));
|
||||
}
|
||||
|
||||
let test_header = &data[..HEADER.len()];
|
||||
@@ -76,11 +76,11 @@ impl<'a> Slatepacker<'a> {
|
||||
debug!("Not a valid binary slatepack: {} - Will try JSON", e);
|
||||
let content = String::from_utf8(data).map_err(|e| {
|
||||
let msg = format!("{}", e);
|
||||
ErrorKind::SlatepackDeser(msg)
|
||||
Error::SlatepackDeser(msg)
|
||||
})?;
|
||||
serde_json::from_str(&content).map_err(|e| {
|
||||
let msg = format!("Error reading JSON slatepack: {}", e);
|
||||
ErrorKind::SlatepackDeser(msg)
|
||||
Error::SlatepackDeser(msg)
|
||||
})?
|
||||
}
|
||||
};
|
||||
@@ -95,10 +95,9 @@ impl<'a> Slatepacker<'a> {
|
||||
/// Create slatepack from slate and args
|
||||
pub fn create_slatepack(&self, slate: &Slate) -> Result<Slatepack, Error> {
|
||||
let out_slate = VersionedSlate::into_version(slate.clone(), SlateVersion::V4)?;
|
||||
let bin_slate =
|
||||
VersionedBinSlate::try_from(out_slate).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
let bin_slate = VersionedBinSlate::try_from(out_slate).map_err(|_| Error::SlatepackSer)?;
|
||||
let mut slatepack = Slatepack::default();
|
||||
slatepack.payload = byte_ser::to_bytes(&bin_slate).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
slatepack.payload = byte_ser::to_bytes(&bin_slate).map_err(|_| Error::SlatepackSer)?;
|
||||
slatepack.sender = self.0.sender.clone();
|
||||
slatepack.try_encrypt_payload(self.0.recipients.clone())?;
|
||||
Ok(slatepack)
|
||||
@@ -115,7 +114,7 @@ impl<'a> Slatepacker<'a> {
|
||||
byte_ser::from_bytes::<VersionedBinSlate>(&slatepack.payload).map_err(|e| {
|
||||
error!("Error reading slate from armored slatepack: {}", e);
|
||||
let msg = format!("{}", e);
|
||||
ErrorKind::SlatepackDeser(msg)
|
||||
Error::SlatepackDeser(msg)
|
||||
})?;
|
||||
Ok(Slate::upgrade(slate_bin.into())?)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use x25519_dalek::StaticSecret;
|
||||
|
||||
use crate::dalek_ser;
|
||||
use crate::grin_core::ser::{self, Readable, Reader, Writeable, Writer};
|
||||
use crate::{Error, ErrorKind};
|
||||
use crate::Error;
|
||||
use grin_wallet_util::byte_ser;
|
||||
|
||||
use super::SlatepackAddress;
|
||||
@@ -147,7 +147,7 @@ impl Slatepack {
|
||||
|
||||
// Create encrypted metadata, which will be length prefixed
|
||||
let bin_meta = SlatepackEncMetadataBin(self.encrypted_meta.clone());
|
||||
let mut to_encrypt = byte_ser::to_bytes(&bin_meta).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
let mut to_encrypt = byte_ser::to_bytes(&bin_meta).map_err(|_| Error::SlatepackSer)?;
|
||||
|
||||
if self.future_test_mode {
|
||||
Slatepack::pad_test_data(&mut to_encrypt);
|
||||
@@ -213,7 +213,7 @@ impl Slatepack {
|
||||
let meta_len = Cursor::new(len_bytes).read_u32::<BigEndian>()?;
|
||||
self.payload = decrypted.split_off(meta_len as usize + 4);
|
||||
let meta = byte_ser::from_bytes::<SlatepackEncMetadataBin>(&decrypted)
|
||||
.map_err(|_| ErrorKind::SlatepackSer)?
|
||||
.map_err(|_| Error::SlatepackSer)?
|
||||
.0;
|
||||
self.sender = meta.sender;
|
||||
self.encrypted_meta.recipients = meta.recipients;
|
||||
@@ -777,8 +777,8 @@ fn slatepack_encrypted_meta() -> Result<(), Error> {
|
||||
slatepack.add_recipient(SlatepackAddress::random());
|
||||
|
||||
let v_slate = VersionedSlate::into_version(Slate::blank(2, false), SlateVersion::V4)?;
|
||||
let bin_slate = VersionedBinSlate::try_from(v_slate).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
slatepack.payload = byte_ser::to_bytes(&bin_slate).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
let bin_slate = VersionedBinSlate::try_from(v_slate).map_err(|_| Error::SlatepackSer)?;
|
||||
slatepack.payload = byte_ser::to_bytes(&bin_slate).map_err(|_| Error::SlatepackSer)?;
|
||||
|
||||
let orig_sp = slatepack.clone();
|
||||
|
||||
@@ -826,8 +826,8 @@ fn slatepack_encrypted_meta_future() -> Result<(), Error> {
|
||||
slatepack.add_recipient(SlatepackAddress::random());
|
||||
|
||||
let v_slate = VersionedSlate::into_version(Slate::blank(2, false), SlateVersion::V4)?;
|
||||
let bin_slate = VersionedBinSlate::try_from(v_slate).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
slatepack.payload = byte_ser::to_bytes(&bin_slate).map_err(|_| ErrorKind::SlatepackSer)?;
|
||||
let bin_slate = VersionedBinSlate::try_from(v_slate).map_err(|_| Error::SlatepackSer)?;
|
||||
slatepack.payload = byte_ser::to_bytes(&bin_slate).map_err(|_| Error::SlatepackSer)?;
|
||||
|
||||
let orig_sp = slatepack.clone();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
//! implementation
|
||||
|
||||
use crate::config::{TorConfig, WalletConfig};
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::Error;
|
||||
use crate::grin_core::core::hash::Hash;
|
||||
use crate::grin_core::core::FeeFields;
|
||||
use crate::grin_core::core::{Output, Transaction, TxKernel};
|
||||
@@ -32,7 +32,6 @@ use crate::InitTxArgs;
|
||||
use chrono::prelude::*;
|
||||
use ed25519_dalek::PublicKey as DalekPublicKey;
|
||||
use ed25519_dalek::Signature as DalekSignature;
|
||||
use failure::ResultExt;
|
||||
use rand::rngs::mock::StepRng;
|
||||
use rand::thread_rng;
|
||||
use serde;
|
||||
@@ -681,7 +680,7 @@ impl BlockIdentifier {
|
||||
/// convert to hex string
|
||||
pub fn from_hex(hex: &str) -> Result<BlockIdentifier, Error> {
|
||||
let hash =
|
||||
Hash::from_hex(hex).context(ErrorKind::GenericError("Invalid hex".to_owned()))?;
|
||||
Hash::from_hex(hex).map_err(|e| Error::GenericError(format!("Invalid hex: {}", e)))?;
|
||||
Ok(BlockIdentifier(hash))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user