|
| 1 | +# Run with python make_raw_tx.py --testnet |
| 2 | +from armoryengine import * |
| 3 | + |
| 4 | +wallet_name = '/home/tom/.armory/testnet3/armory_2bZuo2ari_.wallet' |
| 5 | + |
| 6 | +# |
| 7 | +# Source bitcoin addresses for the transaction |
| 8 | +# |
| 9 | +source_addr_list = ['myHnTiAfku2nqLBvj4CA5DXiXKR1pdaAkW'] |
| 10 | + |
| 11 | +# |
| 12 | +# Destination bitcoin address for the transaction. |
| 13 | +# |
| 14 | +dest_list = [('mk5pFDdTFfnUke4fo9J4weqrX2vKLFokcE', long(1))] |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +# |
| 19 | +# The intermediate file that contains the transaction to be sent to the |
| 20 | +# keepkey. |
| 21 | +# |
| 22 | +tx_unsigned_outfile = 'tx_unsigned_out.dat' |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +def createTxFromAddrList(walletObj, addrList, recipList, \ |
| 27 | + fee=0, changeAddr=None): |
| 28 | + # |
| 29 | + # Warning: Assumes the wallet is synced with the blockchain already. |
| 30 | + # Ensure that you've started armory up already, which does that |
| 31 | + # automatically at startup. |
| 32 | + # |
| 33 | + |
| 34 | + # Check that all addresses are actually in the specified wallet |
| 35 | + print '\nVerifying transaction addresses.' |
| 36 | + for addr in addrList: |
| 37 | + addr160 = addrStr_to_hash160(addr) |
| 38 | + if not walletObj.hasAddr(addr160): |
| 39 | + raise WalletAddressError, 'Address is not in wallet! [%s]' % addr |
| 40 | + |
| 41 | + # |
| 42 | + # Load the block chain |
| 43 | + # |
| 44 | + start = RightNow() |
| 45 | + TheBDM.setBlocking(True) |
| 46 | + TheBDM.setOnlineMode(True) |
| 47 | + # The setOnlineMode should block until blockchain loading is complete |
| 48 | + print 'Loading blockchain took %0.1f sec' % (RightNow() - start) |
| 49 | + |
| 50 | + topBlock = TheBDM.getTopBlockHeight() |
| 51 | + print '\n\nCurrent Top Block is:', topBlock |
| 52 | + TheBDM.getTopBlockHeader().pprint() |
| 53 | + |
| 54 | + print '\nCollecting Unspent TXOut List...' |
| 55 | + # getAddrTxOutList() returns a C++ vector<UnspentTxOut> object, which must |
| 56 | + # be converted to a python object using the [:] notation: it's a weird |
| 57 | + # consequence of mixing C++ code with python via SWIG... |
| 58 | + utxoList = [] |
| 59 | + for addr in addrList: |
| 60 | + addr160 = addrStr_to_hash160(addr) |
| 61 | + unspentTxOuts = walletObj.getAddrTxOutList(addr160, 'Spendable') |
| 62 | + utxoList.extend(unspentTxOuts[:]) |
| 63 | + |
| 64 | + # Display what we found |
| 65 | + totalUtxo = sumTxOutList(utxoList) |
| 66 | + totalSpend = sum([pair[1] for pair in recipList]) |
| 67 | + print 'Available: %d unspent outputs from %d addresses: %s BTC' % \ |
| 68 | + (len(utxoList), len(addrList), coin2str(totalUtxo, ndec=2)) |
| 69 | + |
| 70 | + # Print more detailed information |
| 71 | + pprintUnspentTxOutList(utxoList, 'Available outputs: ') |
| 72 | + |
| 73 | +def main(): |
| 74 | + print "Opening armory wallet %s" % wallet_name |
| 75 | + wlt = PyBtcWallet().readWalletFile(wallet_name) |
| 76 | + TheBDM.registerWallet(wlt) |
| 77 | + |
| 78 | + print "Creating unsigned transaction: " |
| 79 | + print " Testnet test bitcoin : " + source_addr_list[0] |
| 80 | + print " Tx Unsigned Outfile : " + tx_unsigned_outfile |
| 81 | + print " Current blockchain state : " + TheBDM.getBDMState() |
| 82 | + raw_tx = createTxFromAddrList(wlt, source_addr_list, dest_list) |
| 83 | + |
| 84 | + execCleanShutdown() |
| 85 | + |
| 86 | +if __name__ == '__main__': |
| 87 | + main() |
| 88 | + |
| 89 | + |
0 commit comments