chris45 passing again
This commit is contained in:
parent
55bbf5aa74
commit
af73e1a2f5
4 changed files with 38 additions and 70 deletions
|
@ -2280,41 +2280,48 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@requires(WALLET_COMPONENT, conditions=[WALLET_IS_UNLOCKED])
|
@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.
|
Create a support or a tip for name claim.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
support create (<claim_id> | --claim_id=<claim_id>) (<amount> | --amount=<amount>)
|
support create (<claim_id> | --claim_id=<claim_id>) (<amount> | --amount=<amount>)
|
||||||
[--tip] [--account_id=<account_id>]
|
[--tip] [--account_id=<account_id>] [--preview]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--claim_id=<claim_id> : (str) claim_id of the claim to support
|
--claim_id=<claim_id> : (str) claim_id of the claim to support
|
||||||
--amount=<amount> : (decimal) amount of support
|
--amount=<amount> : (decimal) amount of support
|
||||||
--tip : (bool) send support to claim owner, default: false.
|
--tip : (bool) send support to claim owner, default: false.
|
||||||
--account_id=<account_id> : (str) id of the account to use
|
--account_id=<account_id> : (str) id of the account to use
|
||||||
|
--preview : (bool) do not broadcast the transaction
|
||||||
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,
|
|
||||||
}
|
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
amount = self.get_dewies_or_error("amount", amount)
|
amount = self.get_dewies_or_error("amount", amount)
|
||||||
result = await self.wallet_manager.support_claim(name, claim_id, amount, account)
|
claim = await account.ledger.get_claim_by_claim_id(claim_id)
|
||||||
await self.analytics_manager.send_claim_action('new_support')
|
claim_name = claim['name']
|
||||||
# tip:
|
claim_address = claim['address']
|
||||||
validate_claim_id(claim_id)
|
if not tip:
|
||||||
result = await self.wallet_manager.tip_claim(amount, claim_id, account)
|
claim_address = await account.receiving.get_or_create_usable_address()
|
||||||
await self.analytics_manager.send_claim_action('new_support')
|
|
||||||
return result
|
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])
|
@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):
|
async def jsonrpc_support_abandon(self, claim_id=None, txid=None, nout=None, account_id=None, blocking=True):
|
||||||
|
|
|
@ -4,15 +4,13 @@ import logging
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from torba.client.basemanager import BaseWalletManager
|
from torba.client.basemanager import BaseWalletManager
|
||||||
from torba.rpc.jsonrpc import CodeMessageError
|
from torba.rpc.jsonrpc import CodeMessageError
|
||||||
|
|
||||||
from lbrynet.schema.claim import Claim
|
|
||||||
from lbrynet.wallet.ledger import MainNetLedger
|
from lbrynet.wallet.ledger import MainNetLedger
|
||||||
from lbrynet.wallet.account import BaseAccount
|
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.database import WalletDatabase
|
||||||
from lbrynet.wallet.dewies import dewies_to_lbc
|
from lbrynet.wallet.dewies import dewies_to_lbc
|
||||||
|
|
||||||
|
@ -61,10 +59,6 @@ class LbryWalletManager(BaseWalletManager):
|
||||||
def use_encryption(self):
|
def use_encryption(self):
|
||||||
return self.default_account.serialize_encrypted
|
return self.default_account.serialize_encrypted
|
||||||
|
|
||||||
@property
|
|
||||||
def is_first_run(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_wallet_unlocked(self):
|
def is_wallet_unlocked(self):
|
||||||
return not self.default_account.encrypted
|
return not self.default_account.encrypted
|
||||||
|
@ -374,34 +368,6 @@ class LbryWalletManager(BaseWalletManager):
|
||||||
def get_utxos(account: BaseAccount):
|
def get_utxos(account: BaseAccount):
|
||||||
return account.get_utxos()
|
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):
|
async def abandon_claim(self, claim_id, txid, nout, account):
|
||||||
claim = await account.get_claim(claim_id=claim_id, txid=txid, nout=nout)
|
claim = await account.get_claim(claim_id=claim_id, txid=txid, nout=nout)
|
||||||
if not claim:
|
if not claim:
|
||||||
|
@ -439,8 +405,5 @@ class LbryWalletManager(BaseWalletManager):
|
||||||
block_hash = self.ledger.headers.hash(height).decode()
|
block_hash = self.ledger.headers.hash(height).decode()
|
||||||
return self.ledger.network.get_block(block_hash)
|
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):
|
def get_claim_by_outpoint(self, txid, nout):
|
||||||
return self.ledger.get_claim_by_outpoint(txid, nout)
|
return self.ledger.get_claim_by_outpoint(txid, nout)
|
||||||
|
|
|
@ -209,14 +209,12 @@ class Transaction(BaseTransaction):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def support(cls, claim_name: str, claim_id: str, amount: int, holding_address: str,
|
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)
|
ledger = cls.ensure_all_have_same_ledger(funding_accounts, change_account)
|
||||||
support_output = Output.pay_support_pubkey_hash(
|
support_output = Output.pay_support_pubkey_hash(
|
||||||
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
||||||
)
|
)
|
||||||
if signing_channel is not None:
|
return cls.create([], [support_output], funding_accounts, change_account)
|
||||||
support_output.sign(signing_channel, b'placeholder txid:nout')
|
|
||||||
return cls.create([], [support_output], funding_accounts, change_account, sign=False)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def purchase(cls, claim: Output, amount: int, merchant_address: bytes,
|
def purchase(cls, claim: Output, amount: int, merchant_address: bytes,
|
||||||
|
|
|
@ -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
|
# 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
|
# 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(
|
tx = await self.out(self.daemon.jsonrpc_support_create(
|
||||||
'fresh-start', claim_id2, '0.2', account_id=ramsey_account_id
|
claim_id2, '0.2', account_id=ramsey_account_id
|
||||||
))
|
))
|
||||||
await self.confirm_tx(tx['txid'])
|
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
|
# Now he also wanted to support the original creator of the Award Winning Novel
|
||||||
# So he quickly decides to send a tip to him
|
# So he quickly decides to send a tip to him
|
||||||
tx = await self.out(
|
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'])
|
await self.confirm_tx(tx['txid'])
|
||||||
|
|
||||||
# And again checks if it went to the just right place
|
# And again checks if it went to the just right place
|
||||||
|
@ -156,7 +157,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
|
||||||
await self.generate(5)
|
await self.generate(5)
|
||||||
|
|
||||||
# Seeing the ravishing success of his novel Chris adds support to his claim too
|
# 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'])
|
await self.confirm_tx(tx['txid'])
|
||||||
|
|
||||||
# And check if his support showed up
|
# 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!
|
# 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
|
# 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
|
'hit-song', '1.0', data=b'The Whale and The Bookmark', channel_id=channel_id
|
||||||
))
|
)
|
||||||
|
|
||||||
await self.generate(5)
|
await self.generate(5)
|
||||||
|
|
||||||
# He sends the link to Ramsey, all happy and proud
|
# He sends the link to Ramsey, all happy and proud
|
||||||
|
|
Loading…
Reference in a new issue