Bitcoin Forum
May 07, 2024, 07:50:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to get a list of UXTOs?  (Read 1264 times)
chrisrico (OP)
Hero Member
*****
Offline Offline

Activity: 496
Merit: 500


View Profile
October 05, 2014, 12:47:47 AM
 #1

Hi Armory dev team/community!

I'm trying to migrate my cold storage wallet from Armory to my Trezor. I have a bunch of outputs to different addresses, and what I'd like to do is create an UnsignedTransaction for each address, spending all of the funds (minus fees) to a Trezor address (assume I have a sufficient number of these available in a Python list). I've got a lot of these outputs, so I really don't want to do this through the GUI. I didn't see an easy way to do this using armoryd, so I am writing a Python script.

Here's my code so far:

Code:
import sys

sys.path.append('..')

from armoryengine.ALL import *

walletFile = "[REDACTED]"

wallet = PyBtcWallet().readWalletFile(walletFile)
TheBDM.registerWallet(wallet.cppWallet)

TheBDM.setOnlineMode(goOnline=True, wait=True)

for o in wallet.getTxOutList():
output = PyUnspentTxOut(o)
output.pprint()


TheBDM.execCleanShutdown(wait=True)

Every time I run this, I get a Segmentation fault with nothing in the logs. I'm on a Mac and am working from git master. Any ideas?

Here's what I do have in my logs:

Code:
-INFO  - 1412470223: (BlockUtils.cpp:4441) Finished blockchain scan in 6.04233 seconds
-INFO  - 1412470223: (BlockUtils.cpp:4460) Updating registered addresses
-INFO  - 1412470223: (BlockUtils.cpp:4468) Scanning Wallets
-INFO  - 1412470223: (BlockUtils.cpp:4479) Scanning Wallet #1 from height 0
-INFO  - 1412470223: (BlockUtils.cpp:4800) Saving wallet history to DB
Segmentation fault: 11
1715068245
Hero Member
*
Offline Offline

Posts: 1715068245

View Profile Personal Message (Offline)

Ignore
1715068245
Reply with quote  #2

1715068245
Report to moderator
1715068245
Hero Member
*
Offline Offline

Posts: 1715068245

View Profile Personal Message (Offline)

Ignore
1715068245
Reply with quote  #2

1715068245
Report to moderator
Even if you use Bitcoin through Tor, the way transactions are handled by the network makes anonymity difficult to achieve. Do not expect your transactions to be anonymous unless you really know what you're doing.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715068245
Hero Member
*
Offline Offline

Posts: 1715068245

View Profile Personal Message (Offline)

Ignore
1715068245
Reply with quote  #2

1715068245
Report to moderator
etotheipi
Legendary
*
Offline Offline

Activity: 1428
Merit: 1093


Core Armory Developer


View Profile WWW
October 05, 2014, 01:00:01 AM
 #2

First of all, there are some examples you can use in the extras directory in the project.  Also some stuff here:

https://bitcoinarmory.com/developers/python-scripting/

Those might be slightly out of date, but require minimal modification to make them work.  And for such a script, I recommend doing TheBDM.setBlocking(True), which is better for scripts ... it means that the BDM, while still in a separate thread, will behave like it's in the same thread, and every request will block until it's done.  The sample_armory_code.py in the extras directory shows you an example of both.

You can use wlt.getTxOutList('Spendable') to get a list C++ TxOut objects:

https://github.com/etotheipi/BitcoinArmory/blob/master/ui/TxFrames.py#L826

You can then run them right through Armory's coin-selection algorithm:

https://github.com/etotheipi/BitcoinArmory/blob/master/ui/TxFrames.py#L598

That should be enough to hold you over in the short-term Smiley

Founder and CEO of Armory Technologies, Inc.
Armory Bitcoin Wallet: Bringing cold storage to the average user!
Only use Armory software signed by the Armory Offline Signing Key (0x98832223)

Please donate to the Armory project by clicking here!    (or donate directly via 1QBDLYTDFHHZAABYSKGKPWKLSXZWCCJQBX -- yes, it's a real address!)
chrisrico (OP)
Hero Member
*****
Offline Offline

Activity: 496
Merit: 500


View Profile
October 05, 2014, 06:07:02 AM
 #3

Thanks for pointing me in the right direction. Here was my final script:

Code:
import sys

sys.path.append('..')

from armoryengine.ALL import *

receivingAddresses = [...]

walletFile = "..."

wallet = PyBtcWallet().readWalletFile(walletFile)
TheBDM.registerWallet(wallet.cppWallet)

TheBDM.setBlocking(doblock=True, newTimeout=60*60)
TheBDM.setOnlineMode()

for address in wallet.getAddrList():
uxto = wallet.getAddrTxOutList(address.getAddr160())
if len(uxto) == 0:
continue
addressBalance = sum([o.getValue() for o in uxto])
keyMap = {o.getRecipientScrAddr(): address.binPublicKey65.toBinStr() for o in uxto}
outputs = [[addrStr_to_script(receivingAddresses.pop()), addressBalance]]
tx = UnsignedTransaction().createFromTxOutSelection(uxto, outputs, keyMap)
fileName = "armory_{0}_{1}BTC.unsigned.tx".format(tx.asciiID, coin2str(addressBalance, 0, False, 0))
with open(fileName, 'w') as txFile:
txFile.write(tx.serializeAscii())

TheBDM.execCleanShutdown()

Basically, I wanted these unsigned transactions handy to more easily transfer funds to the Trezor as needed/became more comfortable with its security model. I wanted a 1-1 address correspondence between my Armory and Trezor addresses, with no mixing. Fees are negligible because they've been sitting around for so long.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!