def address_reencode( address ): """ Depending on whether or not we're in testnet or mainnet, re-encode an address accordingly. """ vb = pybitcoin.b58check_version_byte( address ) if os.environ.get("BLOCKSTACK_TESTNET") == "1": if vb == 0 or vb == 111: # convert to testnet p2pkh vb = 111 elif vb == 5 or vb == 196: # convert to testnet p2sh vb = 196 else: raise ValueError("unrecognized address %s" % address) else: if vb == 0 or vb == 111: # convert to mainnet p2pkh vb = 0 elif vb == 5 or vb == 196: # convert to mainnet p2sh vb = 5 else: raise ValueError("unrecognized address %s" % address) return pybitcoin.b58check_encode( pybitcoin.b58check_decode(address), vb )
def address_reencode(address): """ Depending on whether or not we're in testnet or mainnet, re-encode an address accordingly. """ vb = pybitcoin.b58check_version_byte(address) if os.environ.get("ZONEFILEMANAGE_TESTNET") == "1": if vb == 0 or vb == 111: # convert to testnet p2pkh vb = 111 elif vb == 5 or vb == 196: # convert to testnet p2sh vb = 196 else: raise ValueError("unrecognized address %s" % address) else: if vb == 0 or vb == 111: # convert to mainnet p2pkh vb = 0 elif vb == 5 or vb == 196: # convert to mainnet p2sh vb = 5 else: raise ValueError("unrecognized address %s" % address) return pybitcoin.b58check_encode(pybitcoin.b58check_decode(address), vb)
def make_transaction(namespace_id, reveal_addr, lifetime, coeff, base_cost, bucket_exponents, nonalpha_discount, no_vowel_discount, payment_addr, blockchain_client, tx_fee=0): """ Propagate a namespace. Arguments: namespace_id human-readable (i.e. base-40) name of the namespace reveal_addr address to own this namespace until it is ready lifetime: the number of blocks for which names will be valid (pass a negative value for "infinite") coeff: cost multipler base_cost: the base cost (i.e. cost of a 1-character name), in satoshis bucket_exponents: bucket cost exponents to which to raise the base cost nonalpha_discount: discount multipler for non-alpha-character names no_vowel_discount: discount multipler for no-vowel names """ namespace_id = str(namespace_id) reveal_addr = str(reveal_addr) lifetime = int(lifetime) coeff = int(coeff) base_cost = int(base_cost) nonalpha_discount = int(nonalpha_discount) no_vowel_discount = int(no_vowel_discount) payment_addr = str(payment_addr) tx_fee = int(tx_fee) assert pybitcoin.b58check_version_byte( payment_addr ) == virtualchain.version_byte, "Only p2pkh reveal addresses are supported" bexp = [] for be in bucket_exponents: bexp.append(int(be)) bucket_exponents = bexp assert is_namespace_valid(namespace_id) nulldata = build(namespace_id, BLOCKSTACK_VERSION, reveal_addr, lifetime, coeff, base_cost, bucket_exponents, nonalpha_discount, no_vowel_discount) # get inputs and from public key inputs = tx_get_unspents(payment_addr, blockchain_client) # build custom outputs here outputs = make_outputs(nulldata, inputs, reveal_addr, payment_addr, tx_fee) return (inputs, outputs)
def is_p2sh_address(address): """ Is the given address a p2sh address? """ vb = pybitcoin.b58check_version_byte(address) if vb == multisig_version_byte: return True else: return False
def is_p2sh_address( address ): """ Is the given address a p2sh address? """ vb = pybitcoin.b58check_version_byte( address ) if vb == multisig_version_byte: return True else: return False
def make_payment_script(address): """ Make a pay-to-address script. * If the address is a pubkey hash, then make a p2pkh script. * If the address is a script hash, then make a p2sh script. """ vb = pybitcoin.b58check_version_byte(address) if vb == version_byte: return pybitcoin.make_pay_to_address_script(address) elif vb == multisig_version_byte: return bitcoin.mk_scripthash_script(address) else: raise ValueError("Unrecognized address '%s'" % address)
def make_payment_script( address ): """ Make a pay-to-address script. * If the address is a pubkey hash, then make a p2pkh script. * If the address is a script hash, then make a p2sh script. """ vb = pybitcoin.b58check_version_byte(address) if vb == version_byte: return pybitcoin.make_pay_to_address_script( address ) elif vb == multisig_version_byte: return bitcoin.mk_scripthash_script( address ) else: raise ValueError("Unrecognized address '%s'" % address )
def make_transaction(namespace_id, register_addr, fee, consensus_hash, preorder_addr, blockchain_client, tx_fee=0, safety=True): """ Propagate a namespace. Arguments: namespace_id human-readable (i.e. base-40) name of the namespace register_addr the addr of the key that will reveal the namespace (mixed into the preorder to prevent name preimage attack races). Must be a p2pkh address private_key the Bitcoin address that created this namespace, and can populate it. """ namespace_id = str(namespace_id) register_addr = str(register_addr) fee = int(fee) consensus_hash = str(consensus_hash) preorder_addr = str(preorder_addr) tx_fee = int(tx_fee) assert is_namespace_valid(namespace_id) assert len(consensus_hash) == LENGTH_CONSENSUS_HASH * 2 assert pybitcoin.b58check_version_byte( preorder_addr ) == virtualchain.version_byte, "Only p2pkh reveal addresses are supported" script_pubkey = virtualchain.make_payment_script(preorder_addr) nulldata = build(namespace_id, script_pubkey, register_addr, consensus_hash) # get inputs and from address inputs = tx_get_unspents(preorder_addr, blockchain_client) if safety: assert len(inputs) > 0 # build custom outputs here outputs = make_outputs(nulldata, inputs, preorder_addr, fee, tx_fee) return (inputs, outputs)