Skip to content

Commit

Permalink
fix script_to_address; check migration_hash instead ledger_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Mar 3, 2025
1 parent 49f413d commit 047ab64
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@
config.BLOCK_FIRST_REGTEST: {
"ledger_hash": "33cf0669a0d309d7e6b1bf79494613b69262b58c0ea03c9c221d955eb4c84fe5",
"txlist_hash": "33cf0669a0d309d7e6b1bf79494613b69262b58c0ea03c9c221d955eb4c84fe5",
"migration_hash": "33cf0669a0d309d7e6b1bf79494613b69262b58c0ea03c9c221d955eb4c84fe5",
},
}

Expand Down
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/lib/parser/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def consensus_hash(db, field, previous_consensus_hash, content):
]
or None
)
if found_hash and field not in ["messages_hash", "migration_hash"]:
if found_hash and field not in ["messages_hash", "ledger_hash"]:
# Check against existing value.
if calculated_hash != found_hash:
raise exceptions.ConsensusError(
Expand All @@ -76,7 +76,7 @@ def consensus_hash(db, field, previous_consensus_hash, content):
network_checkpoints = checkpoints.CHECKPOINTS_MAINNET

if (
field not in ["messages_hash", "migration_hash"]
field not in ["messages_hash", "ledger_hash"]
and block_index in network_checkpoints
and network_checkpoints[block_index][field] != calculated_hash
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ def is_witness_v0_keyhash(scriptpubkey):
def get_address(scriptpubkey, block_index):
if isinstance(scriptpubkey, str):
scriptpubkey = binascii.unhexlify(scriptpubkey)
if protocol.enabled("correct_segwit_txids") and is_witness_v0_keyhash(scriptpubkey):
address = script.script_to_address(scriptpubkey)
return address

pubkeyhash, address_version = get_pubkeyhash(scriptpubkey, block_index)
if not pubkeyhash:
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/utils/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def script_to_address(scriptpubkey):
script = (
bytes(scriptpubkey, "utf-8") if isinstance(scriptpubkey, str) else bytes(scriptpubkey)
) # noqa: E721
return utils.script_to_address(script, config.NETWORK_NAME)
return utils.script_to_address3(script, config.NETWORK_NAME)
except BaseException as e:
raise exceptions.DecodeError("scriptpubkey decoding error") from e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ def test_get_pubkeyhash(current_block_index, monkeypatch):


def test_get_address(current_block_index, monkeypatch):
# "bcrt1q50kxp76j9l0k9jgwasvcz4mcz0v03fv2vmrn2u"
scriptpubkey = b"\x00\x14" + b"\xa3\xec`\xfbR/\xdfb\xc9\x0e\xec\x19\x81Wx\x13\xd8\xf8\xa5\x8a"
assert (
gettxinfolegacy.get_address(scriptpubkey, current_block_index)
== "bcrt1q50kxp76j9l0k9jgwasvcz4mcz0v03fv2vmrn2u"
)
# gettxinfolegacy does not support bech32 addresses
assert not gettxinfolegacy.get_address(scriptpubkey, current_block_index)

scriptpubkey = "a9141f4dfe5d2bdc0778119a834591f8e441ee00ce77"
assert not gettxinfolegacy.get_address(scriptpubkey, current_block_index)
Expand Down
4 changes: 2 additions & 2 deletions counterparty-rs/src/indexer/bitcoin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::iter::repeat;
use std::thread::JoinHandle;

use crate::b58::b58_encode;
use crate::utils::script_to_address;
use crate::utils::script_to_address3;
use bitcoin::{
consensus::serialize,
hashes::{hex::prelude::*, ripemd160, sha256, sha256d::Hash as Sha256dHash, Hash},
Expand Down Expand Up @@ -353,7 +353,7 @@ fn parse_vout(
txid, vi
)));
} else if config.segwit_supported(height) && is_valid_segwit_script(&vout.script_pubkey) {
let destination = script_to_address(
let destination = script_to_address3(
vout.script_pubkey.as_bytes().to_vec(),
config.network.to_string().as_str(),
)
Expand Down

0 comments on commit 047ab64

Please sign in to comment.