-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48b4ca5
commit 6aa0b88
Showing
3 changed files
with
62 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 20 additions & 25 deletions
45
basics/counter/poseidon/ts-programs/src/counterProgramposeidon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
import { Account, Pubkey, Result, i64, u8, Signer } from "@solanaturbine/poseidon"; | ||
import { Account, Pubkey, Result, Signer, i64, u8 } from '@solanaturbine/poseidon'; | ||
|
||
export default class CounterProgramPoseidon { | ||
static PROGRAM_ID = new Pubkey("D5GsmVgazEnZ657NZJS4L6RcmnM8FkhR2qxyxcB4Whb3"); | ||
|
||
initializeCounter(counter: CounterState, user: Signer): Result { | ||
counter.derive(["count"]) | ||
.init(); | ||
// Set the initial value to the `count` field of the account | ||
counter.count = new i64(0); | ||
} | ||
|
||
incrementCounter(counter: CounterState): Result { | ||
counter.derive(["count"]); | ||
counter.count = counter.count.add(1); | ||
} | ||
|
||
decrementCounter(counter: CounterState): Result { | ||
counter.derive(["count"]); | ||
counter.count = counter.count.sub(1); | ||
} | ||
static PROGRAM_ID = new Pubkey('D5GsmVgazEnZ657NZJS4L6RcmnM8FkhR2qxyxcB4Whb3'); | ||
|
||
initializeCounter(counter: CounterState, user: Signer): Result { | ||
counter.derive(['count']).init(); | ||
// Set the initial value to the `count` field of the account | ||
counter.count = new i64(0); | ||
} | ||
|
||
incrementCounter(counter: CounterState): Result { | ||
counter.derive(['count']); | ||
counter.count = counter.count.add(1); | ||
} | ||
|
||
decrementCounter(counter: CounterState): Result { | ||
counter.derive(['count']); | ||
counter.count = counter.count.sub(1); | ||
} | ||
} | ||
|
||
export interface CounterState extends Account { | ||
count: i64; // This field store the counter result | ||
bump: u8; // bump is for PDA (program derieved account, a special type of account which controlled by program on Solana) | ||
count: i64; // This field store the counter result | ||
bump: u8; // bump is for PDA (program derieved account, a special type of account which controlled by program on Solana) | ||
} | ||
|
||
|
||
|
||
|