forked from LBRYCommunity/lbry-sdk
add get transaction and history functions to daemon
This commit is contained in:
parent
cdab127b98
commit
4385b90cca
3 changed files with 93 additions and 9 deletions
|
@ -1003,7 +1003,7 @@ class LBRYumWallet(LBRYWallet):
|
||||||
self.max_behind = self.blocks_behind_alert
|
self.max_behind = self.blocks_behind_alert
|
||||||
self.catchup_progress = int(100 * (self.blocks_behind_alert / (5 + self.max_behind)))
|
self.catchup_progress = int(100 * (self.blocks_behind_alert / (5 + self.max_behind)))
|
||||||
if self._caught_up_counter == 0:
|
if self._caught_up_counter == 0:
|
||||||
alert.info('Catching up to the blockchain...showing blocks left...')
|
alert.info('Catching up with the blockchain...showing blocks left...')
|
||||||
if self._caught_up_counter % 30 == 0:
|
if self._caught_up_counter % 30 == 0:
|
||||||
alert.info('%d...', (remote_height - local_height))
|
alert.info('%d...', (remote_height - local_height))
|
||||||
alert.info("Catching up: " + str(self.catchup_progress) + "%")
|
alert.info("Catching up: " + str(self.catchup_progress) + "%")
|
||||||
|
@ -1128,6 +1128,39 @@ class LBRYumWallet(LBRYWallet):
|
||||||
func = getattr(self.cmd_runner, cmd.name)
|
func = getattr(self.cmd_runner, cmd.name)
|
||||||
return threads.deferToThread(func)
|
return threads.deferToThread(func)
|
||||||
|
|
||||||
|
def get_history(self):
|
||||||
|
cmd = known_commands['history']
|
||||||
|
func = getattr(self.cmd_runner, cmd.name)
|
||||||
|
return threads.deferToThread(func)
|
||||||
|
|
||||||
|
def get_tx_json(self, txid):
|
||||||
|
def _decode(raw_tx):
|
||||||
|
tx = Transaction(raw_tx).deserialize()
|
||||||
|
decoded_tx = {}
|
||||||
|
for txkey in tx.keys():
|
||||||
|
if isinstance(tx[txkey], list):
|
||||||
|
decoded_tx[txkey] = []
|
||||||
|
for i in tx[txkey]:
|
||||||
|
tmp = {}
|
||||||
|
for k in i.keys():
|
||||||
|
if isinstance(i[k], Decimal):
|
||||||
|
tmp[k] = float(i[k] / 1e8)
|
||||||
|
else:
|
||||||
|
tmp[k] = i[k]
|
||||||
|
decoded_tx[txkey].append(tmp)
|
||||||
|
else:
|
||||||
|
decoded_tx[txkey] = tx[txkey]
|
||||||
|
return decoded_tx
|
||||||
|
|
||||||
|
d = self._get_raw_tx(txid)
|
||||||
|
d.addCallback(_decode)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def get_pub_keys(self, wallet):
|
||||||
|
cmd = known_commands['getpubkeys']
|
||||||
|
func = getattr(self.cmd_runner, cmd.name)
|
||||||
|
return threads.deferToThread(func, wallet)
|
||||||
|
|
||||||
def _save_wallet(self, val):
|
def _save_wallet(self, val):
|
||||||
d = threads.deferToThread(self.wallet.storage.write)
|
d = threads.deferToThread(self.wallet.storage.write)
|
||||||
d.addCallback(lambda _: val)
|
d.addCallback(lambda _: val)
|
||||||
|
|
|
@ -1459,6 +1459,50 @@ class LBRYDaemon(jsonrpc.JSONRPC):
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def jsonrpc_get_transaction_history(self):
|
||||||
|
"""
|
||||||
|
Get transaction history
|
||||||
|
|
||||||
|
Args:
|
||||||
|
None
|
||||||
|
Returns:
|
||||||
|
list of transactions
|
||||||
|
"""
|
||||||
|
|
||||||
|
d = self.session.wallet.get_history()
|
||||||
|
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||||
|
return d
|
||||||
|
|
||||||
|
def jsonrpc_get_transaction(self, p):
|
||||||
|
"""
|
||||||
|
Get a decoded transaction from a txid
|
||||||
|
|
||||||
|
Args:
|
||||||
|
txid: txid hex string
|
||||||
|
Returns:
|
||||||
|
JSON formatted transaction
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
txid = p['txid']
|
||||||
|
d = self.session.wallet.get_tx_json(txid)
|
||||||
|
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||||
|
return d
|
||||||
|
|
||||||
|
def jsonrpc_get_public_key_from_wallet(self, p):
|
||||||
|
"""
|
||||||
|
Get public key from wallet address
|
||||||
|
|
||||||
|
Args:
|
||||||
|
wallet: wallet address, base58
|
||||||
|
Returns:
|
||||||
|
public key
|
||||||
|
"""
|
||||||
|
|
||||||
|
wallet = p['wallet']
|
||||||
|
d = self.session.wallet.get_pub_keys(wallet)
|
||||||
|
d.addCallback(lambda r: self._render_response(r, OK_CODE))
|
||||||
|
|
||||||
def jsonrpc_get_time_behind_blockchain(self):
|
def jsonrpc_get_time_behind_blockchain(self):
|
||||||
"""
|
"""
|
||||||
Get number of blocks behind the blockchain
|
Get number of blocks behind the blockchain
|
||||||
|
|
|
@ -72,7 +72,13 @@ def start():
|
||||||
help="Branch of lbry-web-ui repo to use, defaults on HEAD",
|
help="Branch of lbry-web-ui repo to use, defaults on HEAD",
|
||||||
default="HEAD")
|
default="HEAD")
|
||||||
parser.add_argument('--no-launch', dest='launchui', action="store_false")
|
parser.add_argument('--no-launch', dest='launchui', action="store_false")
|
||||||
parser.set_defaults(launchui=True)
|
parser.add_argument('--log-to-console', dest='logtoconsole', action="store_true")
|
||||||
|
parser.add_argument('--quiet', dest='quiet', action="store_true")
|
||||||
|
parser.set_defaults(launchui=True, logtoconsole=False, quiet=False)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.logtoconsole:
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running()
|
JSONRPCProxy.from_url(API_CONNECTION_STRING).is_running()
|
||||||
|
@ -82,14 +88,14 @@ def start():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
log.info("Starting lbrynet-daemon from command line")
|
log.info("Starting lbrynet-daemon from command line")
|
||||||
|
|
||||||
|
if not args.logtoconsole and not args.quiet:
|
||||||
print "Starting lbrynet-daemon from command line"
|
print "Starting lbrynet-daemon from command line"
|
||||||
print "To view activity, view the log file here: " + LOG_FILENAME
|
print "To view activity, view the log file here: " + LOG_FILENAME
|
||||||
print "Web UI is available at http://%s:%i" %(API_INTERFACE, API_PORT)
|
print "Web UI is available at http://%s:%i" %(API_INTERFACE, API_PORT)
|
||||||
print "JSONRPC API is available at " + API_CONNECTION_STRING
|
print "JSONRPC API is available at " + API_CONNECTION_STRING
|
||||||
print "To quit press ctrl-c or call 'stop' via the API"
|
print "To quit press ctrl-c or call 'stop' via the API"
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
if args.branch == "HEAD":
|
if args.branch == "HEAD":
|
||||||
GIT_CMD_STRING = "git ls-remote https://github.com/lbryio/lbry-web-ui.git | grep %s | cut -f 1" % args.branch
|
GIT_CMD_STRING = "git ls-remote https://github.com/lbryio/lbry-web-ui.git | grep %s | cut -f 1" % args.branch
|
||||||
DIST_URL = "https://raw.githubusercontent.com/lbryio/lbry-web-ui/master/dist.zip"
|
DIST_URL = "https://raw.githubusercontent.com/lbryio/lbry-web-ui/master/dist.zip"
|
||||||
|
@ -171,6 +177,7 @@ def start():
|
||||||
if args.launchui:
|
if args.launchui:
|
||||||
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
d.addCallback(lambda _: webbrowser.open(UI_ADDRESS))
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
if not args.logtoconsole and not args.quiet:
|
||||||
print "\nClosing lbrynet-daemon"
|
print "\nClosing lbrynet-daemon"
|
||||||
else:
|
else:
|
||||||
log.info("Not connected to internet, unable to start")
|
log.info("Not connected to internet, unable to start")
|
||||||
|
|
Loading…
Reference in a new issue