Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _add_data_placeholders_to_template(cls, opcodes, template):
num_dp = cls._read_data_placeholders_count(opcodes)
num_2drop = num_dp // 2
num_drop = num_dp % 2
two_drops = [OpCodes.OP_2DROP for _ in range(num_2drop)]
one_drops = [OpCodes.OP_DROP for _ in range(num_drop)]
elements_added = num_dp + num_2drop + num_drop
placeholders = [-1 for _ in range(num_dp)]
drops = two_drops + one_drops
return elements_added, template + placeholders + drops
bytes([OpCodes.OP_0, OpCodes.OP_1]),
bytes([OpCodes.OP_HASH160]),
))
def test_not_op_return(script):
assert coin.hashX_from_script(script) is not None
NAME = "name".encode("ascii")
DAYS = hex(6).encode("ascii")
VALUE = "value".encode("ascii")
ADDRESS_SCRIPT = "address_script".encode("ascii")
OP_NAME_NEW = OpCodes.OP_1
OP_NAME_UPDATE = OpCodes.OP_2
OP_DROP = OpCodes.OP_DROP
OP_2DROP = OpCodes.OP_2DROP
DP_MULT = NameMixin.DATA_PUSH_MULTIPLE
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)
@pytest.mark.parametrize("opcode,pattern", (
bytes([OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
bytes([OpCodes.OP_0, OpCodes.OP_RETURN]),
bytes([OpCodes.OP_0, OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
))
def test_op_return(script):
assert coin.hashX_from_script(script) is None
bytes([OpCodes.OP_0]),
bytes([OpCodes.OP_0, OpCodes.OP_1]),
bytes([OpCodes.OP_HASH160]),
))
def test_not_op_return(script):
assert coin.hashX_from_script(script) is not None
NAME = "name".encode("ascii")
DAYS = hex(6).encode("ascii")
VALUE = "value".encode("ascii")
ADDRESS_SCRIPT = "address_script".encode("ascii")
OP_NAME_NEW = OpCodes.OP_1
OP_NAME_UPDATE = OpCodes.OP_2
OP_DROP = OpCodes.OP_DROP
OP_2DROP = OpCodes.OP_2DROP
DP_MULT = NameMixin.DATA_PUSH_MULTIPLE
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)
bytes([OpCodes.OP_1, OpCodes.OP_RETURN]) + bytes([2, 28, 50]),
bytes([OpCodes.OP_0]),
bytes([OpCodes.OP_0, OpCodes.OP_1]),
bytes([OpCodes.OP_HASH160]),
))
def test_not_op_return(script):
assert coin.hashX_from_script(script) is not None
NAME = "name".encode("ascii")
DAYS = hex(6).encode("ascii")
VALUE = "value".encode("ascii")
ADDRESS_SCRIPT = "address_script".encode("ascii")
OP_NAME_NEW = OpCodes.OP_1
OP_NAME_UPDATE = OpCodes.OP_2
OP_DROP = OpCodes.OP_DROP
OP_2DROP = OpCodes.OP_2DROP
DP_MULT = NameMixin.DATA_PUSH_MULTIPLE
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 _is_anon_input(self):
return (len(self.script) >= self.MIN_ANON_IN_SIZE and
self.script[0] == OpCodes.OP_RETURN and
self.script[1] == self.OP_ANON_MARKER)
TX_COUNT_HEIGHT = 329065
TX_PER_BLOCK = 10
RPC_PORT = 8336
PEERS = [
'electrum-nmc.le-space.de s50002',
'ex.lug.gs s446',
'luggscoqbymhvnkp.onion t82',
'nmc.bitcoins.sk s50002',
'ulrichard.ch s50006 t50005',
]
BLOCK_PROCESSOR = block_proc.NameIndexBlockProcessor
# Name opcodes
OP_NAME_NEW = OpCodes.OP_1
OP_NAME_FIRSTUPDATE = OpCodes.OP_2
OP_NAME_UPDATE = OpCodes.OP_3
# Valid name prefixes.
NAME_NEW_OPS = [OP_NAME_NEW, -1, OpCodes.OP_2DROP]
NAME_FIRSTUPDATE_OPS = [OP_NAME_FIRSTUPDATE, "name", -1, -1,
OpCodes.OP_2DROP, OpCodes.OP_2DROP]
NAME_UPDATE_OPS = [OP_NAME_UPDATE, "name", -1, OpCodes.OP_2DROP,
OpCodes.OP_DROP]
NAME_OPERATIONS = [
NAME_NEW_OPS,
NAME_FIRSTUPDATE_OPS,
NAME_UPDATE_OPS,
]
class NamecoinTestnet(Namecoin):
NAME = "Namecoin"
TX_COUNT = 4415768
TX_COUNT_HEIGHT = 329065
TX_PER_BLOCK = 10
RPC_PORT = 8336
PEERS = [
'electrum-nmc.le-space.de s50002',
'ex.lug.gs s446',
'luggscoqbymhvnkp.onion t82',
'nmc.bitcoins.sk s50002',
'ulrichard.ch s50006 t50005',
]
BLOCK_PROCESSOR = block_proc.NameIndexBlockProcessor
# Name opcodes
OP_NAME_NEW = OpCodes.OP_1
OP_NAME_FIRSTUPDATE = OpCodes.OP_2
OP_NAME_UPDATE = OpCodes.OP_3
# Valid name prefixes.
NAME_NEW_OPS = [OP_NAME_NEW, -1, OpCodes.OP_2DROP]
NAME_FIRSTUPDATE_OPS = [OP_NAME_FIRSTUPDATE, "name", -1, -1,
OpCodes.OP_2DROP, OpCodes.OP_2DROP]
NAME_UPDATE_OPS = [OP_NAME_UPDATE, "name", -1, OpCodes.OP_2DROP,
OpCodes.OP_DROP]
NAME_OPERATIONS = [
NAME_NEW_OPS,
NAME_FIRSTUPDATE_OPS,
NAME_UPDATE_OPS,
]
class NamecoinTestnet(Namecoin):
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
DESERIALIZER = lib_tx.DeserializerAuxPowSegWit
TX_COUNT = 4415768
TX_COUNT_HEIGHT = 329065
TX_PER_BLOCK = 10
RPC_PORT = 8336
PEERS = [
'electrum-nmc.le-space.de s50002',
'ex.lug.gs s446',
'luggscoqbymhvnkp.onion t82',
'nmc.bitcoins.sk s50002',
'ulrichard.ch s50006 t50005',
]
BLOCK_PROCESSOR = block_proc.NameIndexBlockProcessor
# Name opcodes
OP_NAME_NEW = OpCodes.OP_1
OP_NAME_FIRSTUPDATE = OpCodes.OP_2
OP_NAME_UPDATE = OpCodes.OP_3
# Valid name prefixes.
NAME_NEW_OPS = [OP_NAME_NEW, -1, OpCodes.OP_2DROP]
NAME_FIRSTUPDATE_OPS = [OP_NAME_FIRSTUPDATE, "name", -1, -1,
OpCodes.OP_2DROP, OpCodes.OP_2DROP]
NAME_UPDATE_OPS = [OP_NAME_UPDATE, "name", -1, OpCodes.OP_2DROP,
OpCodes.OP_DROP]
NAME_OPERATIONS = [
NAME_NEW_OPS,
NAME_FIRSTUPDATE_OPS,
NAME_UPDATE_OPS,
]