def sweepImportedAddrs(masterWallet): setupTheBDM() recipValuePairs = [] utxoList = [] for importedAddr in masterWallet.getLinearAddrList(): if importedAddr.chainIndex<0: addr160 = importedAddr.getAddr160() utxoList.extend(masterWallet.getAddrTxOutList(addr160)) # get total value totalAvailable = sum([u.getValue() for u in utxoList]) fee = calcMinSuggestedFees(utxoList, totalAvailable, MIN_RELAY_TX_FEE, 1)[1] totalSpend = totalAvailable - fee if totalSpend<0: print '***ERROR: The fees are greater than the funds being swept!' raise NegativeValueError recipValuePairs.append((masterWallet.getNextUnusedAddress().getAddr160(), totalSpend )) # ACR: To support P2SH in general, had to change createFromTxOutSelection # to take full scripts, not just hash160 values. Convert the list # before passing it in scrPairs = [[hash160_to_p2pkhash_script(r), v] for r,v in recipValuePairs] txdp = PyTxDistProposal().createFromTxOutSelection(utxoList, scrPairs) masterWallet.unlock(securePassphrase = SecureBinaryData(getpass('Enter your secret string:'))) # Sign and prepare the final transaction for broadcast masterWallet.signTxDistProposal(txdp) pytx = txdp.prepareFinalTx() print '\nSigned transaction to be broadcast using Armory "offline transactions"...' print txdp.serializeAscii() return pytx
def distributeBtc(masterWallet, amount, sendingAddrList): pytx = None setupTheBDM() try: recipValuePairs = [] utxoList = [] for sendingAddr in sendingAddrList: addr160 = sendingAddr.getAddr160() # Make sure the sending addresses are in the masterWallet if not masterWallet.hasAddr(addr160): raise WalletAddressError, 'Address is not in wallet! [%s]' % sendingAddr.getAddrStr() utxoList.extend(masterWallet.getAddrTxOutList(addr160)) for importedAddr in masterWallet.getLinearAddrList(): if importedAddr.chainIndex<0: recipValuePairs.append((importedAddr.getAddr160(),amount)) totalSpend = len(recipValuePairs)*amount fee = calcMinSuggestedFees(utxoList, totalSpend, MIN_RELAY_TX_FEE, len(recipValuePairs))[1] # Get the necessary utxo list selectedUtxoList = PySelectCoins(utxoList, totalSpend, fee) # get total value totalAvailable = sum([u.getValue() for u in selectedUtxoList]) totalChange = totalAvailable - (totalSpend + fee) # Make sure there are funds to cover the transaction. if totalChange < 0: print '***ERROR: you are trying to spend more than your balance!' raise NegativeValueError recipValuePairs.append((masterWallet.getNextUnusedAddress().getAddr160(), totalChange )) # ACR: To support P2SH in general, had to change createFromTxOutSelection # to take full scripts, not just hash160 values. Convert the list # before passing it in scrPairs = [[hash160_to_p2pkhash_script(r), v] for r,v in recipValuePairs] txdp = PyTxDistProposal().createFromTxOutSelection(selectedUtxoList, scrPairs) masterWallet.unlock(securePassphrase = SecureBinaryData(getpass('Enter your secret string:'))) # Sign and prepare the final transaction for broadcast masterWallet.signTxDistProposal(txdp) pytx = txdp.prepareFinalTx() print '\nSigned transaction to be broadcast using Armory "offline transactions"...' print txdp.serializeAscii() finally: TheBDM.execCleanShutdown() return pytx