From c7e5bdd3aef254094c5a7b8b8bb043b84b694e77 Mon Sep 17 00:00:00 2001 From: hackrush Date: Thu, 30 Aug 2018 01:13:05 +0530 Subject: [PATCH] claim_new_support working in the new wallet --- lbrynet/daemon/Daemon.py | 1 + lbrynet/wallet/manager.py | 8 ++++++++ lbrynet/wallet/script.py | 8 ++++++++ lbrynet/wallet/transaction.py | 14 ++++++++++++++ 4 files changed, 31 insertions(+) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index 9fa0d9992..2540e2b7a 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -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) diff --git a/lbrynet/wallet/manager.py b/lbrynet/wallet/manager.py index 7049e9f60..f6b5bca5e 100644 --- a/lbrynet/wallet/manager.py +++ b/lbrynet/wallet/manager.py @@ -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 diff --git a/lbrynet/wallet/script.py b/lbrynet/wallet/script.py index 93894faba..646b089c4 100644 --- a/lbrynet/wallet/script.py +++ b/lbrynet/wallet/script.py @@ -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={ diff --git a/lbrynet/wallet/transaction.py b/lbrynet/wallet/transaction.py index d71d3ce74..713b1ae01 100644 --- a/lbrynet/wallet/transaction.py +++ b/lbrynet/wallet/transaction.py @@ -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)