Jelajahi Sumber

remove cpi basics old example

John 1 tahun lalu
induk
melakukan
20769542e7
26 mengubah file dengan 0 tambahan dan 225 penghapusan
  1. 0 0
      basics/cross-program-invocation/anchor/.gitignore
  2. 0 0
      basics/cross-program-invocation/anchor/.prettierignore
  3. 0 0
      basics/cross-program-invocation/anchor/Anchor.toml
  4. 0 0
      basics/cross-program-invocation/anchor/Cargo.toml
  5. 0 17
      basics/cross-program-invocation/anchor/cpi-crate/Anchor.toml
  6. 0 14
      basics/cross-program-invocation/anchor/cpi-crate/package.json
  7. 0 21
      basics/cross-program-invocation/anchor/cpi-crate/programs/hand/Cargo.toml
  8. 0 35
      basics/cross-program-invocation/anchor/cpi-crate/programs/hand/src/lib.rs
  9. 0 20
      basics/cross-program-invocation/anchor/cpi-crate/programs/lever/Cargo.toml
  10. 0 47
      basics/cross-program-invocation/anchor/cpi-crate/programs/lever/src/lib.rs
  11. 0 43
      basics/cross-program-invocation/anchor/cpi-crate/tests/test.ts
  12. 0 14
      basics/cross-program-invocation/anchor/cpi-idl/Cargo.toml
  13. 0 2
      basics/cross-program-invocation/anchor/cpi-idl/programs/hand/Xargo.toml
  14. 0 2
      basics/cross-program-invocation/anchor/cpi-idl/programs/lever/Xargo.toml
  15. 0 10
      basics/cross-program-invocation/anchor/cpi-idl/tsconfig.json
  16. 0 0
      basics/cross-program-invocation/anchor/idls/lever.json
  17. 0 0
      basics/cross-program-invocation/anchor/migrations/deploy.ts
  18. 0 0
      basics/cross-program-invocation/anchor/package.json
  19. 0 0
      basics/cross-program-invocation/anchor/programs/hand/Cargo.toml
  20. 0 0
      basics/cross-program-invocation/anchor/programs/hand/Xargo.toml
  21. 0 0
      basics/cross-program-invocation/anchor/programs/hand/src/lib.rs
  22. 0 0
      basics/cross-program-invocation/anchor/programs/lever/Cargo.toml
  23. 0 0
      basics/cross-program-invocation/anchor/programs/lever/Xargo.toml
  24. 0 0
      basics/cross-program-invocation/anchor/programs/lever/src/lib.rs
  25. 0 0
      basics/cross-program-invocation/anchor/tests/cpi.ts
  26. 0 0
      basics/cross-program-invocation/anchor/tsconfig.json

+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/.gitignore → basics/cross-program-invocation/anchor/.gitignore


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/.prettierignore → basics/cross-program-invocation/anchor/.prettierignore


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/Anchor.toml → basics/cross-program-invocation/anchor/Anchor.toml


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-crate/Cargo.toml → basics/cross-program-invocation/anchor/Cargo.toml


+ 0 - 17
basics/cross-program-invocation/anchor/cpi-crate/Anchor.toml

@@ -1,17 +0,0 @@
-[features]
-seeds = false
-skip-lint = false
-
-[programs.localnet]
-hand = "EJfTLXDCJTVwBgGpz9X2Me4CWHbvg8F8zsM7fiVJLLeR"
-lever = "CABVoybzrbAJSv7QhQd6GXNGKxDMRjw9niqFzizhk6uk"
-
-[registry]
-url = "https://api.apr.dev"
-
-[provider]
-cluster = "Localnet"
-wallet = "~/.config/solana/id.json"
-
-[scripts]
-test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

+ 0 - 14
basics/cross-program-invocation/anchor/cpi-crate/package.json

