back ported partial signed supports feature
This commit is contained in:
parent
3f6493dc5c
commit
82cdc8c86a
4 changed files with 51 additions and 6 deletions
|
@ -3277,7 +3277,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
@requires(WALLET_COMPONENT)
|
@requires(WALLET_COMPONENT)
|
||||||
async def jsonrpc_support_create(
|
async def jsonrpc_support_create(
|
||||||
self, claim_id, amount, tip=False, account_id=None, wallet_id=None, funding_account_ids=None,
|
self, claim_id, amount, tip=False, account_id=None, wallet_id=None, funding_account_ids=None,
|
||||||
preview=False, blocking=False):
|
channel_id=None, preview=False, blocking=False):
|
||||||
"""
|
"""
|
||||||
Create a support or a tip for name claim.
|
Create a support or a tip for name claim.
|
||||||
|
|
||||||
|
@ -3301,6 +3301,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||||
assert not wallet.is_locked, "Cannot spend funds with locked wallet, unlock first."
|
assert not wallet.is_locked, "Cannot spend funds with locked wallet, unlock first."
|
||||||
funding_accounts = wallet.get_accounts_or_all(funding_account_ids)
|
funding_accounts = wallet.get_accounts_or_all(funding_account_ids)
|
||||||
|
channel = await self.get_channel_or_none(wallet, None, channel_id, None, for_signing=True)
|
||||||
amount = self.get_dewies_or_error("amount", amount)
|
amount = self.get_dewies_or_error("amount", amount)
|
||||||
claim = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id)
|
claim = await self.ledger.get_claim_by_claim_id(wallet.accounts, claim_id)
|
||||||
claim_address = claim.get_address(self.ledger)
|
claim_address = claim.get_address(self.ledger)
|
||||||
|
@ -3309,7 +3310,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
claim_address = await account.receiving.get_or_create_usable_address()
|
claim_address = await account.receiving.get_or_create_usable_address()
|
||||||
|
|
||||||
tx = await Transaction.support(
|
tx = await Transaction.support(
|
||||||
claim.claim_name, claim_id, amount, claim_address, funding_accounts, funding_accounts[0]
|
claim.claim_name, claim_id, amount, claim_address, funding_accounts, funding_accounts[0], channel
|
||||||
)
|
)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
|
|
|
@ -42,6 +42,17 @@ class OutputScript(BaseOutputScript):
|
||||||
SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
||||||
))
|
))
|
||||||
|
|
||||||
|
SUPPORT_CLAIM_DATA_OPCODES = (
|
||||||
|
OP_SUPPORT_CLAIM, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim_id'), PUSH_SINGLE('support'),
|
||||||
|
OP_2DROP, OP_2DROP
|
||||||
|
)
|
||||||
|
SUPPORT_CLAIM_DATA_PUBKEY = Template('support_claim+data+pay_pubkey_hash', (
|
||||||
|
SUPPORT_CLAIM_DATA_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes
|
||||||
|
))
|
||||||
|
SUPPORT_CLAIM_DATA_SCRIPT = Template('support_claim+data+pay_script_hash', (
|
||||||
|
SUPPORT_CLAIM_DATA_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
||||||
|
))
|
||||||
|
|
||||||
UPDATE_CLAIM_OPCODES = (
|
UPDATE_CLAIM_OPCODES = (
|
||||||
OP_UPDATE_CLAIM, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim_id'), PUSH_SINGLE('claim'),
|
OP_UPDATE_CLAIM, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim_id'), PUSH_SINGLE('claim'),
|
||||||
OP_2DROP, OP_2DROP
|
OP_2DROP, OP_2DROP
|
||||||
|
@ -73,6 +84,8 @@ class OutputScript(BaseOutputScript):
|
||||||
CLAIM_NAME_SCRIPT,
|
CLAIM_NAME_SCRIPT,
|
||||||
SUPPORT_CLAIM_PUBKEY,
|
SUPPORT_CLAIM_PUBKEY,
|
||||||
SUPPORT_CLAIM_SCRIPT,
|
SUPPORT_CLAIM_SCRIPT,
|
||||||
|
SUPPORT_CLAIM_DATA_PUBKEY,
|
||||||
|
SUPPORT_CLAIM_DATA_SCRIPT,
|
||||||
UPDATE_CLAIM_PUBKEY,
|
UPDATE_CLAIM_PUBKEY,
|
||||||
UPDATE_CLAIM_SCRIPT,
|
UPDATE_CLAIM_SCRIPT,
|
||||||
SELL_CLAIM, SELL_SCRIPT,
|
SELL_CLAIM, SELL_SCRIPT,
|
||||||
|
@ -104,6 +117,16 @@ class OutputScript(BaseOutputScript):
|
||||||
'pubkey_hash': pubkey_hash
|
'pubkey_hash': pubkey_hash
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pay_support_data_pubkey_hash(
|
||||||
|
cls, claim_name: bytes, claim_id: bytes, support: bytes, pubkey_hash: bytes):
|
||||||
|
return cls(template=cls.SUPPORT_CLAIM_DATA_PUBKEY, values={
|
||||||
|
'claim_name': claim_name,
|
||||||
|
'claim_id': claim_id,
|
||||||
|
'support': support,
|
||||||
|
'pubkey_hash': pubkey_hash
|
||||||
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sell_script(cls, price):
|
def sell_script(cls, price):
|
||||||
return cls(template=cls.SELL_SCRIPT, values={
|
return cls(template=cls.SELL_SCRIPT, values={
|
||||||
|
|
|
@ -194,6 +194,14 @@ class Output(BaseOutput):
|
||||||
script = cls.script_class.pay_support_pubkey_hash(claim_name.encode(), unhexlify(claim_id)[::-1], pubkey_hash)
|
script = cls.script_class.pay_support_pubkey_hash(claim_name.encode(), unhexlify(claim_id)[::-1], pubkey_hash)
|
||||||
return cls(amount, script)
|
return cls(amount, script)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pay_support_data_pubkey_hash(
|
||||||
|
cls, amount: int, claim_name: str, claim_id: str, support: bytes, pubkey_hash: bytes) -> 'Output':
|
||||||
|
script = OutputScript.pay_support_data_pubkey_hash(
|
||||||
|
claim_name.encode(), unhexlify(claim_id)[::-1], support, pubkey_hash
|
||||||
|
)
|
||||||
|
return cls(amount, script)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_purchase_data(cls, purchase: Purchase) -> 'Output':
|
def add_purchase_data(cls, purchase: Purchase) -> 'Output':
|
||||||
script = cls.script_class.return_data(purchase)
|
script = cls.script_class.return_data(purchase)
|
||||||
|
@ -287,8 +295,13 @@ 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):
|
funding_accounts: List[Account], change_account: Account, signing_channel: Output = None):
|
||||||
ledger, wallet = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
ledger, wallet = cls.ensure_all_have_same_ledger_and_wallet(funding_accounts, change_account)
|
||||||
|
if signing_channel:
|
||||||
|
support_output = Output.pay_support_data_pubkey_hash(
|
||||||
|
amount, claim_name, claim_id, b'beef', ledger.address_to_hash160(holding_address)
|
||||||
|
)
|
||||||
|
else:
|
||||||
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)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1211,3 +1211,11 @@ class SupportCommands(CommandTestCase):
|
||||||
self.assertFalse(txs2[0]['support_info'][0]['is_tip'])
|
self.assertFalse(txs2[0]['support_info'][0]['is_tip'])
|
||||||
self.assertEqual(txs2[0]['value'], '0.0')
|
self.assertEqual(txs2[0]['value'], '0.0')
|
||||||
self.assertEqual(txs2[0]['fee'], '-0.0001415')
|
self.assertEqual(txs2[0]['fee'], '-0.0001415')
|
||||||
|
|
||||||
|
async def test_signed_supports(self):
|
||||||
|
channel_id = self.get_claim_id(await self.channel_create())
|
||||||
|
stream_id = self.get_claim_id(await self.stream_create())
|
||||||
|
await self.support_create(stream_id, '0.3', channel_id=channel_id)
|
||||||
|
supports = await self.daemon.jsonrpc_support_list()
|
||||||
|
self.assertEqual(1, len(supports['items']))
|
||||||
|
self.assertEqual(supports['items'][0].script.values['support'], b'beef')
|
||||||
|
|
Loading…
Add table
Reference in a new issue