diff --git a/lbrynet/lbrynet_daemon/LBRYDaemon.py b/lbrynet/lbrynet_daemon/LBRYDaemon.py index 17be5449e..0731dcb71 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemon.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemon.py @@ -27,7 +27,7 @@ from lbrynet.core.PaymentRateManager import PaymentRateManager from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory from lbrynet.core.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.core.server.ServerProtocol import ServerProtocolFactory -from lbrynet.core.Error import UnknownNameError +from lbrynet.core.Error import UnknownNameError, InsufficientFundsError from lbrynet.lbryfile.StreamDescriptor import LBRYFileStreamType from lbrynet.lbryfile.client.LBRYFileDownloader import LBRYFileSaverFactory, LBRYFileOpenerFactory from lbrynet.lbryfile.client.LBRYFileOptions import add_lbry_file_to_sd_identifier @@ -1789,6 +1789,98 @@ class LBRYDaemon(jsonrpc.JSONRPC): d.addCallback(lambda address: self._render_response(address, OK_CODE)) return d + def jsonrpc_send_amount_to_address(self, p): + """ + Send credits to an address + + Args: + amount: the amount to send + address: the address of the recipient + Returns: + True if payment successfully scheduled + """ + + if 'amount' in p.keys() and 'address' in p.keys(): + amount = p['amount'] + address = p['address'] + else: + return server.failure + + reserved_points = self.session.wallet.reserve_points(address, amount) + if reserved_points is None: + return defer.fail(InsufficientFundsError()) + d = self.session.wallet.send_points_to_address(reserved_points, amount) + d.addCallback(lambda _: self._render_response(True, OK_CODE)) + return d + + def jsonrpc_get_best_blockhash(self): + """ + Get hash of most recent block + + Args: + None + Returns: + Hash of most recent block + """ + + d = self.session.wallet.get_best_blockhash() + d.addCallback(lambda r: self._render_response(r, OK_CODE)) + return d + + def jsonrpc_get_block(self, p): + """ + Get contents of a block + + Args: + blockhash: hash of the block to look up + Returns: + requested block + """ + + if 'blockhash' in p.keys(): + blockhash = p['blockhash'] + else: + return server.failure + + d = self.session.wallet.get_block(blockhash) + d.addCallback(lambda r: self._render_response(r, OK_CODE)) + return d + + def jsonrpc_get_claims_for_tx(self, p): + """ + Get claims for tx + + Args: + txid: txid of a name claim transaction + Returns: + any claims contained in the requested tx + """ + + if 'txid' in p.keys(): + txid = p['txid'] + else: + return server.failure + + d = self.session.wallet.get_claims_from_tx(txid) + d.addCallback(lambda r: self._render_response(r, OK_CODE)) + return d + + + def jsonrpc_get_nametrie(self): + """ + Get the nametrie + + Args: + None + Returns: + Name claim trie + """ + + d = self.session.wallet.get_nametrie() + d.addCallback(lambda r: [i for i in r if 'txid' in i.keys()]) + d.addCallback(lambda r: self._render_response(r, OK_CODE)) + return d + # def jsonrpc_update_name(self, metadata): # def _disp(x): # print x diff --git a/lbrynet/lbrynet_daemon/LBRYDaemonServer.py b/lbrynet/lbrynet_daemon/LBRYDaemonServer.py index 152e9c353..86c28c557 100644 --- a/lbrynet/lbrynet_daemon/LBRYDaemonServer.py +++ b/lbrynet/lbrynet_daemon/LBRYDaemonServer.py @@ -337,8 +337,8 @@ class LBRYDaemonServer(object): d.addCallback(lambda _: _dl_ui()) return d - def _setup_server(self, ui_ver): - self._api = LBRYDaemon(ui_ver, wallet_type=DEFAULT_WALLET) + def _setup_server(self, ui_ver, wallet): + self._api = LBRYDaemon(ui_ver, wallet_type=wallet) self.root = LBRYindex(self.ui_dir) self.root.putChild("css", static.File(os.path.join(self.ui_dir, "css"))) self.root.putChild("font", static.File(os.path.join(self.ui_dir, "font"))) @@ -349,9 +349,9 @@ class LBRYDaemonServer(object): self.root.putChild(API_ADDRESS, self._api) return defer.succeed(True) - def start(self, branch="HEAD", user_specified=False): + def start(self, branch="HEAD", user_specified=False, wallet=DEFAULT_WALLET): d = self.setup(branch=branch, user_specified=user_specified) - d.addCallback(lambda v: self._setup_server(v)) + d.addCallback(lambda v: self._setup_server(v, wallet)) d.addCallback(lambda _: self._api.setup()) return d