Merge branch 'testing' into 13-appointment-signature

This commit is contained in:
Salvatore Ingala
2019-10-18 08:32:38 +08:00
17 changed files with 598 additions and 206 deletions

View File

@@ -11,8 +11,3 @@ logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[
logging.FileHandler(conf.SERVER_LOG_FILE),
logging.StreamHandler()
])
# Create RPC connection with bitcoind
# TODO: Check if a long lived connection like this may create problems (timeouts)
bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST,
conf.BTC_RPC_PORT))

View File

@@ -1,8 +1,8 @@
import binascii
from hashlib import sha256
from pisa import bitcoin_cli
from pisa.logger import Logger
from pisa.tools import bitcoin_cli
from pisa.utils.auth_proxy import JSONRPCException
logger = Logger("BlockProcessor")
@@ -13,7 +13,7 @@ class BlockProcessor:
def get_block(block_hash):
try:
block = bitcoin_cli.getblock(block_hash)
block = bitcoin_cli().getblock(block_hash)
except JSONRPCException as e:
block = None
@@ -25,7 +25,7 @@ class BlockProcessor:
def get_best_block_hash():
try:
block_hash = bitcoin_cli.getbestblockhash()
block_hash = bitcoin_cli().getbestblockhash()
except JSONRPCException as e:
block_hash = None
@@ -37,7 +37,7 @@ class BlockProcessor:
def get_block_count():
try:
block_count = bitcoin_cli.getblockcount()
block_count = bitcoin_cli().getblockcount()
except JSONRPCException as e:
block_count = None
@@ -73,7 +73,7 @@ class BlockProcessor:
try:
# ToDo: #20-test-tx-decrypting-edge-cases
justice_rawtx = appointments[uuid].encrypted_blob.decrypt(dispute_txid)
justice_txid = bitcoin_cli.decoderawtransaction(justice_rawtx).get('txid')
justice_txid = bitcoin_cli().decoderawtransaction(justice_rawtx).get('txid')
logger.info("Match found for locator.", locator=locator, uuid=uuid, justice_txid=justice_txid)
except JSONRPCException as e:

View File

@@ -1,6 +1,6 @@
from pisa.rpc_errors import *
from pisa import bitcoin_cli
from pisa.logger import Logger
from pisa.tools import bitcoin_cli
from pisa.utils.auth_proxy import JSONRPCException
from pisa.errors import UNKNOWN_JSON_RPC_EXCEPTION
@@ -20,7 +20,7 @@ class Carrier:
def send_transaction(self, rawtx, txid):
try:
logger.info("Pushing transaction to the network", txid=txid, rawtx=rawtx)
bitcoin_cli.sendrawtransaction(rawtx)
bitcoin_cli().sendrawtransaction(rawtx)
receipt = Receipt(delivered=True)
@@ -70,7 +70,7 @@ class Carrier:
@staticmethod
def get_transaction(txid):
try:
tx_info = bitcoin_cli.getrawtransaction(txid, 1)
tx_info = bitcoin_cli().getrawtransaction(txid, 1)
except JSONRPCException as e:
tx_info = None

View File

@@ -2,7 +2,6 @@ import re
from pisa import errors
import pisa.conf as conf
from pisa import bitcoin_cli
from pisa.logger import Logger
from pisa.appointment import Appointment
from pisa.block_processor import BlockProcessor

View File

@@ -1,6 +1,7 @@
import json
from queue import Queue
from threading import Thread
from hashlib import sha256
from threading import Thread
from binascii import unhexlify
from pisa.logger import Logger
@@ -34,6 +35,9 @@ class Job:
return job
def to_json(self):
return json.dumps(self.to_dict())
class Responder:
def __init__(self):
@@ -62,6 +66,8 @@ class Responder:
# TODO: Add the missing reasons (e.g. RPC_VERIFY_REJECTED)
pass
return receipt
def create_job(self, uuid, dispute_txid, justice_txid, justice_rawtx, appointment_end, confirmations=0,
retry=False):
@@ -155,7 +161,7 @@ class Responder:
for uuid, job in self.jobs.items():
if job.appointment_end <= height:
tx = Carrier.get_transaction(job.dispute_txid)
tx = Carrier.get_transaction(job.justice_txid)
# FIXME: Should be improved with the librarian
confirmations = tx.get('confirmations')

View File

@@ -1,10 +1,15 @@
import re
from http.client import HTTPException
from pisa import bitcoin_cli
import pisa.conf as conf
from pisa.logger import Logger
from pisa.utils.auth_proxy import JSONRPCException
from pisa.rpc_errors import RPC_INVALID_ADDRESS_OR_KEY
from pisa.utils.auth_proxy import AuthServiceProxy, JSONRPCException
def bitcoin_cli():
return AuthServiceProxy("http://%s:%s@%s:%d" % (conf.BTC_RPC_USER, conf.BTC_RPC_PASSWD, conf.BTC_RPC_HOST,
conf.BTC_RPC_PORT))
# TODO: currently only used in the Responder; might move there or in the BlockProcessor
@@ -13,7 +18,7 @@ def check_tx_in_chain(tx_id, logger=Logger(), tx_label='Transaction'):
confirmations = 0
try:
tx_info = bitcoin_cli.getrawtransaction(tx_id, 1)
tx_info = bitcoin_cli().getrawtransaction(tx_id, 1)
if tx_info.get("confirmations"):
confirmations = int(tx_info.get("confirmations"))
@@ -38,7 +43,7 @@ def can_connect_to_bitcoind():
can_connect = True
try:
bitcoin_cli.help()
bitcoin_cli().help()
except (ConnectionRefusedError, JSONRPCException, HTTPException):
can_connect = False
@@ -50,7 +55,7 @@ def in_correct_network(network):
testnet3_genesis_block_hash = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
correct_network = False
genesis_block_hash = bitcoin_cli.getblockhash(0)
genesis_block_hash = bitcoin_cli().getblockhash(0)
if network == 'mainnet' and genesis_block_hash == mainnet_genesis_block_hash:
correct_network = True
@@ -65,3 +70,4 @@ def in_correct_network(network):
def check_txid_format(txid):
# TODO: #12-check-txid-regexp
return isinstance(txid, str) and re.search(r'^[0-9A-Fa-f]{64}$', txid) is not None