Skip to content

Commit

Permalink
fix: use str with trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati committed Sep 5, 2024
1 parent 2866a35 commit 52166be
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions program_admin/publisher_program_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ def create_buffer_account(
space: int,
lamports: int,
) -> Tuple[PublicKey, TransactionInstruction]:
# The seed should be str but later is used in rust as
# &str and therefore we use latin1 encoding to map byte
# i to char i
seed = bytes(publisher_pubkey).decode("latin-1")
# Since the string representation of the PublicKey is 44 bytes long (base58 encoded)
# and we use 32 bytes of it, the chances of collision are very low.
#
# The seed has a max length of 32 and although the publisher_pubkey is 32 bytes,
# it is impossible to convert it to a string with a length of 32 that the
# underlying library (solders) can handle. We don't know exactly why, but it
# seems to be related to str -> &str conversion in pyo3 that solders uses to
# interact with the Rust implementation of the logic.
seed = str(publisher_pubkey)[:32]
new_account_pubkey = PublicKey.create_with_seed(
base_pubkey,
seed,
Expand Down

0 comments on commit 52166be

Please sign in to comment.