Skip to content

Commit

Permalink
more cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 7, 2025
1 parent 5bb17e5 commit fac3536
Show file tree
Hide file tree
Showing 11 changed files with 4,727 additions and 4,751 deletions.
4,778 changes: 2,389 additions & 2,389 deletions apiary.apib

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion counterparty-core/counterpartycore/lib/api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,6 @@ def get_tx_info(tx_hex, block_index=None):
use_txid = util.enabled("correct_segwit_txids", block_index=block_index)
with LedgerDBConnectionPool().connection() as db:
decoded_tx = deserialize.deserialize_tx(tx_hex, use_txid=use_txid, parse_vouts=True)
print("DEcoded tx", decoded_tx)
source, destination, btc_amount, fee, data, _dispensers_outs, _utxos_info = (
gettxinfo.get_tx_info(
db,
Expand Down
2 changes: 0 additions & 2 deletions counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,6 @@ def info(db, rawtransaction: str, block_index: int = None):
except exceptions.BitcoindRPCError:
source, destination, btc_amount, fee, data = None, None, None, None, None

if "__data__" in decoded_tx:
del decoded_tx["__data__"]
result = {
"source": source,
"destination": destination if destination else None,
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ def parse_new_block(db, decoded_block, tx_index=None):
raw_current_block = backend.bitcoind.getblock(current_block_hash)
decoded_block = deserialize.deserialize_block(
raw_current_block,
use_txid=True,
use_txid=util.enabled("correct_segwit_txids"),
parse_vouts=True,
block_index=previous_block_index + 1,
)
Expand Down
4 changes: 1 addition & 3 deletions counterparty-core/counterpartycore/lib/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def determine_encoding(data, construct_params):

def encrypt_data(data, arc4_key):
key = arc4.init_arc4(binascii.unhexlify(arc4_key))
encrypted_data = key.encrypt(data)
return encrypted_data
return key.encrypt(data)


def prepare_opreturn_output(data, arc4_key):
Expand Down Expand Up @@ -838,7 +837,6 @@ def check_transaction_sanity(tx_info, composed_tx, construct_params):

# check if source address matches the first input address
first_utxo_txid = decoded_tx["vin"][0]["hash"]
# first_utxo_txid = util.inverse_hash(binascii.hexlify(first_utxo_txid).decode("utf-8"))
first_utxo = f"{first_utxo_txid}:{decoded_tx['vin'][0]['n']}"

if util.is_utxo_format(source):
Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/gettxinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ def get_tx_info_new(db, decoded_tx, block_index, p2sh_is_segwit=False, composing
# Get destinations and data outputs.
if "parsed_vouts" not in decoded_tx:
raise DecodeError("no parsed_vouts in decoded_tx")

if isinstance(decoded_tx["parsed_vouts"], Exception):
raise DecodeError(str(decoded_tx["parsed_vouts"]))
elif decoded_tx["parsed_vouts"] == "DecodeError":
if decoded_tx["parsed_vouts"] == "DecodeError":
raise DecodeError("unrecognised output type")

destinations, btc_amount, fee, data, potential_dispensers = decoded_tx["parsed_vouts"]

# source can be determined by parsing the p2sh_data transaction
Expand Down
243 changes: 116 additions & 127 deletions counterparty-core/counterpartycore/test/bytespersigop_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,130 +19,119 @@


def test_bytespersigop(server_db):
with util_test.ConfigContext(DISABLE_ARC4_MOCKING=True):
with util_test.MockProtocolChangesContext(short_tx_type_id=False):
assert util.enabled("bytespersigop") == False # noqa: E712

# ADDR[0], bytespersigop=False, desc 41 bytes, opreturn
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[0],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 41,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(
binascii.unhexlify(txhex["rawtransaction"])
)

print("test_bytespersigop 4")

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_RETURN" in repr(tx.vout[0].scriptPubKey)

# ADDR[0], bytespersigop=False, desc 42 bytes, multisig
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[0],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 42,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(
binascii.unhexlify(txhex["rawtransaction"])
)

assert len(tx.vin) == 1
# assert len(tx.vout) == 3
assert "OP_CHECKMULTISIG" in repr(tx.vout[0].scriptPubKey)
assert "OP_CHECKMULTISIG" in repr(tx.vout[1].scriptPubKey)

# enable byterpersigop
with util_test.MockProtocolChangesContext(bytespersigop=True):
assert util.enabled("bytespersigop") == True # noqa: E712

# ADDR[0], bytespersigop=True, desc 41 bytes, opreturn
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[0],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 41,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(
binascii.unhexlify(txhex["rawtransaction"])
)

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_RETURN" in repr(tx.vout[0].scriptPubKey)

# ADDR[1], bytespersigop=True, desc 41 bytes, opreturn encoding
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[1],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 41,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(
binascii.unhexlify(txhex["rawtransaction"])
)

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_RETURN" in repr(tx.vout[0].scriptPubKey)

# ADDR[1], bytespersigop=True, desc 20 bytes, FORCED encoding=multisig
# will use 2 UTXOs to make the bytes:sigop ratio in our favor
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[1],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 20,
},
{"encoding": "multisig"},
)

print("rawtransaction: ", txhex["rawtransaction"])
tx = bitcoinlib.core.CTransaction.deserialize(
binascii.unhexlify(txhex["rawtransaction"])
)

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_CHECKMULTISIG" in repr(tx.vout[0].scriptPubKey)
with util_test.MockProtocolChangesContext(short_tx_type_id=False):
assert util.enabled("bytespersigop") == False # noqa: E712

# ADDR[0], bytespersigop=False, desc 41 bytes, opreturn
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[0],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 41,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(binascii.unhexlify(txhex["rawtransaction"]))

print("test_bytespersigop 4")

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_RETURN" in repr(tx.vout[0].scriptPubKey)

# ADDR[0], bytespersigop=False, desc 42 bytes, multisig
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[0],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 42,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(binascii.unhexlify(txhex["rawtransaction"]))

assert len(tx.vin) == 1
# assert len(tx.vout) == 3
assert "OP_CHECKMULTISIG" in repr(tx.vout[0].scriptPubKey)
assert "OP_CHECKMULTISIG" in repr(tx.vout[1].scriptPubKey)

# enable byterpersigop
with util_test.MockProtocolChangesContext(bytespersigop=True):
assert util.enabled("bytespersigop") == True # noqa: E712

# ADDR[0], bytespersigop=True, desc 41 bytes, opreturn
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[0],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 41,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(binascii.unhexlify(txhex["rawtransaction"]))

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_RETURN" in repr(tx.vout[0].scriptPubKey)

# ADDR[1], bytespersigop=True, desc 41 bytes, opreturn encoding
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[1],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 41,
},
{},
)

tx = bitcoinlib.core.CTransaction.deserialize(binascii.unhexlify(txhex["rawtransaction"]))

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_RETURN" in repr(tx.vout[0].scriptPubKey)

# ADDR[1], bytespersigop=True, desc 20 bytes, FORCED encoding=multisig
# will use 2 UTXOs to make the bytes:sigop ratio in our favor
txhex = composer.compose_transaction(
server_db,
"issuance",
{
"source": ADDR[1],
"asset": "TESTING",
"quantity": 100,
"transfer_destination": None,
"divisible": False,
"description": "t" * 20,
},
{"encoding": "multisig"},
)

print("rawtransaction: ", txhex["rawtransaction"])
tx = bitcoinlib.core.CTransaction.deserialize(binascii.unhexlify(txhex["rawtransaction"]))

assert len(tx.vin) == 1
assert len(tx.vout) == 2
assert "OP_CHECKMULTISIG" in repr(tx.vout[0].scriptPubKey)
Loading

0 comments on commit fac3536

Please sign in to comment.