Skip to content

Commit

Permalink
Merge remote-tracking branch 'goatpig/master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudd-O committed Jun 12, 2019
2 parents 485f8eb + 1d02a66 commit 2bbb2d4
Show file tree
Hide file tree
Showing 86 changed files with 4,994 additions and 208 deletions.
7 changes: 3 additions & 4 deletions ArmoryQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,13 +1882,12 @@ def setSatoshiPaths(self):


self.satoshiHomePath = BTC_HOME_DIR
if self.settings.hasSetting('SatoshiDatadir') and \
CLI_OPTIONS.satoshiHome==DEFAULT:
if self.settings.hasSetting('SatoshiDatadir'):
# Setting override BTC_HOME_DIR only if it wasn't explicitly
# set as the command line.
manageSatoshi = self.settings.get('ManageSatoshi')
if manageSatoshi == True:
self.satoshiHomePath = self.settings.get('SatoshiDatadir')
self.satoshiHomePath = str(self.settings.get('SatoshiDatadir'))
LOGINFO('Setting satoshi datadir = %s' % self.satoshiHomePath)

TheBDM.setSatoshiDir(self.satoshiHomePath)
Expand Down Expand Up @@ -5357,7 +5356,7 @@ def doTheSystemTrayThing(self):
if pywlt.hasScrAddr(addr):
continue
if len(recipStr)==0:
recipStr = hash160_to_addrStr(addr[1:], addr[0])
recipStr = scrAddr_to_addrStr(addr)
else:
recipStr = self.tr('<Multiple Recipients>')

Expand Down
8 changes: 6 additions & 2 deletions SDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def findBitcoind(self, extraSearchPaths=[]):

searchPaths.extend([os.path.join(sp, 'Bitcoin') for sp in searchPaths])
searchPaths.extend([os.path.join(sp, 'daemon') for sp in searchPaths])
searchPaths.extend([os.path.join(sp, 'bin') for sp in searchPaths])

possBaseDir = []

Expand Down Expand Up @@ -369,6 +370,9 @@ def spawnDB(self, dataDir, dbDir):
blocksdir = os.path.join(self.satoshiHome, 'blocks')
if os.path.exists(blocksdir):
pargs.append('--satoshi-datadir="' + blocksdir + '"')

if (CLI_OPTIONS.satoshiPort):
pargs.append('--satoshi-port=' + str(BITCOIN_PORT))

pargs.append('--datadir="' + dataDir + '"')
pargs.append('--dbdir="' + dbDir + '"')
Expand All @@ -384,9 +388,9 @@ def spawnDB(self, dataDir, dbDir):
pargs.append('--clear_mempool')

if ARMORY_RAM_USAGE != -1:
pargs.append('--ram-usage=' + ARMORY_RAM_USAGE)
pargs.append('--ram-usage=' + str(ARMORY_RAM_USAGE))
if ARMORY_THREAD_COUNT != -1:
pargs.append('--thread-count=' + ARMORY_THREAD_COUNT)
pargs.append('--thread-count=' + str(ARMORY_THREAD_COUNT))

kargs = {}
if OS_WINDOWS:
Expand Down
40 changes: 26 additions & 14 deletions armoryengine/ArmoryUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
LEVELDB_HEADERS = 'leveldb_headers'

# Version Numbers
BTCARMORY_VERSION = (0, 96, 4, 0) # (Major, Minor, Bugfix, AutoIncrement)
BTCARMORY_VERSION = (0, 96, 5, 0) # (Major, Minor, Bugfix, AutoIncrement)
PYBTCWALLET_VERSION = (1, 35, 0, 0) # (Major, Minor, Bugfix, AutoIncrement)

# ARMORY_DONATION_ADDR = '1ArmoryXcfq7TnCSuZa9fQjRYwJ4bkRKfv'
Expand Down Expand Up @@ -325,6 +325,9 @@ class SignerException(Exception): pass
ARMORY_DB_DIR = ''
SUBDIR = 'testnet3' if USE_TESTNET else '' + 'regtest' if USE_REGTEST else ''

#settingsObject = SettingsFile(CLI_OPTIONS.settingsPath)


if not CLI_OPTIONS.satoshiHome==DEFAULT:
BTC_HOME_DIR = CLI_OPTIONS.satoshiHome
if BTC_HOME_DIR.endswith('blocks'):
Expand Down Expand Up @@ -443,8 +446,8 @@ def readVersionInt(verInt):
# constructor completes so that a warning dialog
# can be displayed
pass
# Same for the directory that holds the LevelDB databases
ARMORY_DB_DIR = os.path.join(ARMORY_HOME_DIR, 'databases')
# Same for the directory that holds the LMDB databases
ARMORY_DB_DIR = os.path.join(ARMORY_HOME_DIR, 'databases')

