Compare commits

...

2 Commits

Author SHA1 Message Date
Michał Sałaban bbe45871d8 Don't crash on txes with no blob
2 years ago
Michał Sałaban df9ed224cf Pass output_indices to constructor; add test
2 years ago

@ -1598,6 +1598,7 @@ class JSONRPCDaemon(object):
timestamp=datetime.fromtimestamp(tx["block_timestamp"])
if "block_timestamp" in tx
else None,
output_indices=tx["output_indices"],
blob=binascii.unhexlify(tx["as_hex"]) or None,
json=as_json,
)

@ -0,0 +1,30 @@
{
"credits": 0,
"status": "OK",
"top_hash": "",
"txs": [
{
"as_hex": "",
"as_json": "{\n \"version\": 2, \n \"unlock_time\": 0, \n \"vin\": [ {\n \"key\": {\n \"amount\": 0, \n \"key_offsets\": [ 2313951, 2369591, 6872, 24959, 92810, 7131, 3340, 1143, 339, 738, 2551\n ], \n \"k_image\": \"303a40bcd7ebf070c0fca85e1511dfc0ebfcc22896c26ddb716d10305ac958de\"\n }\n }\n ], \n \"vout\": [ {\n \"amount\": 0, \n \"target\": {\n \"key\": \"a420b2c58787c178692deaf57fac6378c66961aa1a3d8e836e372ecf2f962f4a\"\n }\n }, {\n \"amount\": 0, \n \"target\": {\n \"key\": \"0a000a61af77f57d98b2f5fe8b60916fa352a42d6452e6f944fbbe6afa1932ce\"\n }\n }\n ], \n \"extra\": [ 1, 37, 69, 31, 72, 139, 82, 83, 161, 38, 66, 216, 33, 84, 215, 192, 153, 130, 249, 83, 23, 127, 226, 126, 131, 247, 185, 246, 215, 166, 166, 22, 243, 2, 9, 1, 219, 16, 60, 245, 234, 28, 46, 40\n ], \n \"rct_signatures\": {\n \"type\": 5, \n \"txnFee\": 44980000, \n \"ecdhInfo\": [ {\n \"amount\": \"fd3411b593b40183\"\n }, {\n \"amount\": \"36ced8b3bd8cb576\"\n }], \n \"outPk\": [ \"5f8ee14c061d617aaa5194afd3b9edf16f6fe75991783d20d89681ffd6f4fc9d\", \"1263698276ab4091d4bfb5ec978b8ce67c3702f9bf3c7e511ebb1340e4d407a4\"]\n }\n}",
"block_height": 1077880,
"block_timestamp": 1650746744,
"double_spend_seen": false,
"in_pool": false,
"output_indices": [
4823652,
4823653
],
"prunable_as_hex": "",
"prunable_hash": "58abeb3b8e06ce3320cf503ef15a762258bbcabf0d2bbdc3eb4636b7d9001bcc",
"pruned_as_hex": "02000102000bdf9d8d01b7d09001d835ffc2018ad505db378c1af708d302e205f713303a40bcd7ebf070c0fca85e1511dfc0ebfcc22896c26ddb716d10305ac958de020002a420b2c58787c178692deaf57fac6378c66961aa1a3d8e836e372ecf2f962f4a00020a000a61af77f57d98b2f5fe8b60916fa352a42d6452e6f944fbbe6afa1932ce2c0125451f488b5253a12642d82154d7c09982f953177fe27e83f7b9f6d7a6a616f3020901db103cf5ea1c2e2805a0aeb915fd3411b593b4018336ced8b3bd8cb5765f8ee14c061d617aaa5194afd3b9edf16f6fe75991783d20d89681ffd6f4fc9d1263698276ab4091d4bfb5ec978b8ce67c3702f9bf3c7e511ebb1340e4d407a4",
"tx_hash": "f5aff33df23c1410217f852a3740d1af89a44bdd0b95107e54e161f202f16d3c"
}
],
"txs_as_hex": [
""
],
"txs_as_json": [
"{\n \"version\": 2, \n \"unlock_time\": 0, \n \"vin\": [ {\n \"key\": {\n \"amount\": 0, \n \"key_offsets\": [ 2313951, 2369591, 6872, 24959, 92810, 7131, 3340, 1143, 339, 738, 2551\n ], \n \"k_image\": \"303a40bcd7ebf070c0fca85e1511dfc0ebfcc22896c26ddb716d10305ac958de\"\n }\n }\n ], \n \"vout\": [ {\n \"amount\": 0, \n \"target\": {\n \"key\": \"a420b2c58787c178692deaf57fac6378c66961aa1a3d8e836e372ecf2f962f4a\"\n }\n }, {\n \"amount\": 0, \n \"target\": {\n \"key\": \"0a000a61af77f57d98b2f5fe8b60916fa352a42d6452e6f944fbbe6afa1932ce\"\n }\n }\n ], \n \"extra\": [ 1, 37, 69, 31, 72, 139, 82, 83, 161, 38, 66, 216, 33, 84, 215, 192, 153, 130, 249, 83, 23, 127, 226, 126, 131, 247, 185, 246, 215, 166, 166, 22, 243, 2, 9, 1, 219, 16, 60, 245, 234, 28, 46, 40\n ], \n \"rct_signatures\": {\n \"type\": 5, \n \"txnFee\": 44980000, \n \"ecdhInfo\": [ {\n \"amount\": \"fd3411b593b40183\"\n }, {\n \"amount\": \"36ced8b3bd8cb576\"\n }], \n \"outPk\": [ \"5f8ee14c061d617aaa5194afd3b9edf16f6fe75991783d20d89681ffd6f4fc9d\", \"1263698276ab4091d4bfb5ec978b8ce67c3702f9bf3c7e511ebb1340e4d407a4\"]\n }\n}"
],
"untrusted": false
}

