Skip to content

Commit

Permalink
Merge pull request #77 from mircial/feature/transaction_from_buffer
Browse files Browse the repository at this point in the history
fix tranaction from_buffer method
  • Loading branch information
GitBolt authored Oct 3, 2024
2 parents c88b71b + a394b22 commit 39dd4a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions solathon/core/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def serialize(self) -> bytes:
return bytes(message_buffer)

@classmethod
def from_buffer(buffer: bytes) -> Message:
def from_buffer(cls, buffer: bytes) -> Message:
# Reference: https://github.com/solana-labs/solana-web3.js/blob/a1fafee/packages/library-legacy/src/message/legacy.ts#L267

buffer_array = list(buffer)
Expand Down Expand Up @@ -176,4 +176,4 @@ def from_buffer(buffer: bytes) -> Message:

header = MessageHeader(
num_required_signatures, num_readonly_signed_accounts, num_readonly_unsigned_accounts)
return Message(header, account_keys, instructions, b58encode(recent_blockhash).decode("utf-8"))
return Message(header, account_keys, instructions, b58encode(bytes(recent_blockhash)).decode("utf-8"))
9 changes: 5 additions & 4 deletions solathon/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def add_instructions(self, *instructions: Instruction) -> None:
self.instructions.append(instr)

@classmethod
def populate(self, message: Message, signatures: List[bytes]) -> Transaction:
def populate(self, message: Message, signatures: List[bytes], signers: list[Keypair]) -> Transaction:
decoded_signatures = list(map(lambda x: PKSigPair(
public_key=message.account_keys[x[0]],
signature=None if x[1] == b58encode(
Expand Down Expand Up @@ -286,11 +286,12 @@ def populate(self, message: Message, signatures: List[bytes]) -> Transaction:
fee_payer=fee_payer,
recent_blockhash=message.recent_blockhash,
signatures=decoded_signatures,
instructions=instructions
instructions=instructions,
signers = signers
)

@classmethod
def from_buffer(self, buffer: bytes) -> Transaction:
def from_buffer(self, buffer: bytes, signers: list[Keypair]) -> Transaction:
# Reference: https://github.com/solana-labs/solana-web3.js/blob/a1fafee/packages/library-legacy/src/transaction/legacy.ts#L878
if not isinstance(buffer, bytes):
raise TypeError("Buffer must be a bytes object.")
Expand All @@ -305,4 +306,4 @@ def from_buffer(self, buffer: bytes) -> Transaction:
signatures.append(b58encode(signature))

message: Message = Message.from_buffer(bytes(buffer_array))
return Transaction.populate(message, signatures)
return Transaction.populate(message, signatures, signers)

0 comments on commit 39dd4a9

Please sign in to comment.