Hi there!
I am working since severl months on armoryd, I am on work and have not enough time to compare code files and i dont know which are implemented right now on Armoryd (current version)
here some functions which I have implemented:
Unsigned Transaction (but I use always same change address as fromAddress)
##############################################################################
def jsonrpc_sendtoaddressfromaddress(self, addrFrom, addrTo, amount):
if CLI_OPTIONS.offline:
raise ValueError('Cannot create transactions when offline')
amtCoin = long(round(float(amount))) #ya nos vienen en satoshi
return self.create_unsigned_transaction_address(addrFrom, addrTo, amtCoin)
#############################################################################
def create_unsigned_transaction_address(self, fromAddress, toAddress, amount):
# Get unspent TxOutList and select the coins
#addr160_recipient = addrStr_to_hash160(bitcoinaddress_str)
totalSend = long(amount)
fee = 0
if not checkAddrStrValid(fromAddress):
raise InvalidBitcoinAddress
if not checkAddrStrValid(toAddress):
raise InvalidBitcoinAddress
atype, addr160 = addrStr_to_hash160(fromAddress)
if atype==P2SHBYTE:
raise P2SHNotSupportedError
atype, recip160 = addrStr_to_hash160(toAddress)
if atype==P2SHBYTE:
raise P2SHNotSupportedError
fromAddrScript = hash160_to_p2pkhash_script(addr160)
toAddrScript = hash160_to_p2pkhash_script(recip160)
cppAddr = self.wallet.cppWallet.getScrAddrObjByKey(Hash160ToScrAddr(addr160))
spendBal = cppAddr.getSpendableBalance()
utxoList = self.wallet.getAddrTxOutList(addr160, 'Spendable')
utxoSelect = PySelectCoins(utxoList, totalSend, fee)
minFeeRec = calcMinSuggestedFees(utxoSelect, totalSend, fee, 1)[1]
if fee if totalSend + minFeeRec > spendBal:
raise NotEnoughCoinsError, "You can't afford the fee!"
utxoSelect = PySelectCoins(utxoList, totalSend, minFeeRec)
fee = minFeeRec
if len(utxoSelect)==0:
raise CoinSelectError, "Somehow, coin selection failed. This shouldn't happen"
totalSelected = sum([u.getValue() for u in utxoSelect])
totalChange = totalSelected - (totalSend + fee)
recipValuePairs = []
recipValuePairs.append([toAddrScript, totalSend])
if totalChange > 0:
changeAddress = fromAddress
recipValuePairs.append( [fromAddrScript, totalChange] )
txdp = PyTxDistProposal().createFromTxOutSelection(utxoSelect, recipValuePairs)
utxoList = []
for i in range(len(utxoSelect)):
utxo = utxoSelect[i]
a160 = CheckHash160(utxo.getRecipientScrAddr())
OwnerAddress = hash160_to_addrStr(a160)
Value = AmountToJSON(utxo.getValue())
Confirmmations = utxo.getNumConfirm()
txHashBin = utxo.getTxHash()
txHashHex = binary_to_hex(txHashBin, BIGENDIAN)
TxHash = txHashHex
TxOutIndex = utxo.getTxOutIndex()
TxHeight = utxo.getTxHeight()
utxoList.append( { 'OwnerAddress' : OwnerAddress,
'Value' : Value,
'Confirmmations' : Confirmmations,
'TxHash' : TxHash,
'TxOutIndex' : TxOutIndex,
'TxHeight' : TxHeight
})
jutxoList = {}
jutxoList['utxos'] = utxoList
jutxoList['txAscii'] = txdp.serializeAscii()
return jutxoList
#########################################################################
def jsonrpc_sendmanyfromaddress(self, address, args):
if CLI_OPTIONS.offline:
raise ValueError('Cannot create transactions when offline')
scraddrValuePairs = []
dic = json.loads(args)
for a in dic.keys():
scraddrValuePairs.append([a, long(dic[a])])
return self.create_unsigned_transaction_many_address(address, scraddrValuePairs)
###############################################################################
def create_unsigned_transaction_many_address(self, fromAddress, scraddrValuePairs):
# Get unspent TxOutList and select the coins
#addr160_recipient = addrStr_to_hash160(bitcoinaddress_str)
totalSend = long(sum([rv[1] for rv in scraddrValuePairs]))
fee = 0
if not checkAddrStrValid(fromAddress):
raise InvalidBitcoinAddress
toAddrScripts = []
for rv in scraddrValuePairs:
# Verify validity of address strings
toAddress = rv[0]
if not checkAddrStrValid(toAddress):
raise InvalidBitcoinAddress
atype, recip160 = addrStr_to_hash160(toAddress)
if atype == P2SHBYTE:
raise P2SHNotSupportedError
toAddrScripts.append([hash160_to_p2pkhash_script(recip160), rv[1]])
atype, addr160 = addrStr_to_hash160(fromAddress)
if atype == P2SHBYTE:
raise P2SHNotSupportedError
fromAddrScript = hash160_to_p2pkhash_script(addr160)
cppAddr = self.wallet.cppWallet.getScrAddrObjByKey(Hash160ToScrAddr(addr160))
spendBal = cppAddr.getSpendableBalance() #getAddrBalance(addr160) #getAddrBalance(self, addr160, balType="Spendable",
#currBlk=UINT32_MAX)
utxoList = self.wallet.getAddrTxOutList(addr160, 'Spendable')
utxoSelect = PySelectCoins(utxoList, totalSend, fee)
#minFeeRec = calcMinSuggestedFees(utxoSelect, totalSend, fee)[1] // OLD !!! This Branch requieres 4 Parameters.
minFeeRec = calcMinSuggestedFees(utxoSelect, totalSend, fee, len(toAddrScripts))[1]
if fee < minFeeRec:
if totalSend + minFeeRec > spendBal:
raise NotEnoughCoinsError, "You can't afford the fee!"
utxoSelect = PySelectCoins(utxoList, totalSend, minFeeRec)
fee = minFeeRec
if len(utxoSelect) == 0:
raise CoinSelectError, "Somehow, coin selection failed. This shouldn't happen"
totalSelected = sum([u.getValue() for u in utxoSelect])
totalChange = totalSelected - (totalSend + fee)
recipValuePairs = []
for i in range(len(toAddrScripts)):
recipValuePairs.append([toAddrScripts[i][0], toAddrScripts[i][1]])
if totalChange > 0:
changeAddress = fromAddress
recipValuePairs.append([fromAddrScript, totalChange])
#Armory changed logic on Addresses, now only Script addresses
txdp = PyTxDistProposal().createFromTxOutSelection(utxoSelect, recipValuePairs)
utxoList = []
for i in range(len(utxoSelect)):
utxo = utxoSelect[i]
a160 = CheckHash160(utxo.getRecipientScrAddr())
OwnerAddress = hash160_to_addrStr(a160)
Value = AmountToJSON(utxo.getValue())
Confirmmations = utxo.getNumConfirm()
txHashBin = utxo.getTxHash()
txHashHex = binary_to_hex(txHashBin, BIGENDIAN)
TxHash = txHashHex
TxOutIndex = utxo.getTxOutIndex()
TxHeight = utxo.getTxHeight()
utxoList.append( { 'OwnerAddress' : OwnerAddress,
'Value' : Value,
'Confirmmations' : Confirmmations,
'TxHash' : TxHash,
'TxOutIndex' : TxOutIndex,
'TxHeight' : TxHeight
})
jutxoList = {}
jutxoList['utxos'] = utxoList
jutxoList['txAscii'] = txdp.serializeAscii()
return jutxoList
################################################################################
Utxo List by address
##############################################################################
def jsonrpc_utxolistbyaddress(self, addr58, txType):
atype, a160 = addrStr_to_hash160(addr58, False)
if atype==P2SHBYTE:
raise P2SHNotSupportedError
utxos = self.wallet.getAddrTxOutList(a160, txType)
utxoList = []
for i in range(len(utxos)):
utxo = utxos[i]
outPoint = utxo.getOutPoint()
a160 = CheckHash160(utxo.getRecipientScrAddr())
OwnerAddress = hash160_to_addrStr(a160)
Value = AmountToJSON(utxo.getValue())
Confirmmations = utxo.getNumConfirm()
txHashBin = utxo.getTxHash()
txHashHex = binary_to_hex(txHashBin, BIGENDIAN)
TxHash = txHashHex
TxOutIndex = utxo.getTxOutIndex()
TxHeight = utxo.getTxHeight()
utxoList.append( { 'OwnerAddress' : OwnerAddress,
'Value' : Value,
'Confirmmations' : Confirmmations,
'TxHash' : TxHash,
'TxOutIndex' : TxOutIndex,
'TxHeight' : TxHeight
})
jutxoList = { 'utxos' : utxoList }
return jutxoList
Get HexTx so then you can broadcast it over BitcoinD
##############################################################################
def jsonrpc_gethextxtobroadcast(self, txASCII):
############################## COMMENTED PARA PROBAR CON COLA INTERNA HEARTBEAT
txdp = PyTxDistProposal().unserializeAscii(txASCII)
finalTx = txdp.getBroadcastTxIfReady()
newTxHash = finalTx.getHash()
LOGINFO('Sending Tx, %s', binary_to_hex(newTxHash))
print 'Segun armory Tx, %s', binary_to_hex(newTxHash)
return binary_to_hex(finalTx.serialize())
Get Balance by Address
def jsonrpc_getbalancebyaddress(self, address, baltype='spendable'):
if address == None:
LOGERROR('jsonrpc_getbalancebyaddress address parameter is none')
return -1
if not baltype in ['spendable','spend', 'unconf', 'unconfirmed', \
'total', 'ultimate','unspent', 'full']:
LOGERROR('Unrecognized getbalance string: "%s"', baltype)
return -1
if address == None:
return -1
if CLI_OPTIONS.offline:
raise ValueError('Cannot get received amount when offline')
atype, addr160 = addrStr_to_hash160(address)
if atype == P2SHBYTE:
raise P2SHNotSupportedError
if (not TheBDM.getBDMState() == 'BlockchainReady' and not self.calledFromBDM) or \
not self.wallet.hasAddr(addr160):
return -1
cppAddr = self.wallet.cppWallet.getScrAddrObjByKey(Hash160ToScrAddr(addr160))
currBlk = TheBDM.getTopBlockHeight()
spendBal = 0
if baltype.lower() in ('spendable','spend'):
spendBal = cppAddr.getSpendableBalance(currBlk, IGNOREZC)
elif baltype.lower() in ('unconfirmed','unconf'):
spendBal =cppAddr.getUnconfirmedBalance(currBlk, IGNOREZC)
elif baltype.lower() in ('ultimate','unspent','full'):
spendBal = cppAddr.getFullBalance()
else:
raise TypeError('Unknown balance type!')
return AmountToJSON(spendBal)
Hope noth that much errors in the code