forked from LBRYCommunity/lbry-sdk
+ channel_list command works again but test_commands.py integration test is failing
This commit is contained in:
parent
ff8d37443e
commit
8ab4e3ca49
4 changed files with 49 additions and 6 deletions
|
@ -33,14 +33,14 @@ class Account(BaseAccount):
|
|||
|
||||
@defer.inlineCallbacks
|
||||
def maybe_migrate_certificates(self):
|
||||
failed, succeded, total = 0, 0, 0
|
||||
failed, succeded, done, total = 0, 0, 0, 0
|
||||
for maybe_claim_id in self.certificates.keys():
|
||||
total += 1
|
||||
if ':' not in maybe_claim_id:
|
||||
claims = yield self.ledger.network.get_claims_by_ids(maybe_claim_id)
|
||||
claim = claims[maybe_claim_id]
|
||||
txhash = unhexlify(claim['txid'])[::-1]
|
||||
tx = yield self.ledger.get_transaction(txhash)
|
||||
#txhash = unhexlify(claim['txid'])[::-1]
|
||||
tx = yield self.ledger.get_transaction(claim['txid'])
|
||||
if tx is not None:
|
||||
txo = tx.outputs[claim['nout']]
|
||||
assert txo.script.is_claim_involved,\
|
||||
|
@ -60,7 +60,19 @@ class Account(BaseAccount):
|
|||
maybe_claim_id
|
||||
)
|
||||
failed += 1
|
||||
log.info('Checked: %s, Converted: %s, Failed: %s', total, succeded, failed)
|
||||
else:
|
||||
try:
|
||||
txid, nout = maybe_claim_id.split(':')
|
||||
tx = yield self.ledger.get_transaction(txid)
|
||||
if tx.outputs[int(nout)].script.is_claim_involved:
|
||||
done += 1
|
||||
else:
|
||||
failed += 1
|
||||
except Exception:
|
||||
log.exception("Couldn't verify certificate with look up key: %s", maybe_claim_id)
|
||||
failed += 1
|
||||
|
||||
log.info('Checked: %s, Done: %s, Converted: %s, Failed: %s', total, done, succeded, failed)
|
||||
|
||||
def get_balance(self, confirmations=6, include_claims=False, **constraints):
|
||||
if not include_claims:
|
||||
|
@ -72,6 +84,23 @@ class Account(BaseAccount):
|
|||
constraints.update({'is_claim': 0, 'is_update': 0, 'is_support': 0})
|
||||
return super().get_unspent_outputs(**constraints)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_channels(self):
|
||||
utxos = yield super().get_unspent_outputs(
|
||||
claim_type__any={'is_claim': 1, 'is_update': 1},
|
||||
claim_name__like='@%'
|
||||
)
|
||||
channels = []
|
||||
for utxo in utxos:
|
||||
d = ClaimDict.deserialize(utxo.script.values['claim'])
|
||||
channels.append({
|
||||
'name': utxo.script.values['claim_name'],
|
||||
'txid': utxo.tx_ref.id,
|
||||
'nout': utxo.position,
|
||||
'have_certificate': utxo.ref.id in self.certificates
|
||||
})
|
||||
defer.returnValue(channels)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, ledger, d: dict) -> 'Account':
|
||||
account = super().from_dict(ledger, d)
|
||||
|
|
|
@ -217,6 +217,9 @@ class LbryWalletManager(BaseWalletManager):
|
|||
# TODO: release reserved tx outputs in case anything fails by this point
|
||||
defer.returnValue(tx)
|
||||
|
||||
def channel_list(self):
|
||||
return self.default_account.get_channels()
|
||||
|
||||
def get_certificates(self, name):
|
||||
return self.db.get_certificates(name, [self.default_account], exclude_without_key=True)
|
||||
|
||||
|
|
|
@ -45,13 +45,13 @@ class Transaction(BaseTransaction):
|
|||
return claim_id_hash(self.hash, output_index)
|
||||
|
||||
@classmethod
|
||||
def claim(cls, name, meta, amount, holding_address, funding_accounts, change_account):
|
||||
def claim(cls, name, meta, amount, holding_address, funding_accounts, change_account, spend=None):
|
||||
# type: (bytes, ClaimDict, int, bytes, List[Account], Account) -> defer.Deferred
|
||||
ledger = cls.ensure_all_have_same_ledger(funding_accounts, change_account)
|
||||
claim_output = Output.pay_claim_name_pubkey_hash(
|
||||
amount, name, meta.serialized, ledger.address_to_hash160(holding_address)
|
||||
)
|
||||
return cls.create([], [claim_output], funding_accounts, change_account)
|
||||
return cls.create(spend or [], [claim_output], funding_accounts, change_account)
|
||||
|
||||
@classmethod
|
||||
def abandon(cls, claims: Iterable[Output], funding_accounts: Iterable[Account], change_account: Account):
|
||||
|
|
|
@ -161,6 +161,12 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
|||
self.assertTrue(channel['success'])
|
||||
yield self.d_confirm_tx(channel['txid'])
|
||||
|
||||
# Do we have it locally?
|
||||
channels = yield self.daemon.jsonrpc_channel_list()
|
||||
self.assertEqual(len(channels), 1)
|
||||
self.assertEqual(channels[0]['name'], b'@spam')
|
||||
self.assertTrue(channels[0]['have_certificate'])
|
||||
|
||||
# As the new channel claim travels through the intertubes and makes its
|
||||
# way into the mempool and then a block and then into the claimtrie,
|
||||
# Chris doesn't sit idly by: he checks his balance!
|
||||
|
@ -229,6 +235,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
|||
# giving the link to all his friends.
|
||||
response = yield self.ledger.resolve(0, 10, 'lbry://@spam/hovercraft')
|
||||
self.assertIn('lbry://@spam/hovercraft', response)
|
||||
self.assertIn('claim', response['lbry://@spam/hovercraft'])
|
||||
|
||||
# He goes to tell everyone about it and in the meantime 5 blocks are confirmed.
|
||||
yield self.d_generate(5)
|
||||
|
@ -256,3 +263,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
|||
abandon = yield self.daemon.jsonrpc_claim_abandon(claim1['claim_id'])
|
||||
self.assertTrue(abandon['success'])
|
||||
yield self.d_confirm_tx(abandon['txid'])
|
||||
|
||||
# And checks that the claim doesn't resolve anymore.
|
||||
response = yield self.ledger.resolve(0, 10, 'lbry://@spam/hovercraft')
|
||||
self.assertNotIn('claim', response['lbry://@spam/hovercraft'])
|
||||
|
|
Loading…
Reference in a new issue