Skip to content

Commit

Permalink
Update Kinobi version for Rust client (#49)
Browse files Browse the repository at this point in the history
* Bump Kinobi version

* Update example

* Improve hooked type
  • Loading branch information
febo authored Sep 7, 2023
1 parent e8f2edd commit c1e24c4
Show file tree
Hide file tree
Showing 149 changed files with 12,893 additions and 2,427 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Build Rust client
shell: bash
working-directory: clients/rust
run: cargo build --release
run: cargo build --all-features --release

- name: Upload Rust client builds
uses: actions/upload-artifact@v3
Expand Down
48 changes: 45 additions & 3 deletions clients/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ crate-type = ["cdylib", "lib"]

[features]
test-sbf = []
serde = ["dep:serde", "dep:serde_with"]

[dependencies]
borsh = ">= 0.9"
num-derive = "^0.3"
num-traits = "^0.2"
serde = { version = "^1.0", features = ["derive"], optional = true }
serde_with = { version = "^3.0", optional = true }
solana-program = "^1.14"
thiserror = "^1.0"

Expand Down
51 changes: 26 additions & 25 deletions clients/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Alternatively, you can use the `CreateV1Builder` to create the appropriate instr
```rust
let create_ix = CreateV1Builder::new()
.metadata(metadata)
.master_edition(master_edition)
.master_edition(Some(master_edition))
.mint(mint_pubkey, true)
.authority(payer_pubkey)
.payer(payer_pubkey)
Expand Down Expand Up @@ -169,7 +169,7 @@ pub struct TransferV1Cpi<'a> {
}
```

After filling in the instruction account info and argument fields, you can use the `invoke()` or `invoke_signed(...)` method to perform the CPI:
After filling in the program, instruction accounts and argument fields, you can use the `invoke()` or `invoke_signed(...)` method to perform the CPI:

```rust
// instruction args
Expand All @@ -179,27 +179,29 @@ let mut args = TransferV1InstructionArgs {
};

// instruction accounts
let cpi_transfer = TransferV1Cpi {
__program: metadata_program_info,
__args: args,
token: owner_token_info,
token_owner: owner_info,
destination_token: destination_token_info,
destination_owner: destination_info,
mint: mint_info,
metadata: metadata_info,
authority: vault_info,
payer: payer_info,
system_program: system_program_info,
sysvar_instructions: sysvar_instructions_info,
spl_token_program: spl_token_program_info,
spl_ata_program: spl_ata_program_info,
edition: edition_info,
token_record: None,
destination_token_record: None,
authorization_rules: None,
authorization_rules_program: None,
};
let cpi_transfer = TransferV1Cpi::new(
metadata_program_info,
TransferV1CpiAccounts {
token: owner_token_info,
token_owner: owner_info,
destination_token: destination_token_info,
destination_owner: destination_info,
mint: mint_info,
metadata: metadata_info,
authority: vault_info,
payer: payer_info,
system_program: system_program_info,
sysvar_instructions: sysvar_instructions_info,
spl_token_program: spl_token_program_info,
spl_ata_program: spl_ata_program_info,
edition: edition_info,
token_record: None,
destination_token_record: None,
authorization_rules: None,
authorization_rules_program: None,
},
args,
);

// performs the CPI
cpi_transfer.invoke_signed(&[&signer_seeds])
Expand All @@ -222,8 +224,7 @@ let cpi_transfer = TransferV1CpiBuilder::new(metadata_program_info)
.sysvar_instructions(sysvar_instructions_info)
.spl_token_program(spl_token_program_info)
.spl_ata_program(spl_ata_program_info)
.amount(amount)
.build();
.amount(amount);

// performs the CPI
cpi_transfer.invoke_signed(&[&signer_seeds])
Expand Down
32 changes: 20 additions & 12 deletions clients/rust/src/generated/accounts/collection_authority_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,53 @@ use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectionAuthorityRecord {
pub key: Key,
pub bump: u8,
pub update_authority: Option<Pubkey>,
}

impl CollectionAuthorityRecord {
pub fn find_pda(
mint: &Pubkey,
collection_authority: &Pubkey,
) -> (solana_program::pubkey::Pubkey, u8) {
solana_program::pubkey::Pubkey::find_program_address(
pub fn create_pda(
mint: Pubkey,
collection_authority: Pubkey,
bump: u8,
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
solana_program::pubkey::Pubkey::create_program_address(
&[
"metadata".as_bytes(),
crate::MPL_TOKEN_METADATA_ID.as_ref(),
mint.as_ref(),
"collection_authority".as_bytes(),
collection_authority.as_ref(),
&[bump],
],
&crate::MPL_TOKEN_METADATA_ID,
)
}
pub fn create_pda(
mint: Pubkey,
collection_authority: Pubkey,
bump: u8,
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
solana_program::pubkey::Pubkey::create_program_address(

pub fn find_pda(
mint: &Pubkey,
collection_authority: &Pubkey,
) -> (solana_program::pubkey::Pubkey, u8) {
solana_program::pubkey::Pubkey::find_program_address(
&[
"metadata".as_bytes(),
crate::MPL_TOKEN_METADATA_ID.as_ref(),
mint.as_ref(),
"collection_authority".as_bytes(),
collection_authority.as_ref(),
&[bump],
],
&crate::MPL_TOKEN_METADATA_ID,
)
}

#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}

impl<'a> TryFrom<&'a solana_program::account_info::AccountInfo<'a>> for CollectionAuthorityRecord {
Expand Down
11 changes: 11 additions & 0 deletions clients/rust/src/generated/accounts/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@ use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Edition {
pub key: Key,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub parent: Pubkey,
pub edition: u64,
}

impl Edition {
pub const LEN: usize = 41;

#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}

impl<'a> TryFrom<&'a solana_program::account_info::AccountInfo<'a>> for Edition {
Expand Down
26 changes: 17 additions & 9 deletions clients/rust/src/generated/accounts/edition_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EditionMarker {
pub key: Key,
pub ledger: [u8; 31],
Expand All @@ -19,35 +20,42 @@ pub struct EditionMarker {
impl EditionMarker {
pub const LEN: usize = 32;

pub fn find_pda(mint: &Pubkey, edition_marker: &str) -> (solana_program::pubkey::Pubkey, u8) {
solana_program::pubkey::Pubkey::find_program_address(
pub fn create_pda(
mint: Pubkey,
edition_marker: &str,
bump: u8,
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
solana_program::pubkey::Pubkey::create_program_address(
&[
"metadata".as_bytes(),
crate::MPL_TOKEN_METADATA_ID.as_ref(),
mint.as_ref(),
"edition".as_bytes(),
edition_marker.to_string().as_ref(),
&[bump],
],
&crate::MPL_TOKEN_METADATA_ID,
)
}
pub fn create_pda(
mint: Pubkey,
edition_marker: &str,
bump: u8,
) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
solana_program::pubkey::Pubkey::create_program_address(

pub fn find_pda(mint: &Pubkey, edition_marker: &str) -> (solana_program::pubkey::Pubkey, u8) {
solana_program::pubkey::Pubkey::find_program_address(
&[
"metadata".as_bytes(),
crate::MPL_TOKEN_METADATA_ID.as_ref(),
mint.as_ref(),
"edition".as_bytes(),
edition_marker.to_string().as_ref(),
&[bump],
],
&crate::MPL_TOKEN_METADATA_ID,
)
}

#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}

impl<'a> TryFrom<&'a solana_program::account_info::AccountInfo<'a>> for EditionMarker {
Expand Down
Loading

0 comments on commit c1e24c4

Please sign in to comment.