def add_broadcast_message(self, rawtx, message, sender_wif, dust_limit=common.DUST_LIMIT): """TODO add docstring""" tx = deserialize.tx(rawtx) message = deserialize.unicode_str(message) sender_key = deserialize.key(self.testnet, sender_wif) tx = control.add_broadcast_message(self.testnet, tx, message, sender_key, dust_limit=dust_limit) return serialize.tx(tx)
def test_invalid_netcode(self): testnet_wif = "cNf7CMEHfD2jLtiTASbCAEneVnVmD4syA4A9KhUXqAkRs26Ke6xw" mainnet_wif = "KzU3561hXZwFPrzmHkJ6FLWvykFJMQnMEwSKXW5VPpz6HcxuvpZq" # test positive deserialize.key(True, testnet_wif) # testnet deserialize.key(False, mainnet_wif) # mainnet # testnet negative def callback(): deserialize.key(False, testnet_wif) self.assertRaises(exceptions.InvalidWif, callback) # mainnet negative def callback(): deserialize.key(True, mainnet_wif) self.assertRaises(exceptions.InvalidWif, callback) # testnet non string def callback(): deserialize.key(False, None) self.assertRaises(exceptions.InvalidInput, callback) # mainnet non string def callback(): deserialize.key(True, None) self.assertRaises(exceptions.InvalidInput, callback) # testnet garbage string def callback(): deserialize.key(False, "garbage") self.assertRaises(exceptions.InvalidWif, callback) # mainnet garbage string def callback(): deserialize.key(True, "garbage") self.assertRaises(exceptions.InvalidWif, callback)
def split_utxos(self, wif, limit, fee=10000, max_outputs=100): """Split utxos of <wif> unitil <limit> or <max_outputs> reached.""" key = deserialize.key(self.testnet, wif) limit = deserialize.positive_integer(limit) fee = deserialize.positive_integer(fee) max_outputs = deserialize.positive_integer(max_outputs) spendables = control.retrieve_utxos(self.service, [key.address()]) txids = control.split_utxos(self.service, self.testnet, key, spendables, limit, fee=fee, max_outputs=max_outputs, publish=(not self.dryrun)) return serialize.txids(txids)
def sign_data(self, wif, hexdata): """Signing <hexdata> with <wif> private key.""" data = deserialize.binary(hexdata) key = deserialize.key(self.testnet, wif) sigdata = control.sign_data(self.testnet, data, key) return serialize.signature(sigdata)
def callback(): deserialize.key(True, "garbage")
def validate_key(self, wif): # TODO test try: deserialize.key(self.testnet, wif) return True except exceptions.InvalidInput: return False
def callback(): deserialize.key(True, None)
def callback(): deserialize.key(False, "garbage")
def callback(): deserialize.key(True, mainnet_wif)
def callback(): deserialize.key(False, None)
def callback(): deserialize.key(False, testnet_wif)
def get_address(self, wif): """Return bitcoin address for given wallet. """ return deserialize.key(self.testnet, wif).address()
def key_network(wif, testnet): try: deserialize.key(testnet, wif) return True except exceptions.InvalidInput: return False