From ca1b5ee301aa95070cf6e95f9f2d2330a6d73378 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sat, 5 Feb 2022 17:39:01 +0100 Subject: [PATCH 01/10] GetTransaction bug fix --- Connector/btc/apirpc.py | 3 ++- .../btc/rpcschemas/gettransaction_response.json | 12 +++++++++--- Connector/btc/utils.py | 12 ++++++------ Connector/eth/apirpc.py | 7 ++++--- .../eth/rpcschemas/gettransaction_response.json | 6 ++++++ 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Connector/btc/apirpc.py b/Connector/btc/apirpc.py index 6648e82d..7a1fb004 100644 --- a/Connector/btc/apirpc.py +++ b/Connector/btc/apirpc.py @@ -430,7 +430,8 @@ def getTransaction(id, params, config): response = { "transaction": { "blockHash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, - "fee": -transaction["fee"] if "generated" not in transaction else 0, + "blockNumber": str(transaction["blockheight"]) if transaction["confirmations"] >= 1 else None, + "fee": str(-transaction["fee"]) if "generated" not in transaction else "0", "transfers": utils.parseBalancesToTransfers( vinAddressBalances, transaction["details"], diff --git a/Connector/btc/rpcschemas/gettransaction_response.json b/Connector/btc/rpcschemas/gettransaction_response.json index 9db383c0..55bd22c0 100644 --- a/Connector/btc/rpcschemas/gettransaction_response.json +++ b/Connector/btc/rpcschemas/gettransaction_response.json @@ -16,8 +16,14 @@ "null" ] }, + "blockNumber": { + "type": [ + "string", + "null" + ] + }, "fee": { - "type": "number" + "type": "string" }, "transfers": { "type": "array", @@ -30,10 +36,10 @@ "type": "string" }, "fee": { - "type": "number" + "type": "string" }, "amount": { - "type": "number" + "type": "string" } } } diff --git a/Connector/btc/utils.py b/Connector/btc/utils.py index a25bf4b2..6303c989 100644 --- a/Connector/btc/utils.py +++ b/Connector/btc/utils.py @@ -78,16 +78,16 @@ def parseBalancesToTransfers(vin, vout, fee, amount): transfer = { "from": address, "to": utxo["address"], - "amount": vinAmount, - "fee": round(vinAmount * fee / amount, BTC_PRECISION) + "amount": str(vinAmount), + "fee": str(round(vinAmount * fee / amount, BTC_PRECISION)) } del vin[address] else: transfer = { "from": address, "to": utxo["address"], - "amount": voutAmount, - "fee": round(voutAmount * fee / amount, BTC_PRECISION) + "amount": str(voutAmount), + "fee": str(round(voutAmount * fee / amount, BTC_PRECISION)) } diff = diff + voutAmount - vinAmount @@ -97,8 +97,8 @@ def parseBalancesToTransfers(vin, vout, fee, amount): transfers.append( { "to": utxo["address"], - "fee": 0, - "amount": utxo["amount"] + "fee": "0", + "amount": str(utxo["amount"]) } ) diff --git a/Connector/eth/apirpc.py b/Connector/eth/apirpc.py index 3468074c..9a4d62ef 100644 --- a/Connector/eth/apirpc.py +++ b/Connector/eth/apirpc.py @@ -217,15 +217,16 @@ def getTransaction(id, params, config): response = { "transaction": { - "fee": utils.toHex(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])), + "fee": str(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])), "blockHash": transaction["blockHash"], + "blockNumber": transaction["blockNumber"], "data": transaction, "transfers": [ { "from": transaction["from"], "to": transaction["to"], - "amount": transaction["value"], - "fee": utils.toHex(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])) + "amount": str(utils.toWei(transaction["value"])), + "fee": str(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])) } ] } diff --git a/Connector/eth/rpcschemas/gettransaction_response.json b/Connector/eth/rpcschemas/gettransaction_response.json index 0f6a6cdb..09ccb109 100644 --- a/Connector/eth/rpcschemas/gettransaction_response.json +++ b/Connector/eth/rpcschemas/gettransaction_response.json @@ -13,6 +13,12 @@ "null" ] }, + "blockNumber": { + "type": [ + "string", + "null" + ] + }, "fee": { "type": "string" }, From 937cd04bd28612a8a0f3141e528433fa02daaf74 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sat, 5 Feb 2022 18:10:18 +0100 Subject: [PATCH 02/10] blockNumber stringify --- Connector/eth/apirpc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connector/eth/apirpc.py b/Connector/eth/apirpc.py index 9a4d62ef..0f9aaf05 100644 --- a/Connector/eth/apirpc.py +++ b/Connector/eth/apirpc.py @@ -219,7 +219,7 @@ def getTransaction(id, params, config): "transaction": { "fee": str(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])), "blockHash": transaction["blockHash"], - "blockNumber": transaction["blockNumber"], + "blockNumber": str(int(transaction["blockNumber"], 16)) if transaction["blockNumber"] is not None else None, "data": transaction, "transfers": [ { From e9e0f6bdb2846796106ef186d2b30c978ddbdd30 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sat, 5 Feb 2022 18:37:49 +0100 Subject: [PATCH 03/10] BCH getTransaction bug fix --- Connector/bch/apirpc.py | 3 ++- .../bch/rpcschemas/gettransaction_response.json | 12 +++++++++--- Connector/bch/utils.py | 12 ++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Connector/bch/apirpc.py b/Connector/bch/apirpc.py index 979d9f0b..8d8fe9d7 100644 --- a/Connector/bch/apirpc.py +++ b/Connector/bch/apirpc.py @@ -473,7 +473,8 @@ def getTransaction(id, params, config): response = { "transaction": { "blockHash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, - "fee": -transaction["fee"] if "generated" not in transaction else 0, + "blockNumber": str(transaction["blockheight"]) if transaction["confirmations"] >= 1 else None, + "fee": str(-transaction["fee"]) if "generated" not in transaction else "0", "transfers": utils.parseBalancesToTransfers( vinAddressBalances, transaction["details"], diff --git a/Connector/bch/rpcschemas/gettransaction_response.json b/Connector/bch/rpcschemas/gettransaction_response.json index 9db383c0..55bd22c0 100644 --- a/Connector/bch/rpcschemas/gettransaction_response.json +++ b/Connector/bch/rpcschemas/gettransaction_response.json @@ -16,8 +16,14 @@ "null" ] }, + "blockNumber": { + "type": [ + "string", + "null" + ] + }, "fee": { - "type": "number" + "type": "string" }, "transfers": { "type": "array", @@ -30,10 +36,10 @@ "type": "string" }, "fee": { - "type": "number" + "type": "string" }, "amount": { - "type": "number" + "type": "string" } } } diff --git a/Connector/bch/utils.py b/Connector/bch/utils.py index 0ff93b5e..7fbfdfb7 100644 --- a/Connector/bch/utils.py +++ b/Connector/bch/utils.py @@ -37,16 +37,16 @@ def parseBalancesToTransfers(vin, vout, fee, amount): transfer = { "from": address, "to": utxo["address"], - "amount": vinAmount, - "fee": round(vinAmount * fee / amount, BTC_CASH_PRECISION) + "amount": str(vinAmount), + "fee": str(round(vinAmount * fee / amount, BTC_CASH_PRECISION)) } del vin[address] else: transfer = { "from": address, "to": utxo["address"], - "amount": voutAmount, - "fee": round(voutAmount * fee / amount, BTC_CASH_PRECISION) + "amount": str(voutAmount), + "fee": str(round(voutAmount * fee / amount, BTC_CASH_PRECISION)) } diff = diff + voutAmount - vinAmount @@ -56,8 +56,8 @@ def parseBalancesToTransfers(vin, vout, fee, amount): transfers.append( { "to": utxo["address"], - "fee": 0, - "amount": utxo["amount"] + "fee": "0", + "amount": str(utxo["amount"]) } ) From f46faaae2fc978de311b20f13426927c039ad30c Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sun, 6 Feb 2022 19:39:57 +0100 Subject: [PATCH 04/10] Eth getTransaction returns txHash --- Connector/eth/apirpc.py | 1 + Connector/eth/rpcschemas/gettransaction_response.json | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Connector/eth/apirpc.py b/Connector/eth/apirpc.py index 0f9aaf05..bdd367bf 100644 --- a/Connector/eth/apirpc.py +++ b/Connector/eth/apirpc.py @@ -217,6 +217,7 @@ def getTransaction(id, params, config): response = { "transaction": { + "txHash": params["txHash"], "fee": str(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])), "blockHash": transaction["blockHash"], "blockNumber": str(int(transaction["blockNumber"], 16)) if transaction["blockNumber"] is not None else None, diff --git a/Connector/eth/rpcschemas/gettransaction_response.json b/Connector/eth/rpcschemas/gettransaction_response.json index 09ccb109..f75f3b57 100644 --- a/Connector/eth/rpcschemas/gettransaction_response.json +++ b/Connector/eth/rpcschemas/gettransaction_response.json @@ -7,6 +7,9 @@ "transaction": { "type": "object", "properties": { + "txHash": { + "type": "string" + }, "blockHash": { "type": [ "string", From 25d70f4eedaf53bce46777fe438f40472e4fefc0 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sun, 6 Feb 2022 20:08:14 +0100 Subject: [PATCH 05/10] BTC getTransaction in satoshi unit --- Connector/btc/apirpc.py | 5 +++-- Connector/btc/rpcschemas/gettransaction_response.json | 3 +++ Connector/btc/utils.py | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Connector/btc/apirpc.py b/Connector/btc/apirpc.py index 7a1fb004..3bfe2500 100644 --- a/Connector/btc/apirpc.py +++ b/Connector/btc/apirpc.py @@ -429,9 +429,10 @@ def getTransaction(id, params, config): response = { "transaction": { - "blockHash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, + "txHash": params["txHash"], + "blockhash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, "blockNumber": str(transaction["blockheight"]) if transaction["confirmations"] >= 1 else None, - "fee": str(-transaction["fee"]) if "generated" not in transaction else "0", + "fee": str(utils.convertToSatoshi(-transaction["fee"])) if "generated" not in transaction else "0", "transfers": utils.parseBalancesToTransfers( vinAddressBalances, transaction["details"], diff --git a/Connector/btc/rpcschemas/gettransaction_response.json b/Connector/btc/rpcschemas/gettransaction_response.json index 55bd22c0..25f862b0 100644 --- a/Connector/btc/rpcschemas/gettransaction_response.json +++ b/Connector/btc/rpcschemas/gettransaction_response.json @@ -10,6 +10,9 @@ "null" ], "properties": { + "txHash": { + "type": "string" + }, "blockHash": { "type": [ "string", diff --git a/Connector/btc/utils.py b/Connector/btc/utils.py index 6303c989..8026a073 100644 --- a/Connector/btc/utils.py +++ b/Connector/btc/utils.py @@ -78,16 +78,16 @@ def parseBalancesToTransfers(vin, vout, fee, amount): transfer = { "from": address, "to": utxo["address"], - "amount": str(vinAmount), - "fee": str(round(vinAmount * fee / amount, BTC_PRECISION)) + "amount": str(convertToSatoshi(vinAmount)), + "fee": str(convertToSatoshi(round(vinAmount * fee / amount, BTC_PRECISION))) } del vin[address] else: transfer = { "from": address, "to": utxo["address"], - "amount": str(voutAmount), - "fee": str(round(voutAmount * fee / amount, BTC_PRECISION)) + "amount": str(convertToSatoshi(voutAmount)), + "fee": str(convertToSatoshi(round(voutAmount * fee / amount, BTC_PRECISION))) } diff = diff + voutAmount - vinAmount @@ -98,7 +98,7 @@ def parseBalancesToTransfers(vin, vout, fee, amount): { "to": utxo["address"], "fee": "0", - "amount": str(utxo["amount"]) + "amount": str(convertToSatoshi(utxo["maount"])) } ) From 2121f6631e1b6d1494720c7658d4547595e5b8b4 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sun, 6 Feb 2022 20:21:42 +0100 Subject: [PATCH 06/10] BCH GetTransaction in satoshi unit --- Connector/bch/apirpc.py | 7 +++++++ Connector/bch/constants.py | 2 +- Connector/bch/rpcschemas/gettransaction_response.json | 3 +++ Connector/bch/utils.py | 10 +++++----- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Connector/bch/apirpc.py b/Connector/bch/apirpc.py index 8d8fe9d7..423cd179 100644 --- a/Connector/bch/apirpc.py +++ b/Connector/bch/apirpc.py @@ -472,9 +472,16 @@ def getTransaction(id, params, config): response = { "transaction": { +<<<<<<< HEAD "blockHash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, "blockNumber": str(transaction["blockheight"]) if transaction["confirmations"] >= 1 else None, "fee": str(-transaction["fee"]) if "generated" not in transaction else "0", +======= + "txHash": params["txHash"], + BLOCK_HASH: transaction["blockhash"] if transaction[CONFIRMATIONS] >= 1 else None, + "blockNumber": str(transaction["blockheight"]) if transaction[CONFIRMATIONS] >= 1 else None, + "fee": str(utils.convertToSatoshi(-transaction["fee"])) if "generated" not in transaction else "0", +>>>>>>> d92f934 (BCH GetTransaction in satoshi unit) "transfers": utils.parseBalancesToTransfers( vinAddressBalances, transaction["details"], diff --git a/Connector/bch/constants.py b/Connector/bch/constants.py index 881ff44a..7cbd6596 100644 --- a/Connector/bch/constants.py +++ b/Connector/bch/constants.py @@ -16,7 +16,7 @@ GET_BLOCKCHAIN_INFO = "getblockchaininfo" SYNCING = "syncing" -BTC_CASH_PRECISION = 8 +BCH_PRECISION = 8 VERBOSITY_LESS_MODE = 0 VERBOSITY_DEFAULT_MODE = 1 diff --git a/Connector/bch/rpcschemas/gettransaction_response.json b/Connector/bch/rpcschemas/gettransaction_response.json index 55bd22c0..25f862b0 100644 --- a/Connector/bch/rpcschemas/gettransaction_response.json +++ b/Connector/bch/rpcschemas/gettransaction_response.json @@ -10,6 +10,9 @@ "null" ], "properties": { + "txHash": { + "type": "string" + }, "blockHash": { "type": [ "string", diff --git a/Connector/bch/utils.py b/Connector/bch/utils.py index 7fbfdfb7..49710bca 100644 --- a/Connector/bch/utils.py +++ b/Connector/bch/utils.py @@ -37,16 +37,16 @@ def parseBalancesToTransfers(vin, vout, fee, amount): transfer = { "from": address, "to": utxo["address"], - "amount": str(vinAmount), - "fee": str(round(vinAmount * fee / amount, BTC_CASH_PRECISION)) + "amount": str(convertToSatoshi(vinAmount)), + "fee": str(convertToSatoshi(round(vinAmount * fee / amount, BCH_PRECISION))) } del vin[address] else: transfer = { "from": address, "to": utxo["address"], - "amount": str(voutAmount), - "fee": str(round(voutAmount * fee / amount, BTC_CASH_PRECISION)) + "amount": str(convertToSatoshi(voutAmount)), + "fee": str(convertToSatoshi(round(voutAmount * fee / amount, BCH_PRECISION))) } diff = diff + voutAmount - vinAmount @@ -57,7 +57,7 @@ def parseBalancesToTransfers(vin, vout, fee, amount): { "to": utxo["address"], "fee": "0", - "amount": str(utxo["amount"]) + "amount": str(convertToSatoshi(utxo["amount"])) } ) From deecc385e5235471825703046b4bdd23e7a1a705 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sun, 6 Feb 2022 20:29:28 +0100 Subject: [PATCH 07/10] ETH GetTransaction test --- Connector/tests/eth/test_eth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Connector/tests/eth/test_eth.py b/Connector/tests/eth/test_eth.py index 42d30f2c..108ff5d3 100644 --- a/Connector/tests/eth/test_eth.py +++ b/Connector/tests/eth/test_eth.py @@ -143,13 +143,13 @@ def testGetTransaction(): assert json.dumps(got[TRANSACTION]["data"], sort_keys=True) == json.dumps(expected, sort_keys=True) assert got[TRANSACTION][BLOCK_HASH] == expected[BLOCK_HASH] - assert got[TRANSACTION]["fee"] == utils.toHex(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) + assert got[TRANSACTION]["fee"] == utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"]) for transfer in got[TRANSACTION]["transfers"]: assert transfer[TO] == expected[TO] assert transfer[FROM] == expected[FROM] assert transfer[AMOUNT] == expected[VALUE] - assert transfer["fee"] == utils.toHex(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) + assert transfer["fee"] == utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"]) def testEstimateGas(): From 10e8739b27a75e4b342d758c8da8b43514b6f7e4 Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sun, 6 Feb 2022 20:35:07 +0100 Subject: [PATCH 08/10] ETH GetTransaction test bug fix --- Connector/tests/eth/test_eth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Connector/tests/eth/test_eth.py b/Connector/tests/eth/test_eth.py index 108ff5d3..9acd950f 100644 --- a/Connector/tests/eth/test_eth.py +++ b/Connector/tests/eth/test_eth.py @@ -143,13 +143,13 @@ def testGetTransaction(): assert json.dumps(got[TRANSACTION]["data"], sort_keys=True) == json.dumps(expected, sort_keys=True) assert got[TRANSACTION][BLOCK_HASH] == expected[BLOCK_HASH] - assert got[TRANSACTION]["fee"] == utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"]) + assert got[TRANSACTION]["fee"] == str(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) for transfer in got[TRANSACTION]["transfers"]: assert transfer[TO] == expected[TO] assert transfer[FROM] == expected[FROM] assert transfer[AMOUNT] == expected[VALUE] - assert transfer["fee"] == utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"]) + assert transfer["fee"] == str(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) def testEstimateGas(): From 2dbc2ecdbee3e5044bfbef66a3cdf828b374c36e Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Sun, 6 Feb 2022 20:38:41 +0100 Subject: [PATCH 09/10] ETH GetTransaction test bug fix --- Connector/tests/eth/test_eth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Connector/tests/eth/test_eth.py b/Connector/tests/eth/test_eth.py index 9acd950f..ff1f9f01 100644 --- a/Connector/tests/eth/test_eth.py +++ b/Connector/tests/eth/test_eth.py @@ -148,7 +148,7 @@ def testGetTransaction(): for transfer in got[TRANSACTION]["transfers"]: assert transfer[TO] == expected[TO] assert transfer[FROM] == expected[FROM] - assert transfer[AMOUNT] == expected[VALUE] + assert transfer[AMOUNT] == str(utils.toWei(expected[VALUE])) assert transfer["fee"] == str(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) From f824208d166d39d1d7ed50c6391e39a71aca294e Mon Sep 17 00:00:00 2001 From: swapper-pegasus Date: Tue, 22 Feb 2022 19:53:47 +0100 Subject: [PATCH 10/10] Conflict resolved --- Connector/bch/apirpc.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Connector/bch/apirpc.py b/Connector/bch/apirpc.py index 423cd179..b47e7e59 100644 --- a/Connector/bch/apirpc.py +++ b/Connector/bch/apirpc.py @@ -472,16 +472,10 @@ def getTransaction(id, params, config): response = { "transaction": { -<<<<<<< HEAD - "blockHash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, - "blockNumber": str(transaction["blockheight"]) if transaction["confirmations"] >= 1 else None, - "fee": str(-transaction["fee"]) if "generated" not in transaction else "0", -======= "txHash": params["txHash"], - BLOCK_HASH: transaction["blockhash"] if transaction[CONFIRMATIONS] >= 1 else None, - "blockNumber": str(transaction["blockheight"]) if transaction[CONFIRMATIONS] >= 1 else None, + "blockhash": transaction["blockhash"] if transaction["confirmations"] >= 1 else None, + "blockNumber": str(transaction["blockheight"]) if transaction["confirmations"] >= 1 else None, "fee": str(utils.convertToSatoshi(-transaction["fee"])) if "generated" not in transaction else "0", ->>>>>>> d92f934 (BCH GetTransaction in satoshi unit) "transfers": utils.parseBalancesToTransfers( vinAddressBalances, transaction["details"],