def mktx( amt, tx_fee, recipient_addr, privkey, message=None ): """ Make the transaction with the given fee """ change_addr = virtualchain.BitcoinPrivateKey(privkey).public_key().address() inputs = testlib.get_unspents(change_addr) change = virtualchain.calculate_change_amount(inputs, amt, tx_fee) outputs = [ {'script': virtualchain.make_payment_script(recipient_addr), 'value': amt}, ] if change > 0: # need change and tx fee outputs.append( {'script': virtualchain.make_payment_script(change_addr), "value": change} ) if message: outputs = [ {"script": virtualchain.make_data_script(binascii.hexlify(message)), "value": 0} ] + outputs serialized_tx = blockstack_client.tx.serialize_tx(inputs, outputs) signed_tx = blockstack_client.tx.sign_tx(serialized_tx, privkey) return signed_tx
def check(state_engine): global wallets # not revealed, but ready ns = state_engine.get_namespace_reveal("test") if ns is not None: return False ns = state_engine.get_namespace("test") if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr) if preorder is not None: return False # registered name_rec = state_engine.get_name("foo.test") if name_rec is None: return False # updated, but revoked, so data should be None if name_rec['value_hash'] is not None: return False # transferred if name_rec['address'] != wallets[4].addr or name_rec[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[4].addr): return False # previously owned by... name_rec_prev = state_engine.get_name_at( "foo.test", sorted(name_rec['history'].keys())[-1] - 2)[0] if name_rec_prev['address'] != wallets[3].addr or name_rec_prev[ 'sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): return False # revoked if not name_rec['revoked']: return False # verify that the user wallets (3 and 4) were *not* debited any btc rc = True for wallet in [wallets[3], wallets[4]]: unspents = testlib.get_unspents(wallet.addr) value = sum([us['value'] for us in unspents]) if value < 100000000000: print "value of '%s' is '%s'" % (wallet.addr, value) rc = False return rc
def check( state_engine ): global wallets # not revealed, but ready ns = state_engine.get_namespace_reveal( "test" ) if ns is not None: return False ns = state_engine.get_namespace( "test" ) if ns is None: return False if ns['namespace_id'] != 'test': return False # not preordered preorder = state_engine.get_name_preorder( "foo.test", pybitcoin.make_pay_to_address_script(wallets[2].addr), wallets[3].addr ) if preorder is not None: return False # registered name_rec = state_engine.get_name( "foo.test" ) if name_rec is None: return False # updated, but revoked, so data should be None if name_rec['value_hash'] is not None: return False # transferred if name_rec['address'] != wallets[4].addr or name_rec['sender'] != pybitcoin.make_pay_to_address_script(wallets[4].addr): return False # previously owned by... name_rec_prev = state_engine.get_name_at( "foo.test", sorted( name_rec['history'].keys() )[-1] - 2 )[0] if name_rec_prev['address'] != wallets[3].addr or name_rec_prev['sender'] != pybitcoin.make_pay_to_address_script(wallets[3].addr): return False # revoked if not name_rec['revoked']: return False # verify that the user wallets (3 and 4) were *not* debited any btc rc = True for wallet in [wallets[3], wallets[4]]: unspents = testlib.get_unspents( wallet.addr ) value = sum( [us['value'] for us in unspents] ) if value < 100000000000: print "value of '%s' is '%s'" % (wallet.addr, value) rc = False return rc