Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chainID #24

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions massa_test_framework/massa_py/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base58
import varint
from blake3 import blake3
import struct


class Serializable(ABC):
Expand Down Expand Up @@ -66,10 +67,15 @@ def serialize(self) -> bytes:
enc_op = self.op.serialize()
return bytes(enc_fee + enc_expire_period + enc_type_id + enc_op)

def sign(self, creator_public_key: str, sender_private_key: str) -> bytes:
# massa doc https://docs.massa.net/docs/learn/operation-format-execution
def sign(self, creator_public_key: str, sender_private_key: str, chainID: int) -> bytes:
bilboquet marked this conversation as resolved.
Show resolved Hide resolved
bilboquet marked this conversation as resolved.
Show resolved Hide resolved
enc_data = self.serialize()
enc_sender_pub_key = decode_pubkey_to_bytes(creator_public_key)
enc_data = enc_sender_pub_key + enc_data
enc_sender_pub_key = decode_pubkey_to_bytes(creator_public_key)
# doc https://docs.massa.net/docs/learn/operation-format-execution
# > -> big-endian
# Q -> unsigned long long
enc_data = struct.pack('>Q', chainID) + enc_sender_pub_key + enc_data
damip marked this conversation as resolved.
Show resolved Hide resolved

# Hash
enc_data = blake3(enc_data).digest()

Expand All @@ -83,10 +89,10 @@ def sign(self, creator_public_key: str, sender_private_key: str) -> bytes:

class OperationInput:
def __init__(
self, creator_public_key: str, content: Operation, sender_private_key: str
self, creator_public_key: str, content: Operation, sender_private_key: str, chainID: int
):
self.creator_public_key = creator_public_key
self.signature = content.sign(creator_public_key, sender_private_key).decode(
self.signature = content.sign(creator_public_key, sender_private_key, chainID).decode(
"utf-8"
)
self.serialized_content = list(content.serialize())
Expand Down Expand Up @@ -187,9 +193,10 @@ def create_roll_buy(
fee: int,
expire_period: int,
roll_count: int,
chainID: int,
):
op = Operation(fee, expire_period, RollBuy(roll_count))
op_in = OperationInput(creator_public_key, op, sender_private_key)
op_in = OperationInput(creator_public_key, op, sender_private_key, chainID)
return op_in.__dict__


Expand All @@ -199,9 +206,10 @@ def create_roll_sell(
fee: int,
expire_period: int,
roll_count: int,
chainID: int,
):
op = Operation(fee, expire_period, RollSell(roll_count))
op_in = OperationInput(creator_public_key, op, sender_private_key)
op_in = OperationInput(creator_public_key, op, sender_private_key, chainID)
return op_in.__dict__


Expand All @@ -212,9 +220,10 @@ def create_transaction(
expire_period: int,
recipient_address: str,
amount: int,
chainID: int,
):
op = Operation(fee, expire_period, Transaction(recipient_address, amount))
op_in = OperationInput(creator_public_key, op, sender_private_key)
op_in = OperationInput(creator_public_key, op, sender_private_key, chainID)
return op_in.__dict__


Expand All @@ -228,11 +237,12 @@ def create_call_sc(
param: bytes,
max_gas: int,
coins: int,
chainID: int,
):
op = Operation(
fee, expire_period, CallSC(target_address, target_func, param, max_gas, coins)
)
op_in = OperationInput(creator_public_key, op, sender_private_key)
op_in = OperationInput(creator_public_key, op, sender_private_key, chainID)
return op_in.__dict__


Expand All @@ -245,7 +255,8 @@ def create_execute_sc(
max_gas: int,
max_coins: int,
datastore: Datastore,
chainID: int,
):
op = Operation(fee, expire_period, ExecuteSC(data, max_gas, max_coins, datastore))
op_in = OperationInput(creator_public_key, op, sender_private_key)
op_in = OperationInput(creator_public_key, op, sender_private_key, chainID)
return op_in.__dict__
Loading