Open Ljzn opened 7 months ago
hex_to_bytes = bytes.fromhex
HASHX_LEN = 11
from pycoin.symbols.btc import network
import hashlib
_sha256 = hashlib.sha256
def hex_str_to_hash(x):
'''Convert a displayed hex string to a binary hash.'''
return bytes(reversed(hex_to_bytes(x)))
def scripthash_to_hashX(scripthash):
bin_hash = hex_str_to_hash(scripthash)
if len(bin_hash) == 32:
return bin_hash[:HASHX_LEN]
def address_to_script(addr):
script = network.parse.address(addr).script()
return script.hex()
def address_to_scripthash(addr):
script = network.parse.address(addr).script()
return hashlib.sha256(script).digest()[::-1].hex()
def sha256(x):
'''Simple wrapper of hashlib sha256.'''
return _sha256(x).digest()
def double_sha256(x):
'''SHA-256 of SHA-256, as used extensively in bitcoin.'''
return sha256(sha256(x))
def address_to_scripthash_atomicals(addr):
scripthash = double_sha256(network.parse.address(addr).script())
return scripthash
def hash_to_hex_str(x):
return bytes(reversed(x)).hex()
print(address_to_script('bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh'))
print(address_to_scripthash('bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh'))
print(hash_to_hex_str(address_to_scripthash_atomicals('bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh')))
For convenience to others, the result of that python script is:
0014fb7454e043913f46cee06143ff3f320b6e2f8041
8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721
4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45
Is runhash_to_hex_str
for scripthash
on purpose here? I don't quite understand.
For convenience to others, the result of that python script is:
0014fb7454e043913f46cee06143ff3f320b6e2f8041 8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721 4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45
Is run
hash_to_hex_str
forscripthash
on purpose here? I don't quite understand.
Hexadecimal strings are more human-readable and easier to understand.
For convenience to others, the result of that python script is:为了方便其他人,该 python 脚本的结果是:
0014fb7454e043913f46cee06143ff3f320b6e2f8041 8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721 4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45
Is run
hash_to_hex_str
forscripthash
on purpose here? I don't quite understand.这里是故意的吗hash_to_hex_str
scripthash
?我不太明白。Hexadecimal strings are more human-readable and easier to understand.
Yes, but the scripthash
be converted to hex twice here.
Get atomicals at location returns wrong scripthash.
request:
response:
The
scripthash
here is "4b2ff9b90f0fca6341f6cac374d414a7ee59379a528990cf3a8d1c74bfa4ef45" .Not equal to the correct
scripthash
of address "bc1qld69fczrjyl5dnhqv9pl70ejpdhzlqzpu0mfjh", which should be "8e6cec514958b4af4002f0c0a6f9f7b0a84944fcb7e6034083c112aaf7dea721".We can get the atomical with the correct scripthash:
So I think the
scripthash
in the response ofblockchain.atomicals.at_location
is not correct. Thescript
field is correct.