forked from LBRYCommunity/lbry-sdk
JSON RPC output for TXOs now includes: height, confirmations and valid_signature
This commit is contained in:
parent
f01ad0e4bd
commit
64913c4288
6 changed files with 34 additions and 23 deletions
|
@ -12,6 +12,7 @@ from lbrynet.core.StreamDescriptor import download_sd_blob
|
|||
from lbrynet.file_manager.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory
|
||||
from lbrynet import conf
|
||||
from torba.constants import COIN
|
||||
from lbrynet.wallet.dewies import dewies_to_lbc
|
||||
|
||||
INITIALIZING_CODE = 'initializing'
|
||||
DOWNLOAD_METADATA_CODE = 'downloading_metadata'
|
||||
|
@ -134,10 +135,12 @@ class GetStream:
|
|||
defer.returnValue(downloader)
|
||||
|
||||
def _pay_key_fee(self, address, fee_lbc, name):
|
||||
log.info("Pay key fee %f --> %s", fee_lbc, address)
|
||||
log.info("Pay key fee %s --> %s", dewies_to_lbc(fee_lbc), address)
|
||||
reserved_points = self.wallet.reserve_points(address, fee_lbc)
|
||||
if reserved_points is None:
|
||||
raise InsufficientFundsError('Unable to pay the key fee of %s for %s' % (fee_lbc, name))
|
||||
raise InsufficientFundsError(
|
||||
'Unable to pay the key fee of %s for %s' % (dewies_to_lbc(fee_lbc), name)
|
||||
)
|
||||
return self.wallet.send_points_to_address(reserved_points, fee_lbc)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
|
|
@ -4,11 +4,12 @@ from datetime import datetime
|
|||
from json import JSONEncoder
|
||||
from lbrynet.wallet.transaction import Transaction, Output
|
||||
from lbrynet.wallet.dewies import dewies_to_lbc
|
||||
from lbrynet.wallet.ledger import MainNetLedger
|
||||
|
||||
|
||||
class JSONResponseEncoder(JSONEncoder):
|
||||
|
||||
def __init__(self, *args, ledger, **kwargs):
|
||||
def __init__(self, *args, ledger: MainNetLedger, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.ledger = ledger
|
||||
|
||||
|
@ -38,11 +39,15 @@ class JSONResponseEncoder(JSONEncoder):
|
|||
}
|
||||
|
||||
def encode_output(self, txo):
|
||||
tx_height = txo.tx_ref.height
|
||||
best_height = self.ledger.headers.height
|
||||
output = {
|
||||
'txid': txo.tx_ref.id,
|
||||
'nout': txo.position,
|
||||
'amount': dewies_to_lbc(txo.amount),
|
||||
'address': txo.get_address(self.ledger),
|
||||
'height': tx_height,
|
||||
'confirmations': best_height - tx_height if tx_height > 0 else tx_height
|
||||
}
|
||||
if txo.is_change is not None:
|
||||
output['is_change'] = txo.is_change
|
||||
|
@ -54,22 +59,26 @@ class JSONResponseEncoder(JSONEncoder):
|
|||
'name': txo.claim_name,
|
||||
'claim_id': txo.claim_id,
|
||||
'permanent_url': txo.permanent_url,
|
||||
'is_claim': txo.script.is_claim_name,
|
||||
'is_support': txo.script.is_support_claim,
|
||||
'is_update': txo.script.is_update_claim
|
||||
})
|
||||
|
||||
if txo.script.is_claim_name or txo.script.is_update_claim:
|
||||
output['value'] = txo.claim.claim_dict
|
||||
if txo.claim_name.startswith('@'):
|
||||
output['has_signature'] = txo.has_signature
|
||||
claim = txo.claim
|
||||
output['value'] = claim.claim_dict
|
||||
if claim.has_signature:
|
||||
output['valid_signature'] = None
|
||||
if txo.channel is not None:
|
||||
output['valid_signature'] = claim.validate_signature(
|
||||
txo.get_address(self.ledger), txo.channel.claim
|
||||
)
|
||||
|
||||
if txo.script.is_claim_name:
|
||||
output['category'] = 'claim'
|
||||
output['type'] = 'claim'
|
||||
elif txo.script.is_update_claim:
|
||||
output['category'] = 'update'
|
||||
output['type'] = 'update'
|
||||
elif txo.script.is_support_claim:
|
||||
output['category'] = 'support'
|
||||
output['type'] = 'support'
|
||||
else:
|
||||
output['type'] = 'basic'
|
||||
|
||||
return output
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class WalletDatabase(BaseDatabase):
|
|||
if 'publisherSignature' in txo.claim_dict:
|
||||
channel_ids.add(txo.claim_dict['publisherSignature']['certificateId'])
|
||||
if txo.claim_name.startswith('@') and my_account is not None:
|
||||
txo.signature = my_account.get_certificate_private_key(txo.ref)
|
||||
txo.private_key = my_account.get_certificate_private_key(txo.ref)
|
||||
|
||||
if channel_ids:
|
||||
channels = {
|
||||
|
@ -109,7 +109,7 @@ class WalletDatabase(BaseDatabase):
|
|||
certificates = []
|
||||
if private_key_accounts is not None:
|
||||
for channel in channels:
|
||||
if not channel.has_signature:
|
||||
if not channel.has_private_key:
|
||||
private_key = None
|
||||
for account in private_key_accounts:
|
||||
private_key = account.get_certificate_private_key(channel.ref)
|
||||
|
@ -117,6 +117,6 @@ class WalletDatabase(BaseDatabase):
|
|||
break
|
||||
if private_key is None and exclude_without_key:
|
||||
continue
|
||||
channel.signature = private_key
|
||||
channel.private_key = private_key
|
||||
certificates.append(channel)
|
||||
return certificates
|
||||
|
|
|
@ -355,7 +355,7 @@ class LbryWalletManager(BaseWalletManager):
|
|||
claim_address = yield account.receiving.get_or_create_usable_address()
|
||||
if certificate:
|
||||
claim = claim.sign(
|
||||
certificate.signature, claim_address, certificate.claim_id, curve=SECP256k1
|
||||
certificate.private_key, claim_address, certificate.claim_id, curve=SECP256k1
|
||||
)
|
||||
existing_claims = yield account.get_claims(claim_name=name)
|
||||
if len(existing_claims) == 0:
|
||||
|
|
|
@ -20,19 +20,19 @@ class Output(BaseOutput):
|
|||
script: OutputScript
|
||||
script_class = OutputScript
|
||||
|
||||
__slots__ = '_claim_dict', 'channel', 'signature'
|
||||
__slots__ = '_claim_dict', 'channel', 'private_key'
|
||||
|
||||
def __init__(self, *args, channel: Optional['Output'] = None,
|
||||
signature: Optional[str] = None, **kwargs) -> None:
|
||||
private_key: Optional[str] = None, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self._claim_dict = None
|
||||
self.channel = channel
|
||||
self.signature = signature
|
||||
self.private_key = private_key
|
||||
|
||||
def update_annotations(self, annotated):
|
||||
super().update_annotations(annotated)
|
||||
self.channel = annotated.channel if annotated else None
|
||||
self.signature = annotated.signature if annotated else None
|
||||
self.private_key = annotated.private_key if annotated else None
|
||||
|
||||
def get_fee(self, ledger):
|
||||
name_fee = 0
|
||||
|
@ -81,8 +81,8 @@ class Output(BaseOutput):
|
|||
raise ValueError('No claim associated.')
|
||||
|
||||
@property
|
||||
def has_signature(self):
|
||||
return self.signature is not None
|
||||
def has_private_key(self):
|
||||
return self.private_key is not None
|
||||
|
||||
@classmethod
|
||||
def pay_claim_name_pubkey_hash(
|
||||
|
|
|
@ -196,7 +196,6 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
|||
channels = yield self.out(self.daemon.jsonrpc_channel_list())
|
||||
self.assertEqual(len(channels), 1)
|
||||
self.assertEqual(channels[0]['name'], '@spam')
|
||||
self.assertTrue(channels[0]['has_signature'])
|
||||
|
||||
# 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,
|
||||
|
|
Loading…
Add table
Reference in a new issue