Exemplo n.º 1
0
    async def test_get_utxo(self):
        address = yield self.account.receiving.get_or_create_usable_address()
        hash160 = self.ledger.address_to_hash160(address)

        tx = Transaction(is_verified=True)\
            .add_outputs([Output.pay_pubkey_hash(100, hash160)])
        await self.ledger.db.save_transaction_io('insert', tx, address,
                                                 hash160, f'{tx.id}:1:')

        utxos = await self.account.get_utxos()
        self.assertEqual(len(utxos), 1)

        tx = Transaction(is_verified=True)\
            .add_inputs([Input.spend(utxos[0])])
        await self.ledger.db.save_transaction_io('insert', tx, address,
                                                 hash160, f'{tx.id}:1:')
        self.assertEqual(await self.account.get_balance(include_claims=True),
                         0)

        utxos = await self.account.get_utxos()
        self.assertEqual(len(utxos), 0)
Exemplo n.º 2
0
    async def test_sign(self):
        account = Account.from_dict(
            self.ledger, Wallet(), {
                "seed":
                "carbon smart garage balance margin twelve chest sword toas"
                "t envelope bottom stomach absent"
            })

        await account.ensure_address_gap()
        address1, address2 = await account.receiving.get_addresses(limit=2)
        pubkey_hash1 = self.ledger.address_to_hash160(address1)
        pubkey_hash2 = self.ledger.address_to_hash160(address2)

        tx = Transaction() \
            .add_inputs([Input.spend(get_output(int(2*COIN), pubkey_hash1))]) \
            .add_outputs([Output.pay_pubkey_hash(int(1.9*COIN), pubkey_hash2)])

        await tx.sign([account])

        self.assertEqual(
            hexlify(tx.inputs[0].script.values['signature']),
            b'304402200dafa26ad7cf38c5a971c8a25ce7d85a076235f146126762296b1223c42ae21e022020ef9eeb8'
            b'398327891008c5c0be4357683f12cb22346691ff23914f457bf679601')
Exemplo n.º 3
0
 def txi(self, txo):
     return Input.spend(txo)
Exemplo n.º 4
0
def get_input(amount=CENT, pubkey_hash=NULL_HASH):
    return Input.spend(get_output(amount, pubkey_hash))
Exemplo n.º 5
0
def get_input():
    return Input.spend(get_output())