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)) # 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] # we're providing a key map for the inputs. pubKeyMap = {} for utxo in selectedUtxoList: scrType = getTxOutScriptType(utxo.getScript()) if scrType in CPP_TXOUT_STDSINGLESIG: scrAddr = utxo.getRecipientScrAddr() a160 = scrAddr_to_hash160(scrAddr)[1] addrObj = masterWallet.getAddrByHash160(a160) if addrObj: pubKeyMap[scrAddr] = addrObj.binPublicKey65.toBinStr() ustx = UnsignedTransaction().createFromTxOutSelection(selectedUtxoList, scrPairs, pubKeyMap) masterWallet.unlock(securePassphrase = SecureBinaryData(getpass('Enter your secret string:'))) # Sign and prepare the final transaction for broadcast masterWallet.signUnsignedTx(ustx) pytx = ustx.getPyTxSignedIfPossible() print '\nSigned transaction to be broadcast using Armory "offline transactions"...' print ustx.serializeAscii() finally: TheBDM.beginCleanShutdown() 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] # we're providing a key map for the inputs. pubKeyMap = {} for utxo in selectedUtxoList: scrType = getTxOutScriptType(utxo.getScript()) if scrType in CPP_TXOUT_STDSINGLESIG: scrAddr = utxo.getRecipientScrAddr() a160 = scrAddr_to_hash160(scrAddr)[1] addrObj = masterWallet.getAddrByHash160(a160) if addrObj: pubKeyMap[scrAddr] = addrObj.binPublicKey65.toBinStr() ustx = UnsignedTransaction().createFromTxOutSelection(selectedUtxoList, scrPairs, pubKeyMap) masterWallet.unlock(securePassphrase = SecureBinaryData(getpass('Enter your secret string:'))) # Sign and prepare the final transaction for broadcast masterWallet.signUnsignedTx(ustx) pytx = ustx.getPyTxSignedIfPossible() print '\nSigned transaction to be broadcast using Armory "offline transactions"...' print ustx.serializeAscii() finally: TheBDM.beginCleanShutdown() return pytx
def tearDownClass(self): def tiabBDMShutdownCallback(action, arg): global doneShuttingDownBDM if action == STOPPED_ACTION: doneShuttingDownBDM = True TheBDM.registerCppNotification(tiabBDMShutdownCallback) TheBDM.beginCleanShutdown() i = 0 while not doneShuttingDownBDM: time.sleep(0.5) i += 1 if i >= 40: raise RuntimeError("Timeout waiting for TheBDM to shutdown.") self.tiab.clean()