Skip to content

Commit

Permalink
Replace failure with thiserror (#654)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yeastplume authored Jul 28, 2022
1 parent 67f0e2b commit 64cab53
Show file tree
Hide file tree
Showing 63 changed files with 1,066 additions and 1,586 deletions.
635 changes: 313 additions & 322 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ exclude = ["integration"]
[dependencies]
clap = { version = "2.33", features = ["yaml"] }
rpassword = "4.0"
failure = "0.1"
failure_derive = "0.1"
thiserror = "1"
prettytable-rs = "0.8"
log = "0.4"
linefeed = "0.6"
Expand Down
2 changes: 0 additions & 2 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ exclude = ["**/*.grin", "**/*.grin2"]
edition = "2018"

[dependencies]
failure = "0.1"
failure_derive = "0.1"
log = "0.4"
uuid = { version = "0.8", features = ["serde", "v4"] }
serde = "1"
Expand Down
37 changes: 17 additions & 20 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
use crate::keychain::Keychain;
use crate::libwallet::{
self, BlockFees, CbData, ErrorKind, InitTxArgs, IssueInvoiceTxArgs, NodeClient,
NodeVersionInfo, Slate, SlateVersion, VersionInfo, VersionedCoinbase, VersionedSlate,
WalletLCProvider,
self, BlockFees, CbData, Error, InitTxArgs, IssueInvoiceTxArgs, NodeClient, NodeVersionInfo,
Slate, SlateVersion, VersionInfo, VersionedCoinbase, VersionedSlate, WalletLCProvider,
};
use crate::{Foreign, ForeignCheckMiddlewareFn};
use easy_jsonrpc_mw;
Expand Down Expand Up @@ -62,7 +61,7 @@ pub trait ForeignRpc {
# ,false, 0, false, false);
```
*/
fn check_version(&self) -> Result<VersionInfo, ErrorKind>;
fn check_version(&self) -> Result<VersionInfo, Error>;

/**
Networked Legacy (non-secure token) version of [Foreign::build_coinbase](struct.Foreign.html#method.build_coinbase).
Expand Down Expand Up @@ -111,7 +110,7 @@ pub trait ForeignRpc {
```
*/

fn build_coinbase(&self, block_fees: &BlockFees) -> Result<VersionedCoinbase, ErrorKind>;
fn build_coinbase(&self, block_fees: &BlockFees) -> Result<VersionedCoinbase, Error>;

/**
;Networked version of [Foreign::receive_tx](struct.Foreign.html#method.receive_tx).
Expand Down Expand Up @@ -190,7 +189,7 @@ pub trait ForeignRpc {
slate: VersionedSlate,
dest_acct_name: Option<String>,
dest: Option<String>,
) -> Result<VersionedSlate, ErrorKind>;
) -> Result<VersionedSlate, Error>;

/**
Expand Down Expand Up @@ -284,7 +283,7 @@ pub trait ForeignRpc {
# ,false, 5, false, true);
```
*/
fn finalize_tx(&self, slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind>;
fn finalize_tx(&self, slate: VersionedSlate) -> Result<VersionedSlate, Error>;
}

impl<'a, L, C, K> ForeignRpc for Foreign<'a, L, C, K>
Expand All @@ -293,12 +292,12 @@ where
C: NodeClient + 'a,
K: Keychain + 'a,
{
fn check_version(&self) -> Result<VersionInfo, ErrorKind> {
Foreign::check_version(self).map_err(|e| e.kind())
fn check_version(&self) -> Result<VersionInfo, Error> {
Foreign::check_version(self)
}

fn build_coinbase(&self, block_fees: &BlockFees) -> Result<VersionedCoinbase, ErrorKind> {
let cb: CbData = Foreign::build_coinbase(self, block_fees).map_err(|e| e.kind())?;
fn build_coinbase(&self, block_fees: &BlockFees) -> Result<VersionedCoinbase, Error> {
let cb: CbData = Foreign::build_coinbase(self, block_fees)?;
Ok(VersionedCoinbase::into_version(cb, SlateVersion::V4))
}

Expand All @@ -307,24 +306,22 @@ where
in_slate: VersionedSlate,
dest_acct_name: Option<String>,
dest: Option<String>,
) -> Result<VersionedSlate, ErrorKind> {
) -> Result<VersionedSlate, Error> {
let version = in_slate.version();
let slate_from = Slate::from(in_slate);
let out_slate = Foreign::receive_tx(
self,
&slate_from,
dest_acct_name.as_ref().map(String::as_str),
dest,
)
.map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
)?;
Ok(VersionedSlate::into_version(out_slate, version)?)
}

fn finalize_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, ErrorKind> {
fn finalize_tx(&self, in_slate: VersionedSlate) -> Result<VersionedSlate, Error> {
let version = in_slate.version();
let out_slate =
Foreign::finalize_tx(self, &Slate::from(in_slate), true).map_err(|e| e.kind())?;
Ok(VersionedSlate::into_version(out_slate, version).map_err(|e| e.kind())?)
let out_slate = Foreign::finalize_tx(self, &Slate::from(in_slate), true)?;
Ok(VersionedSlate::into_version(out_slate, version)?)
}
}

Expand All @@ -334,7 +331,7 @@ fn test_check_middleware(
_slate: Option<&Slate>,
) -> Result<(), libwallet::Error> {
// TODO: Implement checks
// return Err(ErrorKind::GenericError("Test Rejection".into()))?
// return Err(Error::GenericError("Test Rejection".into()))?
Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use grin_wallet_util::grin_util as util;
extern crate grin_wallet_impls as impls;
extern crate grin_wallet_libwallet as libwallet;

extern crate failure_derive;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
Expand Down
Loading

0 comments on commit 64cab53

Please sign in to comment.