@@ -1,14 +0,0 @@
-{
-  "dependencies": {
-    "@coral-xyz/anchor": "^0.30.0"
-  },
-  "devDependencies": {
-    "@types/bn.js": "^5.1.0",
-    "@types/chai": "^4.3.0",
-    "@types/mocha": "^9.0.0",
-    "chai": "^4.3.4",
-    "mocha": "^9.0.3",
-    "ts-mocha": "^10.0.0",
-    "typescript": "^4.3.5"
-  }
-}

+ 0 - 21
basics/cross-program-invocation/anchor/cpi-crate/programs/hand/Cargo.toml

@@ -1,21 +0,0 @@
-[package]
-name = "cross-program-invocatio-anchor-hand"
-version = "0.1.0"
-description = "Created with Anchor"
-edition = "2021"
-
-[lib]
-crate-type = ["cdylib", "lib"]
-name = "hand"
-
-[features]
-default = []
-cpi = ["no-entrypoint"]
-no-entrypoint = []
-no-idl = []
-no-log-ix-name = []
-idl-build = ["anchor-lang/idl-build"]
-
-[dependencies]
-anchor-lang = "0.30.0"
-cross-program-invocatio-anchor-lever = { path = "../lever", features = ["cpi"] }

+ 0 - 35
basics/cross-program-invocation/anchor/cpi-crate/programs/hand/src/lib.rs

@@ -1,35 +0,0 @@
-#![allow(clippy::result_large_err)]
-
-use anchor_lang::prelude::*;
-use lever::cpi::accounts::SetPowerStatus;
-use lever::program::Lever;
-use lever::{self, PowerStatus};
-
-declare_id!("EJfTLXDCJTVwBgGpz9X2Me4CWHbvg8F8zsM7fiVJLLeR");
-
-#[program]
-mod hand {
-    use super::*;
-    pub fn pull_lever(ctx: Context<PullLever>, name: String) -> anchor_lang::Result<()> {
-        // Hitting the switch_power method on the lever program
-        //
-        lever::cpi::switch_power(
-            CpiContext::new(
-                ctx.accounts.lever_program.to_account_info(),
-                // Using the accounts context struct from the lever program
-                //
-                SetPowerStatus {
-                    power: ctx.accounts.power.to_account_info(),
-                },
-            ),
-            name,
-        )
-    }
-}
-
-#[derive(Accounts)]
-pub struct PullLever<'info> {
-    #[account(mut)]
-    pub power: Account<'info, PowerStatus>,
-    pub lever_program: Program<'info, Lever>,
-}

+ 0 - 20
basics/cross-program-invocation/anchor/cpi-crate/programs/lever/Cargo.toml

@@ -1,20 +0,0 @@
-[package]
-name = "cross-program-invocatio-anchor-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.0"

+ 0 - 47
basics/cross-program-invocation/anchor/cpi-crate/programs/lever/src/lib.rs

@@ -1,47 +0,0 @@
-#![allow(clippy::result_large_err)]
-
-use anchor_lang::prelude::*;
-
-declare_id!("CABVoybzrbAJSv7QhQd6GXNGKxDMRjw9niqFzizhk6uk");
-
-#[program]
-pub mod lever {
-    use super::*;
-    pub fn initialize(_ctx: Context<InitializeLever>) -> Result<()> {
-        Ok(())
-    }
-
-    pub fn switch_power(ctx: Context<SetPowerStatus>, name: String) -> Result<()> {
-        let power = &mut ctx.accounts.power;
-        power.is_on = !power.is_on;
-
-        msg!("{} is pulling the power switch!", &name);
-
-        match power.is_on {
-            true => msg!("The power is now on."),
-            false => msg!("The power is now off!"),
-        };
-
-        Ok(())
-    }
-}
-
-#[derive(Accounts)]
-pub struct InitializeLever<'info> {
-    #[account(init, payer = user, space = 8 + 8)]
-    pub power: Account<'info, PowerStatus>,
-    #[account(mut)]
-    pub user: Signer<'info>,
-    pub system_program: Program<'info, System>,
-}
-
-#[derive(Accounts)]
-pub struct SetPowerStatus<'info> {
-    #[account(mut)]
-    pub power: Account<'info, PowerStatus>,
-}
-
-#[account]
-pub struct PowerStatus {
-    pub is_on: bool,
-}

