From 91a4ec17689a1b3cfb9337ad0767b41cc39bd2cb Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 4 Oct 2022 06:50:35 +0200 Subject: [PATCH 1/6] Added get_tx_metadata when transaction is not relayed --- monero/backends/jsonrpc/wallet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monero/backends/jsonrpc/wallet.py b/monero/backends/jsonrpc/wallet.py index d12f9fc..31867be 100644 --- a/monero/backends/jsonrpc/wallet.py +++ b/monero/backends/jsonrpc/wallet.py @@ -306,11 +306,12 @@ def transfer( ) ), "priority": priority, - "unlock_time": 0, + "unlock_time": unlock_time, "get_tx_keys": True, "get_tx_hex": True, "new_algorithm": True, "do_not_relay": not relay, + "get_tx_metadata": not relay } if payment_id is not None: data["payment_id"] = str(PaymentID(payment_id)) From 2db2aae4ff111e1ce5687168c818866e0282526b Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 4 Oct 2022 06:53:54 +0200 Subject: [PATCH 2/6] Same changes to sweep_all --- monero/backends/jsonrpc/wallet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monero/backends/jsonrpc/wallet.py b/monero/backends/jsonrpc/wallet.py index 31867be..78f56a8 100644 --- a/monero/backends/jsonrpc/wallet.py +++ b/monero/backends/jsonrpc/wallet.py @@ -362,10 +362,11 @@ def sweep_all( "address": str(address(destination)), "subaddr_indices": list(subaddr_indices), "priority": priority, - "unlock_time": 0, + "unlock_time": unlock_time, "get_tx_keys": True, "get_tx_hex": True, "do_not_relay": not relay, + "get_tx_metadata": not relay } if payment_id is not None: data["payment_id"] = str(PaymentID(payment_id)) From c3f34b119d036413afbf4cae2ddf63358740740f Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 4 Oct 2022 07:19:18 +0200 Subject: [PATCH 3/6] Added tx_metadata if not relayed, still not poped up Transaction object --- monero/backends/jsonrpc/wallet.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/monero/backends/jsonrpc/wallet.py b/monero/backends/jsonrpc/wallet.py index 78f56a8..3d8b54a 100644 --- a/monero/backends/jsonrpc/wallet.py +++ b/monero/backends/jsonrpc/wallet.py @@ -316,22 +316,35 @@ def transfer( if payment_id is not None: data["payment_id"] = str(PaymentID(payment_id)) _transfers = self.raw_request("transfer_split", data) + if relay: + single_keys = ("txid", "amount", "fee", "key", "blob", "payment_id") + single_keys_list = ( + "tx_hash_list", + "amount_list", + "fee_list", + "tx_key_list", + "tx_blob_list", + ) + else: + single_keys = ("txid", "amount", "fee", "key", "blob", "payment_id", "tx_metadata") + single_keys_list = ( + "tx_hash_list", + "amount_list", + "fee_list", + "tx_key_list", + "tx_blob_list", + "tx_metadata_list" + ) _pertx = [ dict(_tx) for _tx in map( lambda vs: zip( - ("txid", "amount", "fee", "key", "blob", "payment_id"), vs + single_keys, vs ), zip( *[ _transfers[k] - for k in ( - "tx_hash_list", - "amount_list", - "fee_list", - "tx_key_list", - "tx_blob_list", - ) + for k in single_keys_list ] ), ) From cfcc1e194a97f5dfd0a724a93c243fd09afb125e Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 4 Oct 2022 07:30:50 +0200 Subject: [PATCH 4/6] Order seem to matter --- monero/backends/jsonrpc/wallet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monero/backends/jsonrpc/wallet.py b/monero/backends/jsonrpc/wallet.py index 3d8b54a..e6c5427 100644 --- a/monero/backends/jsonrpc/wallet.py +++ b/monero/backends/jsonrpc/wallet.py @@ -326,7 +326,7 @@ def transfer( "tx_blob_list", ) else: - single_keys = ("txid", "amount", "fee", "key", "blob", "payment_id", "tx_metadata") + single_keys = ("txid", "amount", "fee", "key", "blob", "tx_metadata", "payment_id") single_keys_list = ( "tx_hash_list", "amount_list", From 0e25551b9cb8683987989a2d127e57467cdf04f9 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 4 Oct 2022 07:55:08 +0200 Subject: [PATCH 5/6] Added to _tx > Transaction --- monero/backends/jsonrpc/wallet.py | 1 + monero/transaction/__init__.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/monero/backends/jsonrpc/wallet.py b/monero/backends/jsonrpc/wallet.py index e6c5427..1c34c2e 100644 --- a/monero/backends/jsonrpc/wallet.py +++ b/monero/backends/jsonrpc/wallet.py @@ -263,6 +263,7 @@ def _tx(self, data): else None, "blob": binascii.unhexlify(data.get("blob", "")), "confirmations": data.get("confirmations", None), + "metadata": data.get("tx_metadata", None) } ) diff --git a/monero/transaction/__init__.py b/monero/transaction/__init__.py index a297dc3..8dab812 100644 --- a/monero/transaction/__init__.py +++ b/monero/transaction/__init__.py @@ -96,6 +96,7 @@ class Transaction(object): json = None version = None pubkeys = None + metadata = None @property def is_coinbase(self): @@ -124,6 +125,7 @@ def __init__(self, **kwargs): self.blob = kwargs.get("blob", self.blob) self.confirmations = kwargs.get("confirmations", self.confirmations) self.output_indices = kwargs.get("output_indices", self.output_indices) + self.metadata = kwargs.get("metadata", self.metadata) self.json = kwargs.get("json", self.json) self.pubkeys = self.pubkeys or [] if self.json: @@ -222,13 +224,13 @@ def _scan_pubkeys( ) """ pre hard fork: - { + { "target": { "key": "ea3f..." } } post hard fork: - { + { "target": { "tagged_key": { "key": "ea3f...", From c1526b1f8f30822da58276ad510ccf095780c5a7 Mon Sep 17 00:00:00 2001 From: euri10 Date: Tue, 4 Oct 2022 08:09:39 +0200 Subject: [PATCH 6/6] Small refactor and addition to sweep_all method as well --- monero/backends/jsonrpc/wallet.py | 58 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/monero/backends/jsonrpc/wallet.py b/monero/backends/jsonrpc/wallet.py index 1c34c2e..6f2bd1b 100644 --- a/monero/backends/jsonrpc/wallet.py +++ b/monero/backends/jsonrpc/wallet.py @@ -16,6 +16,29 @@ _log = logging.getLogger(__name__) +def _extract_keys(relay): + if relay: + single_keys = ("txid", "amount", "fee", "key", "blob", "payment_id") + single_keys_list = ( + "tx_hash_list", + "amount_list", + "fee_list", + "tx_key_list", + "tx_blob_list", + ) + else: + single_keys = ("txid", "amount", "fee", "key", "blob", "tx_metadata", "payment_id") + single_keys_list = ( + "tx_hash_list", + "amount_list", + "fee_list", + "tx_key_list", + "tx_blob_list", + "tx_metadata_list" + ) + return single_keys, single_keys_list + + class JSONRPCWallet(object): """ JSON RPC backend for Monero wallet (``monero-wallet-rpc``) @@ -317,35 +340,17 @@ def transfer( if payment_id is not None: data["payment_id"] = str(PaymentID(payment_id)) _transfers = self.raw_request("transfer_split", data) - if relay: - single_keys = ("txid", "amount", "fee", "key", "blob", "payment_id") - single_keys_list = ( - "tx_hash_list", - "amount_list", - "fee_list", - "tx_key_list", - "tx_blob_list", - ) - else: - single_keys = ("txid", "amount", "fee", "key", "blob", "tx_metadata", "payment_id") - single_keys_list = ( - "tx_hash_list", - "amount_list", - "fee_list", - "tx_key_list", - "tx_blob_list", - "tx_metadata_list" - ) + extract_keys, extract_keys_list = _extract_keys(relay) _pertx = [ dict(_tx) for _tx in map( lambda vs: zip( - single_keys, vs + extract_keys, vs ), zip( *[ _transfers[k] - for k in single_keys_list + for k in extract_keys_list ] ), ) @@ -385,22 +390,17 @@ def sweep_all( if payment_id is not None: data["payment_id"] = str(PaymentID(payment_id)) _transfers = self.raw_request("sweep_all", data) + extract_keys, extract_keys_list = _extract_keys(relay) _pertx = [ dict(_tx) for _tx in map( lambda vs: zip( - ("txid", "amount", "fee", "key", "blob", "payment_id"), vs + extract_keys, vs ), zip( *[ _transfers[k] - for k in ( - "tx_hash_list", - "amount_list", - "fee_list", - "tx_key_list", - "tx_blob_list", - ) + for k in extract_keys_list ] ), )