claim_new_support working in the new wallet
This commit is contained in:
parent
46dcf8a899
commit
c7e5bdd3ae
4 changed files with 31 additions and 0 deletions
|
@ -2388,6 +2388,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
}
|
||||
"""
|
||||
|
||||
amount = self.get_dewies_or_error("amount", amount)
|
||||
result = yield self.wallet_manager.support_claim(name, claim_id, amount)
|
||||
self.analytics_manager.send_claim_action('new_support')
|
||||
defer.returnValue(result)
|
||||
|
|
|
@ -245,6 +245,14 @@ class LbryWalletManager(BaseWalletManager):
|
|||
"claim_sequence": -1,
|
||||
}
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def support_claim(self, claim_name, claim_id, amount):
|
||||
account = self.default_account
|
||||
holding_address = yield account.receiving.get_or_create_usable_address()
|
||||
tx = yield Transaction.support(claim_name, claim_id, amount, holding_address, [account], account)
|
||||
yield account.ledger.broadcast(tx)
|
||||
return tx
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def abandon_claim(self, claim_id, txid, nout):
|
||||
account = self.default_account
|
||||
|
|
|
@ -96,6 +96,14 @@ class OutputScript(BaseOutputScript):
|
|||
'pubkey_hash': pubkey_hash
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def pay_support_pubkey_hash(cls, claim_name: bytes, claim_id: bytes, pubkey_hash: bytes):
|
||||
return cls(template=cls.SUPPORT_CLAIM_PUBKEY, values={
|
||||
'claim_name': claim_name,
|
||||
'claim_id': claim_id,
|
||||
'pubkey_hash': pubkey_hash
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def sell_script(cls, price):
|
||||
return cls(template=cls.SELL_SCRIPT, values={
|
||||
|
|
|
@ -66,6 +66,11 @@ class Output(BaseOutput):
|
|||
claim_name.encode(), unhexlify(claim_id)[::-1], claim, pubkey_hash)
|
||||
return cls(amount, script)
|
||||
|
||||
@classmethod
|
||||
def pay_support_pubkey_hash(cls, amount: int, claim_name: str, claim_id: str, pubkey_hash: bytes) -> 'Output':
|
||||
script = cls.script_class.pay_support_pubkey_hash(claim_name.encode(), unhexlify(claim_id)[::-1], pubkey_hash)
|
||||
return cls(amount, script)
|
||||
|
||||
|
||||
class Transaction(BaseTransaction):
|
||||
|
||||
|
@ -106,6 +111,15 @@ class Transaction(BaseTransaction):
|
|||
)
|
||||
return cls.create([Input.spend(previous_claim)], [updated_claim], funding_accounts, change_account)
|
||||
|
||||
@classmethod
|
||||
def support(cls, claim_name: str, claim_id: str, amount: int, holding_address: bytes,
|
||||
funding_accounts: List[Account], change_account: Account):
|
||||
ledger = cls.ensure_all_have_same_ledger(funding_accounts, change_account)
|
||||
output = Output.pay_support_pubkey_hash(
|
||||
amount, claim_name, claim_id, ledger.address_to_hash160(holding_address)
|
||||
)
|
||||
return cls.create([], [output], funding_accounts, change_account)
|
||||
|
||||
@classmethod
|
||||
def abandon(cls, claims: Iterable[Output], funding_accounts: Iterable[Account], change_account: Account):
|
||||
return cls.create([Input.spend(txo) for txo in claims], [], funding_accounts, change_account)
|
||||
|
|
Loading…
Reference in a new issue