if not CLI_OPTIONS.armoryDBDir==DEFAULT:
try:
Expand All @@ -460,6 +463,7 @@ def readVersionInt(verInt):
pass



# Change the log file to use
ARMORY_LOG_FILE = os.path.join(ARMORY_HOME_DIR, 'armorylog.txt')
ARMCPP_LOG_FILE = os.path.join(ARMORY_HOME_DIR, 'armorycpplog.txt')
Expand Down Expand Up @@ -508,6 +512,8 @@ def readVersionInt(verInt):
from CppBlockUtils import BlockDataManagerConfig
bdmConfig = BlockDataManagerConfig()

BECH32_PREFIX = "tb" #default to testnet

if not USE_TESTNET and not USE_REGTEST:
# TODO: The testnet genesis tx hash can't be the same...?
BITCOIN_PORT = 8333
Expand All @@ -521,11 +527,12 @@ def readVersionInt(verInt):
ADDRBYTE = '\x00'
P2SHBYTE = '\x05'
PRIVKEYBYTE = '\x80'
BECH32_PREFIX = "bc"

# This will usually just be used in the GUI to make links for the user
BLOCKEXPLORE_NAME = 'blockchain.info'
BLOCKEXPLORE_URL_TX = 'https://blockchain.info/tx/%s'
BLOCKEXPLORE_URL_ADDR = 'https://blockchain.info/address/%s'
BLOCKEXPLORE_NAME = 'blockstream.info'
BLOCKEXPLORE_URL_TX = 'https://blockstream.info/tx/%s'
BLOCKEXPLORE_URL_ADDR = 'https://blockstream.info/address/%s'
else:
#set static members of BDMconfig for address generation on C++ side
bdmConfig.selectNetwork("Test")
Expand Down Expand Up @@ -569,8 +576,11 @@ def readVersionInt(verInt):
SCRADDR_P2SH_BYTE = '\x05'
SCRADDR_MULTISIG_BYTE = '\xfe'
SCRADDR_NONSTD_BYTE = '\xff'
SCRADDR_P2WPKH_BYTE = '\x90'
SCRADDR_P2WSH_BYTE = '\x95'
SCRADDR_BYTE_LIST = [ADDRBYTE, \
P2SHBYTE, \
SCRADDR_P2WPKH_BYTE, SCRADDR_P2WSH_BYTE, \
SCRADDR_MULTISIG_BYTE, \
SCRADDR_NONSTD_BYTE]

Expand Down Expand Up @@ -605,8 +615,8 @@ def readVersionInt(verInt):
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_MULTISIG] = 'Multi-Signature'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_P2SH] = 'Standard (P2SH)'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_NONSTANDARD] = 'Non-Standard'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_P2WPKH] = 'Standard (P2WPKH)'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_P2WSH] = 'Standard (P2WSH)'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_P2WPKH] = 'SegWit (P2WPKH)'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_P2WSH] = 'SegWit (P2WSH)'
CPP_TXOUT_SCRIPT_NAMES[CPP_TXOUT_OPRETURN] = 'Meta Data (OP_RETURN)'

