working jsonrpc_account_deposit
This commit is contained in:
parent
dd503fbb82
commit
16eb50a291
3 changed files with 30 additions and 10 deletions
|
@ -277,7 +277,7 @@ class Template:
|
||||||
elif isinstance(opcode, PUSH_INTEGER):
|
elif isinstance(opcode, PUSH_INTEGER):
|
||||||
data = values[opcode.name]
|
data = values[opcode.name]
|
||||||
source.write_many(push_data(
|
source.write_many(push_data(
|
||||||
data.to_bytes((data.bit_length() + 7) // 8, byteorder='little')
|
data.to_bytes((data.bit_length() + 8) // 8, byteorder='little', signed=True)
|
||||||
))
|
))
|
||||||
elif isinstance(opcode, PUSH_SUBSCRIPT):
|
elif isinstance(opcode, PUSH_SUBSCRIPT):
|
||||||
data = values[opcode.name]
|
data = values[opcode.name]
|
||||||
|
@ -417,6 +417,10 @@ class InputScript(Script):
|
||||||
'script': script
|
'script': script
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_script_hash(self):
|
||||||
|
return self.template.name.startswith('script_hash+')
|
||||||
|
|
||||||
|
|
||||||
class OutputScript(Script):
|
class OutputScript(Script):
|
||||||
|
|
||||||
|
|
|
@ -718,8 +718,11 @@ class Transaction:
|
||||||
stream.write_compact_size(len(self._inputs))
|
stream.write_compact_size(len(self._inputs))
|
||||||
for i, txin in enumerate(self._inputs):
|
for i, txin in enumerate(self._inputs):
|
||||||
if signing_input == i:
|
if signing_input == i:
|
||||||
assert txin.txo_ref.txo is not None
|
if txin.script.is_script_hash:
|
||||||
txin.serialize_to(stream, txin.txo_ref.txo.script.source)
|
txin.serialize_to(stream, txin.script.values['script'].source)
|
||||||
|
else:
|
||||||
|
assert txin.txo_ref.txo is not None
|
||||||
|
txin.serialize_to(stream, txin.txo_ref.txo.script.source)
|
||||||
else:
|
else:
|
||||||
txin.serialize_to(stream, b'')
|
txin.serialize_to(stream, b'')
|
||||||
self._serialize_outputs(stream)
|
self._serialize_outputs(stream)
|
||||||
|
@ -949,9 +952,13 @@ class Transaction:
|
||||||
return cls.create([], [payment, data], funding_accounts, change_account)
|
return cls.create([], [payment, data], funding_accounts, change_account)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def spend_time_lock(cls, time_locked_txo: Output, script: bytes, account: 'Account'):
|
async def spend_time_lock(cls, time_locked_txo: Output, script: bytes, account: 'Account'):
|
||||||
txi = Input.spend_time_lock(time_locked_txo, script)
|
txi = Input.spend_time_lock(time_locked_txo, script)
|
||||||
return cls.create([txi], [], [account], account, sign=False)
|
txi.sequence = 0xFFFFFFFE
|
||||||
|
tx = await cls.create([txi], [], [account], account, sign=False)
|
||||||
|
tx.locktime = txi.script.values['script'].values['height']
|
||||||
|
tx._reset()
|
||||||
|
return tx
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def my_inputs(self):
|
def my_inputs(self):
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
from binascii import unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
|
|
||||||
from lbry.testcase import CommandTestCase
|
from lbry.testcase import CommandTestCase
|
||||||
|
from lbry.wallet.script import InputScript
|
||||||
from lbry.wallet.dewies import dewies_to_lbc
|
from lbry.wallet.dewies import dewies_to_lbc
|
||||||
from lbry.wallet.account import DeterministicChannelKeyManager
|
from lbry.wallet.account import DeterministicChannelKeyManager
|
||||||
|
from lbry.crypto.hash import hash160
|
||||||
from lbry.crypto.base58 import Base58
|
from lbry.crypto.base58 import Base58
|
||||||
|
|
||||||
|
|
||||||
|
@ -293,15 +295,22 @@ class AccountManagement(CommandTestCase):
|
||||||
async def test_time_locked_transactions(self):
|
async def test_time_locked_transactions(self):
|
||||||
address = await self.account.receiving.get_or_create_usable_address()
|
address = await self.account.receiving.get_or_create_usable_address()
|
||||||
private_key = await self.ledger.get_private_key_for_address(self.wallet, address)
|
private_key = await self.ledger.get_private_key_for_address(self.wallet, address)
|
||||||
redeem = await self.blockchain.add_time_locked_address(210, address)
|
|
||||||
|
script = InputScript(
|
||||||
|
template=InputScript.TIME_LOCK_SCRIPT,
|
||||||
|
values={'height': 210, 'pubkey_hash': self.ledger.address_to_hash160(address)}
|
||||||
|
)
|
||||||
|
script_address = self.ledger.hash160_to_script_address(hash160(script.source))
|
||||||
|
script_source = hexlify(script.source).decode()
|
||||||
|
|
||||||
await self.assertBalance(self.account, '10.0')
|
await self.assertBalance(self.account, '10.0')
|
||||||
tx = await self.daemon.jsonrpc_account_send('4.0', redeem['address'])
|
tx = await self.daemon.jsonrpc_account_send('4.0', script_address)
|
||||||
await self.confirm_tx(tx.id)
|
await self.confirm_tx(tx.id)
|
||||||
await self.generate(510)
|
await self.generate(510)
|
||||||
await self.assertBalance(self.account, '5.999877')
|
await self.assertBalance(self.account, '5.999877')
|
||||||
tx = await self.daemon.jsonrpc_account_deposit(
|
tx = await self.daemon.jsonrpc_account_deposit(
|
||||||
tx.id, 0, redeem['redeemScript'],
|
tx.id, 0, script_source,
|
||||||
Base58.encode_check(self.ledger.private_key_to_wif(private_key.private_key_bytes))
|
Base58.encode_check(self.ledger.private_key_to_wif(private_key.private_key_bytes))
|
||||||
)
|
)
|
||||||
await self.confirm_tx(tx.id)
|
await self.confirm_tx(tx.id)
|
||||||
await self.assertBalance(self.account, '9.999877')
|
await self.assertBalance(self.account, '9.9997545')
|
||||||
|
|
Loading…
Reference in a new issue