Skip to content

Commit

Permalink
edit examples with payer argument for init & initIfNeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrinathNR committed Oct 30, 2024
1 parent 1ae1673 commit 3bd1381
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions examples/escrow/typescript/escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default class EscrowProgram {

// Here like we mentioned in counter we are deriving a PDA for TokenAccount
// <TokenAccount>.derive([...], <mint of the token acc>, <authority of the token acc>)
vault.derive(["vault", escrow.key], makerMint, auth.key).init()
vault.derive(["vault", escrow.key], makerMint, auth.key).init(maker)

// here we can see that we are deriving using seed(u64), so we would do change it to bytes by <arg>.toBytes() which makes it consumable for derive
escrow.derive(["escrow", maker.key, seed.toBytes()])
.init()
.init(maker)

escrow.authBump = auth.getBump()
escrow.vaultBump = vault.getBump()
Expand Down Expand Up @@ -88,11 +88,11 @@ export default class EscrowProgram {
// <AssociatedTokenAccount>.derive(<mint of the token acc>, <authority of the token acc>)
takerAta
.derive(makerMint, taker.key)
.initIfNeeded(); // if you're not sure that the Ata will exist, just chain initIfNeeded method instead of init
.initIfNeeded(taker); // if you're not sure that the Ata will exist, just chain initIfNeeded method instead of init

takerReceiveAta
.derive(makerMint, taker.key)
.initIfNeeded()
.initIfNeeded(taker)

makerAta.derive(makerMint, maker.key)

Expand Down
2 changes: 1 addition & 1 deletion examples/vault/typescript/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class VaultProgram {
): Result {

auth.derive(['auth', state.key])
state.derive(['state', owner.key]).init()
state.derive(['state', owner.key]).init(owner)
vault.derive(['vault', auth.key])

// assigning a arguement of type Pubkey to the custom_Acc(state) by calling the key property
Expand Down
2 changes: 1 addition & 1 deletion examples/vote/typescript/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class VoteProgram {
// where inside array we can pass string, Uint8Array, pubkey
// we can also derive PDAs which are token account, associated token account which will be covered in vault and escrow
state.derive(["vote"])
.init() // we can initialise PDA just by chaining a init method to the derive method
.init(user) // we can initialise PDA just by chaining a init method to the derive method

// defining properties(vote) of custom_Acc(state)
state.vote = new i64(0)
Expand Down
4 changes: 2 additions & 2 deletions src/rs_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ impl ProgramInstruction {
ix.uses_system_program = true;
cur_ix_acc.is_init = true;
cur_ix_acc.payer = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
} else if prop.contains("initIfNeeded") {
} else if prop == "initIfNeeded" {
ix.uses_system_program = true;
cur_ix_acc.is_initifneeded = true;
cur_ix_acc.payer = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
} else if prop.contains("close") {
} else if prop == "close" {
cur_ix_acc.close = Some(c.args[0].expr.as_ident().ok_or(PoseidonError::IdentNotFound)?.sym.as_ref().to_case(Case::Snake));
cur_ix_acc.is_mut = true;
}
Expand Down

0 comments on commit 3bd1381

Please sign in to comment.