Skip to content

Commit

Permalink
use new mint fn from nifty client; pack instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal committed Mar 31, 2024
1 parent bfe52fc commit f32e46e
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 288 deletions.
411 changes: 191 additions & 220 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ path = "src/main.rs"

[dependencies]
anyhow = "1.0.75"
bincode = "1.3.3"
borsh = { version = "0.9.3" }
clap = { version = "4.4.10", features = ["derive"] }
dirs = "5.0.1"
indexmap = { version = "2.1.0", features = ["serde"] }
indicatif = "0.17.8"
nifty-asset = { version = "0.1.0", features = ["serde"] }
nifty-asset-types = { version = "0.1.0" }
# nifty-asset = { version = "0.1.0", features = ["serde"] }
nifty-asset = { path = "../asset/clients/rust/asset", features = ["serde"] }
# nifty-asset-types = { version = "0.1.0" }
nifty-asset-types = { path = "../asset/programs/asset/types" }
podded = "0.5.1"
retry = "2.0.0"
serde = "1.0.193"
Expand Down
3 changes: 2 additions & 1 deletion example_extensions/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
{
"extension_type": "Metadata",
"value": {
"symbol": "SMB",
"symbol": "SAKURA",
"description": "example description",
"uri": "https://arweave.net/62Z5yOFbIeFqvoOl-aq75EAGSDzS-GxpIKC2ws5LVDc"
}
}
Expand Down
52 changes: 0 additions & 52 deletions example_extensions/image-asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,6 @@
"asset_keypair_file": null,
"owner": "Dn5Pq1Nus6Wt1Lw8rLuH7XgMfRUKxXzMR9BEta45TzAs",
"extensions": [
{
"extension_type": "Creators",
"value": [
{
"address": "AaSZHtdnHTcW4En23vJfmXxhZceoAfZnAjc8kYvherJ8",
"verified": true,
"share": 70
},
{
"address": "8UWRNwLHxD5DmEJ2cjVFdVpCNhfxL7bLkYpXG1o9srEN",
"verified": false,
"share": 20
},
{
"address": "5rH8qo7XzGaR5N8tMVQ32GuSw4HvwdBdnGN37ZGgsHnC",
"verified": false,
"share": 5
},
{
"address": "5Bw5EaQrCvgom3HFQ3ojUg2jd87nwzonPj4r5dVZKj7F",
"verified": false,
"share": 5
},
{
"address": "6367jssNbexBy38ydoZjBQJPGVN9oP6yteyfK5HCERki",
"verified": false,
"share": 0
}
]
},
{
"extension_type": "Attributes",
"value": [
{
"name": "skin",
"value": "blue"
}
]
},
{
"extension_type": "Links",
"value": [
{
"name": "twitter",
"value": "https://twitter.com/sakura"
},
{
"name": "instagram",
"value": "https://instagram.com/sakura"
}
]
},
{
"extension_type": "Blob",
"value": {
Expand Down
17 changes: 17 additions & 0 deletions example_extensions/metadata-asset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Sakura Kinomoto",
"mutable": false,
"standard": "NonFungible",
"asset_keypair_file": null,
"owner": "Dn5Pq1Nus6Wt1Lw8rLuH7XgMfRUKxXzMR9BEta45TzAs",
"extensions": [
{
"extension_type": "Metadata",
"value": {
"symbol": "SYMBOL",
"description": "Description",
"uri": "https://arweave.net/62Z5yOFbIeFqvoOl-aq75EAGSDzS-GxpIKC2ws5LVDc"
}
}
]
}
4 changes: 2 additions & 2 deletions src/commands/decode.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{fmt, ops::Deref};

use nifty_asset::{
extensions::{Blob, Links, Manager, Royalties},
extensions::{Attributes, Blob, ExtensionData, Grouping, Links, Manager, Metadata, Royalties},
types::Creator,
JsonCreator,
};
use nifty_asset_types::{
constraints::{
And, Constraint, FromBytes, Not, Operator, OperatorType, Or, OwnedBy, PubkeyMatch,
},
extensions::{Attributes, Extension, ExtensionData, ExtensionType, Grouping, Metadata},
extensions::{Extension, ExtensionType},
podded::ZeroCopy,
};
use serde_json::{json, Value};
Expand Down
12 changes: 6 additions & 6 deletions src/commands/mint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::fs::File;

use nifty_asset::{AssetArgs, AssetFile, ExtensionArgs, MintAccounts, MintIxArgs};
use crate::transaction::pack_instructions;

use super::*;

Expand Down Expand Up @@ -42,7 +40,6 @@ pub async fn handle_mint(args: MintArgs) -> Result<()> {
.map(|extension| ExtensionArgs {
extension_type: extension.extension_type.clone(),
data: extension.value.clone().into_data(),
chunked: true,
})
.collect::<Vec<ExtensionArgs>>();

Expand All @@ -52,8 +49,11 @@ pub async fn handle_mint(args: MintArgs) -> Result<()> {
extension_args,
})?;

for instruction in instructions {
let sig = send_and_confirm_tx(&config.client, &[&authority_sk, &asset_sk], &[instruction])?;
let packed_instructions = pack_instructions(2, &authority_sk.pubkey(), &instructions);

// Instructions are packed to max data length sizes, so we only put one in each tx.
for instructions in packed_instructions {
let sig = send_and_confirm_tx(&config.client, &[&authority_sk, &asset_sk], &instructions)?;
println!("sig: {}", sig);
}

Expand Down
10 changes: 7 additions & 3 deletions src/commands/mint_batch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{sync::Arc, time::Duration};

use crate::transaction::pack_instructions;

use super::*;

use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -108,7 +110,6 @@ pub async fn handle_mint_batch(args: MintBatchArgs) -> Result<()> {
.map(|extension| ExtensionArgs {
extension_type: extension.extension_type.clone(),
data: extension.value.clone().into_data(),
chunked: true,
})
.collect::<Vec<ExtensionArgs>>();

Expand Down Expand Up @@ -146,10 +147,13 @@ pub async fn handle_mint_batch(args: MintBatchArgs) -> Result<()> {
let pb = mp.add(ProgressBar::new(asset_instructions.len() as u64));
pb.set_style(sty.clone());

for instruction in asset_instructions {
let packed_instructions =
pack_instructions(2, &authority_sk.pubkey(), &asset_instructions);

for instructions in packed_instructions {
let asset_sk = &asset_keys.lock().await[i];
let asset_address = &asset_sk.pubkey();
let res = send_and_confirm_tx(&client, &[&authority_sk, &asset_sk], &[instruction]);
let res = send_and_confirm_tx(&client, &[&authority_sk, &asset_sk], &instructions);
pb.set_message(format!("sending transactions for asset {asset_address}"));
pb.inc(1);

Expand Down
3 changes: 2 additions & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ pub use {
},
serde::{Deserialize, Serialize},
solana_program::system_program,
solana_sdk::pubkey::Pubkey,
solana_sdk::{
pubkey::Pubkey,
signature::{read_keypair_file, Keypair},
signer::Signer,
transaction::Transaction,
},
};
2 changes: 1 addition & 1 deletion src/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn handle_transfer(args: TransferArgs) -> Result<()> {
asset,
signer,
recipient,
group_asset: None,
group: None,
}
.instruction();

Expand Down
29 changes: 29 additions & 0 deletions src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use anyhow::Result;
use nifty_asset::MAX_TX_SIZE;
use retry::{delay::Exponential, retry};
use solana_client::rpc_client::RpcClient;
use solana_program::instruction::Instruction;
use solana_sdk::{
pubkey::Pubkey,
signature::{Keypair, Signature},
signer::Signer,
transaction::Transaction,
Expand Down Expand Up @@ -47,3 +49,30 @@ pub fn send_and_confirm_tx_with_retries(

Ok(res)
}

pub fn pack_instructions<'a>(
num_signers: u32,
payer: &'a Pubkey,
ixs: &'a [Instruction],
) -> Vec<Vec<Instruction>> {
let mut instructions = vec![];
let mut tx_instructions = vec![];

// 64 bytes for each signature + Message size
let max_payload_size = MAX_TX_SIZE - std::mem::size_of::<Signature>() * num_signers as usize;

for ix in ixs {
tx_instructions.push(ix.clone());
let tx = Transaction::new_with_payer(tx_instructions.as_slice(), Some(payer));
let tx_len = bincode::serialize(&tx).unwrap().len();

if tx_len > max_payload_size {
let last_ix = tx_instructions.pop().unwrap();
instructions.push(tx_instructions.clone());
tx_instructions.clear();
tx_instructions.push(last_ix);
}
}

instructions
}

0 comments on commit f32e46e

Please sign in to comment.