Bladeren bron

anchor basics working

John 1 jaar geleden
bovenliggende
commit
905b445dc8

+ 1 - 1
basics/close-account/anchor/programs/close-account/src/instructions/create_user.rs

@@ -22,7 +22,7 @@ pub struct CreateUserContext<'info> {
 
 pub fn create_user(ctx: Context<CreateUserContext>, name: String) -> Result<()> {
     *ctx.accounts.user_account = UserState {
-        bump: *ctx.bumps.get("user_account").unwrap(),
+        bump: ctx.bumps.user_account,
         user: ctx.accounts.user.key(),
         name,
     };

+ 1 - 1
basics/pda-rent-payer/anchor/programs/anchor-program-example/src/instructions/create_new_account.rs

@@ -19,7 +19,7 @@ pub struct CreateNewAccount<'info> {
 
 pub fn create_new_account(ctx: Context<CreateNewAccount>) -> Result<()> {
     // PDA signer seeds
-    let signer_seeds: &[&[&[u8]]] = &[&[b"rent_vault", &[*ctx.bumps.get("rent_vault").unwrap()]]];
+    let signer_seeds: &[&[&[u8]]] = &[&[b"rent_vault", &[ctx.bumps.rent_vault]]];
 
     // The minimum lamports for rent exemption
     let lamports = (Rent::get()?).minimum_balance(0);

+ 1 - 2
basics/program-derived-addresses/anchor/programs/anchor-program-example/Cargo.toml

@@ -17,5 +17,4 @@ no-log-ix-name = []
 idl-build = ["anchor-lang/idl-build"]
 
 [dependencies]
-anchor-lang = "0.30.0"
-ahash = "=0.8.6"
+anchor-lang = "0.30.0"

+ 6 - 7
basics/rent/anchor/tests/test.ts

@@ -1,5 +1,6 @@
 import * as anchor from "@coral-xyz/anchor";
-import { RentExample, IDL } from "../target/types/rent_example";
+import { RentExample } from "../target/types/rent_example";
+import Idl from "../target/idl/rent_example.json";
 
 describe("Create a system account", () => {
   const provider = anchor.AnchorProvider.env();
@@ -10,7 +11,7 @@ describe("Create a system account", () => {
   it("Create the account", async () => {
     const newKeypair = anchor.web3.Keypair.generate();
 
-    const addressData: anchor.IdlTypes<RentExample>["AddressData"] = {
+    const addressData: anchor.IdlTypes<RentExample>["addressData"] = {
       name: "Marcus",
       address: "123 Main St. San Francisco, CA",
     };
@@ -18,10 +19,9 @@ describe("Create a system account", () => {
     // We're just going to serialize our object here so we can check
     //  the size on the client side against the program logs
     //
-    const addressDataBuffer = new anchor.BorshCoder(IDL).types.encode(
-      "AddressData",
-      addressData
-    );
+    const addressDataBuffer = new anchor.BorshCoder(
+      Idl as anchor.Idl
+    ).types.encode("AddressData", addressData);
     console.log(`Address data buffer length: ${addressDataBuffer.length}`);
 
     await program.methods
@@ -29,7 +29,6 @@ describe("Create a system account", () => {
       .accounts({
         payer: wallet.publicKey,
         newAccount: newKeypair.publicKey,
-        systemProgram: anchor.web3.SystemProgram.programId,
       })
       .signers([wallet.payer, newKeypair])
       .rpc();

+ 1 - 0
basics/rent/anchor/tsconfig.json

@@ -5,6 +5,7 @@
     "lib": ["es2015"],
     "module": "commonjs",
     "target": "es6",
+    "resolveJsonModule": true,
     "esModuleInterop": true
   }
 }