-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored codebase, added poseidon_cross_program_invocation logic
- Loading branch information
adpthegreat
committed
Oct 21, 2024
1 parent
771832c
commit 335a143
Showing
15 changed files
with
161 additions
and
80 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
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
7 changes: 5 additions & 2 deletions
7
basics/cross-program-invocation/poseidon/cross_program_invocation/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...grams/cross_program_invocation/Cargo.toml → ...ogram_invocation/programs/hand/Cargo.toml
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
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
basics/cross-program-invocation/poseidon/cross_program_invocation/programs/hand/src/lib.rs
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use anchor_lang::prelude::*; | ||
declare_id!("Cd86dtBUzQKYTFtcB8zDxPRUPCtKPocyetWZSnq6PNxv"); | ||
#[program] | ||
pub mod hand { | ||
use super::*; | ||
pub fn initialize(ctx: Context<InitializeContext>) -> Result<()> { | ||
Ok(()) | ||
} | ||
pub fn pull_lever(ctx: Context<PullLeverContext>) -> Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
#[derive(Accounts)] | ||
pub struct InitializeContext<'info> { | ||
#[account(mut)] | ||
pub power: Signer<'info>, | ||
#[account(mut)] | ||
pub user: Signer<'info>, | ||
} | ||
#[derive(Accounts)] | ||
pub struct PullLeverContext<'info> { | ||
#[account(init, payer = user, space = 8, seeds = [b"hand"], bump)] | ||
pub power: Account<'info, PowerStatus>, | ||
#[account(mut)] | ||
pub user: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
} | ||
#[account] | ||
pub struct PowerStatus {} |
20 changes: 20 additions & 0 deletions
20
basics/cross-program-invocation/poseidon/cross_program_invocation/programs/lever/Cargo.toml
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "lever" | ||
version = "0.1.0" | ||
description = "Created with Anchor" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "lever" | ||
|
||
[features] | ||
default = [] | ||
cpi = ["no-entrypoint"] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
idl-build = ["anchor-lang/idl-build"] | ||
|
||
[dependencies] | ||
anchor-lang = "0.30.1" |
2 changes: 2 additions & 0 deletions
2
basics/cross-program-invocation/poseidon/cross_program_invocation/programs/lever/Xargo.toml
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, it } from 'node:test'; | ||
import * as anchor from '@coral-xyz/anchor'; | ||
import { Keypair, PublicKey } from '@solana/web3.js'; | ||
import { BankrunProvider } from 'anchor-bankrun'; | ||
import { startAnchor } from 'solana-bankrun'; | ||
import type { Hand } from '../target/types/hand'; | ||
import type { Lever } from '../target/types/lever'; | ||
|
||
const HAND_IDL = require('../target/idl/hand.json'); | ||
const LEVER_IDL = require('../target/idl/lever.json'); | ||
const HAND_PROGRAM_ID = new PublicKey(HAND_IDL.address); | ||
const LEVER_PROGRAM_ID = new PublicKey(LEVER_IDL.address); | ||
|
||
describe('cpi', async () => { | ||
const context = await startAnchor( | ||
'', | ||
[ | ||
{ | ||
name: 'hand', | ||
programId: HAND_PROGRAM_ID, | ||
}, | ||
{ | ||
name: 'lever', | ||
programId: LEVER_PROGRAM_ID, | ||
}, | ||
], | ||
[], | ||
); | ||
const provider = new BankrunProvider(context); | ||
|
||
const hand = new anchor.Program<Hand>(HAND_IDL, provider); | ||
const lever = new anchor.Program<Lever>(LEVER_IDL, provider); | ||
|
||
// Generate a new keypair for the power account | ||
const powerAccount = new anchor.web3.Keypair(); | ||
|
||
it('Initialize the lever!', async () => { | ||
await lever.methods | ||
.initialize() | ||
.accounts({ | ||
power: powerAccount.publicKey, | ||
user: provider.wallet.publicKey, | ||
}) | ||
.signers([powerAccount]) | ||
.rpc(); | ||
}); | ||
|
||
it('Pull the lever!', async () => { | ||
await hand.methods.pullLever().accounts({}).rpc(); | ||
}); | ||
}); |
16 changes: 0 additions & 16 deletions
16
...ss-program-invocation/poseidon/cross_program_invocation/tests/cross_program_invocation.ts
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
...-invocation/poseidon/cross_program_invocation/ts-programs/src/cross_program_invocation.ts
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
basics/cross-program-invocation/poseidon/cross_program_invocation/ts-programs/src/hand.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Account, Pubkey, Result, Signer } from '@solanaturbine/poseidon'; | ||
|
||
export default class Hand { | ||
static PROGRAM_ID = new Pubkey('Cd86dtBUzQKYTFtcB8zDxPRUPCtKPocyetWZSnq6PNxv'); | ||
|
||
initialize(user: Signer, power: Signer) {} | ||
|
||
pullLever( | ||
user: Signer, | ||
power: PowerStatus, | ||
// name: String | ||
): Result { | ||
power.derive(['hand']).init(); | ||
} | ||
// switchPower(name: String) {} | ||
} | ||
|
||
export interface PowerStatus extends Account { | ||
// is_on: bool | ||
} |
19 changes: 19 additions & 0 deletions
19
basics/cross-program-invocation/poseidon/cross_program_invocation/ts-programs/src/lever.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Account, Pubkey, Result, Signer } from '@solanaturbine/poseidon'; | ||
|
||
export default class Lever { | ||
static PROGRAM_ID = new Pubkey('9aM9w7ozrZwXx9bQHbBx6QjWc6F46tdN9ayt86vt9uLL'); | ||
|
||
initialize(user: Signer, power: Signer) {} | ||
|
||
// switchPower(name: String) {} | ||
|
||
initializeLever(user: Signer, power: PowerStatus): Result { | ||
power.derive(['lever']).init(); | ||
} | ||
|
||
setPowerStatus(user: Signer, power: PowerStatus): Result {} | ||
} | ||
|
||
export interface PowerStatus extends Account { | ||
// is_on: bool | ||
} |