Merge pull request #395 from lbryio/fix_publish_output

Fix Daemon RPC command publish output
This commit is contained in:
Job Evers‐Meltzer 2017-01-13 14:02:23 -06:00 committed by GitHub
commit 2b2fa29db5
3 changed files with 38 additions and 14 deletions

View file

@ -604,7 +604,21 @@ class Wallet(object):
meta_for_return[k] = new_metadata[k] meta_for_return[k] = new_metadata[k]
return defer.succeed(Metadata(meta_for_return)) return defer.succeed(Metadata(meta_for_return))
"""
Claim a name, update if name already claimed by user
@param name: name to claim
@param bid: bid amount
@param m: metadata
@return: Deferred which returns a dict containing below items
txid - txid of the resulting transaction
nout - nout of the resulting claim
fee - transaction fee paid to make claim
claim_id - claim id of the claim
"""
def claim_name(self, name, bid, m): def claim_name(self, name, bid, m):
def _save_metadata(claim_out, metadata): def _save_metadata(claim_out, metadata):
if not claim_out['success']: if not claim_out['success']:
@ -630,6 +644,7 @@ class Wallet(object):
lambda new_metadata: self._send_name_claim_update(name, claim['claim_id'], lambda new_metadata: self._send_name_claim_update(name, claim['claim_id'],
claim_outpoint, claim_outpoint,
new_metadata, _bid)) new_metadata, _bid))
d.addCallback(lambda claim_out: claim_out.update({'claim_id': claim['claim_id']}))
return d return d
meta = Metadata(m) meta = Metadata(m)

View file

@ -1748,7 +1748,7 @@ class Daemon(AuthJSONRPCServer):
'txid' : txid of resulting transaction if succesful 'txid' : txid of resulting transaction if succesful
'nout' : nout of the resulting support claim if succesful 'nout' : nout of the resulting support claim if succesful
'fee' : fee paid for the claim transaction if succesful 'fee' : fee paid for the claim transaction if succesful
'claimid' : claimid of the resulting transaction 'claim_id' : claim id of the resulting transaction
""" """
def _set_address(address, currency, m): def _set_address(address, currency, m):

View file

@ -30,6 +30,8 @@ class Publisher(object):
self.lbry_file = None self.lbry_file = None
self.txid = None self.txid = None
self.nout = None self.nout = None
self.claim_id = None
self.fee = None
self.stream_hash = None self.stream_hash = None
# TODO: this needs to be passed into the constructor # TODO: this needs to be passed into the constructor
reflector_server = random.choice(conf.settings.reflector_servers) reflector_server = random.choice(conf.settings.reflector_servers)
@ -38,13 +40,18 @@ class Publisher(object):
def start(self, name, file_path, bid, metadata): def start(self, name, file_path, bid, metadata):
log.info('Starting publish for %s', name) log.info('Starting publish for %s', name)
def _show_result(): def _show_result():
log.info("Success! Published %s --> lbry://%s txid: %s nout: %d", log.info(
self.file_name, self.publish_name, self.txid, self.nout) "Success! Published %s --> lbry://%s txid: %s nout: %d",
out = {} self.file_name, self.publish_name, self.txid, self.nout
out['nout'] = self.nout )
out['txid'] = self.txid return defer.succeed({
return defer.succeed(out) 'nout': self.nout,
'txid': self.txid,
'claim_id': self.claim_id,
'fee': self.fee,
})
self.publish_name = name self.publish_name = name
self.file_path = file_path self.file_path = file_path
@ -136,15 +143,17 @@ class Publisher(object):
self._update_metadata() self._update_metadata()
m = Metadata(self.metadata) m = Metadata(self.metadata)
def set_txid_nout(claim_out): def set_claim_out(claim_out):
txid = claim_out['txid'] log.debug('Name claimed using txid: %s, nout: %d, claim_id: %s, fee :%f',
nout = claim_out['nout'] claim_out['txid'], claim_out['nout'],
log.debug('Name claimed using txid: %s, nout: %d', txid, nout) claim_out['claim_id'], claim_out['fee'])
self.txid = txid self.txid = claim_out['txid']
self.nout = nout self.nout = claim_out['nout']
self.claim_id = claim_out['claim_id']
self.fee = claim_out['fee']
d = self.wallet.claim_name(self.publish_name, self.bid_amount, m) d = self.wallet.claim_name(self.publish_name, self.bid_amount, m)
d.addCallback(set_txid_nout) d.addCallback(set_claim_out)
return d return d
def _update_metadata(self): def _update_metadata(self):