Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Added get_tx_metadata when transaction is not relayed #124

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions monero/backends/jsonrpc/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``)
Expand Down Expand Up @@ -263,6 +286,7 @@ def _tx(self, data):
else None,
"blob": binascii.unhexlify(data.get("blob", "")),
"confirmations": data.get("confirmations", None),
"metadata": data.get("tx_metadata", None)
}
)

Expand Down Expand Up @@ -306,31 +330,27 @@ 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))
_transfers = self.raw_request("transfer_split", 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
]
),
)
Expand Down Expand Up @@ -361,30 +381,26 @@ 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))
_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
]
),
)
Expand Down
6 changes: 4 additions & 2 deletions monero/transaction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Transaction(object):
json = None
version = None
pubkeys = None
metadata = None

@property
def is_coinbase(self):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -222,13 +224,13 @@ def _scan_pubkeys(
)
"""
pre hard fork:
{
{
"target": {
"key": "ea3f..."
}
}
post hard fork:
{
{
"target": {
"tagged_key": {
"key": "ea3f...",
Expand Down