# Copied from cppForSwig/BtcUtils.h::getTxInScriptTypeInt(script)
Expand Down Expand Up @@ -815,7 +825,7 @@ def LOGDEBUG(msg, *a):
try:
logstr = msg if len(a)==0 else (msg%a)
callerStr = getCallerLine() + ' - '
logging.debug(callerStr + logstr)
logging.debug(callerStr + str(logstr))
except TypeError:
traceback.print_stack()
raise
Expand All @@ -824,39 +834,39 @@ def LOGINFO(msg, *a):
try:
logstr = msg if len(a)==0 else (msg%a)
callerStr = getCallerLine() + ' - '
logging.info(callerStr + logstr)
logging.info(callerStr + str(logstr))
except TypeError:
traceback.print_stack()
raise
def LOGWARN(msg, *a):
try:
logstr = msg if len(a)==0 else (msg%a)
callerStr = getCallerLine() + ' - '
logging.warn(callerStr + logstr)
logging.warn(callerStr + str(logstr))
except TypeError:
traceback.print_stack()
raise
def LOGERROR(msg, *a):
try:
logstr = msg if len(a)==0 else (msg%a)
callerStr = getCallerLine() + ' - '
logging.error(callerStr + logstr)
logging.error(callerStr + str(logstr))
except TypeError:
traceback.print_stack()
raise
def LOGCRIT(msg, *a):
try:
logstr = msg if len(a)==0 else (msg%a)
callerStr = getCallerLine() + ' - '
logging.critical(callerStr + logstr)
logging.critical(callerStr + str(logstr))
except TypeError:
traceback.print_stack()
raise
def LOGEXCEPT(msg, *a):
try:
logstr = msg if len(a)==0 else (msg%a)
callerStr = getCallerLine() + ' - '
logging.exception(callerStr + logstr)
logging.exception(callerStr + str(logstr))
except TypeError:
traceback.print_stack()
raise
Expand Down Expand Up @@ -1659,6 +1669,8 @@ def scrAddr_to_addrStr(scrAddr):
return hash160_to_addrStr(scrAddr[1:])
elif prefix==P2SHBYTE:
return hash160_to_p2shAddrStr(scrAddr[1:])
elif prefix==SCRADDR_P2WPKH_BYTE or prefix==SCRADDR_P2WSH_BYTE:
return Cpp.BtcUtils_scriptToBech32(scrAddr[1:], BECH32_PREFIX)
else:
LOGERROR('Unsupported scrAddr type: "%s"' % binary_to_hex(scrAddr))
raise BadAddressError('Can only convert P2PKH and P2SH scripts')
Expand Down
10 changes: 1 addition & 9 deletions armoryengine/BDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def unregisterCppNotification(self, cppNotificationListener):

#############################################################################
@ActLikeASingletonBDM
def goOnline(self, satoshiDir=None, armoryDBDir=None, armoryHomeDir=None):
def goOnline(self):
self.bdv().goOnline()
self.callback = PySide_CallBack(self).__disown__()
self.callback.startLoop()
Expand Down Expand Up @@ -269,14 +269,6 @@ def setSatoshiDir(self, newBtcDir):
return

self.btcdir = newBtcDir

#############################################################################
@ActLikeASingletonBDM
def setArmoryDBDir(self, armoryDBDir):
if not os.path.exists(armoryDBDir):
os.makedirs(armoryDBDir)

self.armoryDBDir = armoryDBDir

