Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
merge from upstream (#5)
Browse files Browse the repository at this point in the history
* V2 slate versioning enablement (mimblewimble#85)

* fix for command line listener port override

* reduce parameter query size

* Add slate versioning

* rustfmt

* bump version number

* Add tests for slate version conversion

* rustfmt

* Updates and test addition based on bdap's review

* rustfmt

* fix mimblewimble#88 (mimblewimble#89)

* Add `check_version` function to Foreign API (mimblewimble#87)

* move api deser types into separate types mod

* rustfmt

* missing types file

* make all exports from libwallet more explicit

* rustfmt

* add version check function to foreign api

* rustfmt

* change check_version return value to result, for consistency

* fix the merge missed parts

* rustfmt
  • Loading branch information
garyyu committed Apr 26, 2019
1 parent 61cdaf6 commit 0964187
Show file tree
Hide file tree
Showing 50 changed files with 4,163 additions and 565 deletions.
457 changes: 229 additions & 228 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet"
version = "1.1.0-beta.1"
version = "1.1.0-beta.2"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Simple, private and scalable cryptocurrency implementation based on the MimbleWimble chain format."
license = "Apache-2.0"
Expand Down Expand Up @@ -29,13 +29,13 @@ prettytable-rs = "0.7"
log = "0.4"
linefeed = "0.5"

grin_wallet_api = { path = "./api", version = "1.1.0-beta.1" }
grin_wallet_impls = { path = "./impls", version = "1.1.0-beta.1" }
grin_wallet_libwallet = { path = "./libwallet", version = "1.1.0-beta.1" }
grin_wallet_controller = { path = "./controller", version = "1.1.0-beta.1" }
grin_wallet_config = { path = "./config", version = "1.1.0-beta.1" }
grin_wallet_api = { path = "./api", version = "1.1.0-beta.2" }
grin_wallet_impls = { path = "./impls", version = "1.1.0-beta.2" }
grin_wallet_libwallet = { path = "./libwallet", version = "1.1.0-beta.2" }
grin_wallet_controller = { path = "./controller", version = "1.1.0-beta.2" }
grin_wallet_config = { path = "./config", version = "1.1.0-beta.2" }

grin_wallet_util = { path = "./util", version = "1.1.0-beta.1" }
grin_wallet_util = { path = "./util", version = "1.1.0-beta.2" }

[build-dependencies]
built = "0.3"
12 changes: 6 additions & 6 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_wallet_api"
version = "1.1.0-beta.1"
version = "1.1.0-beta.2"
authors = ["Grin Developers <mimblewimble@lists.launchpad.net>"]
description = "Grin Wallet API"
license = "Apache-2.0"
Expand All @@ -15,14 +15,14 @@ failure_derive = "0.1"
log = "0.4"
uuid = { version = "0.7", features = ["serde", "v4"] }
serde_json = "1"
easy-jsonrpc = "0.4.1"
easy-jsonrpc = "0.5.1"
chrono = { version = "0.4.4", features = ["serde"] }

grin_wallet_libwallet = { path = "../libwallet", version = "1.1.0-beta.1" }
grin_wallet_config = { path = "../config", version = "1.1.0-beta.1" }
grin_wallet_impls = { path = "../impls", version = "1.1.0-beta.1" }
grin_wallet_libwallet = { path = "../libwallet", version = "1.1.0-beta.2" }
grin_wallet_config = { path = "../config", version = "1.1.0-beta.2" }
grin_wallet_impls = { path = "../impls", version = "1.1.0-beta.2" }

grin_wallet_util = { path = "../util", version = "1.1.0-beta.1" }
grin_wallet_util = { path = "../util", version = "1.1.0-beta.2" }

[dev-dependencies]
serde_json = "1"
Expand Down
33 changes: 25 additions & 8 deletions api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

use crate::keychain::Keychain;
use crate::libwallet::api_impl::foreign;
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{BlockFees, CbData, NodeClient, WalletBackend};
use crate::libwallet::Error;
use crate::libwallet::{BlockFees, CbData, Error, NodeClient, Slate, VersionInfo, WalletBackend};
use crate::util::Mutex;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down Expand Up @@ -91,7 +89,7 @@ where
/// use api::Foreign;
/// use config::WalletConfig;
/// use impls::{HTTPNodeClient, LMDBBackend};
/// use libwallet::types::WalletBackend;
/// use libwallet::WalletBackend;
///
/// let mut wallet_config = WalletConfig::default();
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
Expand Down Expand Up @@ -125,6 +123,26 @@ where
}
}

/// Return the version capabilities of the running ForeignApi Node
/// # Arguments
/// None
/// # Returns
/// * [`VersionInfo`](../grin_wallet_libwallet/api_impl/types/struct.VersionInfo.html)
/// # Example
/// Set up as in [`new`](struct.Foreign.html#method.new) method above.
/// ```
/// # grin_wallet_api::doctest_helper_setup_doc_env_foreign!(wallet, wallet_config);
///
/// let mut api_foreign = Foreign::new(wallet.clone());
///
/// let version_info = api_foreign.check_version();
/// // check and proceed accordingly
/// ```

pub fn check_version(&self) -> Result<VersionInfo, Error> {
Ok(foreign::check_version())
}

/// Builds a new unconfirmed coinbase output in the wallet, generally for inclusion in a
/// potential new block's coinbase output during mining.
///
Expand All @@ -136,7 +154,7 @@ where
///
/// # Arguments
///
/// * `block_fees` - A [`BlockFees`](../grin_wallet_libwallet/types/struct.BlockFees.html)
/// * `block_fees` - A [`BlockFees`](../grin_wallet_libwallet/api_impl/types/struct.BlockFees.html)
/// struct, set up as follows:
///
/// `fees` - should contain the sum of all transaction fees included in the potential
Expand All @@ -149,7 +167,7 @@ where
/// id will be assigned
///
/// # Returns
/// * `Ok`([`cb_data`](../grin_wallet_libwallet/types/struct.CbData.html)`)` if successful. This
/// * `Ok`([`cb_data`](../grin_wallet_libwallet/api_impl/types/struct.CbData.html)`)` if successful. This
/// will contain the corresponding output, kernel and keyID used to create the coinbase output.
/// * or [`libwallet::Error`](../grin_wallet_libwallet/struct.Error.html) if an error is encountered.
///
Expand Down Expand Up @@ -305,7 +323,6 @@ macro_rules! doctest_helper_setup_doc_env_foreign {
use grin_wallet_libwallet as libwallet;
use grin_wallet_util::grin_keychain as keychain;
use grin_wallet_util::grin_util as util;
use libwallet::slate::Slate;

use keychain::ExtKeychain;
use tempfile::tempdir;
Expand All @@ -316,7 +333,7 @@ macro_rules! doctest_helper_setup_doc_env_foreign {
use api::Foreign;
use config::WalletConfig;
use impls::{HTTPNodeClient, LMDBBackend, WalletSeed};
use libwallet::types::{BlockFees, WalletBackend};
use libwallet::{BlockFees, Slate, WalletBackend};

let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
let dir = dir
Expand Down
60 changes: 51 additions & 9 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
//! JSON-RPC Stub generation for the Foreign API

use crate::keychain::Keychain;
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{BlockFees, CbData, InitTxArgs, NodeClient, WalletBackend};
use crate::libwallet::ErrorKind;
use crate::libwallet::{
BlockFees, CbData, ErrorKind, InitTxArgs, NodeClient, Slate, VersionInfo, VersionedSlate,
WalletBackend,
};
use crate::Foreign;
use easy_jsonrpc;

Expand All @@ -27,6 +28,40 @@ use easy_jsonrpc;
/// * The endpoint only supports POST operations, with the json-rpc request as the body
#[easy_jsonrpc::rpc]
pub trait ForeignRpc {
/**
Networked version of [Foreign::check_version](struct.Foreign.html#method.check_version).
# Json rpc example
```
# grin_wallet_api::doctest_helper_json_rpc_foreign_assert_response!(
# r#"
{
"jsonrpc": "2.0",
"method": "check_version",
"id": 1,
"params": []
}
# "#
# ,
# r#"
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"Ok": {
"default_slate_version": 2,
"foreign_api_version": 2
}
}
}
# "#
# , 0, false);
```
*/
fn check_version(&self) -> Result<VersionInfo, ErrorKind>;

/**
Networked version of [Foreign::build_coinbase](struct.Foreign.html#method.build_coinbase).
Expand Down Expand Up @@ -310,10 +345,10 @@ pub trait ForeignRpc {
*/
fn receive_tx(
&self,
slate: Slate,
slate: VersionedSlate,
dest_acct_name: Option<String>,
message: Option<String>,
) -> Result<Slate, ErrorKind>;
) -> Result<VersionedSlate, ErrorKind>;
}

impl<W: ?Sized, C, K> ForeignRpc for Foreign<W, C, K>
Expand All @@ -322,6 +357,10 @@ where
C: NodeClient,
K: Keychain,
{
fn check_version(&self) -> Result<VersionInfo, ErrorKind> {
Foreign::check_version(self).map_err(|e| e.kind())
}

fn build_coinbase(&self, block_fees: &BlockFees) -> Result<CbData, ErrorKind> {
Foreign::build_coinbase(self, block_fees).map_err(|e| e.kind())
}
Expand All @@ -332,18 +371,21 @@ where

fn receive_tx(
&self,
slate: Slate,
slate: VersionedSlate,
dest_acct_name: Option<String>,
message: Option<String>,
) -> Result<Slate, ErrorKind> {
) -> Result<VersionedSlate, ErrorKind> {
let version = slate.version();
let slate: Slate = slate.into();
let slate = Foreign::receive_tx(
self,
&slate,
dest_acct_name.as_ref().map(String::as_str),
message,
)
.map_err(|e| e.kind())?;
Ok(slate)

Ok(VersionedSlate::into_version(slate, version))
}
}

Expand Down Expand Up @@ -437,7 +479,7 @@ pub fn run_doctest_foreign(
let mut api_foreign = Foreign::new(wallet1.clone());
api_foreign.doctest_mode = true;
let foreign_api = &api_foreign as &dyn ForeignRpc;
Ok(foreign_api.handle_request(request))
Ok(foreign_api.handle_request(request).as_option())
}

#[doc(hidden)]
Expand Down
1 change: 1 addition & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ pub use crate::foreign_rpc::ForeignRpc;
pub use crate::owner::Owner;
pub use crate::owner_rpc::OwnerRpc;

pub use crate::foreign_rpc::foreign_rpc as foreign_rpc_client;
pub use crate::foreign_rpc::run_doctest_foreign;
pub use crate::owner_rpc::run_doctest_owner;
12 changes: 5 additions & 7 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ use crate::core::core::Transaction;
use crate::impls::{HTTPWalletCommAdapter, KeybaseWalletCommAdapter};
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::api_impl::owner;
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{
AcctPathMapping, InitTxArgs, NodeClient, NodeHeightResult, OutputCommitMapping,
PaymentCommitMapping, TxLogEntry, WalletBackend, WalletInfo,
use crate::libwallet::{
AcctPathMapping, Error, ErrorKind, InitTxArgs, NodeClient, NodeHeightResult,
OutputCommitMapping, PaymentCommitMapping, Slate, TxLogEntry, WalletBackend, WalletInfo,
};
use crate::libwallet::{Error, ErrorKind};

/// Main interface into all wallet API functions.
/// Wallet APIs are split into two seperate blocks of functionality
Expand Down Expand Up @@ -99,7 +97,7 @@ where
/// use api::Owner;
/// use config::WalletConfig;
/// use impls::{HTTPNodeClient, LMDBBackend};
/// use libwallet::types::WalletBackend;
/// use libwallet::WalletBackend;
///
/// let mut wallet_config = WalletConfig::default();
/// # let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
Expand Down Expand Up @@ -1068,7 +1066,7 @@ macro_rules! doctest_helper_setup_doc_env {
use api::Owner;
use config::WalletConfig;
use impls::{HTTPNodeClient, LMDBBackend, WalletSeed};
use libwallet::types::{InitTxArgs, WalletBackend};
use libwallet::{InitTxArgs, WalletBackend};

let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
let dir = dir
Expand Down
10 changes: 4 additions & 6 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ use uuid::Uuid;

use crate::core::core::Transaction;
use crate::keychain::{Identifier, Keychain};
use crate::libwallet::slate::Slate;
use crate::libwallet::types::{
AcctPathMapping, InitTxArgs, NodeClient, NodeHeightResult, OutputCommitMapping, TxLogEntry,
WalletBackend, WalletInfo,
use crate::libwallet::{
AcctPathMapping, ErrorKind, InitTxArgs, NodeClient, NodeHeightResult, OutputCommitMapping,
Slate, TxLogEntry, WalletBackend, WalletInfo,
};
use crate::libwallet::ErrorKind;
use crate::Owner;
use easy_jsonrpc;

Expand Down Expand Up @@ -1204,7 +1202,7 @@ pub fn run_doctest_owner(
let mut api_owner = Owner::new(wallet1.clone());
api_owner.doctest_mode = true;
let owner_api = &api_owner as &dyn OwnerRpc;
Ok(owner_api.handle_request(request))
Ok(owner_api.handle_request(request).as_option())
}

#[doc(hidden)]
Expand Down
Loading

0 comments on commit 0964187

Please sign in to comment.