@@ -405,12 +405,19 @@ def getTransaction(id, params, config):
405405 ]
406406 )
407407
408- transactionBlock = RPCConnector .request (
409- endpoint = config .bitcoincoreRpcEndpoint ,
410- id = id ,
411- method = "getblock" ,
412- params = [transaction ["blockhash" ], 1 ]
413- )
408+ isConfirmed = "blockhash" in transaction
409+
410+ if isConfirmed :
411+ transactionBlock = RPCConnector .request (
412+ endpoint = config .bitcoincoreRpcEndpoint ,
413+ id = id ,
414+ method = "getblock" ,
415+ params = [transaction ["blockhash" ], 1 ]
416+ )
417+ blockNumber = transactionBlock ["height" ]
418+ else :
419+ blockNumber = None
420+
414421
415422 transactionDetails = utils .decodeTransactionDetails (transaction , config .bitcoincoreRpcEndpoint )
416423
@@ -425,7 +432,7 @@ def getTransaction(id, params, config):
425432 "transaction" : {
426433 "txId" : transaction ["txid" ],
427434 "txHash" : transaction ["hash" ],
428- "blockNumber" : str (transactionBlock [ "height" ]) ,
435+ "blockNumber" : str (blockNumber ) if blockNumber is not None else blockNumber ,
429436 "fee" : transactionDetails ["fee" ],
430437 "inputs" : transactionDetails ["inputs" ],
431438 "outputs" : transactionDetails ["outputs" ],
0 commit comments