@ -164,7 +164,12 @@ class BitcoinCoreInterface(BlockchainInterface):
def __init__ ( self , jsonRpc , network ) :
def __init__ ( self , jsonRpc , network ) :
super ( BitcoinCoreInterface , self ) . __init__ ( )
super ( BitcoinCoreInterface , self ) . __init__ ( )
self . jsonRpc = jsonRpc
self . jsonRpc = jsonRpc
blockchainInfo = self . jsonRpc . call ( " getblockchaininfo " , [ ] )
blockchainInfo = self . rpc ( " getblockchaininfo " , [ ] )
if not blockchainInfo :
# see note in BitcoinCoreInterface.rpc - here
# we have to create this object before reactor start,
# so sys.exit *is* the right call:
sys . exit ( EXIT_FAILURE )
actualNet = blockchainInfo [ ' chain ' ]
actualNet = blockchainInfo [ ' chain ' ]
netmap = { ' main ' : ' mainnet ' , ' test ' : ' testnet ' , ' regtest ' : ' regtest ' }
netmap = { ' main ' : ' mainnet ' , ' test ' : ' testnet ' , ' regtest ' : ' regtest ' }
@ -183,12 +188,33 @@ class BitcoinCoreInterface(BlockchainInterface):
return block
return block
def rpc ( self , method , args ) :
def rpc ( self , method , args ) :
""" Returns the result of an rpc call to the Bitcoin Core RPC API.
If the connection is permanently or unrecognizably broken , None
is returned * and the reactor is shutdown * ( because we consider this
condition unsafe - TODO possibly create a " freeze " mode that could
restart when the connection is healed , but that is tricky ) .
"""
if method not in [ ' importaddress ' , ' walletpassphrase ' , ' getaccount ' ,
if method not in [ ' importaddress ' , ' walletpassphrase ' , ' getaccount ' ,
' gettransaction ' , ' getrawtransaction ' , ' gettxout ' ,
' gettransaction ' , ' getrawtransaction ' , ' gettxout ' ,
' importmulti ' , ' listtransactions ' , ' getblockcount ' ,
' importmulti ' , ' listtransactions ' , ' getblockcount ' ,
' scantxoutset ' ] :
' scantxoutset ' ] :
log . debug ( ' rpc: ' + method + " " + str ( args ) )
log . debug ( ' rpc: ' + method + " " + str ( args ) )
try :
res = self . jsonRpc . call ( method , args )
res = self . jsonRpc . call ( method , args )
except JsonRpcConnectionError as e :
# note that we only raise this in case the connection error is
# a refusal, or is unrecognized/unknown by our code. So this does
# NOT happen in a reset or broken pipe scenario.
# It is safest to simply shut down.
# Why not sys.exit? sys.exit calls do *not* work inside delayedCalls
# or deferreds in twisted, since a bare exception catch prevents
# an actual system exit (i.e. SystemExit is caught as a
# BareException type).
log . error ( " Failure of RPC connection to Bitcoin Core. "
" Application cannot continue, shutting down. " )
if reactor . running :
reactor . stop ( )
return None
return res
return res
def is_address_labeled ( self , utxo , walletname ) :
def is_address_labeled ( self , utxo , walletname ) :