def test_database_cache_create_drop(self):
     dbtmp = DbCache(DATABASEFILE_CACHE_TMP)
     srv = Service(cache_uri=DATABASEFILE_CACHE_TMP,
                   exclude_providers=['bitaps', 'bitgo'])
     t = srv.gettransaction(
         '68104dbd6819375e7bdf96562f89290b41598df7b002089ecdd3c8d999025b13')
     if t:
         self.assertGreaterEqual(srv.results_cache_n, 0)
         srv.gettransaction(
             '68104dbd6819375e7bdf96562f89290b41598df7b002089ecdd3c8d999025b13'
         )
         self.assertGreaterEqual(srv.results_cache_n, 1)
         dbtmp.drop_db()
         self.assertRaisesRegex(
             OperationalError, "", srv.gettransaction,
             '68104dbd6819375e7bdf96562f89290b41598df7b002089ecdd3c8d999025b13'
         )
Exemple #2
0
     '474c0e24e530d78716fc9c88ac00000000'
print("\nSEND Raw Transaction:")
srv = Service(network='testnet')
if srv.sendrawtransaction(rt):
    print("Transaction send, result: ")
    pprint(srv.results)
else:
    print("Transaction could not be send, errors:")
    pprint(srv.errors)

# Get current estimated networks fees
print("\nCurrent estimated networks fees:")
srv = Service(min_providers=10)
srv.estimatefee(5)
pprint(srv.results)

# Test address with huge number of UTXO's
# addresslst = '16ZbpCEyVVdqu8VycWR8thUL2Rd9JnjzHt'
# addresslst = '1KwA4fS4uVuCNjCtMivE7m5ATbv93UZg8V'
# srv = Service(network='bitcoin', min_providers=10)
# utxos = srv.getutxos(addresslst)
# results = srv.results
# for res in results:
#     print(res, len(results[res]))

# Get transactions by hash
srv = Service()
res = srv.gettransaction(
    '2ae77540ec3ef7b5001de90194ed0ade7522239fe0fc57c12c772d67274e2700')
pprint(res)
from bitcoinlib.services.services import Service

bdc = BitcoindClient()

# Check bitcoind connection
pprint(bdc.proxy.getnetworkinfo())

# Get latest block
latest_block_hash = bdc.proxy.getbestblockhash()
print("Getting latest block with hash %s" % latest_block_hash)
latest_block = bdc.proxy.getblock(latest_block_hash)
transactions = latest_block['tx']
print("Found %d transactions" % len(transactions))

srv = Service(network='bitcoin')

MAX_TRANSACTIONS = 100
count = 0
count_segwit = 0
for txid in transactions[:MAX_TRANSACTIONS]:
    print("\n=== Deserialize transaction #%d (segwit %d) ===" %
          (count, count_segwit))
    count += 1
    t = srv.gettransaction(txid)
    t.verify()
    t.info()
    if t.witness_type != 'legacy':
        count_segwit += 1
    if not t.verified:
        input("Transaction could not be verified, press any key to continue")