Example #1
0
 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)
Example #2
0
 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)
Example #3
0
    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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
    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)
Example #7
0
 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)
Example #8
0
 def callback():
     deserialize.key(True, "garbage")
Example #9
0
 def callback():
     deserialize.key(True, "garbage")
Example #10
0
 def validate_key(self, wif):  # TODO test
     try:
         deserialize.key(self.testnet, wif)
         return True
     except exceptions.InvalidInput:
         return False
Example #11
0
 def callback():
     deserialize.key(True, None)
Example #12
0
 def callback():
     deserialize.key(False, "garbage")
Example #13
0
 def callback():
     deserialize.key(True, mainnet_wif)
Example #14
0
 def callback():
     deserialize.key(False, None)
Example #15
0
 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)
Example #16
0
 def validate_key(self, wif):  # TODO test
     try:
         deserialize.key(self.testnet, wif)
         return True
     except exceptions.InvalidInput:
         return False
Example #17
0
 def callback():
     deserialize.key(False, testnet_wif)
Example #18
0
 def callback():
     deserialize.key(False, "garbage")
Example #19
0
 def callback():
     deserialize.key(True, None)
Example #20
0
 def callback():
     deserialize.key(False, None)
Example #21
0
 def callback():
     deserialize.key(True, mainnet_wif)
Example #22
0
 def get_address(self, wif):
     """Return bitcoin address for given wallet. """
     return deserialize.key(self.testnet, wif).address()
Example #23
0
 def callback():
     deserialize.key(False, testnet_wif)
Example #24
0
 def get_address(self, wif):
     """Return bitcoin address for given wallet. """
     return deserialize.key(self.testnet, wif).address()
Example #25
0
def key_network(wif, testnet):
    try:
        deserialize.key(testnet, wif)
        return True
    except exceptions.InvalidInput:
        return False