def send_to_bitcoin(wif, change_address, payload: bytes, is_testnet=True, is_dryrun=True, fee=10000): if is_dryrun: print("*** DRY RUN ***") else: print("*** LIVE ***") if is_testnet: print("*** TEST NET ***") else: print("*** MAIN NET ***") api = BtcTxStore(testnet=is_testnet, dryrun=is_dryrun) data = hexlify(payload) transaction_id = api.store_nulldata(hexdata=data, wifs=[wif], change_address=change_address, fee=fee) return transaction_id
class TestStoreNulldata(unittest.TestCase): def setUp(self): self.api = BtcTxStore(dryrun=True, testnet=True) def test_store_nulldata_alpha(self): wifs = fixtures["store_nulldata"]["alpha"]["wifs"] result = self.api.store_nulldata("f483", wifs) expected = fixtures["store_nulldata"]["alpha"]["expected"] self.assertEqual(result, expected) def test_store_nulldata_beta(self): wifs = fixtures["store_nulldata"]["beta"]["wifs"] expected = fixtures["store_nulldata"]["beta"]["expected"] data = binascii.hexlify(b"github.com/F483/btctxstore") result = self.api.store_nulldata(data, wifs) self.assertEqual(result, expected) def test_store_nulldata_insufficient_funds(self): wifs = fixtures["store_nulldata"]["insufficient_funds"]["wifs"] data = binascii.hexlify(b"f483") def callback(): self.api.store_nulldata(data, wifs) self.assertRaises(exceptions.InsufficientFunds, callback) def test_store_nulldata_txouts(self): wifs = fixtures["store_nulldata"]["txouts"]["wifs"] txouts = fixtures["store_nulldata"]["txouts"]["txouts"] expected = fixtures["store_nulldata"]["txouts"]["expected"] result = self.api.store_nulldata("f483", wifs, txouts=txouts) self.assertEqual(result, expected) def test_store_nulldata_change_address(self): _fixtures = fixtures["store_nulldata"]["change_address"] wifs = _fixtures["wifs"] change_address = _fixtures["change_address"] expected = _fixtures["expected"] result = self.api.store_nulldata("f483", wifs, change_address) self.assertEqual(result, expected)
class TestStoreNulldata(unittest.TestCase): def setUp(self): self.api = BtcTxStore(dryrun=True, testnet=True) def test_store_nulldata_alpha(self): wifs = fixtures["store_nulldata"]["alpha"]["wifs"] result = self.api.store_nulldata("f483", wifs) expected = fixtures["store_nulldata"]["alpha"]["expected"] self.assertEqual(result, expected) def test_store_nulldata_beta(self): wifs = fixtures["store_nulldata"]["beta"]["wifs"] expected = fixtures["store_nulldata"]["beta"]["expected"] data = binascii.hexlify(b"github.com/F483/btctxstore") result = self.api.store_nulldata(data, wifs) self.assertIn(result, expected) def test_store_nulldata_insufficient_funds(self): wifs = fixtures["store_nulldata"]["insufficient_funds"]["wifs"] data = binascii.hexlify(b"f483") def callback(): self.api.store_nulldata(data, wifs) self.assertRaises(exceptions.InsufficientFunds, callback) def test_store_nulldata_txouts(self): wifs = fixtures["store_nulldata"]["txouts"]["wifs"] txouts = fixtures["store_nulldata"]["txouts"]["txouts"] expected = fixtures["store_nulldata"]["txouts"]["expected"] result = self.api.store_nulldata("f483", wifs, txouts=txouts) self.assertEqual(result, expected) def test_store_nulldata_change_address(self): _fixtures = fixtures["store_nulldata"]["change_address"] wifs = _fixtures["wifs"] change_address = _fixtures["change_address"] expected = _fixtures["expected"] result = self.api.store_nulldata("f483", wifs, change_address) self.assertEqual(result, expected)
#!/usr/bin/env python # coding: utf-8 # Copyright (c) 2015 Fabian Barkhau <*****@*****.**> # License: MIT (see LICENSE file) from __future__ import print_function from __future__ import unicode_literals import binascii from btctxstore import BtcTxStore # Wallet used to pay for fee. Please do not spend the testnet coins is # this wallet or the example will fail due to lack of funds. wifs = ["cUZfG8KJ3BrXneg2LjUX4VoMg76Fcgx6QDiAZj2oGbuw6da8Lzv1"] # use testnet and dont post tx to blockchain for example api = BtcTxStore(testnet=True, dryrun=True) # store data in blockchain as nulldata output (max 40bytes) data = binascii.hexlify(b"github.com/F483/btctxstore") txid = api.store_nulldata(data, wifs) print(txid)