chris45 passing again

This commit is contained in:
Lex Berezhny 2019-03-24 18:14:02 -04:00
parent 55bbf5aa74
commit af73e1a2f5
4 changed files with 38 additions and 70 deletions

View file

@ -2280,41 +2280,48 @@ class Daemon(metaclass=JSONRPCServerType):
"""
@requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED])
async def jsonrpc_support_create(self, claim_id, amount, tip=False, account_id=None):
async def jsonrpc_support_create(self, claim_id, amount, tip=False, account_id=None, preview=False):
"""
Create a support or a tip for name claim.
Usage:
support create (<claim_id> | --claim_id=<claim_id>) (<amount> | --amount=<amount>)
[--tip] [--account_id=<account_id>]
[--tip] [--account_id=<account_id>] [--preview]
Options:
--claim_id=<claim_id> : (str) claim_id of the claim to support
--amount=<amount> : (decimal) amount of support
--tip : (bool) send support to claim owner, default: false.
--account_id=<account_id> : (str) id of the account to use
Returns:
(dict) Dictionary containing the transaction information
{
"hex": (str) raw transaction,
"inputs": (list) inputs(dict) used for the transaction,
"outputs": (list) outputs(dict) for the transaction,
"total_fee": (int) fee in dewies,
"total_input": (int) total of inputs in dewies,
"total_output": (int) total of outputs in dewies(input - fees),
"txid": (str) txid of the transaction,
}
--preview : (bool) do not broadcast the transaction
"""
account = self.get_account_or_default(account_id)
amount = self.get_dewies_or_error("amount", amount)
result = await self.wallet_manager.support_claim(name, claim_id, amount, account)
await self.analytics_manager.send_claim_action('new_support')
# tip:
validate_claim_id(claim_id)
result = await self.wallet_manager.tip_claim(amount, claim_id, account)
await self.analytics_manager.send_claim_action('new_support')
return result
claim = await account.ledger.get_claim_by_claim_id(claim_id)
claim_name = claim['name']
claim_address = claim['address']
if not tip:
claim_address = await account.receiving.get_or_create_usable_address()
tx = await Transaction.support(
claim_name, claim_id, amount, claim_address, [account], account
)
if not preview:
await tx.sign([account])
await account.ledger.broadcast(tx)
await self.storage.save_supports(claim_id, [{
'txid': tx.id,
'nout': tx.position,
'address': claim_address,
'claim_id': claim_id,
'amount': dewies_to_lbc(amount)
}])
await self.analytics_manager.send_claim_action('new_support')
else:
await account.ledger.release_tx(tx)
return tx
@requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED])
async def jsonrpc_support_abandon(self, claim_id=None, txid=None, nout=None, account_id=None, blocking=True):

View file

@ -4,15 +4,13 @@ import logging
from binascii import unhexlify
from datetime import datetime
from typing import Optional
from torba.client.basemanager import BaseWalletManager
from torba.rpc.jsonrpc import CodeMessageError
from lbrynet.schema.claim import Claim
from lbrynet.wallet.ledger import MainNetLedger
from lbrynet.wallet.account import BaseAccount
from lbrynet.wallet.transaction import Transaction, Output, Input
from lbrynet.wallet.transaction import Transaction
from lbrynet.wallet.database import WalletDatabase
from lbrynet.wallet.dewies import dewies_to_lbc
@ -61,10 +59,6 @@ class LbryWalletManager(BaseWalletManager):
def use_encryption(self):
return self.default_account.serialize_encrypted
@property
def is_first_run(self):
return True
@property
def is_wallet_unlocked(self):
return not self.default_account.encrypted
@ -374,34 +368,6 @@ class LbryWalletManager(BaseWalletManager):
def get_utxos(account: BaseAccount):
return account.get_utxos()
async def support_claim(self, claim_name, claim_id, amount, account):
holding_address = await account.receiving.get_or_create_usable_address()
tx = await Transaction.support(claim_name, claim_id, amount, holding_address, [account], account)
await account.ledger.broadcast(tx)
await self.old_db.save_supports(claim_id, [{
'txid': tx.id,
'nout': tx.position,
'address': holding_address,
'claim_id': claim_id,
'amount': dewies_to_lbc(amount)
}])
return tx
async def tip_claim(self, amount, claim_id, account):
claim_to_tip = await self.get_claim_by_claim_id(claim_id)
tx = await Transaction.support(
claim_to_tip['name'], claim_id, amount, claim_to_tip['address'], [account], account
)
await account.ledger.broadcast(tx)
await self.old_db.save_supports(claim_id, [{
'txid': tx.id,
'nout': tx.position,
'address': claim_to_tip['address'],
'claim_id': claim_id,
'amount': dewies_to_lbc(amount)
}])
return tx
async def abandon_claim(self, claim_id, txid, nout, account):
claim = await account.get_claim(claim_id=claim_id, txid=txid, nout=nout)
if not claim:
@ -439,8 +405,5 @@ class LbryWalletManager(BaseWalletManager):
block_hash = self.ledger.headers.hash(height).decode()
return self.ledger.network.get_block(block_hash)
def get_claim_by_claim_id(self, claim_id):
return self.ledger.get_claim_by_claim_id(claim_id)
def get_claim_by_outpoint(self, txid, nout):
return self.ledger.get_claim_by_outpoint(txid, nout)

View file

@ -209,14 +209,12 @@ class Transaction(BaseTransaction):
@classmethod
def support(cls, claim_name: str, claim_id: str, amount: int, holding_address: str,
funding_accounts: List[Account], change_account: Account, signing_channel: Output = None):
funding_accounts: List[Account], change_account: Account):
ledger = cls.ensure_all_have_same_ledger(funding_accounts, change_account)
support_output = Output.pay_support_pubkey_hash(
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
)
if signing_channel is not None:
support_output.sign(signing_channel, b'placeholder txid:nout')
return cls.create([], [support_output], funding_accounts, change_account, sign=False)
return cls.create([], [support_output], funding_accounts, change_account)
@classmethod
def purchase(cls, claim: Output, amount: int, merchant_address: bytes,

View file

@ -128,8 +128,8 @@ class EpicAdventuresOfChris45(CommandTestCase):
# And voila, and bravo and encore! His Best Friend Ramsey read the story and immediately knew this was a hit
# Now to keep this claim winning on the lbry blockchain he immediately supports the claim
tx = await self.out(self.daemon.jsonrpc_claim_new_support(
'fresh-start', claim_id2, '0.2', account_id=ramsey_account_id
tx = await self.out(self.daemon.jsonrpc_support_create(
claim_id2, '0.2', account_id=ramsey_account_id
))
await self.confirm_tx(tx['txid'])
@ -145,7 +145,8 @@ class EpicAdventuresOfChris45(CommandTestCase):
# Now he also wanted to support the original creator of the Award Winning Novel
# So he quickly decides to send a tip to him
tx = await self.out(
self.daemon.jsonrpc_claim_tip(claim_id2, '0.3', account_id=ramsey_account_id))
self.daemon.jsonrpc_support_create(claim_id2, '0.3', tip=True, account_id=ramsey_account_id)
)
await self.confirm_tx(tx['txid'])
# And again checks if it went to the just right place
@ -156,7 +157,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
await self.generate(5)
# Seeing the ravishing success of his novel Chris adds support to his claim too
tx = await self.out(self.daemon.jsonrpc_claim_new_support('fresh-start', claim_id2, '0.4'))
tx = await self.out(self.daemon.jsonrpc_support_create(claim_id2, '0.4'))
await self.confirm_tx(tx['txid'])
# And check if his support showed up
@ -172,10 +173,9 @@ class EpicAdventuresOfChris45(CommandTestCase):
# his song, seeing as his novel had smashed all the records, he was the perfect candidate!
# .......
# Chris agrees.. 17 hours 43 minutes and 14 seconds later, he makes his publish
tx = await self.out(self.daemon.jsonrpc_publish(
tx = await self.create_claim(
'hit-song', '1.0', data=b'The Whale and The Bookmark', channel_id=channel_id
))
)
await self.generate(5)
# He sends the link to Ramsey, all happy and proud