diff --git a/Connector/bch/apirpc.py b/Connector/bch/apirpc.py index 979d9f0b..b47e7e59 100644 --- a/Connector/bch/apirpc.py +++ b/Connector/bch/apirpc.py @@ -472,8 +472,10 @@ 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, + "txHash": params["txHash"], + "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", "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 9db383c0..25f862b0 100644 --- a/Connector/bch/rpcschemas/gettransaction_response.json +++ b/Connector/bch/rpcschemas/gettransaction_response.json @@ -10,14 +10,23 @@ "null" ], "properties": { + "txHash": { + "type": "string" + }, "blockHash": { "type": [ "string", "null" ] }, + "blockNumber": { + "type": [ + "string", + "null" + ] + }, "fee": { - "type": "number" + "type": "string" }, "transfers": { "type": "array", @@ -30,10 +39,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..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": vinAmount, - "fee": 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": voutAmount, - "fee": round(voutAmount * fee / amount, BTC_CASH_PRECISION) + "amount": str(convertToSatoshi(voutAmount)), + "fee": str(convertToSatoshi(round(voutAmount * fee / amount, BCH_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(convertToSatoshi(utxo["amount"])) } ) diff --git a/Connector/btc/apirpc.py b/Connector/btc/apirpc.py index 6648e82d..3bfe2500 100644 --- a/Connector/btc/apirpc.py +++ b/Connector/btc/apirpc.py @@ -429,8 +429,10 @@ 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, + "txHash": params["txHash"], + "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", "transfers": utils.parseBalancesToTransfers( vinAddressBalances, transaction["details"], diff --git a/Connector/btc/rpcschemas/gettransaction_response.json b/Connector/btc/rpcschemas/gettransaction_response.json index 9db383c0..25f862b0 100644 --- a/Connector/btc/rpcschemas/gettransaction_response.json +++ b/Connector/btc/rpcschemas/gettransaction_response.json @@ -10,14 +10,23 @@ "null" ], "properties": { + "txHash": { + "type": "string" + }, "blockHash": { "type": [ "string", "null" ] }, + "blockNumber": { + "type": [ + "string", + "null" + ] + }, "fee": { - "type": "number" + "type": "string" }, "transfers": { "type": "array", @@ -30,10 +39,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..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": vinAmount, - "fee": 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": voutAmount, - "fee": round(voutAmount * fee / amount, BTC_PRECISION) + "amount": str(convertToSatoshi(voutAmount)), + "fee": str(convertToSatoshi(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(convertToSatoshi(utxo["maount"])) } ) diff --git a/Connector/eth/apirpc.py b/Connector/eth/apirpc.py index 3468074c..bdd367bf 100644 --- a/Connector/eth/apirpc.py +++ b/Connector/eth/apirpc.py @@ -217,15 +217,17 @@ def getTransaction(id, params, config): response = { "transaction": { - "fee": utils.toHex(utils.toWei(transaction["gasPrice"]) * utils.toWei(transaction["gas"])), + "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, "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..f75f3b57 100644 --- a/Connector/eth/rpcschemas/gettransaction_response.json +++ b/Connector/eth/rpcschemas/gettransaction_response.json @@ -7,12 +7,21 @@ "transaction": { "type": "object", "properties": { + "txHash": { + "type": "string" + }, "blockHash": { "type": [ "string", "null" ] }, + "blockNumber": { + "type": [ + "string", + "null" + ] + }, "fee": { "type": "string" }, diff --git a/Connector/tests/eth/test_eth.py b/Connector/tests/eth/test_eth.py index 42d30f2c..ff1f9f01 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"] == 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.toHex(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) + assert transfer[AMOUNT] == str(utils.toWei(expected[VALUE])) + assert transfer["fee"] == str(utils.toWei(expected["gas"]) * utils.toWei(expected["gasPrice"])) def testEstimateGas():