-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
263 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ target | |
.DS_Store | ||
test-ledger/ | ||
.anchor | ||
target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
idls/solprofile.json |
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,21 @@ | ||
[package] | ||
name = "solprofile-example" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "create" | ||
path = "src/create.rs" | ||
|
||
[[bin]] | ||
name = "get" | ||
path = "src/get.rs" | ||
|
||
[[bin]] | ||
name = "update" | ||
path = "src/update.rs" | ||
|
||
[dependencies] | ||
anchor-lang = "0.30.1" | ||
anchor-client = "0.30.1" | ||
shellexpand = "3.1.0" |
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,37 @@ | ||
# Examples | ||
|
||
## Run on localnet | ||
|
||
### Setup | ||
|
||
#### Deploy Program | ||
|
||
See [Run on localnet](https://github.com/hirokisan/solprofile?tab=readme-ov-file#run-on-localnet). | ||
|
||
#### Copy IDL | ||
|
||
Copy `../../target/idl/solprofile.json` to `idls/solprofile.json`. | ||
|
||
### Create a profile | ||
|
||
```console | ||
$ cargo run --quiet --bin create | ||
``` | ||
|
||
### Get a profile | ||
|
||
```console | ||
$ cargo run --quiet --bin get | ||
``` | ||
|
||
Tips. | ||
|
||
```console | ||
$ anchor account solprofile.Profile {ADDRESS} --idl=idls/solprofile.json | ||
``` | ||
|
||
### Update a profile | ||
|
||
```console | ||
$ cargo run --quiet --bin update | ||
``` |
Empty file.
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,46 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use anchor_client::{ | ||
solana_sdk::{ | ||
signature::{read_keypair_file, Signer}, | ||
system_program, | ||
}, | ||
Client, Cluster, | ||
}; | ||
|
||
use crate::util::{get_default_signer_keypair_path, get_profile_account}; | ||
use std::rc::Rc; | ||
|
||
declare_program!(solprofile); | ||
|
||
use solprofile::client::{accounts, args}; | ||
|
||
mod util; | ||
|
||
fn main() { | ||
let program_id = solprofile::ID; | ||
let system_program_key = system_program::id(); | ||
|
||
let signer_keypair_path = get_default_signer_keypair_path(); | ||
let signer = read_keypair_file(&signer_keypair_path).unwrap(); | ||
let signer_key = Signer::pubkey(&signer); | ||
|
||
let client = Client::new(Cluster::Localnet, Rc::new(&signer)); | ||
let program = client.program(program_id).unwrap(); | ||
|
||
let (profile_key, _) = get_profile_account(&signer_key, &program_id); | ||
|
||
let tx = program | ||
.request() | ||
.accounts(accounts::Create { | ||
profile: profile_key, | ||
owner: signer_key, | ||
system_program: system_program_key, | ||
}) | ||
.args(args::Create) | ||
.signer(&signer) | ||
.send() | ||
.unwrap(); | ||
|
||
println!("tx: {}", tx); | ||
} |
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,30 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use anchor_client::{ | ||
solana_sdk::signature::{read_keypair_file, Signer}, | ||
Client, Cluster, | ||
}; | ||
|
||
use crate::util::{get_default_signer_keypair_path, get_profile_account}; | ||
use std::rc::Rc; | ||
|
||
declare_program!(solprofile); | ||
|
||
mod util; | ||
|
||
fn main() { | ||
let program_id = solprofile::ID; | ||
|
||
let signer_keypair_path = get_default_signer_keypair_path(); | ||
let signer = read_keypair_file(signer_keypair_path).unwrap(); | ||
let signer_key = Signer::pubkey(&signer); | ||
|
||
let client = Client::new(Cluster::Localnet, Rc::new(&signer)); | ||
let program = client.program(program_id).unwrap(); | ||
|
||
let (profile_key, _) = get_profile_account(&signer_key, &program_id); | ||
|
||
let data: solprofile::accounts::Profile = program.account(profile_key).unwrap(); | ||
|
||
println!("data: {data:#?}"); | ||
} |
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 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use anchor_client::{ | ||
solana_sdk::{ | ||
signature::{read_keypair_file, Signer}, | ||
system_program, | ||
}, | ||
Client, Cluster, | ||
}; | ||
|
||
use crate::util::{get_default_signer_keypair_path, get_profile_account}; | ||
use std::rc::Rc; | ||
|
||
declare_program!(solprofile); | ||
|
||
use solprofile::client::{accounts, args}; | ||
use solprofile::types; | ||
|
||
mod util; | ||
|
||
fn main() { | ||
let program_id = solprofile::ID; | ||
let system_program_key = system_program::id(); | ||
|
||
let signer_keypair_path = get_default_signer_keypair_path(); | ||
let signer = read_keypair_file(signer_keypair_path).unwrap(); | ||
let signer_key = Signer::pubkey(&signer); | ||
|
||
let client = Client::new(Cluster::Localnet, Rc::new(&signer)); | ||
let program = client.program(program_id).unwrap(); | ||
|
||
let (profile_key, _) = get_profile_account(&signer_key, &program_id); | ||
|
||
let tx = program | ||
.request() | ||
.accounts(accounts::Update { | ||
profile: profile_key, | ||
owner: signer_key, | ||
system_program: system_program_key, | ||
}) | ||
.args(args::Update { | ||
args: types::UpdateArgs { | ||
name: Some("updated_name".to_string()), | ||
}, | ||
}) | ||
.signer(&signer) | ||
.send() | ||
.unwrap(); | ||
|
||
println!("tx: {}", tx); | ||
} |
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,10 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
pub fn get_default_signer_keypair_path() -> String { | ||
shellexpand::tilde("~/.config/solana/id.json").to_string() | ||
} | ||
|
||
pub fn get_profile_account(owner: &Pubkey, program_id: &Pubkey) -> (Pubkey, u8) { | ||
pub const PROFILE_SEED: &'static [u8] = b"profile"; | ||
Pubkey::find_program_address(&[PROFILE_SEED, owner.to_bytes().as_ref()], program_id) | ||
} |