@ -0,0 +1,18 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"subaddress_accounts": [
{
"account_index": 0,
"balance": 11709717332048,
"base_address": "54LUsTyVL2haFdvkUVngGCiacaRYkjrUvfhvnF6JS2fXNL6twQUQf7PEPtf9MvRYXvhVmtzcV2MUefinDjjwVcH56xm3AHx",
"label": "Primary account",
"tag": "",
"unlocked_balance": 11709717332048
}
],
"total_balance": 11709717332048,
"total_unlocked_balance": 11709717332048
}
}

@ -0,0 +1,7 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"key": "a759f8631116a607e0d905c09c633e320825d3a05e2b5fc54ab5f812f01a1d04"
}
}

@ -0,0 +1,63 @@
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"address": "54LUsTyVL2haFdvkUVngGCiacaRYkjrUvfhvnF6JS2fXNL6twQUQf7PEPtf9MvRYXvhVmtzcV2MUefinDjjwVcH56xm3AHx",
"addresses": [
{
"address": "54LUsTyVL2haFdvkUVngGCiacaRYkjrUvfhvnF6JS2fXNL6twQUQf7PEPtf9MvRYXvhVmtzcV2MUefinDjjwVcH56xm3AHx",
"address_index": 0,
"label": "Primary account",
"used": true
},
{
"address": "74fu2Uiveqg8XwxtLK4kdMPkCZNuW8gGC7nWgB8kJF1rACfbGvPKirrSaKFnxtUJePfnGTPRQ1Tp3jR2PKAavqQ7RNrsJbb",
"address_index": 1,
"label": "(Untitled address)",
"used": true
},
{
"address": "72KSFPEUK5MDvo716tgRrndsRgB3UtWczAXVBjqDZCvRitvUKKA8saNH9LCD1ExCM5VAKuZJTtnH495vEupxRn7EEYbUrGV",
"address_index": 2,
"label": "(Untitled address)",
"used": true
},
{
"address": "7As2Hf3RwGWSCJAPFFHXDyLg5qywN8MiqcmpWPiM3Mc7bmuoA1V78HWEf3GctXtveHSH35hk6NVGK7TAQoyXpy3ATvEYgPz",
"address_index": 3,
"label": "(Untitled address)",
"used": true
},
{
"address": "771dkwjPR1UDTMM7NVbJ6LDX2pQdBaHqDZKSzViPTDaxVjG7idfF9uP2i8xftcV1JfZYESDzvFvAUJ1ym89uPy7VQ9Nd9BA",
"address_index": 4,
"label": "(Untitled address)",
"used": true
},
{
"address": "798wHkYNUqc5UWYdeYiFmrYeXV7Rd23MqasV3YWAYLbeieYb3ogLEkB9TugZkP72qMMtnhxAuyr62P9GLk3Ai5EMS6mCTdu",
"address_index": 5,
"label": "(Untitled address)",
"used": true
},
{
"address": "7AVgqHzSLu227tv2HGvPAYcbVqTzbbNsAC99QpPZwZzudGsEypD4ZjrQQcansdaQGDLtUbdEhqHfeNjgEWPFAUoVGq1dnbE",
"address_index": 6,
"label": "(Untitled address)",
"used": true
},
{
"address": "77xBMPG3k5qEmQmreBbeqJYwcx9kkEz2y2abCFvRRrjKZVr2LVois3kGRM4kzXUqmj7PtTkiUza6rXnNZ5HM17pd2AbsVEA",
"address_index": 7,
"label": "(Untitled address)",
"used": true
},
{
"address": "72barfe7Sp9JZkyLCYLn3wfGhysUUQJqgJPp7DtjStjFdFUXR376ypzYKyxgMcXNE3AStjFmaSKAq6pv78jKPsbTTLq3uNb",
"address_index": 8,
"label": "(Untitled address)",
"used": true
}
]
}
}