+ 0 - 43
basics/cross-program-invocation/anchor/cpi-crate/tests/test.ts

@@ -1,43 +0,0 @@
-import * as anchor from "@coral-xyz/anchor";
-import { Hand } from "../target/types/hand";
-import { Lever } from "../target/types/lever";
-import { Keypair } from "@solana/web3.js";
-
-describe("CPI Example", () => {
-  const provider = anchor.AnchorProvider.env();
-  anchor.setProvider(provider);
-  const hand = anchor.workspace.Hand as anchor.Program<Hand>;
-  const lever = anchor.workspace.Lever as anchor.Program<Lever>;
-
-  // Generate a new keypair for the power account
-  const powerAccount = new 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("Chris")
-      .accounts({
-        power: powerAccount.publicKey,
-      })
-      .rpc();
-  });
-
-  it("Pull it again!", async () => {
-    await hand.methods
-      .pullLever("Ashley")
-      .accounts({
-        power: powerAccount.publicKey,
-      })
-      .rpc();
-  });
-});

+ 0 - 14
basics/cross-program-invocation/anchor/cpi-idl/Cargo.toml

@@ -1,14 +0,0 @@
-[workspace]
-members = [
-    "programs/*"
-]
-resolver = "2"
-
-[profile.release]
-overflow-checks = true
-lto = "fat"
-codegen-units = 1
-[profile.release.build-override]
-opt-level = 3
-incremental = false
-codegen-units = 1

+ 0 - 2
basics/cross-program-invocation/anchor/cpi-idl/programs/hand/Xargo.toml

@@ -1,2 +0,0 @@
-[target.bpfel-unknown-unknown.dependencies.std]
-features = []

+ 0 - 2
basics/cross-program-invocation/anchor/cpi-idl/programs/lever/Xargo.toml

@@ -1,2 +0,0 @@
-[target.bpfel-unknown-unknown.dependencies.std]
-features = []

+ 0 - 10
basics/cross-program-invocation/anchor/cpi-idl/tsconfig.json

@@ -1,10 +0,0 @@
-{
-  "compilerOptions": {
-    "types": ["mocha", "chai"],
-    "typeRoots": ["./node_modules/@types"],
-    "lib": ["es2015"],
-    "module": "commonjs",
-    "target": "es6",
-    "esModuleInterop": true
-  }
-}

+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/idls/lever.json → basics/cross-program-invocation/anchor/idls/lever.json


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/migrations/deploy.ts → basics/cross-program-invocation/anchor/migrations/deploy.ts


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/package.json → basics/cross-program-invocation/anchor/package.json


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/programs/hand/Cargo.toml → basics/cross-program-invocation/anchor/programs/hand/Cargo.toml


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-crate/programs/hand/Xargo.toml → basics/cross-program-invocation/anchor/programs/hand/Xargo.toml


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/programs/hand/src/lib.rs → basics/cross-program-invocation/anchor/programs/hand/src/lib.rs


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/programs/lever/Cargo.toml → basics/cross-program-invocation/anchor/programs/lever/Cargo.toml


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-crate/programs/lever/Xargo.toml → basics/cross-program-invocation/anchor/programs/lever/Xargo.toml


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/programs/lever/src/lib.rs → basics/cross-program-invocation/anchor/programs/lever/src/lib.rs


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-idl/tests/cpi.ts → basics/cross-program-invocation/anchor/tests/cpi.ts


+ 0 - 0
basics/cross-program-invocation/anchor/cpi-crate/tsconfig.json → basics/cross-program-invocation/anchor/tsconfig.json