jpcaulfi 3 éve
szülő
commit
fcb3de7a0c

+ 1 - 1
accounts/rent/anchor/Anchor.toml

@@ -1,7 +1,7 @@
 [features]
 seeds = false
 [programs.localnet]
-rent_example = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
+rent_example = "ED6f4gweAE7hWPQPXMt4kWxzDJne8VQEm9zkb1tMpFNB"
 
 [registry]
 url = "https://anchor.projectserum.com"

+ 1 - 1
accounts/rent/anchor/package.json

@@ -1,6 +1,6 @@
 {
     "dependencies": {
-        "@project-serum/anchor": "^0.24.2"
+        "@project-serum/anchor": "0.25.0"
     },
     "devDependencies": {
         "@types/bn.js": "^5.1.0",

+ 10 - 4
accounts/rent/anchor/programs/rent-example/src/lib.rs

@@ -2,21 +2,21 @@ use anchor_lang::prelude::*;
 use anchor_lang::system_program;
 
 
-declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
+declare_id!("ED6f4gweAE7hWPQPXMt4kWxzDJne8VQEm9zkb1tMpFNB");
 
 
 #[program]
 pub mod rent_example {
     use super::*;
 
-    pub fn create_system_account(ctx: Context<CreateSystemAccount>) -> Result<()> {
+    pub fn create_system_account(ctx: Context<CreateSystemAccount>, address_data: AddressData) -> Result<()> {
 
         msg!("Program invoked. Creating a system account...");
         msg!("  New public key will be: {}", &ctx.accounts.new_account.key().to_string());
 
         // Determine the necessary minimum rent by calculating the account's size
         //
-        let account_span = amount as usize;
+        let account_span = (address_data.try_to_vec()?).len();
         let lamports_required = (Rent::get()?).minimum_balance(account_span);
 
         msg!("Account span: {}", &account_span);
@@ -31,7 +31,7 @@ pub mod rent_example {
                 },
             ),
             lamports_required,
-            account_span,
+            account_span as u64,
             &ctx.accounts.system_program.key(),
         )?;
 
@@ -47,4 +47,10 @@ pub struct CreateSystemAccount<'info> {
     #[account(mut)]
     pub new_account: Signer<'info>,
     pub system_program: Program<'info, System>,
+}
+
+#[derive(AnchorSerialize, AnchorDeserialize, Debug)]
+pub struct AddressData {
+    name: String,
+    address: String,
 }

+ 11 - 3
accounts/rent/anchor/tests/test.ts

@@ -1,5 +1,5 @@
 import * as anchor from "@project-serum/anchor";
-import { CreateSystemAccount } from "../target/types/create_system_account";
+import { RentExample, IDL } from "../target/types/rent_example";
 
 
 describe("Create a system account", () => {
@@ -7,13 +7,21 @@ describe("Create a system account", () => {
   const provider = anchor.AnchorProvider.env();
   anchor.setProvider(provider);
   const wallet = provider.wallet as anchor.Wallet;
-  const program = anchor.workspace.CreateSystemAccount as anchor.Program<CreateSystemAccount>;
+  const program = anchor.workspace.RentExample as anchor.Program<RentExample>;
 
   it("Create the account", async () => {
 
     const newKeypair = anchor.web3.Keypair.generate();
+
+    const addressData: anchor.IdlTypes<RentExample>["AddressData"] = {
+      name: "Marcus",
+      address: "123 Main St. San Francisco, CA"
+    };
+
+    const addressDataBuffer = new anchor.BorshCoder(IDL).types.encode("AddressData", addressData);
+    console.log(`Address data buffer length: ${addressDataBuffer.length}`);
     
-    await program.methods.createSystemAccount()
+    await program.methods.createSystemAccount(addressData)
     .accounts({
       payer: wallet.publicKey,
       newAccount: newKeypair.publicKey,

+ 1 - 1
accounts/rent/native/program/src/lib.rs

@@ -43,7 +43,7 @@ fn process_instruction(
             &payer.key,
             &new_account.key,
             lamports_required,
-            instruction_data.len() as u64,
+            account_span as u64,
             &system_program::ID,
         ),
         &[

+ 0 - 1
accounts/rent/native/tests/test.ts

@@ -59,7 +59,6 @@ describe("Create a system account", async () => {
         });
 
         const addressDataBuffer = addressData.toBuffer();
-
         console.log(`Address data buffer length: ${addressDataBuffer.length}`)
 
         let ix = new TransactionInstruction({