mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 15:21:39 +02:00
Add check_version function to Foreign API (#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
This commit is contained in:
+25
-8
@@ -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;
|
||||
@@ -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();
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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;
|
||||
@@ -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
|
||||
|
||||
+42
-3
@@ -15,9 +15,10 @@
|
||||
//! JSON-RPC Stub generation for the Foreign API
|
||||
|
||||
use crate::keychain::Keychain;
|
||||
use crate::libwallet::types::{BlockFees, CbData, InitTxArgs, NodeClient, WalletBackend};
|
||||
use crate::libwallet::ErrorKind;
|
||||
use crate::libwallet::{Slate, VersionedSlate};
|
||||
use crate::libwallet::{
|
||||
BlockFees, CbData, ErrorKind, InitTxArgs, NodeClient, Slate, VersionInfo, VersionedSlate,
|
||||
WalletBackend,
|
||||
};
|
||||
use crate::Foreign;
|
||||
use easy_jsonrpc;
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
+5
-7
@@ -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, TxLogEntry,
|
||||
WalletBackend, WalletInfo,
|
||||
use crate::libwallet::{
|
||||
AcctPathMapping, Error, ErrorKind, InitTxArgs, NodeClient, NodeHeightResult,
|
||||
OutputCommitMapping, 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
|
||||
@@ -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();
|
||||
@@ -1018,7 +1016,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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user