Skip to content

Commit

Permalink
Add wallet command to create a send coins request for cold wallet input
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Feb 5, 2024
1 parent 0c4f5f7 commit d64c851
Show file tree
Hide file tree
Showing 12 changed files with 857 additions and 83 deletions.
26 changes: 26 additions & 0 deletions test-rpc-functions/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use chainstate_types::vrf_tools::{construct_transcript, verify_vrf_and_get_vrf_output};
use common::{
address::Address,
chain::config::regtest::genesis_values,
chain::{
block::timestamp::BlockTimestamp,
Expand Down Expand Up @@ -107,6 +108,12 @@ trait RpcTestFunctionsRpc {
amount_to_spend: u64,
fee_per_tx: u64,
) -> rpc::RpcResult<Vec<HexEncoded<SignedTransaction>>>;

#[method(name = "address_to_destination")]
async fn address_to_destination(
&self,
address: String,
) -> rpc::RpcResult<HexEncoded<Destination>>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -327,6 +334,25 @@ impl RpcTestFunctionsRpcServer for super::RpcTestFunctionsHandle {

Ok(transactions)
}

async fn address_to_destination(
&self,
address: String,
) -> rpc::RpcResult<HexEncoded<Destination>> {
let destination = self
.call(move |this| {
this.get_chain_config().map(|chain| {
Address::<Destination>::from_str(&chain, &address)
.and_then(|addr| addr.decode_object(&chain))
})
})
.await
.expect("Subsystem call ok")
.expect("chain config is present")
.map(HexEncoded::new);

rpc::handle_result(destination)
}
}

async fn assert_genesis_values(
Expand Down
2 changes: 2 additions & 0 deletions test/functional/test_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def init_mintlayer_types():
],
},

"PublicKeyHash": "[u8; 20]",

"PublicKey": {
"type": "struct",
"type_mapping": [
Expand Down
11 changes: 8 additions & 3 deletions test/functional/test_framework/wallet_cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ async def set_lookahead_size(self, size: int, force_reduce: bool) -> str:
i_know_what_i_am_doing = "i-know-what-i-am-doing" if force_reduce else ""
return await self._write_command(f"wallet-set-lookahead-size {size} {i_know_what_i_am_doing}\n")

async def new_public_key(self) -> bytes:
addr = await self.new_address()
public_key = await self._write_command(f"address-reveal-public-key-as-hex {addr}\n")
async def new_public_key(self, address: Optional[str] = None) -> bytes:
if address is None:
address = await self.new_address()
public_key = await self._write_command(f"address-reveal-public-key-as-hex {address}\n")

self.log.info(f'pub key output: {public_key}')
# remove the pub key enum value, the first one byte
Expand All @@ -216,6 +217,10 @@ async def get_transaction(self, tx_id: str) -> str:
async def get_raw_signed_transaction(self, tx_id: str) -> str:
return await self._write_command(f"transaction-get-signed-raw {tx_id}\n")

async def send_from_cold_address(self, address: str, amount: int, selected_utxo: UtxoOutpoint, change_address: Optional[str] = None) -> str:
change_address_str = '' if change_address is None else f"--change {change_address}"
return await self._write_command(f"transaction-send-from-cold-input {address} {amount} {str(selected_utxo)} {change_address_str}\n")

async def send_to_address(self, address: str, amount: int, selected_utxos: List[UtxoOutpoint] = []) -> str:
return await self._write_command(f"address-send {address} {amount} {' '.join(map(str, selected_utxos))}\n")

Expand Down
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class UnicodeOnWindowsError(ValueError):
'feature_db_reinit.py',
'feature_lmdb_backend_test.py',
'wallet_conflict.py',
'wallet_cold_wallet_send.py',
'wallet_tx_compose.py',
'wallet_data_deposit.py',
'wallet_submit_tx.py',
Expand Down
Loading

0 comments on commit d64c851

Please sign in to comment.