Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert spk['hex'] == tx_pks.hex()
if "addresses" in spk:
assert len(spk["addresses"]) == 1
address = spk["addresses"][0]
else:
address = spk["address"]
assert coin.address_to_hashX(address) == coin.hashX_from_script(tx_pks)
if issubclass(coin, Namecoin):
if "nameOp" not in spk or "name" not in spk["nameOp"]:
assert coin.name_hashX_from_script(tx_pks) is None
else:
OP_NAME_UPDATE = OpCodes.OP_3
normalized_name_op_script = bytearray()
normalized_name_op_script.append(OP_NAME_UPDATE)
normalized_name_op_script.extend(Script.push_data(spk["nameOp"]["name"].encode("ascii")))
normalized_name_op_script.extend(Script.push_data(bytes([])))
normalized_name_op_script.append(OpCodes.OP_2DROP)
normalized_name_op_script.append(OpCodes.OP_DROP)
normalized_name_op_script.append(OpCodes.OP_RETURN)
assert coin.name_hashX_from_script(tx_pks) == Coin.hashX_from_script(normalized_name_op_script)
def create_script(pattern, address_script):
script = bytearray()
for item in pattern:
if type(item) == int:
script.append(item)
else:
script.extend(Script.push_data(item))
script.extend(address_script)
return bytes(script)
def build_name_index_script(cls, name):
"""Returns the script by which names are indexed"""
from electrumx.lib.script import Script
res = bytearray()
res.append(cls.OP_NAME_UPDATE)
res.extend(Script.push_data(name))
res.extend(Script.push_data(bytes([])))
res.append(OpCodes.OP_2DROP)
res.append(OpCodes.OP_DROP)
res.append(OpCodes.OP_RETURN)
return bytes(res)
def P2PKH_script(cls, hash160):
return (bytes([OpCodes.OP_DUP, OpCodes.OP_HASH160])
+ Script.push_data(hash160)
+ bytes([OpCodes.OP_EQUALVERIFY, OpCodes.OP_CHECKSIG]))
def build_name_index_script(cls, name):
"""Returns the script by which names are indexed"""
from electrumx.lib.script import Script
res = bytearray()
res.append(cls.OP_NAME_UPDATE)
res.extend(Script.push_data(name))
res.extend(Script.push_data(bytes([])))
res.append(OpCodes.OP_2DROP)
res.append(OpCodes.OP_DROP)
res.append(OpCodes.OP_RETURN)
return bytes(res)
if name_script_op_count is None:
return None, script
name_end_pos = cls.find_end_position_of_name(script, name_script_op_count)
# Strip the name data to yield the address script
address_script = script[name_end_pos:]
if name_pushdata is None:
return None, address_script
normalized_name_op_script = bytearray()
normalized_name_op_script.append(OP_NAME_UPDATE)
normalized_name_op_script.extend(Script.push_data(name_pushdata[1]))
normalized_name_op_script.extend(Script.push_data(bytes([])))
normalized_name_op_script.append(OpCodes.OP_2DROP)
normalized_name_op_script.append(OpCodes.OP_DROP)
normalized_name_op_script.append(OpCodes.OP_RETURN)
return bytes(normalized_name_op_script), address_script
name_pushdata = ops[1]
if name_script_op_count is None:
return None, script
name_end_pos = cls.find_end_position_of_name(script, name_script_op_count)
# Strip the name data to yield the address script
address_script = script[name_end_pos:]
if name_pushdata is None:
return None, address_script
normalized_name_op_script = bytearray()
normalized_name_op_script.append(OP_NAME_UPDATE)
normalized_name_op_script.extend(Script.push_data(name_pushdata[1]))
normalized_name_op_script.extend(Script.push_data(bytes([])))
normalized_name_op_script.append(OpCodes.OP_2DROP)
normalized_name_op_script.append(OpCodes.OP_DROP)
normalized_name_op_script.append(OpCodes.OP_RETURN)
return bytes(normalized_name_op_script), address_script
def P2SH_script(cls, hash160):
return (bytes([OpCodes.OP_HASH160])
+ Script.push_data(hash160)
+ bytes([OpCodes.OP_EQUAL]))