@ -23,8 +23,45 @@ class OutputTestCase(JSONTestCase):
wallet_jsonrpc_url = "http://127.0.0.1:38083/json_rpc"
@responses.activate
def test_multiple_outputs(self):
def test_v2_single_output(self):
responses.add(
responses.POST,
self.wallet_jsonrpc_url,
json=self._read("test_v2_single_output-wallet-00-get_accounts.json"),
status=200,
)
responses.add(
responses.POST,
self.wallet_jsonrpc_url,
json=self._read("test_v2_single_output-wallet-01-query_key.json"),
status=200,
)
responses.add(
responses.POST,
self.wallet_jsonrpc_url,
json=self._read("test_v2_single_output-wallet-02-addresses-account-0.json"),
status=200,
)
responses.add(
responses.POST,
self.daemon_transactions_url,
json=self._read("test_v2_single_output-daemon-00-get_transactions.json"),
status=200,
)
wallet = Wallet(JSONRPCWallet(host="127.0.0.1", port=38083))
daemon = Daemon(JSONRPCDaemon(host="127.0.0.1", port=38081))
tx = daemon.transactions(
"f5aff33df23c1410217f852a3740d1af89a44bdd0b95107e54e161f202f16d3c"
)[0]
outs = tx.outputs(wallet=wallet)
self.assertEqual(len(outs), 2)
self.assertIsNone(outs[0].payment)
self.assertIsNotNone(outs[1].payment)
self.assertEqual(outs[1].amount, Decimal("2.718281828459"))
self.assertEqual(outs[1].index, 4823653)
@responses.activate
def test_multiple_outputs(self):
responses.add(
responses.POST,
self.wallet_jsonrpc_url,
@ -56,6 +93,7 @@ class OutputTestCase(JSONTestCase):
json=self._read("test_multiple_outputs-daemon-00-get_transactions.json"),
status=200,
)
daemon = Daemon(JSONRPCDaemon(host="127.0.0.1", port=38081))
tx = daemon.transactions(
"f79a10256859058b3961254a35a97a3d4d5d40e080c6275a3f9779acde73ca8d"
)[0]

@ -6,6 +6,7 @@ import operator
import re
import sys
from monero import exceptions
from monero.backends.jsonrpc import JSONRPCDaemon
from monero.daemon import Daemon
@ -55,7 +56,10 @@ for tx in txs:
print(
"height: {:s}".format("None" if tx.height is None else "{:d}".format(tx.height))
)
print("size: {:d}".format(tx.size))
try:
print("size: {:d}".format(tx.size))
except exceptions.TransactionWithoutBlob:
print("no blob, cannot check size")
print("JSON:")
print(json.dumps(tx.json, indent=2))
print("-" * 79)

Loading…
Cancel
Save