Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Dec 7, 2024
1 parent 42e8632 commit 487a0a6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
16 changes: 8 additions & 8 deletions counterparty-core/counterpartycore/lib/gettxinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def get_der_signature_sighash_flag(value):
return value[-1:]
if value.startswith(binascii.unhexlify("3045")) and len(value) == 72:
return value[-1:]
if value.startswith(binascii.unhexlify("3046")) and len(value) == 73:
return value[-1:]
return None


Expand Down Expand Up @@ -242,20 +244,18 @@ def check_signatures_sighash_flag(decoded_tx):

flags = collect_sighash_flagss(script_sig, witnesses)

print("script_sig", script_sig)
print("witnesses", witnesses)
print("flags", flags)

if len(flags) == 0:
raise SighashFlagError(
f"impossible to determine SIGHASH flag for transaction {decoded_tx['tx_hash']}"
)
error = f"impossible to determine SIGHASH flag for transaction {decoded_tx['tx_hash']}"
logger.debug(error)
raise SighashFlagError(error)

# first input must be signed with SIGHASH_ALL or SIGHASH_ALL|SIGHASH_ANYONECANPAY
authorized_flags = [b"\x01", b"\x81"]
for flag in flags:
if flag not in authorized_flags:
raise SighashFlagError(f"invalid SIGHASH flag for transaction {decoded_tx['tx_hash']}")
error = f"invalid SIGHASH flag for transaction {decoded_tx['tx_hash']}"
logger.debug(error)
raise SighashFlagError(error)


def get_transaction_sources(decoded_tx):
Expand Down
50 changes: 31 additions & 19 deletions counterparty-core/counterpartycore/test/regtest/regtestnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from bitcoinutils.transactions import Transaction, TxInput, TxOutput
from counterpartycore.lib import arc4, config, database

WALLET_NAME = "xcpwallet"

setup("regtest")

WALLET_NAME = "xcpwallet"


class ServerNotReady(Exception):
pass
Expand Down Expand Up @@ -56,6 +56,7 @@ def __init__(
f"-datadir={self.datadir}/node2",
)
self.bitcoin_wallet = self.bitcoin_cli.bake(f"-rpcwallet={WALLET_NAME}")
self.bitcoin_wallet_2 = self.bitcoin_cli_2.bake(f"-rpcwallet={WALLET_NAME}")
self.bitcoind_process = None
self.addresses = []
self.block_count = 0
Expand Down Expand Up @@ -163,6 +164,22 @@ def compose_and_send_transaction(

return f"{utxo['txid']}:{utxo['vout']}", tx_hash

def compose(self, source, tx_name, params):
query_string = []
for key, value in params.items():
if not isinstance(value, list):
query_string.append(urllib.parse.urlencode({key: value}))
else:
for i in range(len(value)):
query_string.append(urllib.parse.urlencode({key: value[i]}))
query_string = "&".join(query_string)

if tx_name in ["detach", "movetoutxo"]:
compose_url = f"utxos/{source}/compose/{tx_name}?{query_string}"
else:
compose_url = f"addresses/{source}/compose/{tx_name}?{query_string}"
return self.api_call(compose_url)

def send_transaction(
self,
source,
Expand All @@ -182,20 +199,8 @@ def send_transaction(
# params["inputs_set"] = self.get_inputs_set(source)
# print("Inputs set:", params["inputs_set"])

query_string = []
for key, value in params.items():
if not isinstance(value, list):
query_string.append(urllib.parse.urlencode({key: value}))
else:
for i in range(len(value)):
query_string.append(urllib.parse.urlencode({key: value[i]}))
query_string = "&".join(query_string)
result = self.compose(source, tx_name, params)

if tx_name in ["detach", "movetoutxo"]:
compose_url = f"utxos/{source}/compose/{tx_name}?{query_string}"
else:
compose_url = f"addresses/{source}/compose/{tx_name}?{query_string}"
result = self.api_call(compose_url)
# print(result)
if "error" in result:
if result["error"] == "Counterparty not ready":
Expand Down Expand Up @@ -317,10 +322,15 @@ def generate_xcp(self):
self.mine_blocks(1)
self.wait_for_counterparty_server()

def get_inputs_set(self, address):
list_unspent = json.loads(
self.bitcoin_cli("listunspent", 0, 9999999, json.dumps([address])).strip()
)
def get_inputs_set(self, address, node=1):
if node == 1:
list_unspent = json.loads(
self.bitcoin_cli("listunspent", 0, 9999999, json.dumps([address])).strip()
)
else:
list_unspent = json.loads(
self.bitcoin_cli_2("listunspent", 0, 9999999, json.dumps([address])).strip()
)
sorted(list_unspent, key=lambda x: -x["amount"])
inputs = []
for utxo in list_unspent:
Expand Down Expand Up @@ -575,6 +585,8 @@ def get_burn_count(self, address):
def get_xcp_balance(self, address):
try:
return self.api_call(f"addresses/{address}/balances/XCP")["result"][0]["quantity"]
except IndexError: # no XCP balance
return 0
except KeyError:
print("Error getting XCP balance, retrying in 2 seconds...")
time.sleep(2)
Expand Down

0 comments on commit 487a0a6

Please sign in to comment.