Skip to content
Merged
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
6 changes: 4 additions & 2 deletions Connector/bch/apirpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion Connector/bch/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions Connector/bch/rpcschemas/gettransaction_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -30,10 +39,10 @@
"type": "string"
},
"fee": {
"type": "number"
"type": "string"
},
"amount": {
"type": "number"
"type": "string"
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Connector/bch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]))
}
)

Expand Down
6 changes: 4 additions & 2 deletions Connector/btc/apirpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
15 changes: 12 additions & 3 deletions Connector/btc/rpcschemas/gettransaction_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -30,10 +39,10 @@
"type": "string"
},
"fee": {
"type": "number"
"type": "string"
},
"amount": {
"type": "number"
"type": "string"
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Connector/btc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]))
}
)

Expand Down
8 changes: 5 additions & 3 deletions Connector/eth/apirpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))
}
]
}
Expand Down
9 changes: 9 additions & 0 deletions Connector/eth/rpcschemas/gettransaction_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
"transaction": {
"type": "object",
"properties": {
"txHash": {
"type": "string"
},
"blockHash": {
"type": [
"string",
"null"
]
},
"blockNumber": {
"type": [
"string",
"null"
]
},
"fee": {
"type": "string"
},
Expand Down
6 changes: 3 additions & 3 deletions Connector/tests/eth/test_eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down