forked from LBRYCommunity/lbry-sdk
daemon json rpc return type docs
This commit is contained in:
parent
362ed3f1c8
commit
93220c3874
2 changed files with 143 additions and 106 deletions
|
@ -105,6 +105,15 @@ SHORT_ID_LEN = 20
|
||||||
MAX_UPDATE_FEE_ESTIMATE = 0.3
|
MAX_UPDATE_FEE_ESTIMATE = 0.3
|
||||||
|
|
||||||
|
|
||||||
|
def encode_pagination_doc(items):
|
||||||
|
return {
|
||||||
|
"page": "Page number of the current items.",
|
||||||
|
"page_size": "Number of items to show on a page.",
|
||||||
|
"total_pages": "Total number of pages.",
|
||||||
|
"items": [items],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def maybe_paginate(get_records: Callable, get_record_count: Callable,
|
async def maybe_paginate(get_records: Callable, get_record_count: Callable,
|
||||||
page: Optional[int], page_size: Optional[int], **constraints):
|
page: Optional[int], page_size: Optional[int], **constraints):
|
||||||
if None not in (page, page_size):
|
if None not in (page, page_size):
|
||||||
|
@ -932,8 +941,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
LBC account is specified (default: false)
|
LBC account is specified (default: false)
|
||||||
--show_seed : (bool) show the seed for the account
|
--show_seed : (bool) show the seed for the account
|
||||||
|
|
||||||
Returns:
|
Returns: {List[Account]}
|
||||||
(map) balance of account(s)
|
|
||||||
"""
|
"""
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'confirmations': confirmations,
|
'confirmations': confirmations,
|
||||||
|
@ -984,9 +992,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--public_key=<public_key> : (str) public key for new account
|
--public_key=<public_key> : (str) public key for new account
|
||||||
--single_key : (bool) create single key account, default is multi-key
|
--single_key : (bool) create single key account, default is multi-key
|
||||||
|
|
||||||
Returns:
|
Returns: {Account}
|
||||||
(map) added account details
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
account = LBCAccount.from_dict(
|
account = LBCAccount.from_dict(
|
||||||
self.ledger, self.default_wallet, {
|
self.ledger, self.default_wallet, {
|
||||||
|
@ -1005,12 +1011,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
|
|
||||||
result = account.to_dict()
|
return account
|
||||||
result['id'] = account.id
|
|
||||||
result['status'] = 'added'
|
|
||||||
result.pop('certificates', None)
|
|
||||||
result['is_default'] = self.default_wallet.accounts[0] == account
|
|
||||||
return result
|
|
||||||
|
|
||||||
@requires("wallet")
|
@requires("wallet")
|
||||||
async def jsonrpc_account_create(self, account_name, single_key=False):
|
async def jsonrpc_account_create(self, account_name, single_key=False):
|
||||||
|
@ -1025,9 +1026,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_name=<account_name> : (str) name of the account to create
|
--account_name=<account_name> : (str) name of the account to create
|
||||||
--single_key : (bool) create single key account, default is multi-key
|
--single_key : (bool) create single key account, default is multi-key
|
||||||
|
|
||||||
Returns:
|
Returns: {Account}
|
||||||
(map) new account details
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
account = LBCAccount.generate(
|
account = LBCAccount.generate(
|
||||||
self.ledger, self.default_wallet, account_name, {
|
self.ledger, self.default_wallet, account_name, {
|
||||||
|
@ -1040,12 +1039,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
|
|
||||||
result = account.to_dict()
|
return account
|
||||||
result['id'] = account.id
|
|
||||||
result['status'] = 'created'
|
|
||||||
result.pop('certificates', None)
|
|
||||||
result['is_default'] = self.default_wallet.accounts[0] == account
|
|
||||||
return result
|
|
||||||
|
|
||||||
@requires("wallet")
|
@requires("wallet")
|
||||||
def jsonrpc_account_remove(self, account_id):
|
def jsonrpc_account_remove(self, account_id):
|
||||||
|
@ -1058,18 +1052,12 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
Options:
|
Options:
|
||||||
--account_id=<account_id> : (str) id of the account to remove
|
--account_id=<account_id> : (str) id of the account to remove
|
||||||
|
|
||||||
Returns:
|
Returns: {Account}
|
||||||
(map) details of removed account
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_error(account_id)
|
account = self.get_account_or_error(account_id)
|
||||||
self.default_wallet.accounts.remove(account)
|
self.default_wallet.accounts.remove(account)
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
result = account.to_dict()
|
return account
|
||||||
result['id'] = account.id
|
|
||||||
result['status'] = 'removed'
|
|
||||||
result.pop('certificates', None)
|
|
||||||
return result
|
|
||||||
|
|
||||||
@requires("wallet")
|
@requires("wallet")
|
||||||
def jsonrpc_account_set(
|
def jsonrpc_account_set(
|
||||||
|
@ -1095,9 +1083,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--change_max_uses=<change_max_uses> : (int) set the maximum number of times to
|
--change_max_uses=<change_max_uses> : (int) set the maximum number of times to
|
||||||
use a change address
|
use a change address
|
||||||
|
|
||||||
Returns:
|
Returns: {Account}
|
||||||
(map) updated account details
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_error(account_id)
|
account = self.get_account_or_error(account_id)
|
||||||
change_made = False
|
change_made = False
|
||||||
|
@ -1127,11 +1113,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
account.modified_on = time.time()
|
account.modified_on = time.time()
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
|
|
||||||
result = account.to_dict()
|
return account
|
||||||
result['id'] = account.id
|
|
||||||
result.pop('certificates', None)
|
|
||||||
result['is_default'] = self.default_wallet.accounts[0] == account
|
|
||||||
return result
|
|
||||||
|
|
||||||
@requires(WALLET_COMPONENT)
|
@requires(WALLET_COMPONENT)
|
||||||
def jsonrpc_account_unlock(self, password, account_id=None):
|
def jsonrpc_account_unlock(self, password, account_id=None):
|
||||||
|
@ -1250,9 +1232,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--outputs=<outputs> : (int) split payment across many outputs, default: 1.
|
--outputs=<outputs> : (int) split payment across many outputs, default: 1.
|
||||||
--broadcast : (bool) actually broadcast the transaction, default: false.
|
--broadcast : (bool) actually broadcast the transaction, default: false.
|
||||||
|
|
||||||
Returns:
|
Returns: {Transaction}
|
||||||
(map) transaction performing requested action
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
to_account = self.get_account_or_default(to_account, 'to_account')
|
to_account = self.get_account_or_default(to_account, 'to_account')
|
||||||
from_account = self.get_account_or_default(from_account, 'from_account')
|
from_account = self.get_account_or_default(from_account, 'from_account')
|
||||||
|
@ -1278,7 +1258,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) account to fund the transaction
|
--account_id=<account_id> : (str) account to fund the transaction
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
Returns:
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
|
||||||
|
@ -1414,8 +1394,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
Returns:
|
Returns: {Paginated[Address]}
|
||||||
List of wallet addresses
|
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
return maybe_paginate(
|
return maybe_paginate(
|
||||||
|
@ -1436,8 +1415,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
Options:
|
Options:
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
|
|
||||||
Returns:
|
Returns: {Address}
|
||||||
(str) Unused wallet address in base58
|
|
||||||
"""
|
"""
|
||||||
return self.get_account_or_default(account_id).receiving.get_or_create_usable_address()
|
return self.get_account_or_default(account_id).receiving.get_or_create_usable_address()
|
||||||
|
|
||||||
|
@ -1476,49 +1454,13 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--sort=<sort_by> : (str) field to sort by (one of the above filter fields)
|
--sort=<sort_by> : (str) field to sort by (one of the above filter fields)
|
||||||
--comparison=<comparison> : (str) logical comparision, (eq | ne | g | ge | l | le)
|
--comparison=<comparison> : (str) logical comparision, (eq | ne | g | ge | l | le)
|
||||||
|
|
||||||
Returns:
|
Returns: {List[File]}
|
||||||
(list) List of files
|
|
||||||
|
|
||||||
[
|
|
||||||
{
|
|
||||||
'completed': (bool) true if download is completed,
|
|
||||||
'file_name': (str) name of file,
|
|
||||||
'download_directory': (str) download directory,
|
|
||||||
'points_paid': (float) credit paid to download file,
|
|
||||||
'stopped': (bool) true if download is stopped,
|
|
||||||
'stream_hash': (str) stream hash of file,
|
|
||||||
'stream_name': (str) stream name ,
|
|
||||||
'suggested_file_name': (str) suggested file name,
|
|
||||||
'sd_hash': (str) sd hash of file,
|
|
||||||
'download_path': (str) download path of file,
|
|
||||||
'mime_type': (str) mime type of file,
|
|
||||||
'key': (str) key attached to file,
|
|
||||||
'total_bytes_lower_bound': (int) lower bound file size in bytes,
|
|
||||||
'total_bytes': (int) file upper bound size in bytes,
|
|
||||||
'written_bytes': (int) written size in bytes,
|
|
||||||
'blobs_completed': (int) number of fully downloaded blobs,
|
|
||||||
'blobs_in_stream': (int) total blobs on stream,
|
|
||||||
'blobs_remaining': (int) total blobs remaining to download,
|
|
||||||
'status': (str) downloader status
|
|
||||||
'claim_id': (str) None if claim is not found else the claim id,
|
|
||||||
'txid': (str) None if claim is not found else the transaction id,
|
|
||||||
'nout': (int) None if claim is not found else the transaction output index,
|
|
||||||
'outpoint': (str) None if claim is not found else the tx and output,
|
|
||||||
'metadata': (dict) None if claim is not found else the claim metadata,
|
|
||||||
'channel_claim_id': (str) None if claim is not found or not signed,
|
|
||||||
'channel_name': (str) None if claim is not found or not signed,
|
|
||||||
'claim_name': (str) None if claim is not found else the claim name
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
sort = sort or 'rowid'
|
sort = sort or 'rowid'
|
||||||
comparison = comparison or 'eq'
|
comparison = comparison or 'eq'
|
||||||
return [
|
return self.stream_manager.get_filtered_streams(
|
||||||
stream.as_dict() for stream in self.stream_manager.get_filtered_streams(
|
|
||||||
sort, reverse, comparison, **kwargs
|
sort, reverse, comparison, **kwargs
|
||||||
)
|
)
|
||||||
]
|
|
||||||
|
|
||||||
@requires(STREAM_MANAGER_COMPONENT)
|
@requires(STREAM_MANAGER_COMPONENT)
|
||||||
async def jsonrpc_file_set_status(self, status, **kwargs):
|
async def jsonrpc_file_set_status(self, status, **kwargs):
|
||||||
|
@ -1632,6 +1574,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) id of the account to query
|
--account_id=<account_id> : (str) id of the account to query
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
|
Returns: {Paginated[Output]}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
return maybe_paginate(
|
return maybe_paginate(
|
||||||
|
@ -1662,6 +1606,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--winning : (bool) limit to winning claims
|
--winning : (bool) limit to winning claims
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
|
Returns: {Paginated[Output]}
|
||||||
"""
|
"""
|
||||||
claims = []
|
claims = []
|
||||||
if name is not None:
|
if name is not None:
|
||||||
|
@ -1771,6 +1717,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--claim_address=<claim_address>: (str) address where the channel is sent to, if not specified
|
--claim_address=<claim_address>: (str) address where the channel is sent to, if not specified
|
||||||
it will be determined automatically from the account
|
it will be determined automatically from the account
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
self.valid_channel_name_or_error(name)
|
self.valid_channel_name_or_error(name)
|
||||||
|
@ -1879,6 +1827,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--claim_address=<claim_address>: (str) address where the channel is sent
|
--claim_address=<claim_address>: (str) address where the channel is sent
|
||||||
--new_signing_key : (bool) generate a new signing key, will invalidate all previous publishes
|
--new_signing_key : (bool) generate a new signing key, will invalidate all previous publishes
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
|
||||||
|
@ -1950,6 +1900,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
--blocking : (bool) wait until abandon is in mempool
|
--blocking : (bool) wait until abandon is in mempool
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
|
||||||
|
@ -1991,9 +1943,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
Returns:
|
Returns: {Paginated[Output]}
|
||||||
(list) ClaimDict, includes 'is_mine' field to indicate if the certificate claim
|
|
||||||
is in the wallet.
|
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
return maybe_paginate(
|
return maybe_paginate(
|
||||||
|
@ -2142,6 +2092,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
|
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
|
||||||
it will be determined automatically from the account
|
it will be determined automatically from the account
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
self.valid_stream_name_or_error(name)
|
self.valid_stream_name_or_error(name)
|
||||||
account = self.get_account_or_default(kwargs.get('account_id'))
|
account = self.get_account_or_default(kwargs.get('account_id'))
|
||||||
|
@ -2262,6 +2214,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
|
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
|
||||||
it will be determined automatically from the account
|
it will be determined automatically from the account
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
self.valid_stream_name_or_error(name)
|
self.valid_stream_name_or_error(name)
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
@ -2408,6 +2362,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
|
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
|
||||||
it will be determined automatically from the account
|
it will be determined automatically from the account
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
|
||||||
|
@ -2486,6 +2442,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
--blocking : (bool) wait until abandon is in mempool
|
--blocking : (bool) wait until abandon is in mempool
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
|
||||||
|
@ -2526,6 +2484,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) id of the account to query
|
--account_id=<account_id> : (str) id of the account to query
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
|
Returns: {Paginated[Output]}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
return maybe_paginate(
|
return maybe_paginate(
|
||||||
|
@ -2572,6 +2532,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--tip : (bool) send support to claim owner, default: false.
|
--tip : (bool) send support to claim owner, default: false.
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
amount = self.get_dewies_or_error("amount", amount)
|
amount = self.get_dewies_or_error("amount", amount)
|
||||||
|
@ -2614,6 +2576,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) id of the account to query
|
--account_id=<account_id> : (str) id of the account to query
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
|
Returns: {Paginated[Output]}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
return maybe_paginate(
|
return maybe_paginate(
|
||||||
|
@ -2642,6 +2606,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
--blocking : (bool) wait until abandon is in mempool
|
--blocking : (bool) wait until abandon is in mempool
|
||||||
|
|
||||||
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
|
|
||||||
|
@ -2764,8 +2730,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
Options:
|
Options:
|
||||||
--txid=<txid> : (str) txid of the transaction
|
--txid=<txid> : (str) txid of the transaction
|
||||||
|
|
||||||
Returns:
|
Returns: {Transaction}
|
||||||
(dict) JSON formatted transaction
|
|
||||||
"""
|
"""
|
||||||
return self.wallet_manager.get_transaction(txid)
|
return self.wallet_manager.get_transaction(txid)
|
||||||
|
|
||||||
|
@ -2787,22 +2752,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
--page=<page> : (int) page to return during paginating
|
--page=<page> : (int) page to return during paginating
|
||||||
--page_size=<page_size> : (int) number of items on page during pagination
|
--page_size=<page_size> : (int) number of items on page during pagination
|
||||||
|
|
||||||
Returns:
|
Returns: {Paginated[Output]}
|
||||||
(list) List of unspent transaction outputs (UTXOs)
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"address": (str) the output address
|
|
||||||
"amount": (float) unspent amount
|
|
||||||
"height": (int) block height
|
|
||||||
"is_claim": (bool) is the tx a claim
|
|
||||||
"is_coinbase": (bool) is the tx a coinbase tx
|
|
||||||
"is_support": (bool) is the tx a support
|
|
||||||
"is_update": (bool) is the tx an update
|
|
||||||
"nout": (int) nout of the output
|
|
||||||
"txid": (str) txid of the output
|
|
||||||
},
|
|
||||||
...
|
|
||||||
]
|
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
return maybe_paginate(
|
return maybe_paginate(
|
||||||
|
|
|
@ -5,14 +5,86 @@ from datetime import datetime
|
||||||
from json import JSONEncoder
|
from json import JSONEncoder
|
||||||
from ecdsa import BadSignatureError
|
from ecdsa import BadSignatureError
|
||||||
from lbrynet.schema.claim import Claim
|
from lbrynet.schema.claim import Claim
|
||||||
from lbrynet.wallet.ledger import MainNetLedger
|
from lbrynet.wallet.ledger import MainNetLedger, Account
|
||||||
from lbrynet.wallet.transaction import Transaction, Output
|
from lbrynet.wallet.transaction import Transaction, Output
|
||||||
from lbrynet.wallet.dewies import dewies_to_lbc
|
from lbrynet.wallet.dewies import dewies_to_lbc
|
||||||
|
from lbrynet.stream.managed_stream import ManagedStream
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def encode_txo_doc():
|
||||||
|
return {
|
||||||
|
'txid': "hash of transaction in hex",
|
||||||
|
'height': "block where transaction was recorded",
|
||||||
|
'nout': "position in the transaction",
|
||||||
|
'amount': "value of the txo as a decimal",
|
||||||
|
'address': "address of who can spend the txo",
|
||||||
|
'confirmations': "number of confirmed blocks"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def encode_tx_doc():
|
||||||
|
return {
|
||||||
|
'txid': "hash of transaction in hex",
|
||||||
|
'height': "block where transaction was recorded",
|
||||||
|
'inputs': [encode_txo_doc()],
|
||||||
|
'outputs': [encode_txo_doc()],
|
||||||
|
'total_input': "sum of inputs as a decimal",
|
||||||
|
'total_output': "sum of outputs, sans fee, as a decimal",
|
||||||
|
'total_fee': "fee amount",
|
||||||
|
'hex': "entire transaction encoded in hex",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def encode_account_doc():
|
||||||
|
return {
|
||||||
|
'id': 'account_id',
|
||||||
|
'is_default': 'this account is used by default',
|
||||||
|
'ledger': 'name of crypto currency and network',
|
||||||
|
'name': 'optional account name',
|
||||||
|
'seed': 'human friendly words from which account can be recreated',
|
||||||
|
'encrypted': 'if account is encrypted',
|
||||||
|
'private_key': 'extended private key',
|
||||||
|
'public_key': 'extended public key',
|
||||||
|
'address_generator': 'settings for generating addresses',
|
||||||
|
'modified_on': 'date of last modification to account settings'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def encode_file_doc():
|
||||||
|
return {
|
||||||
|
'completed': '(bool) true if download is completed',
|
||||||
|
'file_name': '(str) name of file',
|
||||||
|
'download_directory': '(str) download directory',
|
||||||
|
'points_paid': '(float) credit paid to download file',
|
||||||
|
'stopped': '(bool) true if download is stopped',
|
||||||
|
'stream_hash': '(str) stream hash of file',
|
||||||
|
'stream_name': '(str) stream name',
|
||||||
|
'suggested_file_name': '(str) suggested file name',
|
||||||
|
'sd_hash': '(str) sd hash of file',
|
||||||
|
'download_path': '(str) download path of file',
|
||||||
|
'mime_type': '(str) mime type of file',
|
||||||
|
'key': '(str) key attached to file',
|
||||||
|
'total_bytes_lower_bound': '(int) lower bound file size in bytes',
|
||||||
|
'total_bytes': '(int) file upper bound size in bytes',
|
||||||
|
'written_bytes': '(int) written size in bytes',
|
||||||
|
'blobs_completed': '(int) number of fully downloaded blobs',
|
||||||
|
'blobs_in_stream': '(int) total blobs on stream',
|
||||||
|
'blobs_remaining': '(int) total blobs remaining to download',
|
||||||
|
'status': '(str) downloader status',
|
||||||
|
'claim_id': '(str) None if claim is not found else the claim id',
|
||||||
|
'txid': '(str) None if claim is not found else the transaction id',
|
||||||
|
'nout': '(int) None if claim is not found else the transaction output index',
|
||||||
|
'outpoint': '(str) None if claim is not found else the tx and output',
|
||||||
|
'metadata': '(dict) None if claim is not found else the claim metadata',
|
||||||
|
'channel_claim_id': '(str) None if claim is not found or not signed',
|
||||||
|
'channel_name': '(str) None if claim is not found or not signed',
|
||||||
|
'claim_name': '(str) None if claim is not found else the claim name'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class JSONResponseEncoder(JSONEncoder):
|
class JSONResponseEncoder(JSONEncoder):
|
||||||
|
|
||||||
def __init__(self, *args, ledger: MainNetLedger, **kwargs):
|
def __init__(self, *args, ledger: MainNetLedger, **kwargs):
|
||||||
|
@ -20,6 +92,10 @@ class JSONResponseEncoder(JSONEncoder):
|
||||||
self.ledger = ledger
|
self.ledger = ledger
|
||||||
|
|
||||||
def default(self, obj): # pylint: disable=method-hidden
|
def default(self, obj): # pylint: disable=method-hidden
|
||||||
|
if isinstance(obj, Account):
|
||||||
|
return self.encode_account(obj)
|
||||||
|
if isinstance(obj, ManagedStream):
|
||||||
|
return self.encode_file(obj)
|
||||||
if isinstance(obj, Transaction):
|
if isinstance(obj, Transaction):
|
||||||
return self.encode_transaction(obj)
|
return self.encode_transaction(obj)
|
||||||
if isinstance(obj, Output):
|
if isinstance(obj, Output):
|
||||||
|
@ -117,3 +193,14 @@ class JSONResponseEncoder(JSONEncoder):
|
||||||
'txid': txi.txo_ref.tx_ref.id,
|
'txid': txi.txo_ref.tx_ref.id,
|
||||||
'nout': txi.txo_ref.position
|
'nout': txi.txo_ref.position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def encode_account(self, account):
|
||||||
|
result = account.to_dict()
|
||||||
|
result['id'] = account.id
|
||||||
|
result.pop('certificates', None)
|
||||||
|
result['is_default'] = self.ledger.accounts[0] == account
|
||||||
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def encode_file(managed_stream):
|
||||||
|
return managed_stream.as_dict()
|
||||||
|
|
Loading…
Reference in a new issue