#############################################################################
@ActLikeASingletonBDM
Expand Down
5 changes: 4 additions & 1 deletion armoryengine/PyBtcWallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,10 @@ def getAddrCommentIfAvail(self, txHash):
# If we haven't extracted relevant addresses for this tx, yet -- do it
if not self.txAddrMap.has_key(txHash):
self.txAddrMap[txHash] = []
tx = TheBDM.bdv().getTxByHash(txHash)
try:
tx = TheBDM.bdv().getTxByHash(txHash)
except:
return ''
if tx.isInitialized():
for i in range(tx.getNumTxOut()):
txout = tx.getTxOutCopy(i)
Expand Down
20 changes: 16 additions & 4 deletions armoryengine/Transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def __init__(self, rawSupportTx='',
self.value = txout.getValue()
self.contribID = '' if contribID is None else contribID
self.contribLabel= '' if contribLabel is None else contribLabel
self.p2shMap = p2shMap
self.p2shMap = p2shMap if p2shMap is not None else dict()
self.sequence = sequence

# Each of these will be a single value for single-signature UTXOs
Expand Down Expand Up @@ -1827,7 +1827,11 @@ def evaluateSigningStatus(self, cppWlt=None, pytx=None):
signStatus.wltIsRelevant = False
signStatus.wltCanSign = False

if self.signerType in [SIGNER_CPP, SIGNER_BCH]:
signertype = self.signerType
if pytx is not None:
signertype = pytx.signerType_

if signertype in [SIGNER_CPP, SIGNER_BCH]:
if pytx == None:
raise Exception("need pytx cppsigner state to evaluate signing status")

Expand Down Expand Up @@ -1997,6 +2001,8 @@ def __init__(self, script=None, value=None, p2sh=None,
self.multiInfo['Addr160s'] = a160s
self.multiInfo['PubKeys'] = pubs

if self.scriptType in [CPP_TXOUT_P2WPKH, CPP_TXOUT_P2WSH]:
self.version = version | 0xFF000000

#############################################################################
def setAuthData(self, authType, authObj):
Expand Down Expand Up @@ -2115,6 +2121,9 @@ def serialize(self):

bp = BinaryPacker()
bp.put(UINT32, self.version)
if (self.version & 0xFF000000) == 0xFF000000:
bp.put(UINT32, 0xDEADBEEF)

bp.put(BINARY_CHUNK, MAGIC_BYTES)
bp.put(VAR_STR, self.binScript)
bp.put(UINT64, self.value)
Expand All @@ -2133,6 +2142,9 @@ def serialize(self):
def unserialize(self, rawData, skipMagicCheck=False):
bu = BinaryUnpacker(rawData)
version = bu.get(UINT32)
if (version & 0xFF000000) == 0xFF000000:
bu.get(UINT32)

magic = bu.get(BINARY_CHUNK, 4)
script = bu.get(VAR_STR)
value = bu.get(UINT64)
Expand All @@ -2150,7 +2162,7 @@ def unserialize(self, rawData, skipMagicCheck=False):
raise NetworkIDError('Network magic bytes mismatch')


if not version==UNSIGNED_TX_VERSION:
if not (version & 0x00FFFFFF) == UNSIGNED_TX_VERSION:
LOGWARN('Unserialing UnsignedTxInput of different version')
LOGWARN(' USTX Version: %d' % version)
LOGWARN(' Armory Version: %d' % UNSIGNED_TX_VERSION)
Expand All @@ -2159,7 +2171,7 @@ def unserialize(self, rawData, skipMagicCheck=False):
authDataObj = NullAuthData().unserialize(authData)

self.__init__(script, value, p2shScr, wltLoc,
authMeth, authDataObj, contribID, contribLBL)
authMeth, authDataObj, contribID, contribLBL, version)
return self


Expand Down
43 changes: 27 additions & 16 deletions armoryengine/UserAddressUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def getWltIDForScrAddr(scrAddr, walletMap):
wltID = None
lboxID = None
hasAddrInIt = True
isBech32 = False

# Check if this corresponds to a lockbox
if isBareLockbox(userStr) or isP2SHLockbox(userStr):
Expand All @@ -81,33 +82,40 @@ def getWltIDForScrAddr(scrAddr, walletMap):
scrAddr = script_to_scrAddr(outScript)
wltID = getWltIDForScrAddr(scrAddr, wltMap)
else:
scrAddr = addrStr_to_scrAddr(userStr, ADDRBYTE, P2SHBYTE)
a160 = scrAddr_to_hash160(scrAddr)[1]
outScript = scrAddr_to_script(scrAddr)
hasAddrInIt = True

# Check if it's a wallet scrAddr
wltID = getWltIDForScrAddr(scrAddr, wltMap)

# Check if it's a known P2SH
for lbox in lboxList:
if lbox.getAddr() == scrAddr:
lboxID = lbox.uniqueIDB58
break
try:
scrAddr = addrStr_to_scrAddr(userStr, ADDRBYTE, P2SHBYTE)
a160 = scrAddr_to_hash160(scrAddr)[1]
outScript = scrAddr_to_script(scrAddr)
hasAddrInIt = True

# Check if it's a wallet scrAddr
wltID = getWltIDForScrAddr(scrAddr, wltMap)

# Check if it's a known P2SH
for lbox in lboxList:
if lbox.getAddr() == scrAddr:
lboxID = lbox.uniqueIDB58
break
except:
outScript = Cpp.BtcUtils.bech32ToScript(userStr, BECH32_PREFIX)
isBech32 = True


# Caller might be expecting to see None, instead of '' (empty string)
wltID = None if not wltID else wltID
lboxID = None if not lboxID else lboxID
return {'Script': outScript,
'WltID': wltID,
'LboxID': lboxID,
'ShowID': hasAddrInIt}
'ShowID': hasAddrInIt,
'IsBech32' : isBech32}
except:
#LOGEXCEPT('Invalid user string entered')
return {'Script': None,
'WltID': None,
'LboxID': None,
'ShowID': None}
'ShowID': None,
'IsBech32' : isBech32}



Expand Down Expand Up @@ -268,7 +276,10 @@ def truncateStr(theStr, maxLen):

# If we're here, it didn't match any loaded wlt or lockbox
dispStr = ''
if scriptType in CPP_TXOUT_HAS_ADDRSTR:
if scriptType == CPP_TXOUT_P2WPKH or scriptType == CPP_TXOUT_P2WSH:
dispStr = Cpp.BtcUtils_scriptToBech32(binScript[2:], BECH32_PREFIX)
addrStr = dispStr
elif scriptType in CPP_TXOUT_HAS_ADDRSTR:
addrStr = script_to_addrStr(binScript)
if len(addrStr) <= maxChars:
dispStr = addrStr
Expand Down
Loading

0 comments on commit 2bbb2d4

Please sign in to comment.