Post
Topic
Board Armory
Re: Armory - Discussion Thread
by
chrcoe01
on 12/08/2013, 20:32:08 UTC
Here's my code for my watching only script to load the blockchain and read a balance for some addresses.  Hope this helps.

Code:
import sys
sys.path.append('..')
sys.path.append('.')

from armoryengine import *
from time import sleep
start = RightNow()

TheBDM.setBlocking(True)
TheBDM.setOnlineMode(True)
print 'Loading blockchain took %0.1f sec' % (RightNow() - start)
start = RightNow()
topBlock = TheBDM.getTopBlockHeight()
print '\n\nCurrent Top Block is:', topBlock
TheBDM.getTopBlockHeader().pprint()

cppWallet = Cpp.BtcWallet()
cppWallet.addAddress_1_( addrStr_to_hash160("1ArmoryXcfq7TnCSuZa9fQjRYwJ4bkRKfv") )

print cppWallet.getNumAddr(),' addresses in this wallet'
print '\n\nRegistering the wallet with the BlockDataManager & loading...'
TheBDM.registerWallet(cppWallet)
TheBDM.scanBlockchainForTx(cppWallet)
print '\n\nTransaction history of this wallet:'
ledger = cppWallet.getTxLedger()
for le in ledger:
le.pprintOneLine()
print '\n\n************************************\nBalance of this wallet:', coin2str(cppWallet.getSpendableBalance())
print 'Unspent outputs:'
unspentTxOuts = cppWallet.getSpendableTxOutList(topBlock)
for utxo in unspentTxOuts:
utxoAddr = hash160_to_addrStr(utxo.getRecipientAddr())
print utxoAddr," ",float(utxo.getValue())/100000000.0, " ",utxo.getNumConfirm()

while True:
if TheBDM.getBDMState()=='BlockchainReady':
prevTopBlock = TheBDM.getTopBlockHeight()
newBlks = TheBDM.readBlkFileUpdate()
if newBlks>0:
print newBlks," new blocks found"
latestBlockNum = TheBDM.getTopBlockHeight()
topTimestamp   = TheBDM.getTopBlockHeader().getTimestamp()

TheBDM.scanBlockchainForTx(cppWallet)
print '\n\nTransaction history of this wallet:'
ledger = cppWallet.getTxLedger()
for le in ledger:
le.pprintOneLine()
print '\n\n************************************\nBalance of this wallet:', coin2str(cppWallet.getSpendableBalance())
print 'Unspent outputs:'
unspentTxOuts = cppWallet.getSpendableTxOutList(topBlock)
for utxo in unspentTxOuts:
utxoAddr = hash160_to_addrStr(utxo.getRecipientAddr())
print utxoAddr," ",float(utxo.getValue())/100000000.0, " ",utxo.getNumConfirm()
time.sleep(10)

this is helpful for sure!

etotheipi - I spent the last hour or two going through the example scripts, I am sure I will be able to get it going how I want, if I need to discuss this more, I may split it out as you suggest.