mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-12-03 12:24:27 +01:00
merge upstream staging into contracts
This commit is contained in:
@@ -376,7 +376,15 @@ pub fn run_doctest_foreign(
|
||||
|
||||
util::init_test_logger();
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
||||
global::set_global_chain_type(ChainTypes::AutomatedTesting);
|
||||
|
||||
let _ = fs::create_dir_all(test_dir);
|
||||
let config = initial_setup_wallet(
|
||||
&ChainTypes::AutomatedTesting,
|
||||
Some(PathBuf::from(test_dir)),
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let _ = fs::create_dir_all(test_dir);
|
||||
let config = initial_setup_wallet(
|
||||
|
||||
+83
-7
@@ -477,6 +477,69 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns max available value to send for selecting all outputs.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `keychain_mask` - Wallet secret mask to XOR against the stored wallet seed before using, if
|
||||
/// being used.
|
||||
/// * `refresh_from_node` - If true, the wallet will attempt to contact
|
||||
/// a node (via the [`NodeClient`](../grin_wallet_libwallet/types/trait.NodeClient.html)
|
||||
/// provided during wallet instantiation). If `false`, the results will
|
||||
/// contain transaction information that may be out-of-date (from the last time
|
||||
/// the wallet's output set was refreshed against the node).
|
||||
/// Note this setting is ignored if the updater process is running via a call to
|
||||
/// [`start_updater`](struct.Owner.html#method.start_updater)
|
||||
/// * `minimum_confirmations` - The minimum number of confirmations an output
|
||||
/// should have before it's included in the 'amount_currently_spendable' total
|
||||
///
|
||||
/// # Returns
|
||||
/// * `(bool, u64, u64, u32)` - A tuple:
|
||||
/// * The first `bool` element indicates whether the data was successfully
|
||||
/// refreshed from the node (note this may be false even if the `refresh_from_node`
|
||||
/// argument was set to `true`).
|
||||
/// * The second `u64` is amount to send.
|
||||
/// * The third element is fee
|
||||
/// * The fourth is maximum input count
|
||||
///
|
||||
/// # Example
|
||||
/// Set up as in [`new`](struct.Owner.html#method.new) method above.
|
||||
/// ```
|
||||
/// # grin_wallet_api::doctest_helper_setup_doc_env!(wallet, wallet_config);
|
||||
///
|
||||
/// let api_owner = Owner::new(wallet.clone(), None, std::path::PathBuf::from("grin-wallet.toml"));
|
||||
/// let update_from_node = true;
|
||||
/// let minimum_confirmations = 10;
|
||||
/// let result = api_owner.estimate_max_sendable(None, update_from_node, minimum_confirmations);
|
||||
///
|
||||
/// if let Ok((was_updated, amount, fee, max_inputs)) = result {
|
||||
/// //...
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
pub fn estimate_max_sendable(
|
||||
&self,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
refresh_from_node: bool,
|
||||
minimum_confirmations: u64,
|
||||
) -> Result<(bool, u64, u64, u32), Error> {
|
||||
let tx = {
|
||||
let t = self.status_tx.lock();
|
||||
t.clone()
|
||||
};
|
||||
let refresh_from_node = match self.updater_running.load(Ordering::Relaxed) {
|
||||
true => false,
|
||||
false => refresh_from_node,
|
||||
};
|
||||
|
||||
owner::estimate_max_sendable(
|
||||
self.wallet_inst.clone(),
|
||||
keychain_mask,
|
||||
&tx,
|
||||
refresh_from_node,
|
||||
minimum_confirmations,
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a list of [Transaction Log Entries](../grin_wallet_libwallet/types/struct.TxLogEntry.html)
|
||||
/// from the active account in the wallet.
|
||||
///
|
||||
@@ -608,21 +671,34 @@ where
|
||||
refresh_from_node: bool,
|
||||
minimum_confirmations: u64,
|
||||
) -> Result<(bool, WalletInfo), Error> {
|
||||
let (updated, _, info) = self.retrieve_summary_info_with_refresh_status(
|
||||
keychain_mask,
|
||||
refresh_from_node,
|
||||
minimum_confirmations,
|
||||
)?;
|
||||
Ok((updated, info))
|
||||
}
|
||||
|
||||
/// Retrieve summary info and whether refresh was skipped.
|
||||
pub fn retrieve_summary_info_with_refresh_status(
|
||||
&self,
|
||||
keychain_mask: Option<&SecretKey>,
|
||||
refresh_from_node: bool,
|
||||
minimum_confirmations: u64,
|
||||
) -> Result<(bool, bool, WalletInfo), Error> {
|
||||
let tx = {
|
||||
let t = self.status_tx.lock();
|
||||
t.clone()
|
||||
};
|
||||
let refresh_from_node = match self.updater_running.load(Ordering::Relaxed) {
|
||||
true => false,
|
||||
false => refresh_from_node,
|
||||
};
|
||||
owner::retrieve_summary_info(
|
||||
let refresh_skipped = refresh_from_node && self.updater_running.load(Ordering::Relaxed);
|
||||
let (updated, info) = owner::retrieve_summary_info(
|
||||
self.wallet_inst.clone(),
|
||||
keychain_mask,
|
||||
&tx,
|
||||
refresh_from_node,
|
||||
refresh_from_node && !refresh_skipped,
|
||||
minimum_confirmations,
|
||||
)
|
||||
)?;
|
||||
Ok((updated, refresh_skipped, info))
|
||||
}
|
||||
|
||||
/// Initiates a new transaction as the sender, creating a new
|
||||
|
||||
+113
-44
@@ -231,6 +231,51 @@ pub trait OwnerRpc {
|
||||
tx_id: Option<u32>,
|
||||
) -> Result<(bool, Vec<OutputCommitMapping>), Error>;
|
||||
|
||||
/**
|
||||
Networked version of [Owner::estimate_max_sendable](struct.Owner.html#method.estimate_max_sendable).
|
||||
|
||||
# Json rpc example
|
||||
|
||||
```
|
||||
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
|
||||
# r#"
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "estimate_max_sendable",
|
||||
"params": {
|
||||
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
|
||||
"refresh_from_node": true,
|
||||
"minimum_confirmations": 1
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
# "#
|
||||
# ,
|
||||
# r#"
|
||||
{
|
||||
"id": 1,
|
||||
"jsonrpc": "2.0",
|
||||
"result": {
|
||||
"Ok": [
|
||||
true,
|
||||
59987500000,
|
||||
12500000,
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
# "#
|
||||
# , 4, false, false, false, false);
|
||||
```
|
||||
*/
|
||||
|
||||
fn estimate_max_sendable(
|
||||
&self,
|
||||
token: Token,
|
||||
refresh_from_node: bool,
|
||||
minimum_confirmations: u64,
|
||||
) -> Result<(bool, u64, u64, u32), Error>;
|
||||
|
||||
/**
|
||||
Networked version of [Owner::retrieve_txs](struct.Owner.html#method.retrieve_txs).
|
||||
|
||||
@@ -464,7 +509,7 @@ pub trait OwnerRpc {
|
||||
) -> Result<(bool, WalletInfo), Error>;
|
||||
|
||||
/**
|
||||
;Networked version of [Owner::init_send_tx](struct.Owner.html#method.init_send_tx).
|
||||
Networked version of [Owner::init_send_tx](struct.Owner.html#method.init_send_tx).
|
||||
|
||||
```
|
||||
# grin_wallet_api::doctest_helper_json_rpc_owner_assert_response!(
|
||||
@@ -481,6 +526,7 @@ pub trait OwnerRpc {
|
||||
"max_outputs": 500,
|
||||
"num_change_outputs": 1,
|
||||
"selection_strategy_is_use_all": true,
|
||||
"refresh_outputs_from_node": true,
|
||||
"target_slate_version": null,
|
||||
"payment_proof_recipient_address": "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp",
|
||||
"ttl_blocks": null,
|
||||
@@ -641,6 +687,7 @@ pub trait OwnerRpc {
|
||||
"max_outputs": 500,
|
||||
"num_change_outputs": 1,
|
||||
"selection_strategy_is_use_all": true,
|
||||
"refresh_outputs_from_node": true,
|
||||
"target_slate_version": null,
|
||||
"payment_proof_recipient_address": null,
|
||||
"ttl_blocks": null,
|
||||
@@ -1163,54 +1210,54 @@ pub trait OwnerRpc {
|
||||
fn node_height(&self, token: Token) -> Result<NodeHeightResult, Error>;
|
||||
|
||||
/**
|
||||
Initializes the secure JSON-RPC API. This function must be called and a shared key
|
||||
established before any other OwnerAPI JSON-RPC function can be called.
|
||||
Initializes the secure JSON-RPC API. This function must be called and a shared key
|
||||
established before any other OwnerAPI JSON-RPC function can be called.
|
||||
|
||||
The shared key will be derived using ECDH with the provided public key on the secp256k1 curve. This
|
||||
function will return its public key used in the derivation, which the caller should multiply by its
|
||||
private key to derive the shared key.
|
||||
The shared key will be derived using ECDH with the provided public key on the secp256k1 curve. This
|
||||
function will return its public key used in the derivation, which the caller should multiply by its
|
||||
private key to derive the shared key.
|
||||
|
||||
Once the key is established, all further requests and responses are encrypted and decrypted with the
|
||||
following parameters:
|
||||
* AES-256 in GCM mode with 128-bit tags and 96 bit nonces
|
||||
* 12 byte nonce which must be included in each request/response to use on the decrypting side
|
||||
* Empty vector for additional data
|
||||
* Suffix length = AES-256 GCM mode tag length = 16 bytes
|
||||
*
|
||||
Once the key is established, all further requests and responses are encrypted and decrypted with the
|
||||
following parameters:
|
||||
* AES-256 in GCM mode with 128-bit tags and 96 bit nonces
|
||||
* 12 byte nonce which must be included in each request/response to use on the decrypting side
|
||||
* Empty vector for additional data
|
||||
* Suffix length = AES-256 GCM mode tag length = 16 bytes
|
||||
*
|
||||
|
||||
Fully-formed JSON-RPC requests (as documented) should be encrypted using these parameters, encoded
|
||||
into base64 and included with the one-time nonce in a request for the `encrypted_request_v3` method
|
||||
as follows:
|
||||
Fully-formed JSON-RPC requests (as documented) should be encrypted using these parameters, encoded
|
||||
into base64 and included with the one-time nonce in a request for the `encrypted_request_v3` method
|
||||
as follows:
|
||||
|
||||
```
|
||||
# let s = r#"
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "encrypted_request_v3",
|
||||
"id": "1",
|
||||
"params": {
|
||||
"nonce": "ef32...",
|
||||
"body_enc": "e0bcd..."
|
||||
}
|
||||
}
|
||||
# "#;
|
||||
```
|
||||
```
|
||||
# let s = r#"
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "encrypted_request_v3",
|
||||
"id": "1",
|
||||
"params": {
|
||||
"nonce": "ef32...",
|
||||
"body_enc": "e0bcd..."
|
||||
}
|
||||
}
|
||||
# "#;
|
||||
```
|
||||
|
||||
With a typical response being:
|
||||
With a typical response being:
|
||||
|
||||
```
|
||||
# let s = r#"{
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "encrypted_response_v3",
|
||||
"id": "1",
|
||||
"Ok": {
|
||||
"nonce": "340b...",
|
||||
"body_enc": "3f09c..."
|
||||
}
|
||||
}
|
||||
# }"#;
|
||||
```
|
||||
```
|
||||
# let s = r#"{
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "encrypted_response_v3",
|
||||
"id": "1",
|
||||
"Ok": {
|
||||
"nonce": "340b...",
|
||||
"body_enc": "3f09c..."
|
||||
}
|
||||
}
|
||||
# }"#;
|
||||
```
|
||||
|
||||
*/
|
||||
|
||||
@@ -2106,6 +2153,20 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
fn estimate_max_sendable(
|
||||
&self,
|
||||
token: Token,
|
||||
refresh_from_node: bool,
|
||||
minimum_confirmations: u64,
|
||||
) -> Result<(bool, u64, u64, u32), Error> {
|
||||
Owner::estimate_max_sendable(
|
||||
self,
|
||||
(&token.keychain_mask).as_ref(),
|
||||
refresh_from_node,
|
||||
minimum_confirmations,
|
||||
)
|
||||
}
|
||||
|
||||
fn retrieve_txs(
|
||||
&self,
|
||||
token: Token,
|
||||
@@ -2595,7 +2656,15 @@ pub fn run_doctest_owner(
|
||||
|
||||
util::init_test_logger();
|
||||
let _ = fs::remove_dir_all(test_dir);
|
||||
global::set_local_chain_type(ChainTypes::AutomatedTesting);
|
||||
global::set_global_chain_type(ChainTypes::AutomatedTesting);
|
||||
|
||||
let _ = fs::create_dir_all(test_dir);
|
||||
let config = initial_setup_wallet(
|
||||
&ChainTypes::AutomatedTesting,
|
||||
Some(PathBuf::from(test_dir)),
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let _ = fs::create_dir_all(test_dir);
|
||||
let config = initial_setup_wallet(
|
||||
|
||||
Reference in New Issue
Block a user