From 0adcaa6a5d4e2b544e7aba00d1b45f5d55f96f7a Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Wed, 19 Sep 2018 09:58:50 -0400 Subject: [PATCH] utxo_list, transaction_show --- lbrynet/daemon/Daemon.py | 30 ++++++++++--------------- lbrynet/daemon/json_response_encoder.py | 6 ++++- lbrynet/wallet/manager.py | 6 +++++ 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 7e0b91b6b..693753e41 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -2765,22 +2765,18 @@ class Daemon(AuthJSONRPCServer): Returns: (dict) JSON formatted transaction """ - - d = self.wallet_manager.get_transaction(txid) - d.addCallback(lambda r: self._render_response(r)) - return d + return self.wallet_manager.get_transaction(txid) @requires(WALLET_COMPONENT) - @defer.inlineCallbacks - def jsonrpc_utxo_list(self): + def jsonrpc_utxo_list(self, account_id=None): """ List unspent transaction outputs Usage: - utxo_list + utxo_list [] Options: - None + --account= : (str) id of the account to query Returns: (list) List of unspent transaction outputs (UTXOs) @@ -2799,16 +2795,9 @@ class Daemon(AuthJSONRPCServer): ... ] """ - - unspent = yield self.wallet_manager.list_unspent() - for i, utxo in enumerate(unspent): - utxo['txid'] = utxo.pop('prevout_hash') - utxo['nout'] = utxo.pop('prevout_n') - utxo['amount'] = utxo.pop('value') - utxo['is_coinbase'] = utxo.pop('coinbase') - unspent[i] = utxo - - defer.returnValue(unspent) + return self.wallet_manager.get_utxos( + self.get_account_or_default('account', account_id) + ) @requires(WALLET_COMPONENT) def jsonrpc_block_show(self, blockhash=None, height=None): @@ -3355,6 +3344,11 @@ class Daemon(AuthJSONRPCServer): return certificates[0] raise ValueError("Couldn't find channel because a channel name or channel_id was not provided.") + def get_account_or_default(self, argument: str, account_id: str, lbc_only=True): + if account_id is None: + return self.default_account + return self.get_account_or_error(argument, account_id, lbc_only) + def get_account_or_error(self, argument: str, account_id: str, lbc_only=True): for account in self.default_wallet.accounts: if account.id == account_id: diff --git a/lbrynet/daemon/json_response_encoder.py b/lbrynet/daemon/json_response_encoder.py index 3ab26cb42..b725f3700 100644 --- a/lbrynet/daemon/json_response_encoder.py +++ b/lbrynet/daemon/json_response_encoder.py @@ -37,9 +37,13 @@ class JSONResponseEncoder(JSONEncoder): def encode_output(self, txo): return { + 'txid': txo.tx_ref.id, 'nout': txo.position, 'amount': txo.amount, - 'address': txo.get_address(self.ledger) + 'address': txo.get_address(self.ledger), + 'is_claim': txo.script.is_claim_name, + 'is_support': txo.script.is_support_claim, + 'is_update': txo.script.is_update_claim } def encode_input(self, txi): diff --git a/lbrynet/wallet/manager.py b/lbrynet/wallet/manager.py index 739c77474..0c0a4f9de 100644 --- a/lbrynet/wallet/manager.py +++ b/lbrynet/wallet/manager.py @@ -204,9 +204,15 @@ class LbryWalletManager(BaseWalletManager): def address_is_mine(self, address): return defer.succeed(True) + def get_transaction(self, txid): + return self.default_account.ledger.get_transaction(txid) + def get_history(self): return defer.succeed([]) + def get_utxos(self, account): + return account.get_unspent_outputs() + @defer.inlineCallbacks def claim_name(self, name, amount, claim_dict, certificate=None, claim_address=None): account = self.default_account