def get_channel_update(self, channel, amount, key=b'a'): self._set_channel_key(channel, key) return self._make_tx( Output.pay_update_claim_pubkey_hash(amount, channel.claim_name, channel.claim_id, channel.claim, b'abc'), Input.spend(channel))
def test_get_utxo(self): address = yield self.account.receiving.get_or_create_usable_address() hash160 = self.ledger.address_to_hash160(address) tx = Transaction().add_outputs([Output.pay_pubkey_hash(100, hash160)]) yield self.ledger.db.save_transaction_io('insert', tx, True, address, hash160, '{}:{}:'.format(tx.id, 1)) utxos = yield self.account.get_unspent_outputs() self.assertEqual(len(utxos), 1) tx = Transaction().add_inputs([Input.spend(utxos[0])]) yield self.ledger.db.save_transaction_io('insert', tx, True, address, hash160, '{}:{}:'.format(tx.id, 1)) balance = yield self.account.get_balance(0, include_claims=True) self.assertEqual(balance, 0) utxos = yield self.account.get_unspent_outputs() self.assertEqual(len(utxos), 0)
async def test_sign(self): account = self.ledger.account_class.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')
async def test_creating_updating_and_abandoning_claim_with_channel(self): await self.account.ensure_address_gap() address1, address2 = await self.account.receiving.get_addresses( limit=2, only_usable=True) sendtxid1 = await self.blockchain.send_to_address(address1, 5) sendtxid2 = await self.blockchain.send_to_address(address2, 5) await self.blockchain.generate(1) await asyncio.wait([ self.on_transaction_id(sendtxid1), self.on_transaction_id(sendtxid2) ]) self.assertEqual(d2l(await self.account.get_balance()), '10.0') channel = Claim() channel_txo = Output.pay_claim_name_pubkey_hash( l2d('1.0'), '@bar', channel, self.account.ledger.address_to_hash160(address1)) channel_txo.generate_channel_private_key() channel_txo.script.generate() channel_tx = await Transaction.create([], [channel_txo], [self.account], self.account) stream = Claim() stream.stream.source.media_type = "video/mp4" stream_txo = Output.pay_claim_name_pubkey_hash( l2d('1.0'), 'foo', stream, self.account.ledger.address_to_hash160(address1)) stream_tx = await Transaction.create([], [stream_txo], [self.account], self.account) stream_txo.sign(channel_txo) await stream_tx.sign([self.account]) await self.broadcast(channel_tx) await self.broadcast(stream_tx) await asyncio.wait([ # mempool self.ledger.wait(channel_tx), self.ledger.wait(stream_tx) ]) await self.blockchain.generate(1) await asyncio.wait([ # confirmed self.ledger.wait(channel_tx), self.ledger.wait(stream_tx) ]) self.assertEqual(d2l(await self.account.get_balance()), '7.985786') self.assertEqual( d2l(await self.account.get_balance(include_claims=True)), '9.985786') response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo') self.assertIn('lbry://@bar/foo', response) self.assertIn('claim', response['lbry://@bar/foo']) abandon_tx = await Transaction.create( [Input.spend(stream_tx.outputs[0])], [], [self.account], self.account) await self.broadcast(abandon_tx) await self.ledger.wait(abandon_tx) await self.blockchain.generate(1) await self.ledger.wait(abandon_tx) response = await self.ledger.resolve(0, 10, 'lbry://@bar/foo') self.assertNotIn('claim', response['lbry://@bar/foo']) # checks for expected format in inexistent URIs response = await self.ledger.resolve(0, 10, 'lbry://404', 'lbry://@404') self.assertEqual('URI lbry://404 cannot be resolved', response['lbry://404']['error']) self.assertEqual('URI lbry://@404 cannot be resolved', response['lbry://@404']['error'])
def get_input(): return Input.spend(get_output())
def get_stream_abandon(self, tx): claim = Transaction(tx[0].serialize()).outputs[0] return self._make_tx(Output.pay_pubkey_hash(claim.amount, b'abc'), Input.spend(claim))
def get_stream_update(self, tx, amount): claim = Transaction(tx[0].serialize()).outputs[0] return self._make_tx( Output.pay_update_claim_pubkey_hash(amount, claim.claim_name, claim.claim_id, claim.claim, b'abc'), Input.spend(claim))