Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches #50

Merged
merged 34 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,229 changes: 617 additions & 612 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions crates/cmds-pdg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ once_cell = "1.17.1"
uuid = { version = "1.3.1", features = ["serde"] }
tracing = "0.1.37"
tokio = "1.33.0"
rand = "0.8"
rand_chacha = "0.3"
78 changes: 78 additions & 0 deletions crates/cmds-pdg/node-definitions/generate_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"type": "native",
"data": {
"node_definition_version": "0.1",
"unique_id": "",
"node_id": "generate_base",
"version": "0.1",
"display_name": "Generate Base",
"description": "",
"tags": [],
"related_to": [
{
"id": "",
"type": "",
"relationship": ""
}
],
"resources": {
"source_code_url": "",
"documentation_url": ""
},
"usage": {
"license": "Apache-2.0",
"license_url": "",
"pricing": {
"currency": "USDC",
"purchase_price": 0,
"price_per_run": 0,
"custom": {
"unit": "monthly",
"value": "0"
}
}
},
"authors": [
{
"name": "Space Operator",
"contact": ""
}
],
"design": {
"width": 0,
"height": 0,
"icon_url": "",
"backgroundColorDark": "#000000",
"backgroundColor": "#fff"
},
"options": {}
},
"sources": [
{
"name": "attributes",
"type": "object",
"defaultValue": "",
"tooltip": ""
}
],
"targets": [
{
"name": "seed",
"type_bounds": ["u64"],
"required": false,
"passthrough": false,
"defaultValue": null,
"tooltip": "Optional random seed to use."
},
{
"name": "defaults",
"type_bounds": ["object"],
"required": false,
"passthrough": false,
"defaultValue": null,
"tooltip": "Default values to overwrite randomly generated values."
}
],
"targets_form.json_schema": {},
"targets_form.ui_schema": {}
}
8 changes: 8 additions & 0 deletions crates/cmds-pdg/node-definitions/parse_pdg_attrs.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
"passthrough": false,
"defaultValue": true,
"tooltip": "Check human-readable attributes to see if they match."
},
{
"name": "defaults",
"type_bounds": ["object"],
"required": false,
"passthrough": false,
"defaultValue": null,
"tooltip": "Supply default values for missing attributes."
}
],
"targets_form.json_schema": {},
Expand Down
2 changes: 1 addition & 1 deletion crates/cmds-pdg/src/gen_pdg_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Output {
async fn run(_: Context, input: Input) -> Result<Output, CommandError> {
let attributes = match input.flag {
Some(flag) => match flag.as_str() {
"base" => RenderParams::generate_base(),
"base" => RenderParams::generate_base(&mut rand::thread_rng()),
_ => RenderParams::default(),
},
None => input.attributes.unwrap_or_default(),
Expand Down
50 changes: 50 additions & 0 deletions crates/cmds-pdg/src/generate_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use flow_lib::{
command::{
builder::{BuildResult, BuilderCache, CmdBuilder},
CommandDescription, CommandError,
},
Context,
};
use pdg_common::nft_metadata::RenderParams;
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use serde::{Deserialize, Serialize};

const NAME: &str = "generate_base";

fn build() -> BuildResult {
static CACHE: BuilderCache = BuilderCache::new(|| {
CmdBuilder::new(flow_lib::node_definition!("generate_base.json"))?.check_name(NAME)
});
Ok(CACHE.clone()?.build(run))
}

flow_lib::submit!(CommandDescription::new(NAME, |_| build()));

#[derive(Deserialize, Debug)]
struct Input {
#[serde(default)]
seed: Option<u64>,
#[serde(default)]
defaults: flow_lib::value::Map,
}

#[derive(Serialize, Debug)]
struct Output {
attributes: RenderParams,
}

async fn run(_: Context, input: Input) -> Result<Output, CommandError> {
let mut rng = match input.seed {
Some(seed) => ChaCha20Rng::seed_from_u64(seed),
None => ChaCha20Rng::from_entropy(),
};

let attributes = RenderParams::generate_base(&mut rng);

let mut map = flow_lib::value::to_map(&attributes)?;
map.extend(input.defaults.into_iter());
let attributes = flow_lib::value::from_map(map)?;

Ok(Output { attributes })
}
1 change: 1 addition & 0 deletions crates/cmds-pdg/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod gen_metaplex_attrs;
pub mod gen_pdg_attrs;
pub mod generate_base;
pub mod get_effect_list;
pub mod parse_pdg_attrs;
pub mod pdg_render;
Expand Down
5 changes: 5 additions & 0 deletions crates/cmds-pdg/src/parse_pdg_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use flow_lib::{
};
use pdg_common::nft_metadata::RenderParams;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use std::collections::HashMap;

const PARSE_PDG_ATTRS: &str = "parse_pdg_attrs";

Expand All @@ -29,6 +31,8 @@ struct Input {
attributes: Value,
#[serde(default = "bool_true")]
check_human_readable: bool,
#[serde(default)]
defaults: HashMap<String, JsonValue>,
}

#[derive(Serialize, Debug)]
Expand All @@ -41,6 +45,7 @@ async fn run(_: Context, input: Input) -> Result<Output, CommandError> {
attributes: RenderParams::from_pdg_metadata(
&mut input.attributes.into(),
input.check_human_readable,
&input.defaults,
)?,
})
}
15 changes: 13 additions & 2 deletions crates/cmds-pdg/src/pdg_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,26 @@ async fn ws_wait(
async fn run(_: Context, input: Input) -> Result<Output, CommandError> {
let (mut ws, _) = tokio_tungstenite::connect_async(&input.url).await?;

let rand_seed = input.rand_seed.or_else(|| {
Some(
input
.attributes
.get("wedgeindex")?
.pointer("/value/0")?
.as_i64()?
.to_string(),
)
});

// send the request
ws.send({
tracing::debug!(
"rand_seed={}",
&input.rand_seed.as_ref().unwrap_or(&"".to_owned())
&rand_seed.as_ref().unwrap_or(&"".to_owned())
);
let text = serde_json::to_string({
&RenderRequest {
rand_seed: input.rand_seed,
rand_seed,
version: "6".to_owned(),
workitem: WorkItem {
attributes: input.attributes,
Expand Down
2 changes: 1 addition & 1 deletion crates/cmds-solana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde_with = "3.1.0"
bs58 = "0.4"
tracing = "0.1"
once_cell = "1.17"
rand = "0.7.3"
rand = "0.8"
hex = "0.4.3"
byteorder = "1.4.3"
primitive-types = { version = "0.9.0", default-features = false }
Expand Down
10 changes: 5 additions & 5 deletions crates/cmds-solana/src/find_pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,32 @@ impl CommandTrait for FindPDA {
async fn run(&self, _: Context, mut inputs: ValueSet) -> Result<ValueSet, CommandError> {
let Input { program_id } = value::from_map(inputs.clone())?;

let seed_1: Option<Value> = inputs.remove(SEED_1);
let seed_1: Option<Value> = inputs.swap_remove(SEED_1);
let seed_1 = match seed_1 {
Some(Value::B32(v)) => v.to_vec(),
Some(Value::String(v)) => v.as_bytes().to_vec(),
_ => vec![],
};

let seed_2: Option<Value> = inputs.remove(SEED_2);
let seed_2: Option<Value> = inputs.swap_remove(SEED_2);
let seed_2 = match seed_2 {
Some(Value::B32(v)) => v.to_vec(),
Some(Value::String(v)) => v.as_bytes().to_vec(),
_ => vec![],
};
let seed_3: Option<Value> = inputs.remove(SEED_3);
let seed_3: Option<Value> = inputs.swap_remove(SEED_3);
let seed_3 = match seed_3 {
Some(Value::B32(v)) => v.to_vec(),
Some(Value::String(v)) => v.as_bytes().to_vec(),
_ => vec![],
};
let seed_4: Option<Value> = inputs.remove(SEED_4);
let seed_4: Option<Value> = inputs.swap_remove(SEED_4);
let seed_4 = match seed_4 {
Some(Value::B32(v)) => v.to_vec(),
Some(Value::String(v)) => v.as_bytes().to_vec(),
_ => vec![],
};
let seed_5: Option<Value> = inputs.remove(SEED_5);
let seed_5: Option<Value> = inputs.swap_remove(SEED_5);
let seed_5 = match seed_5 {
Some(Value::B32(v)) => v.to_vec(),
Some(Value::String(v)) => v.as_bytes().to_vec(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cmds-solana/src/nft/arweave_nft_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl bundlr_sdk::Signer for BundlrSigner {
const PUB_LENGTH: u16 = Ed25519Signer::PUB_LENGTH;

fn sign(&self, msg: bytes::Bytes) -> Result<bytes::Bytes, BundlrError> {
let sig = if self.keypair.is_user_wallet() {
let sig = if self.keypair.is_adapter_wallet() {
let rt = self
.ctx
.get::<tokio::runtime::Handle>()
Expand Down
5 changes: 1 addition & 4 deletions crates/cmds-solana/src/nft/v1/delegate_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,10 +752,7 @@ impl From<DelegateArgs> for mpl_token_metadata::types::DelegateArgs {
authorization_data,
} => Self::LockedTransferV1 {
amount,
locked_address: locked_address
.to_bytes()
.try_into()
.expect("locked_address should be 32 bytes"),
locked_address: locked_address.to_bytes().into(),
authorization_data: authorization_data.map(Into::into),
},
DelegateArgs::ProgrammableConfigV1 { authorization_data } => {
Expand Down
4 changes: 2 additions & 2 deletions crates/cmds-solana/src/std/json_get_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl CommandTrait for JsonGetField {
let Input { field } = value::from_map(inputs.clone())?;

let json = inputs
.remove(JSON_OR_STRING)
.swap_remove(JSON_OR_STRING)
.ok_or_else(|| crate::Error::ValueNotFound(JSON_OR_STRING.into()))?;

match json {
Expand All @@ -95,7 +95,7 @@ impl CommandTrait for JsonGetField {

let value = json
.ok()
.and_then(|mut object| object.remove(&field))
.and_then(|mut object| object.swap_remove(&field))
.unwrap_or_default();

let result_json: JsonValue = value;
Expand Down
2 changes: 1 addition & 1 deletion crates/cmds-solana/src/std/to_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl CommandTrait for ToString {
}

async fn run(&self, _: Context, mut inputs: ValueSet) -> Result<ValueSet, CommandError> {
let input = inputs.remove(STRINGIFY).unwrap_or("".into());
let input = inputs.swap_remove(STRINGIFY).unwrap_or("".into());

let result = match input {
Value::Decimal(v) => v.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions crates/cmds-solana/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub async fn try_sign_wallet(

let futs = keypairs
.iter()
.filter(|&k| k.is_user_wallet())
.filter(|&k| k.is_adapter_wallet())
.map(|k| k.pubkey())
.collect::<BTreeSet<_>>()
.into_iter()
Expand All @@ -95,7 +95,7 @@ pub async fn try_sign_wallet(
}

for k in keypairs {
if !k.is_user_wallet() {
if !k.is_adapter_wallet() {
signers.push(*k);
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/cmds-solana/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ enum WalletError {
}

fn adapter_wallet(pubkey: Pubkey) -> Output {
let mut buf = [0u8; 64];
buf[32..].copy_from_slice(&pubkey.to_bytes());
let keypair = Keypair::from_bytes(&buf).expect("correct size, never fail");
Output { pubkey, keypair }
Output {
pubkey,
keypair: Keypair::new_adapter_wallet(pubkey),
}
}

impl FormData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async fn run(mut ctx: Context, input: Input) -> Result<Output, CommandError> {
let ins = Instructions {
fee_payer: input.payer.pubkey(),
signers: [input.payer.clone_keypair()].into(),
instructions: instructions.into(),
instructions,
};

let ins = input.submit.then_some(ins).unwrap_or_default();
Expand Down
4 changes: 2 additions & 2 deletions crates/cmds-std/benches/postgrest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ pub fn criterion_benchmark(c: &mut Criterion) {
.unwrap()
})
});
c.bench_function("build_header", |b| b.iter(|| build_header()));
c.bench_function("build_header", |b| b.iter(build_header));
let value = Value::Array(array![array!["accept", "application/json"]]);
c.bench_function("deser_vec_tuple", |b| {
b.iter(|| value::from_value::<Vec<(String, String)>>(black_box(value.clone())).unwrap())
});
c.bench_function("new_reqwest_client", |b| b.iter(|| reqwest::Client::new()));
c.bench_function("new_reqwest_client", |b| b.iter(reqwest::Client::new));
}

criterion_group!(benches, criterion_benchmark);
Expand Down
2 changes: 1 addition & 1 deletion crates/cmds-std/src/print_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl CommandTrait for PrintCommand {

async fn run(&self, _ctx: Context, mut inputs: ValueSet) -> Result<ValueSet, CommandError> {
let input = inputs
.remove(PRINT)
.swap_remove(PRINT)
.ok_or_else(|| anyhow!("input not found: {}", PRINT))?;
let output = match input {
Value::Decimal(v) => v.to_string(),
Expand Down
Loading
Loading