Skip to content

Commit e372bd9

Browse files
committed
fix: use type encode methods in payloads instead of raw encoding functions
Replace raw_bytes() with encode() for Address, and append_var_int(self.amount.value) with append_fixed_bytes(self.amount.encode()) in all payload encode methods. Also fix ruff errors: missing encoding import in bls/public_key, shadowed builtin round, inline import in block.py
1 parent 949eb0b commit e372bd9

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

pactus/transaction/payload/bond.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def __init__(
1919
self.stake = stake
2020

2121
def encode(self, buf: list) -> None:
22-
encoding.append_fixed_bytes(buf, self.sender.raw_bytes())
23-
encoding.append_fixed_bytes(buf, self.receiver.raw_bytes())
22+
encoding.append_fixed_bytes(buf, self.sender.encode())
23+
encoding.append_fixed_bytes(buf, self.receiver.encode())
2424
encoding.append_fixed_bytes(buf, self.public_key)
25-
encoding.append_var_int(buf, self.stake.value)
25+
encoding.append_fixed_bytes(buf, self.stake.encode())
2626

2727
def get_type(self) -> PayloadType:
2828
return PayloadType.BOND

pactus/transaction/payload/sortition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self, address: Address, proof: bytes) -> None:
1010
self.proof = proof
1111

1212
def encode(self, buf: list) -> None:
13-
encoding.append_fixed_bytes(buf, self.address.raw_bytes())
13+
encoding.append_fixed_bytes(buf, self.address.encode())
1414
encoding.append_fixed_bytes(buf, self.proof)
1515

1616
def get_type(self) -> PayloadType:

pactus/transaction/payload/transfer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def __init__(self, sender: Address, receiver: Address, amount: Amount) -> None:
1212
self.amount = amount
1313

1414
def encode(self, buf: list) -> None:
15-
encoding.append_fixed_bytes(buf, self.sender.raw_bytes())
16-
encoding.append_fixed_bytes(buf, self.receiver.raw_bytes())
17-
encoding.append_var_int(buf, self.amount.value)
15+
encoding.append_fixed_bytes(buf, self.sender.encode())
16+
encoding.append_fixed_bytes(buf, self.receiver.encode())
17+
encoding.append_fixed_bytes(buf, self.amount.encode())
1818

1919
def get_type(self) -> PayloadType:
2020
return PayloadType.TRANSFER

pactus/transaction/payload/unbond.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(self, validator: Address) -> None:
99
self.validator = validator
1010

1111
def encode(self, buf: list) -> None:
12-
encoding.append_fixed_bytes(buf, self.validator.raw_bytes())
12+
encoding.append_fixed_bytes(buf, self.validator.encode())
1313

1414
def get_type(self) -> PayloadType:
1515
return PayloadType.UNBOND

pactus/transaction/payload/withdraw.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def __init__(self, from_addr: Address, to_addr: Address, amount: Amount) -> None
1212
self.amount = amount
1313

1414
def encode(self, buf: list) -> None:
15-
encoding.append_fixed_bytes(buf, self.from_addr.raw_bytes())
16-
encoding.append_fixed_bytes(buf, self.to_addr.raw_bytes())
17-
encoding.append_var_int(buf, self.amount.value)
15+
encoding.append_fixed_bytes(buf, self.from_addr.encode())
16+
encoding.append_fixed_bytes(buf, self.to_addr.encode())
17+
encoding.append_fixed_bytes(buf, self.amount.encode())
1818

1919
def get_type(self) -> PayloadType:
2020
return PayloadType.WITHDRAW

0 commit comments

Comments
 (0)