Skip to content

Commit 52166be

Browse files
committed
fix: use str with trimming
1 parent 2866a35 commit 52166be

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

program_admin/publisher_program_instructions.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,15 @@ def create_buffer_account(
7373
space: int,
7474
lamports: int,
7575
) -> Tuple[PublicKey, TransactionInstruction]:
76-
# The seed should be str but later is used in rust as
77-
# &str and therefore we use latin1 encoding to map byte
78-
# i to char i
79-
seed = bytes(publisher_pubkey).decode("latin-1")
76+
# Since the string representation of the PublicKey is 44 bytes long (base58 encoded)
77+
# and we use 32 bytes of it, the chances of collision are very low.
78+
#
79+
# The seed has a max length of 32 and although the publisher_pubkey is 32 bytes,
80+
# it is impossible to convert it to a string with a length of 32 that the
81+
# underlying library (solders) can handle. We don't know exactly why, but it
82+
# seems to be related to str -> &str conversion in pyo3 that solders uses to
83+
# interact with the Rust implementation of the logic.
84+
seed = str(publisher_pubkey)[:32]
8085
new_account_pubkey = PublicKey.create_with_seed(
8186
base_pubkey,
8287
seed,

0 commit comments

Comments
 (0)