Skip to content

Commit 371c8a6

Browse files
committed
fix: poseidon errors
1 parent 0c96167 commit 371c8a6

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

basics/account-data/poseidon/programs/account-data/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ pub mod account_data {
1919
}
2020
#[derive(Accounts)]
2121
pub struct CreateAddressInfoContext<'info> {
22-
#[account(mut)]
22+
#[account(
23+
init,
24+
payer = owner,
25+
space = 171,
26+
seeds = [b"address_info", owner.key().as_ref()],
27+
bump,
28+
)]
2329
pub address_info: Account<'info, AddressInfo>,
30+
#[account(mut)]
31+
pub owner: Signer<'info>,
2432
pub system_program: Program<'info, System>,
2533
}
2634
#[account]
Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
import * as anchor from '@coral-xyz/anchor';
2-
import { Program } from '@coral-xyz/anchor';
3-
import { AccountData } from '../target/types/account_data';
2+
import { PublicKey } from '@solana/web3.js';
3+
import type { AccountData } from '../target/types/account_data';
44

5-
describe('account-data', () => {
6-
// Configure the client to use the local cluster.
7-
anchor.setProvider(anchor.AnchorProvider.env());
5+
describe('Account Data!', () => {
6+
const provider = anchor.AnchorProvider.env();
7+
anchor.setProvider(provider);
8+
const payer = provider.wallet as anchor.Wallet;
9+
const program = anchor.workspace.AccountData as anchor.Program<AccountData>;
810

9-
const program = anchor.workspace.AccountData as Program<AccountData>;
11+
// Generate a new keypair for the addressInfo account
12+
const [addressInfoAccount] = PublicKey.findProgramAddressSync([Buffer.from('address_info'), payer.publicKey.toBuffer()], program.programId);
1013

11-
it('Is initialized!', async () => {
12-
// Add your test here.
13-
const tx = await program.methods.initialize().rpc();
14-
console.log('Your transaction signature', tx);
14+
it('Create the address info account', async () => {
15+
console.log(`Payer Address : ${payer.publicKey}`);
16+
console.log(`Address Info Acct : ${addressInfoAccount}`);
17+
18+
// Instruction Ix data
19+
const addressInfo = {
20+
name: 'Joe C',
21+
houseNumber: 136,
22+
street: 'Mile High Dr.',
23+
city: 'Solana Beach',
24+
};
25+
26+
await program.methods
27+
.createAddressInfo(addressInfo.name, addressInfo.houseNumber, addressInfo.street, addressInfo.city)
28+
.accounts({
29+
addressInfo: addressInfoAccount,
30+
payer: payer.publicKey,
31+
})
32+
.rpc();
33+
});
34+
35+
it("Read the new account's data", async () => {
36+
const addressInfo = await program.account.addressInfo.fetch(addressInfoAccount);
37+
console.log(`Name : ${addressInfo.name}`);
38+
console.log(`House Num: ${addressInfo.houseNumber}`);
39+
console.log(`Street : ${addressInfo.street}`);
40+
console.log(`City : ${addressInfo.city}`);
1541
});
1642
});

basics/account-data/poseidon/ts-programs/src/accountData.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { Account, String as PoseidonString, Pubkey, type Result, u8 } from '@solanaturbine/poseidon';
1+
import { Account, String as PoseidonString, Pubkey, type Result, Signer, u8 } from '@solanaturbine/poseidon';
22

33
export default class AccountData {
4-
static PROGRAM_ID = new Pubkey('3cvZMR8oDVXVcxcfuPmBpsEWnGMYh2uomwYohNSJSWwk');
4+
static PROGRAM_ID = new Pubkey('CFiSZ4w8WcG7U8Axq3Lx5zpbyLiMMBde6HGKtZvRCn6U');
55

66
createAddressInfo(
7+
owner: Signer,
78
addressInfo: AddressInfo,
89
name: PoseidonString<50>,
910
houseNumber: u8,
1011
street: PoseidonString<50>,
1112
city: PoseidonString<50>,
1213
): Result {
14+
addressInfo.derive(['address_info', owner.key]).init(owner);
1315
addressInfo.name = name;
1416
addressInfo.houseNumber = houseNumber;
1517
addressInfo.street = street;

0 commit comments

Comments
 (0)