Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
juchiast committed Feb 2, 2024
1 parent 213ea68 commit 970ac93
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 382 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cmds-pdg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ once_cell = "1.17.1"
uuid = { version = "1.3.1", features = ["serde"] }
tracing = "0.1.37"
tokio = "1.33.0"
rand = "0.8"
70 changes: 70 additions & 0 deletions crates/cmds-pdg/node-definitions/generate_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"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": "defaults",
"type_bounds": ["object"],
"required": false,
"passthrough": false,
"defaultValue": null,
"tooltip": "Default values to use."
}
],
"targets_form.json_schema": {},
"targets_form.ui_schema": {}
}
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
41 changes: 41 additions & 0 deletions crates/cmds-pdg/src/generate_base.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use flow_lib::{
command::{
builder::{BuildResult, BuilderCache, CmdBuilder},
CommandDescription, CommandError,
},
Context,
};
use pdg_common::nft_metadata::RenderParams;
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)]
defaults: flow_lib::value::Map,
}

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

async fn run(_: Context, input: Input) -> Result<Output, CommandError> {
let attributes = RenderParams::generate_base(&mut rand::thread_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
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
Loading

0 comments on commit 970ac93

Please sign in to comment.