From 5c8dcb00f0bf094b30a7b6b3d22725443b08f4c5 Mon Sep 17 00:00:00 2001 From: Nuno Boavida <45330362+nmboavida@users.noreply.github.com> Date: Sat, 7 Jan 2023 01:25:22 +0000 Subject: [PATCH 1/3] Init cli --- Cargo.lock | 322 +++++++++++++++++- Cargo.toml | 20 +- crates/byte_cli/Cargo.toml | 15 + crates/byte_cli/src/cli.rs | 47 +++ crates/byte_cli/src/consts.rs | 2 + crates/byte_cli/src/lib.rs | 3 + crates/byte_cli/src/main.rs | 16 + crates/byte_cli/src/prelude.rs | 2 + crates/gutenberg/Cargo.toml | 15 + {src => crates/gutenberg/src}/err.rs | 0 {src => crates/gutenberg/src}/lib.rs | 0 {src => crates/gutenberg/src}/main.rs | 0 {src => crates/gutenberg/src}/prelude.rs | 0 {src => crates/gutenberg/src}/schema.rs | 0 {src => crates/gutenberg/src}/types.rs | 0 .../gutenberg/templates}/template.move | 0 .../gutenberg/templates}/template.yaml | 0 {tests => crates/gutenberg/tests}/generate.rs | 0 18 files changed, 423 insertions(+), 19 deletions(-) create mode 100644 crates/byte_cli/Cargo.toml create mode 100644 crates/byte_cli/src/cli.rs create mode 100644 crates/byte_cli/src/consts.rs create mode 100644 crates/byte_cli/src/lib.rs create mode 100644 crates/byte_cli/src/main.rs create mode 100644 crates/byte_cli/src/prelude.rs create mode 100644 crates/gutenberg/Cargo.toml rename {src => crates/gutenberg/src}/err.rs (100%) rename {src => crates/gutenberg/src}/lib.rs (100%) rename {src => crates/gutenberg/src}/main.rs (100%) rename {src => crates/gutenberg/src}/prelude.rs (100%) rename {src => crates/gutenberg/src}/schema.rs (100%) rename {src => crates/gutenberg/src}/types.rs (100%) rename {templates => crates/gutenberg/templates}/template.move (100%) rename {templates => crates/gutenberg/templates}/template.yaml (100%) rename {tests => crates/gutenberg/tests}/generate.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index c1032fa..7422596 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,79 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "anyhow" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "byte_cli" +version = "0.2.0" +dependencies = [ + "anyhow", + "clap", + "pretty_assertions", + "serde", + "serde_yaml", + "tokio", +] + +[[package]] +name = "cc" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" + +[[package]] +name = "clap" +version = "4.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +dependencies = [ + "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "ctor" version = "0.1.26" @@ -24,6 +91,27 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "gumdrop" version = "0.8.1" @@ -62,6 +150,21 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "indexmap" version = "1.9.2" @@ -72,12 +175,68 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" + +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + [[package]] name = "output_vt100" version = "0.1.3" @@ -87,6 +246,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + [[package]] name = "pretty_assertions" version = "1.3.0" @@ -99,6 +264,30 @@ dependencies = [ "yansi", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.49" @@ -117,6 +306,20 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.12" @@ -125,18 +328,18 @@ checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "serde" -version = "1.0.151" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.151" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", @@ -162,6 +365,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26cdabcdab6da7e8c2ac1160e917ec83e78bbe3e10325e17d532718c67a4828f" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.107" @@ -173,6 +382,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.38" @@ -193,6 +411,30 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio" +version = "1.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae" +dependencies = [ + "autocfg", + "num_cpus", + "pin-project-lite", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "unicode-ident" version = "1.0.6" @@ -205,6 +447,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc7ed8ba44ca06be78ea1ad2c3682a43349126c8818054231ee6f4748012aed2" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "winapi" version = "0.3.9" @@ -221,12 +469,78 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index e61b260..f3d2834 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,5 @@ -[package] -name = "gutenberg" -version = "0.2.0" -edition = "2021" - -[dependencies] -thiserror = "1.0" -strfmt = "0.2" -gumdrop = "0.8" - -serde = { version = "1.0", features = ["derive"] } -serde_yaml = "0.9" - -[dev-dependencies] -pretty_assertions = "1.3.0" +[workspace] +members = [ + "crates/gutenberg", + "crates/byte_cli", +] diff --git a/crates/byte_cli/Cargo.toml b/crates/byte_cli/Cargo.toml new file mode 100644 index 0000000..30ac83e --- /dev/null +++ b/crates/byte_cli/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "byte_cli" +version = "0.2.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_yaml = "0.9" +# thiserror = "1.0" +tokio = {version = "1.24", features = ["macros", "rt-multi-thread"]} +clap = {version = "4.0", features = ["derive"]} +anyhow = "1.0" + +[dev-dependencies] +pretty_assertions = "1.3.0" diff --git a/crates/byte_cli/src/cli.rs b/crates/byte_cli/src/cli.rs new file mode 100644 index 0000000..a17b10e --- /dev/null +++ b/crates/byte_cli/src/cli.rs @@ -0,0 +1,47 @@ +use clap::{Parser, Subcommand}; + +pub use crate::consts::DEFAULT_ASSETS_FOLDER; + +#[derive(Parser)] +#[clap(author, version, about)] +pub struct Cli { + #[clap(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand)] +pub enum Commands { + /// Creates or adds confiiguration to JSON config file to be read by + /// Gutenberg for the purpose of building the Move module + InitCollectionConfig {}, + + /// Creates or adds configuration to JSON config file to be read the asset + /// deployer for the purpose of deploying assets, usually to an off-chain + /// storage service + InitUploadConfig { + /// Path to the directory with the assets + #[clap(default_value = DEFAULT_ASSETS_FOLDER)] + assets_dir: String, + }, + + /// Combines `InitCollectionConfig` and `InitUploadConfig in one single flow, + /// hence make the UX seamless for the majority of use cases + InitConfig { + /// Path to the directory with the assets + #[clap(default_value = DEFAULT_ASSETS_FOLDER)] + assets_dir: String, + }, + + /// Deploys assets to a storage service + DeployAssets { + /// Path to the directory with the assets + #[clap(default_value = DEFAULT_ASSETS_FOLDER)] + assets_dir: String, + }, + + /// Deploys NFT contract to Sui Blockchain + DeployContract {}, + + /// Mints NFTs by calling the deployed contract + MintNfts {}, +} diff --git a/crates/byte_cli/src/consts.rs b/crates/byte_cli/src/consts.rs new file mode 100644 index 0000000..199622e --- /dev/null +++ b/crates/byte_cli/src/consts.rs @@ -0,0 +1,2 @@ +/// Default path for assets folder. +pub const DEFAULT_ASSETS_FOLDER: &str = "assets"; diff --git a/crates/byte_cli/src/lib.rs b/crates/byte_cli/src/lib.rs new file mode 100644 index 0000000..438d7e0 --- /dev/null +++ b/crates/byte_cli/src/lib.rs @@ -0,0 +1,3 @@ +pub mod cli; +pub mod consts; +pub mod prelude; diff --git a/crates/byte_cli/src/main.rs b/crates/byte_cli/src/main.rs new file mode 100644 index 0000000..959bff1 --- /dev/null +++ b/crates/byte_cli/src/main.rs @@ -0,0 +1,16 @@ +pub mod cli; +pub mod consts; +pub mod prelude; + +use crate::prelude::*; +use anyhow::Result; +use clap::Parser; + +#[tokio::main] +async fn main() {} + +async fn run() -> Result<()> { + let _cli = Cli::parse(); + + Ok(()) +} diff --git a/crates/byte_cli/src/prelude.rs b/crates/byte_cli/src/prelude.rs new file mode 100644 index 0000000..efa075e --- /dev/null +++ b/crates/byte_cli/src/prelude.rs @@ -0,0 +1,2 @@ +pub use crate::cli::Cli; +pub use crate::consts; diff --git a/crates/gutenberg/Cargo.toml b/crates/gutenberg/Cargo.toml new file mode 100644 index 0000000..e61b260 --- /dev/null +++ b/crates/gutenberg/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "gutenberg" +version = "0.2.0" +edition = "2021" + +[dependencies] +thiserror = "1.0" +strfmt = "0.2" +gumdrop = "0.8" + +serde = { version = "1.0", features = ["derive"] } +serde_yaml = "0.9" + +[dev-dependencies] +pretty_assertions = "1.3.0" diff --git a/src/err.rs b/crates/gutenberg/src/err.rs similarity index 100% rename from src/err.rs rename to crates/gutenberg/src/err.rs diff --git a/src/lib.rs b/crates/gutenberg/src/lib.rs similarity index 100% rename from src/lib.rs rename to crates/gutenberg/src/lib.rs diff --git a/src/main.rs b/crates/gutenberg/src/main.rs similarity index 100% rename from src/main.rs rename to crates/gutenberg/src/main.rs diff --git a/src/prelude.rs b/crates/gutenberg/src/prelude.rs similarity index 100% rename from src/prelude.rs rename to crates/gutenberg/src/prelude.rs diff --git a/src/schema.rs b/crates/gutenberg/src/schema.rs similarity index 100% rename from src/schema.rs rename to crates/gutenberg/src/schema.rs diff --git a/src/types.rs b/crates/gutenberg/src/types.rs similarity index 100% rename from src/types.rs rename to crates/gutenberg/src/types.rs diff --git a/templates/template.move b/crates/gutenberg/templates/template.move similarity index 100% rename from templates/template.move rename to crates/gutenberg/templates/template.move diff --git a/templates/template.yaml b/crates/gutenberg/templates/template.yaml similarity index 100% rename from templates/template.yaml rename to crates/gutenberg/templates/template.yaml diff --git a/tests/generate.rs b/crates/gutenberg/tests/generate.rs similarity index 100% rename from tests/generate.rs rename to crates/gutenberg/tests/generate.rs From b06130477ebc7b706a96909dc4136973dda352b2 Mon Sep 17 00:00:00 2001 From: Nuno Boavida <45330362+nmboavida@users.noreply.github.com> Date: Mon, 9 Jan 2023 09:44:29 +0000 Subject: [PATCH 2/3] Set up flow --- Cargo.lock | 32 ++++++++++++++++++++++++++++++++ crates/byte_cli/Cargo.toml | 1 + crates/byte_cli/src/cli.rs | 6 +++++- crates/byte_cli/src/consts.rs | 4 ++++ crates/byte_cli/src/main.rs | 28 ++++++++++++++++++++++++++-- crates/byte_cli/src/prelude.rs | 2 +- 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7422596..00f6571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,7 @@ version = "0.2.0" dependencies = [ "anyhow", "clap", + "console", "pretty_assertions", "serde", "serde_yaml", @@ -75,6 +76,19 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "console" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys", +] + [[package]] name = "ctor" version = "0.1.26" @@ -91,6 +105,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + [[package]] name = "errno" version = "0.2.8" @@ -203,6 +223,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.139" @@ -441,6 +467,12 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "unsafe-libyaml" version = "0.2.5" diff --git a/crates/byte_cli/Cargo.toml b/crates/byte_cli/Cargo.toml index 30ac83e..e1bffdc 100644 --- a/crates/byte_cli/Cargo.toml +++ b/crates/byte_cli/Cargo.toml @@ -10,6 +10,7 @@ serde_yaml = "0.9" tokio = {version = "1.24", features = ["macros", "rt-multi-thread"]} clap = {version = "4.0", features = ["derive"]} anyhow = "1.0" +console = "0.15.4" [dev-dependencies] pretty_assertions = "1.3.0" diff --git a/crates/byte_cli/src/cli.rs b/crates/byte_cli/src/cli.rs index a17b10e..2ad15cd 100644 --- a/crates/byte_cli/src/cli.rs +++ b/crates/byte_cli/src/cli.rs @@ -43,5 +43,9 @@ pub enum Commands { DeployContract {}, /// Mints NFTs by calling the deployed contract - MintNfts {}, + MintNfts { + /// Path to the directory with the assets + #[clap(default_value = DEFAULT_ASSETS_FOLDER)] + assets_dir: String, + }, } diff --git a/crates/byte_cli/src/consts.rs b/crates/byte_cli/src/consts.rs index 199622e..761c430 100644 --- a/crates/byte_cli/src/consts.rs +++ b/crates/byte_cli/src/consts.rs @@ -1,2 +1,6 @@ +use console::Emoji; + /// Default path for assets folder. pub const DEFAULT_ASSETS_FOLDER: &str = "assets"; + +pub const ROCKET_EMOJI: Emoji<'_, '_> = Emoji("🚀 ", ""); diff --git a/crates/byte_cli/src/main.rs b/crates/byte_cli/src/main.rs index 959bff1..57ce19b 100644 --- a/crates/byte_cli/src/main.rs +++ b/crates/byte_cli/src/main.rs @@ -5,12 +5,36 @@ pub mod prelude; use crate::prelude::*; use anyhow::Result; use clap::Parser; +use console::style; #[tokio::main] -async fn main() {} +async fn main() { + match run().await { + Ok(()) => { + println!( + "\n{}{}", + consts::ROCKET_EMOJI, + style("Process ran successfully.").green().bold().dim() + ); + } + Err(err) => { + println!("\n{}", err,); + std::process::exit(1); + } + } +} async fn run() -> Result<()> { - let _cli = Cli::parse(); + let cli = Cli::parse(); + + match cli.command { + Commands::InitCollectionConfig {} => {} + Commands::InitUploadConfig { assets_dir } => {} + Commands::InitConfig { assets_dir } => {} + Commands::DeployAssets { assets_dir } => {} + Commands::DeployContract {} => {} + Commands::MintNfts { assets_dir } => {} + } Ok(()) } diff --git a/crates/byte_cli/src/prelude.rs b/crates/byte_cli/src/prelude.rs index efa075e..ff55808 100644 --- a/crates/byte_cli/src/prelude.rs +++ b/crates/byte_cli/src/prelude.rs @@ -1,2 +1,2 @@ -pub use crate::cli::Cli; +pub use crate::cli::{Cli, Commands}; pub use crate::consts; From ec6e21fb64b7f9539a5c3a6cc0b76522d966b926 Mon Sep 17 00:00:00 2001 From: Nuno Boavida <45330362+nmboavida@users.noreply.github.com> Date: Fri, 13 Jan 2023 10:41:28 +0000 Subject: [PATCH 3/3] Added support for JSON --- Cargo.lock | 12 ++ README.md | 2 +- crates/byte_cli/src/main.rs | 8 +- crates/gutenberg/Cargo.toml | 1 + crates/gutenberg/examples/bytes.json | 31 ++++ crates/gutenberg/examples/packages/Move.toml | 23 +++ .../examples/packages/sources/suimarines.move | 123 +++++++++++++ .../examples/packages/sources/suitraders.move | 162 ++++++++++++++++++ crates/gutenberg/examples/suimarines.yaml | 10 ++ crates/gutenberg/examples/suitraders.yaml | 26 +++ crates/gutenberg/src/main.rs | 33 +++- crates/gutenberg/tests/generate.rs | 25 ++- examples/bytes.json | 31 ++++ templates/template.move | 121 +++++++++++++ templates/template.yaml | 27 +++ 15 files changed, 620 insertions(+), 15 deletions(-) create mode 100644 crates/gutenberg/examples/bytes.json create mode 100644 crates/gutenberg/examples/packages/Move.toml create mode 100644 crates/gutenberg/examples/packages/sources/suimarines.move create mode 100644 crates/gutenberg/examples/packages/sources/suitraders.move create mode 100644 crates/gutenberg/examples/suimarines.yaml create mode 100644 crates/gutenberg/examples/suitraders.yaml create mode 100644 examples/bytes.json create mode 100644 templates/template.move create mode 100644 templates/template.yaml diff --git a/Cargo.lock b/Cargo.lock index 00f6571..4feff95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,6 +159,7 @@ dependencies = [ "gumdrop", "pretty_assertions", "serde", + "serde_json", "serde_yaml", "strfmt", "thiserror", @@ -372,6 +373,17 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_yaml" version = "0.9.16" diff --git a/README.md b/README.md index b0759b2..6573841 100644 --- a/README.md +++ b/README.md @@ -139,7 +139,7 @@ You can obtain a `gutenberg` executable by building it using [cargo](https://doc ```shell cd gutenberg cargo build --release -cargo run ./examples/suimarines.yaml +cargo run --bin gutenberg ./examples/suimarines.yaml ``` Alternatively, you can [download a pre-built executable](https://github.com/Origin-Byte/nft-protocol/tags) once these become available. diff --git a/crates/byte_cli/src/main.rs b/crates/byte_cli/src/main.rs index 57ce19b..fc4d25b 100644 --- a/crates/byte_cli/src/main.rs +++ b/crates/byte_cli/src/main.rs @@ -29,11 +29,11 @@ async fn run() -> Result<()> { match cli.command { Commands::InitCollectionConfig {} => {} - Commands::InitUploadConfig { assets_dir } => {} - Commands::InitConfig { assets_dir } => {} - Commands::DeployAssets { assets_dir } => {} + Commands::InitUploadConfig { assets_dir: _ } => {} + Commands::InitConfig { assets_dir: _ } => {} + Commands::DeployAssets { assets_dir: _ } => {} Commands::DeployContract {} => {} - Commands::MintNfts { assets_dir } => {} + Commands::MintNfts { assets_dir: _ } => {} } Ok(()) diff --git a/crates/gutenberg/Cargo.toml b/crates/gutenberg/Cargo.toml index e61b260..8fe0977 100644 --- a/crates/gutenberg/Cargo.toml +++ b/crates/gutenberg/Cargo.toml @@ -10,6 +10,7 @@ gumdrop = "0.8" serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.9" +serde_json = "1.0" [dev-dependencies] pretty_assertions = "1.3.0" diff --git a/crates/gutenberg/examples/bytes.json b/crates/gutenberg/examples/bytes.json new file mode 100644 index 0000000..ee5fd94 --- /dev/null +++ b/crates/gutenberg/examples/bytes.json @@ -0,0 +1,31 @@ +{ + "NftType": "Classic", + "Collection": { + "name": "Bytes", + "description": "A unique NFT collection of Bytes on Sui", + "symbol": "SUIM", + "tags": ["Art", "ProfilePicture"], + "royalty_fee_bps": "100", + "url": "https://originbyte.io/" + }, + "Listings": [ + { + "receiver": "@0xcf9bcdb25929869053dd4a2c467539f8b792346f", + "markets": [ + { + "FixedPrice": { + "token": "sui::sui::SUI", + "price": 500, + "is_whitelisted": false + } + }, + { + "DutchAuction": { + "token": "sui::sui::SUI", + "reserve_price": 100, + "is_whitelisted": true + } + }] + } + ] +} diff --git a/crates/gutenberg/examples/packages/Move.toml b/crates/gutenberg/examples/packages/Move.toml new file mode 100644 index 0000000..0335d48 --- /dev/null +++ b/crates/gutenberg/examples/packages/Move.toml @@ -0,0 +1,23 @@ +[package] +name = "Gutenberg" +version = "0.14.0" + +[dependencies.Sui] +git = "https://github.com/MystenLabs/sui.git" +subdir = "crates/sui-framework" +# devnet-0.19.0 +rev = "a8af20d94e951ecfb6d0cd47c23cf6393013d8a8" + +[dependencies.Movemate] +git = "https://github.com/Origin-Byte/movemate.git" +subdir = "sui" +# devnet-0.19.0 +rev = "115d56bd59cd9c0f59ac3a39b4c83872efa78608" + +[dependencies.NftProtocol] +git = "https://github.com/Origin-Byte/nft-protocol" +# version 0.16.0 +rev = "484ffaca16d561d8123c14138770fa99fe5591af" + +[addresses] +gutenberg = "0x0" diff --git a/crates/gutenberg/examples/packages/sources/suimarines.move b/crates/gutenberg/examples/packages/sources/suimarines.move new file mode 100644 index 0000000..bbe8563 --- /dev/null +++ b/crates/gutenberg/examples/packages/sources/suimarines.move @@ -0,0 +1,123 @@ +module gutenberg::suimarines { + use std::string::{Self, String}; + + use sui::url; + use sui::balance; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + + use nft_protocol::nft; + use nft_protocol::tags; + use nft_protocol::royalty; + use nft_protocol::display; + use nft_protocol::creators; + use nft_protocol::inventory::{Self, Inventory}; + use nft_protocol::royalties::{Self, TradePayment}; + use nft_protocol::collection::{Self, Collection, MintCap}; + + /// One time witness is only instantiated in the init method + struct SUIMARINES has drop {} + + /// Can be used for authorization of other actions post-creation. It is + /// vital that this struct is not freely given to any contract, because it + /// serves as an auth token. + struct Witness has drop {} + + fun init(witness: SUIMARINES, ctx: &mut TxContext) { + let (mint_cap, collection) = collection::create( + &witness, + ctx, + ); + + collection::add_domain( + &mut collection, + &mut mint_cap, + creators::from_address(tx_context::sender(ctx)) + ); + + // Register custom domains + display::add_collection_display_domain( + &mut collection, + &mut mint_cap, + string::utf8(b"Suimarines"), + string::utf8(b"A unique NFT collection of Suimarines on Sui"), + ); + + display::add_collection_url_domain( + &mut collection, + &mut mint_cap, + sui::url::new_unsafe_from_bytes(b"https://originbyte.io/"), + ); + + display::add_collection_symbol_domain( + &mut collection, + &mut mint_cap, + string::utf8(b"SUIM") + ); + + let royalty = royalty::new(ctx); + royalty::add_proportional_royalty( + &mut royalty, + nft_protocol::royalty_strategy_bps::new(100), + ); + royalty::add_royalty_domain(&mut collection, &mut mint_cap, royalty); + + let tags = tags::empty(ctx); + tags::add_tag(&mut tags, tags::art()); + tags::add_collection_tag_domain(&mut collection, &mut mint_cap, tags); + + transfer::transfer(mint_cap, tx_context::sender(ctx)); + transfer::share_object(collection); + } + + /// Calculates and transfers royalties to the `RoyaltyDomain` + public entry fun collect_royalty( + payment: &mut TradePayment, + collection: &mut Collection, + ctx: &mut TxContext, + ) { + let b = royalties::balance_mut(Witness {}, payment); + + let domain = royalty::royalty_domain(collection); + let royalty_owed = + royalty::calculate_proportional_royalty(domain, balance::value(b)); + + royalty::collect_royalty(collection, b, royalty_owed); + royalties::transfer_remaining_to_beneficiary(Witness {}, payment, ctx); + } + + public entry fun mint_nft( + name: String, + description: String, + url: vector, + attribute_keys: vector, + attribute_values: vector, + _mint_cap: &MintCap, + inventory: &mut Inventory, + ctx: &mut TxContext, + ) { + let nft = nft::new(tx_context::sender(ctx), ctx); + + display::add_display_domain( + &mut nft, + name, + description, + ctx, + ); + + display::add_url_domain( + &mut nft, + url::new_unsafe_from_bytes(url), + ctx, + ); + + display::add_attributes_domain_from_vec( + &mut nft, + attribute_keys, + attribute_values, + ctx, + ); + + inventory::deposit_nft(inventory, nft); + } +} diff --git a/crates/gutenberg/examples/packages/sources/suitraders.move b/crates/gutenberg/examples/packages/sources/suitraders.move new file mode 100644 index 0000000..7a582a3 --- /dev/null +++ b/crates/gutenberg/examples/packages/sources/suitraders.move @@ -0,0 +1,162 @@ +module gutenberg::suitraders { + use std::string::{Self, String}; + + use sui::url; + use sui::balance; + use sui::transfer; + use sui::tx_context::{Self, TxContext}; + + use nft_protocol::nft; + use nft_protocol::tags; + use nft_protocol::royalty; + use nft_protocol::display; + use nft_protocol::creators; + use nft_protocol::inventory::{Self, Inventory}; + use nft_protocol::royalties::{Self, TradePayment}; + use nft_protocol::collection::{Self, Collection, MintCap}; + + /// One time witness is only instantiated in the init method + struct SUITRADERS has drop {} + + /// Can be used for authorization of other actions post-creation. It is + /// vital that this struct is not freely given to any contract, because it + /// serves as an auth token. + struct Witness has drop {} + + fun init(witness: SUITRADERS, ctx: &mut TxContext) { + let (mint_cap, collection) = collection::create( + &witness, + ctx, + ); + + collection::add_domain( + &mut collection, + &mut mint_cap, + creators::from_address(tx_context::sender(ctx)) + ); + + // Register custom domains + display::add_collection_display_domain( + &mut collection, + &mut mint_cap, + string::utf8(b"Suitraders"), + string::utf8(b"A unique NFT collection of Suitraders on Sui"), + ); + + display::add_collection_url_domain( + &mut collection, + &mut mint_cap, + sui::url::new_unsafe_from_bytes(b"https://originbyte.io/"), + ); + + display::add_collection_symbol_domain( + &mut collection, + &mut mint_cap, + string::utf8(b"SUITR") + ); + + let royalty = royalty::new(ctx); + royalty::add_proportional_royalty( + &mut royalty, + nft_protocol::royalty_strategy_bps::new(100), + ); + royalty::add_royalty_domain(&mut collection, &mut mint_cap, royalty); + + let tags = tags::empty(ctx); + tags::add_tag(&mut tags, tags::art()); + tags::add_collection_tag_domain(&mut collection, &mut mint_cap, tags); + + let marketplace = nft_protocol::marketplace::new( + tx_context::sender(ctx), + @0xcf9bcdb25929869053dd4a2c467539f8b792346f, + nft_protocol::flat_fee::new(0, ctx), + ctx, + ); + + let listing = nft_protocol::listing::new( + tx_context::sender(ctx), + @0xcf9bcdb25929869053dd4a2c467539f8b792346f, + ctx, + ); + + let inventory_id = + nft_protocol::listing::create_inventory(&mut listing, ctx); + + nft_protocol::fixed_price::create_market_on_listing( + &mut listing, + inventory_id, + false, + 500, + ctx, + ); + + let inventory_id = + nft_protocol::listing::create_inventory(&mut listing, ctx); + + nft_protocol::dutch_auction::create_market_on_listing( + &mut listing, + inventory_id, + true, + 100, + ctx, + ); + + transfer::share_object(listing); + + transfer::share_object(marketplace); + + transfer::transfer(mint_cap, tx_context::sender(ctx)); + transfer::share_object(collection); + } + + /// Calculates and transfers royalties to the `RoyaltyDomain` + public entry fun collect_royalty( + payment: &mut TradePayment, + collection: &mut Collection, + ctx: &mut TxContext, + ) { + let b = royalties::balance_mut(Witness {}, payment); + + let domain = royalty::royalty_domain(collection); + let royalty_owed = + royalty::calculate_proportional_royalty(domain, balance::value(b)); + + royalty::collect_royalty(collection, b, royalty_owed); + royalties::transfer_remaining_to_beneficiary(Witness {}, payment, ctx); + } + + public entry fun mint_nft( + name: String, + description: String, + url: vector, + attribute_keys: vector, + attribute_values: vector, + _mint_cap: &MintCap, + inventory: &mut Inventory, + ctx: &mut TxContext, + ) { + let nft = nft::new(tx_context::sender(ctx), ctx); + + display::add_display_domain( + &mut nft, + name, + description, + ctx, + ); + + display::add_url_domain( + &mut nft, + url::new_unsafe_from_bytes(url), + ctx, + ); + + display::add_attributes_domain_from_vec( + &mut nft, + attribute_keys, + attribute_values, + ctx, + ); + + inventory::deposit_nft(inventory, nft); + } +} diff --git a/crates/gutenberg/examples/suimarines.yaml b/crates/gutenberg/examples/suimarines.yaml new file mode 100644 index 0000000..d8bd51d --- /dev/null +++ b/crates/gutenberg/examples/suimarines.yaml @@ -0,0 +1,10 @@ +NftType: "Classic" + +Collection: + name: "Suimarines" + description: "A unique NFT collection of Suimarines on Sui" + symbol: "SUIM" + tags: + - "Art" + royalty_fee_bps: "100" + url: "https://originbyte.io/" \ No newline at end of file diff --git a/crates/gutenberg/examples/suitraders.yaml b/crates/gutenberg/examples/suitraders.yaml new file mode 100644 index 0000000..ad57f82 --- /dev/null +++ b/crates/gutenberg/examples/suitraders.yaml @@ -0,0 +1,26 @@ +NftType: "Classic" + +Collection: + name: "Suitraders" + description: "A unique NFT collection of Suitraders on Sui" + symbol: "SUITR" + tags: + - "Art" + royalty_fee_bps: "100" + url: "https://originbyte.io/" + +Marketplace: + receiver: "@0xcf9bcdb25929869053dd4a2c467539f8b792346f" + +Listings: + - receiver: "@0xcf9bcdb25929869053dd4a2c467539f8b792346f" + markets: + - !FixedPrice + token: "sui::sui::SUI" + price: 500 + is_whitelisted: false + + - !DutchAuction + token: "sui::sui::SUI" + reserve_price: 100 + is_whitelisted: true diff --git a/crates/gutenberg/src/main.rs b/crates/gutenberg/src/main.rs index 861f36d..ad47a64 100644 --- a/crates/gutenberg/src/main.rs +++ b/crates/gutenberg/src/main.rs @@ -2,6 +2,7 @@ use gutenberg::prelude::*; use gumdrop::Options; +use std::ffi::OsStr; use std::fs; use std::path::PathBuf; @@ -18,13 +19,35 @@ struct Opt { fn main() -> Result<(), GutenError> { let opt = Opt::parse_args_default_or_exit(); - let f = fs::File::open(opt.config)?; + let extension = opt.config.extension().and_then(OsStr::to_str); - let schema: Schema = match serde_yaml::from_reader(f) { - Ok(schema) => schema, - Err(err) => { + let f = fs::File::open(&opt.config)?; + + let schema: Schema = match extension { + Some("yaml") => match serde_yaml::from_reader(f) { + Ok(schema) => schema, + Err(err) => { + eprintln!("Gutenberg could not generate smart contract due to"); + eprintln!("{}", err); + std::process::exit(2); + } + }, + Some("json") => match serde_json::from_reader(f) { + Ok(schema) => schema, + Err(err) => { + eprintln!("Gutenberg could not generate smart contract due to"); + eprintln!("{}", err); + std::process::exit(2); + } + }, + Some(_) => { + eprintln!("Gutenberg could not generate smart contract due to"); + eprintln!("File extension not supported"); + std::process::exit(2); + } + None => { eprintln!("Gutenberg could not generate smart contract due to"); - eprintln!("{}", err); + eprintln!("File has no extension"); std::process::exit(2); } }; diff --git a/crates/gutenberg/tests/generate.rs b/crates/gutenberg/tests/generate.rs index fa95a31..9f94e5a 100644 --- a/crates/gutenberg/tests/generate.rs +++ b/crates/gutenberg/tests/generate.rs @@ -1,6 +1,7 @@ //! Integration tests directly check the generated examples in the parent directory use gutenberg::schema::Schema; +use std::ffi::OsStr; use std::fs::{self, File}; /// Check that all examples have correct schema @@ -12,8 +13,10 @@ fn example_schema() { // Filter out packages directory .filter(|f| f.file_type().unwrap().is_file()) .map(|dir| { - let config = File::open(dir.path()).unwrap(); - assert_schema(config); + let path = dir.path(); + let file_type = path.extension().and_then(OsStr::to_str); + let config = File::open(&path).unwrap(); + assert_schema(config, file_type.unwrap()); }) .collect::<()>() } @@ -38,16 +41,28 @@ fn setup(config: &str, expected: &str) -> (File, String) { } /// Asserts that the config file has correct schema -fn assert_schema(config: File) -> Schema { - serde_yaml::from_reader::<_, Schema>(config).unwrap() +fn assert_schema(config: File, file_type: &str) -> Schema { + match file_type { + "yaml" => serde_yaml::from_reader::<_, Schema>(config).unwrap(), + "json" => serde_json::from_reader::<_, Schema>(config).unwrap(), + _ => { + eprintln!("Extension not supported"); + std::process::exit(2); + } + } } /// Asserts that the generated file matches the expected output fn assert_equal(config: &str, expected: &str) { + let len = config.len(); + let extension = &config[len - 4..len]; + let (config, expected) = setup(config, expected); let mut output = Vec::new(); - assert_schema(config).write_move(&mut output).unwrap(); + assert_schema(config, extension) + .write_move(&mut output) + .unwrap(); let output = String::from_utf8(output).unwrap(); pretty_assertions::assert_eq!(output, expected); diff --git a/examples/bytes.json b/examples/bytes.json new file mode 100644 index 0000000..ee5fd94 --- /dev/null +++ b/examples/bytes.json @@ -0,0 +1,31 @@ +{ + "NftType": "Classic", + "Collection": { + "name": "Bytes", + "description": "A unique NFT collection of Bytes on Sui", + "symbol": "SUIM", + "tags": ["Art", "ProfilePicture"], + "royalty_fee_bps": "100", + "url": "https://originbyte.io/" + }, + "Listings": [ + { + "receiver": "@0xcf9bcdb25929869053dd4a2c467539f8b792346f", + "markets": [ + { + "FixedPrice": { + "token": "sui::sui::SUI", + "price": 500, + "is_whitelisted": false + } + }, + { + "DutchAuction": { + "token": "sui::sui::SUI", + "reserve_price": 100, + "is_whitelisted": true + } + }] + } + ] +} diff --git a/templates/template.move b/templates/template.move new file mode 100644 index 0000000..e976237 --- /dev/null +++ b/templates/template.move @@ -0,0 +1,121 @@ +module gutenberg::{module_name} {{ + use std::string::{{Self, String}}; + + use sui::url; + use sui::balance; + use sui::transfer; + use sui::tx_context::{{Self, TxContext}}; + + use nft_protocol::nft; + use nft_protocol::tags; + use nft_protocol::royalty; + use nft_protocol::display; + use nft_protocol::creators; + use nft_protocol::inventory::{{Self, Inventory}}; + use nft_protocol::royalties::{{Self, TradePayment}}; + use nft_protocol::collection::{{Self, Collection, MintCap}}; + + /// One time witness is only instantiated in the init method + struct {witness} has drop {{}} + + /// Can be used for authorization of other actions post-creation. It is + /// vital that this struct is not freely given to any contract, because it + /// serves as an auth token. + struct Witness has drop {{}} + + fun init(witness: {witness}, ctx: &mut TxContext) {{ + let (mint_cap, collection) = collection::create<{witness}>( + &witness, + ctx, + ); + + collection::add_domain( + &mut collection, + &mut mint_cap, + creators::from_address(tx_context::sender(ctx)) + ); + + // Register custom domains + display::add_collection_display_domain( + &mut collection, + &mut mint_cap, + string::utf8(b"{name}"), + string::utf8(b"{description}"), + ); + + display::add_collection_url_domain( + &mut collection, + &mut mint_cap, + sui::url::new_unsafe_from_bytes(b"{url}"), + ); + + display::add_collection_symbol_domain( + &mut collection, + &mut mint_cap, + string::utf8(b"{symbol}") + ); + + let royalty = royalty::new(ctx); + royalty::add_proportional_royalty( + &mut royalty, + nft_protocol::royalty_strategy_bps::new({royalty_fee_bps}), + ); + royalty::add_royalty_domain(&mut collection, &mut mint_cap, royalty); + + {tags} +{init_marketplace}{init_listings}{share_marketplace} + transfer::transfer(mint_cap, tx_context::sender(ctx)); + transfer::share_object(collection); + }} + + /// Calculates and transfers royalties to the `RoyaltyDomain` + public entry fun collect_royalty( + payment: &mut TradePayment<{witness}, FT>, + collection: &mut Collection<{witness}>, + ctx: &mut TxContext, + ) {{ + let b = royalties::balance_mut(Witness {{}}, payment); + + let domain = royalty::royalty_domain(collection); + let royalty_owed = + royalty::calculate_proportional_royalty(domain, balance::value(b)); + + royalty::collect_royalty(collection, b, royalty_owed); + royalties::transfer_remaining_to_beneficiary(Witness {{}}, payment, ctx); + }} + + public entry fun mint_nft( + name: String, + description: String, + url: vector, + attribute_keys: vector, + attribute_values: vector, + _mint_cap: &MintCap<{witness}>, + inventory: &mut Inventory, + ctx: &mut TxContext, + ) {{ + let nft = nft::new<{witness}>(tx_context::sender(ctx), ctx); + + display::add_display_domain( + &mut nft, + name, + description, + ctx, + ); + + display::add_url_domain( + &mut nft, + url::new_unsafe_from_bytes(url), + ctx, + ); + + display::add_attributes_domain_from_vec( + &mut nft, + attribute_keys, + attribute_values, + ctx, + ); + + inventory::deposit_nft(inventory, nft); + }} +}} diff --git a/templates/template.yaml b/templates/template.yaml new file mode 100644 index 0000000..0dc1aa1 --- /dev/null +++ b/templates/template.yaml @@ -0,0 +1,27 @@ +NftType: + +Collection: + name: + description: + symbol: + tags: + royalty_fee_bps: + url: + +Marketplace: + admin: + receiver: + +Listings: + - admin: + receiver: + markets: + - !FixedPrice + token: + price: + is_whitelisted: + + - !DutchAuction + token: + reserve_price: + is_whitelisted: