Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions address/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ impl Address {
#[cfg(feature = "sha2")]
pub fn create_with_seed(
base: &Address,
seed: &str,
seed: &(impl AsRef<[u8]> + ?Sized),
owner: &Address,
) -> Result<Address, AddressError> {
if seed.len() > MAX_SEED_LEN {
let seed_bytes: &[u8] = seed.as_ref();
if seed_bytes.len() > MAX_SEED_LEN {
return Err(AddressError::MaxSeedLengthExceeded);
}

Expand All @@ -250,7 +251,7 @@ impl Address {
return Err(AddressError::IllegalOwner);
}
}
let hash = solana_sha256_hasher::hashv(&[base.as_ref(), seed.as_ref(), owner]);
let hash = solana_sha256_hasher::hashv(&[base.as_ref(), seed_bytes, owner]);
Ok(Address::from(hash.to_bytes()))
}

Expand Down
2 changes: 1 addition & 1 deletion sdk-wasm-js/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Address {
}

/// Derive an Address from anothern Address, string seed, and a program id
pub fn createWithSeed(base: &Self, seed: &str, owner: &Self) -> Result<Self, JsValue> {
pub fn createWithSeed(base: &Self, seed: &[u8], owner: &Self) -> Result<Self, JsValue> {
solana_address::Address::create_with_seed(&base.inner, seed, &owner.inner)
.map(Into::into)
.map_err(display_to_jsvalue)
Expand Down
3 changes: 2 additions & 1 deletion sdk-wasm-js/tests/address.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ describe("Address", function () {

it("createWithSeed", async () => {
const defaultPublicKey = new Address("11111111111111111111111111111111");
const bytes = Uint8Array.from("limber chicken: 4/45", c => c.charCodeAt(0));
const derivedKey = Address.createWithSeed(
defaultPublicKey,
"limber chicken: 4/45",
bytes,
defaultPublicKey
);

Expand Down
26 changes: 13 additions & 13 deletions system-interface/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const NONCE_STATE_SIZE: usize = 80;
/// An instruction to the system program.
#[cfg_attr(
feature = "frozen-abi",
solana_frozen_abi_macro::frozen_abi(digest = "CBvp4X1gf36kwDqnprAa6MpKckptiAHfXSxFRHFnNRVw"),
solana_frozen_abi_macro::frozen_abi(digest = "7Hc7pX4JYnEsBEyixxKP76aDSq3668bLUc1V7L9Vqm68"),
derive(
solana_frozen_abi_macro::AbiExample,
solana_frozen_abi_macro::AbiEnumVisitor
Expand Down Expand Up @@ -132,7 +132,7 @@ pub enum SystemInstruction {
base: Address,

/// String of ASCII chars, no longer than `Address::MAX_SEED_LEN`
seed: String,
seed: Vec<u8>,

/// Number of lamports to transfer to the new account
lamports: u64,
Expand Down Expand Up @@ -208,7 +208,7 @@ pub enum SystemInstruction {
base: Address,

/// String of ASCII chars, no longer than `Address::MAX_SEED_LEN`
seed: String,
seed: Vec<u8>,

/// Number of bytes of memory to allocate
space: u64,
Expand All @@ -227,7 +227,7 @@ pub enum SystemInstruction {
base: Address,

/// String of ASCII chars, no longer than `Address::MAX_SEED_LEN`
seed: String,
seed: Vec<u8>,

/// Owner program account
owner: Address,
Expand All @@ -244,7 +244,7 @@ pub enum SystemInstruction {
lamports: u64,

/// Seed to use to derive the funding account address
from_seed: String,
from_seed: Vec<u8>,

/// Owner to use to derive the funding account address
from_owner: Address,
Expand Down Expand Up @@ -479,7 +479,7 @@ pub fn create_account_with_seed(
from_address: &Address,
to_address: &Address, // must match create_with_seed(base, seed, owner)
base: &Address,
seed: &str,
seed: &[u8],
lamports: u64,
space: u64,
owner: &Address,
Expand All @@ -496,7 +496,7 @@ pub fn create_account_with_seed(
ID,
&SystemInstruction::CreateAccountWithSeed {
base: *base,
seed: seed.to_string(),
seed: seed.to_vec(),
lamports,
space,
owner: *owner,
Expand Down Expand Up @@ -680,7 +680,7 @@ pub fn assign(address: &Address, owner: &Address) -> Instruction {
pub fn assign_with_seed(
address: &Address, // must match create_with_seed(base, seed, owner)
base: &Address,
seed: &str,
seed: &[u8],
owner: &Address,
) -> Instruction {
let account_metas = vec![
Expand All @@ -691,7 +691,7 @@ pub fn assign_with_seed(
ID,
&SystemInstruction::AssignWithSeed {
base: *base,
seed: seed.to_string(),
seed: seed.to_vec(),
owner: *owner,
},
account_metas,
Expand Down Expand Up @@ -873,7 +873,7 @@ pub fn transfer(from_address: &Address, to_address: &Address, lamports: u64) ->
pub fn transfer_with_seed(
from_address: &Address, // must match create_with_seed(base, seed, owner)
from_base: &Address,
from_seed: String,
from_seed: Vec<u8>,
from_owner: &Address,
to_address: &Address,
lamports: u64,
Expand Down Expand Up @@ -1068,7 +1068,7 @@ pub fn allocate(address: &Address, space: u64) -> Instruction {
pub fn allocate_with_seed(
address: &Address, // must match create_with_seed(base, seed, owner)
base: &Address,
seed: &str,
seed: &[u8],
space: u64,
owner: &Address,
) -> Instruction {
Expand All @@ -1080,7 +1080,7 @@ pub fn allocate_with_seed(
ID,
&SystemInstruction::AllocateWithSeed {
base: *base,
seed: seed.to_string(),
seed: seed.to_vec(),
space,
owner: *owner,
},
Expand Down Expand Up @@ -1236,7 +1236,7 @@ pub fn create_nonce_account_with_seed(
from_address: &Address,
nonce_address: &Address,
base: &Address,
seed: &str,
seed: &[u8],
authority: &Address,
lamports: u64,
) -> Vec<Instruction> {
Expand Down
8 changes: 4 additions & 4 deletions system-wasm-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl SystemInstruction {
from: &Address,
to: &Address,
base: &Address,
seed: &str,
seed: &[u8],
lamports: u64,
space: u64,
owner: &Address,
Expand All @@ -46,7 +46,7 @@ impl SystemInstruction {
pub fn assignWithSeed(
address: &Address,
base: &Address,
seed: &str,
seed: &[u8],
owner: &Address,
) -> Instruction {
assign_with_seed(address, base, seed, owner).into()
Expand All @@ -59,7 +59,7 @@ impl SystemInstruction {
pub fn transferWithSeed(
from: &Address,
from_base: &Address,
from_seed: String,
from_seed: Vec<u8>,
from_owner: &Address,
to: &Address,
lamports: u64,
Expand All @@ -74,7 +74,7 @@ impl SystemInstruction {
pub fn allocateWithSeed(
address: &Address,
base: &Address,
seed: &str,
seed: &[u8],
space: u64,
owner: &Address,
) -> Instruction {
Expand Down
10 changes: 5 additions & 5 deletions vote-interface/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn initialize_account(vote_pubkey: &Pubkey, vote_init: &VoteInit) -> Instruction

pub struct CreateVoteAccountConfig<'a> {
pub space: u64,
pub with_seed: Option<(&'a Pubkey, &'a str)>,
pub with_seed: Option<(&'a Pubkey, &'a [u8])>,
}

impl Default for CreateVoteAccountConfig<'_> {
Expand Down Expand Up @@ -356,7 +356,7 @@ pub fn authorize_with_seed(
vote_pubkey: &Pubkey,
current_authority_base_key: &Pubkey,
current_authority_derived_key_owner: &Pubkey,
current_authority_derived_key_seed: &str,
current_authority_derived_key_seed: &[u8],
new_authority: &Pubkey,
authorization_type: VoteAuthorize,
) -> Instruction {
Expand All @@ -371,7 +371,7 @@ pub fn authorize_with_seed(
&VoteInstruction::AuthorizeWithSeed(VoteAuthorizeWithSeedArgs {
authorization_type,
current_authority_derived_key_owner: *current_authority_derived_key_owner,
current_authority_derived_key_seed: current_authority_derived_key_seed.to_string(),
current_authority_derived_key_seed: current_authority_derived_key_seed.to_vec(),
new_authority: *new_authority,
}),
account_metas,
Expand All @@ -383,7 +383,7 @@ pub fn authorize_checked_with_seed(
vote_pubkey: &Pubkey,
current_authority_base_key: &Pubkey,
current_authority_derived_key_owner: &Pubkey,
current_authority_derived_key_seed: &str,
current_authority_derived_key_seed: &[u8],
new_authority: &Pubkey,
authorization_type: VoteAuthorize,
) -> Instruction {
Expand All @@ -399,7 +399,7 @@ pub fn authorize_checked_with_seed(
&VoteInstruction::AuthorizeCheckedWithSeed(VoteAuthorizeCheckedWithSeedArgs {
authorization_type,
current_authority_derived_key_owner: *current_authority_derived_key_owner,
current_authority_derived_key_seed: current_authority_derived_key_seed.to_string(),
current_authority_derived_key_seed: current_authority_derived_key_seed.to_vec(),
}),
account_metas,
)
Expand Down
4 changes: 2 additions & 2 deletions vote-interface/src/state/vote_instruction_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub enum VoteAuthorize {
pub struct VoteAuthorizeWithSeedArgs {
pub authorization_type: VoteAuthorize,
pub current_authority_derived_key_owner: Pubkey,
pub current_authority_derived_key_seed: String,
pub current_authority_derived_key_seed: Vec<u8>,
pub new_authority: Pubkey,
}

Expand All @@ -222,5 +222,5 @@ pub struct VoteAuthorizeWithSeedArgs {
pub struct VoteAuthorizeCheckedWithSeedArgs {
pub authorization_type: VoteAuthorize,
pub current_authority_derived_key_owner: Pubkey,
pub current_authority_derived_key_seed: String,
pub current_authority_derived_key_seed: Vec<u8>,
}