-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/method get transaction only returns in wallet transactions #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
18db7c7
0991160
ad65ece
caad11c
f20a1ad
3c65feb
34d37ad
96ad332
2bd0344
32ecfc0
d0f567e
66cb7c3
0045052
78b679d
b160596
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from logger import logger | ||
| from rpcutils import error | ||
| from rpcutils.rpcconnector import RPCConnector | ||
| from rpcutils.rpcsocketconnector import RPCSocketConnector | ||
| from . import utils | ||
| from .constants import * | ||
|
|
||
|
|
@@ -383,7 +384,6 @@ def getTransactionHex(id, params, config): | |
| @rpcmethod.rpcMethod(coin=COIN_SYMBOL) | ||
| @httpmethod.postHttpMethod(coin=COIN_SYMBOL) | ||
| def getTransaction(id, params, config): | ||
|
|
||
| logger.printInfo(f"Executing RPC method getTransaction with id {id} and params {params}") | ||
|
|
||
| requestSchema, responseSchema = utils.getMethodSchemas(GET_TRANSACTION) | ||
|
|
@@ -393,53 +393,48 @@ def getTransaction(id, params, config): | |
| raise error.RpcBadRequestError(err.message) | ||
|
|
||
| try: | ||
| # Parameters: TransactionId, include_watchonly, verbose | ||
| transaction = RPCConnector.request( | ||
| endpoint=config.bitcoincoreRpcEndpoint, | ||
| id=id, | ||
| method=GET_TRANSACTION_METHOD, | ||
| method="getrawtransaction", | ||
| params=[ | ||
| params["txHash"], | ||
| True, | ||
| True | ||
| ] | ||
| ) | ||
|
|
||
| vinAddressBalances = {} | ||
| transactionAmount = 0 | ||
| isConfirmed = "blockhash" in transaction | ||
bridgedragon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if isConfirmed: | ||
| transactionBlock = RPCConnector.request( | ||
| endpoint=config.bitcoincoreRpcEndpoint, | ||
| id=id, | ||
| method="getblock", | ||
bridgedragon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| params=[transaction["blockhash"], 1] | ||
| ) | ||
| blockNumber = transactionBlock["height"] | ||
| else: | ||
| blockNumber = None | ||
|
|
||
| if "generated" not in transaction: | ||
|
|
||
| for vin in transaction["decoded"]["vin"]: | ||
| inputTransaction = RPCConnector.request( | ||
| endpoint=config.bitcoincoreRpcEndpoint, | ||
| id=id, | ||
| method=GET_TRANSACTION_METHOD, | ||
| params=[ | ||
| vin["txid"], | ||
| True, | ||
| True | ||
| ] | ||
| ) | ||
| transactionDetails = utils.decodeTransactionDetails(transaction, config.bitcoincoreRpcEndpoint) | ||
|
|
||
| transactionAmount += inputTransaction["decoded"]["vout"][vin["vout"]]["value"] | ||
| address = inputTransaction["decoded"]["vout"][vin["vout"]]["scriptPubKey"]["addresses"][0] | ||
| value = inputTransaction["decoded"]["vout"][vin["vout"]]["value"] | ||
| vinAddressBalances[address] = value | ||
| # Converting all transaction details to str | ||
| transactionDetails["fee"] = str(transactionDetails["fee"]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to store the string value, just return the string value in response variable, "fee":str(transactionDetails["fee"])
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree with this, because we are converting all elements in the array at once. I do not want to mix str variables with not-str ones in the same array.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is that the behaviour is the same if you delete this line and add |
||
| for input in transactionDetails["inputs"]: | ||
| input["amount"] = str(input["amount"]) | ||
| for output in transactionDetails["outputs"]: | ||
| output["amount"] = str(output["amount"]) | ||
|
|
||
| response = { | ||
| "transaction": { | ||
| "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"], | ||
| -transaction["fee"] if "generated" not in transaction else 0, | ||
| transactionAmount | ||
| ), | ||
| "data": transaction["decoded"] | ||
| "txId": transaction["txid"], | ||
| "txHash": transaction["hash"], | ||
| "blockNumber": str(blockNumber) if blockNumber is not None else blockNumber, | ||
| "fee": transactionDetails["fee"], | ||
| "inputs": transactionDetails["inputs"], | ||
| "outputs": transactionDetails["outputs"], | ||
| "data": transaction | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.