forked from LBRYCommunity/lbry-sdk
fix transaction_show
This commit is contained in:
parent
b36a5f9b6b
commit
f7c7cb9535
4 changed files with 46 additions and 2 deletions
|
@ -4,6 +4,7 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
|
from aiorpcx.jsonrpc import CodeMessageError
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
@ -292,8 +293,20 @@ class LbryWalletManager(BaseWalletManager):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_transaction(self, txid: str):
|
async def get_transaction(self, txid):
|
||||||
return self.default_account.ledger.get_transaction(txid)
|
tx = await self.db.get_transaction(txid=txid)
|
||||||
|
if not tx:
|
||||||
|
try:
|
||||||
|
_raw = await self.ledger.network.get_transaction(txid)
|
||||||
|
except CodeMessageError as e:
|
||||||
|
return {'success': False, 'code': e.code, 'message': e.message}
|
||||||
|
# this is a workaround for the current protocol. Should be fixed when lbryum support is over and we
|
||||||
|
# are able to use the modern get_transaction call, which accepts verbose to show height and other fields
|
||||||
|
height = await self.ledger.network.get_transaction_height(txid)
|
||||||
|
tx = self.ledger.transaction_class(unhexlify(_raw))
|
||||||
|
if tx and height > 0:
|
||||||
|
await self.ledger.maybe_verify_transaction(tx, height + 1) # off by one from server side, yes...
|
||||||
|
return tx
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_history(account: BaseAccount, **constraints):
|
async def get_history(account: BaseAccount, **constraints):
|
||||||
|
|
|
@ -20,3 +20,7 @@ class Network(BaseNetwork):
|
||||||
|
|
||||||
def get_claims_for_name(self, name):
|
def get_claims_for_name(self, name):
|
||||||
return self.rpc('blockchain.claimtrie.getclaimsforname', name)
|
return self.rpc('blockchain.claimtrie.getclaimsforname', name)
|
||||||
|
|
||||||
|
def get_transaction_height(self, txid):
|
||||||
|
# 1.0 protocol specific workaround. Newer protocol should use get_transaction with verbose True
|
||||||
|
return self.rpc('blockchain.transaction.get_height', txid)
|
||||||
|
|
|
@ -737,3 +737,29 @@ class ClaimManagement(CommandTestCase):
|
||||||
self.assertEqual(txs2[0]['support_info'][0]['is_tip'], False)
|
self.assertEqual(txs2[0]['support_info'][0]['is_tip'], False)
|
||||||
self.assertEqual(txs2[0]['value'], '0.0')
|
self.assertEqual(txs2[0]['value'], '0.0')
|
||||||
self.assertEqual(txs2[0]['fee'], '-0.0001415')
|
self.assertEqual(txs2[0]['fee'], '-0.0001415')
|
||||||
|
|
||||||
|
|
||||||
|
class TransactionCommandsTestCase(CommandTestCase):
|
||||||
|
|
||||||
|
async def test_transaction_show(self):
|
||||||
|
# local tx
|
||||||
|
result = await self.out(self.daemon.jsonrpc_wallet_send(
|
||||||
|
'5.0', await self.daemon.jsonrpc_address_unused(self.account.id)
|
||||||
|
))
|
||||||
|
await self.confirm_tx(result['txid'])
|
||||||
|
tx = await self.daemon.jsonrpc_transaction_show(result['txid'])
|
||||||
|
self.assertEqual(tx.id, result['txid'])
|
||||||
|
|
||||||
|
# someone's tx
|
||||||
|
change_address = await self.blockchain.get_raw_change_address()
|
||||||
|
sendtxid = await self.blockchain.send_to_address(change_address, 10)
|
||||||
|
tx = await self.daemon.jsonrpc_transaction_show(sendtxid)
|
||||||
|
self.assertEqual(tx.id, sendtxid)
|
||||||
|
self.assertEqual(tx.height, -1)
|
||||||
|
await self.generate(1)
|
||||||
|
tx = await self.daemon.jsonrpc_transaction_show(sendtxid)
|
||||||
|
self.assertEqual(tx.height, self.ledger.headers.height)
|
||||||
|
|
||||||
|
# inexistent
|
||||||
|
result = await self.daemon.jsonrpc_transaction_show('0'*64)
|
||||||
|
self.assertFalse(result['success'])
|
||||||
|
|
1
tox.ini
1
tox.ini
|
@ -23,3 +23,4 @@ commands =
|
||||||
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_regular_supports_and_tip_supports
|
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_regular_supports_and_tip_supports
|
||||||
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_create_update_and_abandon_claim
|
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_create_update_and_abandon_claim
|
||||||
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.EpicAdventuresOfChris45
|
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.EpicAdventuresOfChris45
|
||||||
|
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.TransactionCommandsTestCase
|
||||||
|
|
Loading…
Reference in a new issue