def test_wallet_transaction(self):
        client = self.setup_api_client()

        wallet = client.init_wallet("unittest-transaction", "password")

        confirmed, unconfirmed = wallet.get_balance()
        self.assertGreater(unconfirmed + confirmed, 0)
        self.assertGreater(confirmed, 0)

        path, address = wallet.get_new_address_pair()
        self.assertTrue("M/9999'/0" in path)
        # self.assertEqual(address, "2MzyKviSL6pnWxkbHV7ecFRE3hWKfzmT8WS" # validate address)

        value = blocktrail.to_satoshi(0.0002)
        txhash = wallet.pay([(address, value)])

        self.assertTrue(txhash)

        time.sleep(1)

        tx = client.transaction(txhash)

        self.assertTrue(tx)
        self.assertEqual(tx['hash'], txhash)
        self.assertTrue(len(tx['outputs']) <= 2)
        self.assertTrue(value in map(lambda o: o['value'], tx['outputs']))
    def test_new_blank_wallet(self):
        client = self.setup_api_client()

        identifier = self.get_random_test_identifier()

        # wallet shouldn't exist yet
        wallet = None
        try:
            wallet = client.init_wallet(identifier, 'password')
        except ObjectNotFound as e:
            pass
        self.assertFalse(wallet)

        # create wallet
        wallet, primary_mnemonic, backup_mnemonic, blocktrail_pubkeys = client.create_new_wallet(
            identifier, "password", 9999)

        self.cleanup_data.setdefault('wallets', []).append(wallet)

        # wallet shouldn't be able to pay
        txhash = None
        try:
            txhash = wallet.pay({
                "2N6Fg6T74Fcv1JQ8FkPJMs8mYmbm9kitTxy":
                blocktrail.to_satoshi(0.001)
            })
        except:
            pass
        self.assertFalse(txhash)

        # same wallet with bad password shouldn't be initialized
        wallet = None
        try:
            wallet = client.init_wallet(identifier, "badpassword")
        except:
            pass
        self.assertFalse(wallet)
示例#3
0
from __future__ import print_function
import blocktrail
from blocktrail.exceptions import ObjectNotFound

client = blocktrail.APIClient("MY_APIKEY", "MY_APISECRET", testnet=True)

try:
    wallet = client.init_wallet("example-wallet", "example-strong-password")
except ObjectNotFound:
    wallet, primary_mnemonic, backup_mnemonic, blocktrail_pubkeys = client.create_new_wallet(
        "example-wallet", "example-strong-password", key_index=9999)
    wallet.do_discovery()

print(wallet.get_new_address_pair())

print(wallet.get_balance())

path, address = wallet.get_new_address_pair()

print(wallet.pay([(address, blocktrail.to_satoshi(0.001))]))
示例#4
0
    def test_coin_value(self):
        assert 1 == blocktrail.to_satoshi(0.00000001)
        assert 1.0, blocktrail.to_btc(100000000)

        assert 123456789, blocktrail.to_satoshi(1.23456789)
        assert 1.23456789, blocktrail.to_btc(123456789)
    def test_coin_value(self):
        assert 1 == blocktrail.to_satoshi(0.00000001)
        assert 1.0, blocktrail.to_btc(100000000)

        assert 123456789, blocktrail.to_satoshi(1.23456789)
        assert 1.23456789, blocktrail.to_btc(123456789)
from __future__ import print_function
import blocktrail

client = blocktrail.APIClient("YOUR_APIKEY_HERE", "YOUR_APISECRET_HERE")

address = client.address("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp")
print(address['address'], address['balance'])

print(len(client.address_transactions("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp")['data']))

print(client.verify_address("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk="))

# Dealing with numbers
print("123456789 Satoshi to BTC: ", blocktrail.to_btc(123456789))
print("1.23456789 BTC to Satoshi: ", blocktrail.to_satoshi(1.23456789))
from __future__ import print_function
import blocktrail

client = blocktrail.APIClient("YOUR_APIKEY_HERE", "YOUR_APISECRET_HERE")

address = client.address("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp")
print(address['address'], address['balance'])

print(
    len(
        client.address_transactions("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp")
        ['data']))

print(
    client.verify_address(
        "16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z",
        "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk="
    ))

# Dealing with numbers
print("123456789 Satoshi to BTC: ", blocktrail.to_btc(123456789))
print("1.23456789 BTC to Satoshi: ", blocktrail.to_satoshi(1.23456789))