Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.
Open
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
328 changes: 328 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/byte_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.2.0"
edition = "2021"

[dependencies]
gutenberg = { path = "../gutenberg" }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
# thiserror = "1.0"
Expand Down
1 change: 1 addition & 0 deletions crates/byte_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::prelude::*;
use anyhow::Result;
use clap::Parser;
use console::style;
use gutenberg;

#[tokio::main]
async fn main() {
Expand Down
7 changes: 4 additions & 3 deletions crates/gutenberg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ edition = "2021"
thiserror = "1.0"
strfmt = "0.2"
gumdrop = "0.8"
bevy_reflect = {version = "0.9.1"}

serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"]}
serde_yaml = "0.9"
serde_json = "1.0"
serde_json = {version = "1.0", features = ["preserve_order"]}

[dev-dependencies]
pretty_assertions = "1.3.0"
pretty_assertions = "1.3"
31 changes: 0 additions & 31 deletions crates/gutenberg/examples/bytes.json

This file was deleted.

52 changes: 52 additions & 0 deletions crates/gutenberg/examples/newbytes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"Collection": {
"name": "Newbytes",
"description": "A unique NFT collection of Bytes on Sui",
"symbol": "BYTE",
"tags": ["Art", "ProfilePicture"],
"url": "https://originbyte.io/"
},
"Nft": {
"fields": {
"display": true,
"url": true,
"attributes": true,
"tags": true
},
"behaviours": {
"composable": true,
"loose": false
},
"supplyPolicy": "unlimited",
"mintStrategy": {
"direct": true,
"airdrop": true,
"launchpad": true
}
},
"Royalties": {
"Proportional": {"bps": 100}
},
"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
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gutenberg::suimarines {
module gutenberg::newbytes {
use std::string::{Self, String};

use sui::url;
Expand All @@ -16,15 +16,15 @@ module gutenberg::suimarines {
use nft_protocol::collection::{Self, Collection, MintCap};

/// One time witness is only instantiated in the init method
struct SUIMARINES has drop {}
struct NEWBYTES 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<SUIMARINES>(
fun init(witness: NEWBYTES, ctx: &mut TxContext) {
let (mint_cap, collection) = collection::create<NEWBYTES>(
&witness,
ctx,
);
Expand All @@ -39,8 +39,8 @@ module gutenberg::suimarines {
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"),
string::utf8(b"Newbytes"),
string::utf8(b"A unique NFT collection of Bytes on Sui"),
);

display::add_collection_url_domain(
Expand Down Expand Up @@ -72,8 +72,8 @@ module gutenberg::suimarines {

/// Calculates and transfers royalties to the `RoyaltyDomain`
public entry fun collect_royalty<FT>(
payment: &mut TradePayment<SUIMARINES, FT>,
collection: &mut Collection<SUIMARINES>,
payment: &mut TradePayment<NEWBYTES, FT>,
collection: &mut Collection<NEWBYTES>,
ctx: &mut TxContext,
) {
let b = royalties::balance_mut(Witness {}, payment);
Expand All @@ -92,11 +92,11 @@ module gutenberg::suimarines {
url: vector<u8>,
attribute_keys: vector<String>,
attribute_values: vector<String>,
_mint_cap: &MintCap<SUIMARINES>,
_mint_cap: &MintCap<NEWBYTES>,
inventory: &mut Inventory,
ctx: &mut TxContext,
) {
let nft = nft::new<SUIMARINES>(tx_context::sender(ctx), ctx);
let nft = nft::new<NEWBYTES>(tx_context::sender(ctx), ctx);

display::add_display_domain(
&mut nft,
Expand Down
2 changes: 1 addition & 1 deletion crates/gutenberg/examples/packages/sources/suimarines.move
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module gutenberg::suimarines {
royalties::transfer_remaining_to_beneficiary(Witness {}, payment, ctx);
}

public entry fun mint_nft(
public entry fun mint_to_warehouse(
name: String,
description: String,
url: vector<u8>,
Expand Down
2 changes: 1 addition & 1 deletion crates/gutenberg/examples/packages/sources/suitraders.move
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module gutenberg::suitraders {
royalties::transfer_remaining_to_beneficiary(Witness {}, payment, ctx);
}

public entry fun mint_nft(
public entry fun mint_to_warehouse(
name: String,
description: String,
url: vector<u8>,
Expand Down
24 changes: 20 additions & 4 deletions crates/gutenberg/examples/suimarines.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
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/"
url: "https://originbyte.io/"

Nft:
fields:
display: true
url: true
attributes: true
tags: false
behaviours:
composable: false
loose: false
supplyPolicy: "unlimited"
mintStrategy:
direct: false
airdrop: false
launchpad: true

Royalties:
!Proportional
bps: 100
22 changes: 19 additions & 3 deletions crates/gutenberg/examples/suitraders.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
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/"

Nft:
fields:
display: true
url: true
attributes: true
tags: false
behaviours:
composable: false
loose: false
supplyPolicy: "unlimited"
mintStrategy:
direct: false
airdrop: false
launchpad: true

Royalties:
!Proportional
bps: 100

Marketplace:
receiver: "@0xcf9bcdb25929869053dd4a2c467539f8b792346f"

Expand Down
10 changes: 10 additions & 0 deletions crates/gutenberg/src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ pub enum GutenError {
SerdeYaml(#[from] serde_yaml::Error),
#[error("An IO error has occured")]
IoError(#[from] std::io::Error),
#[error("The tag provided is not supported")]
UnsupportedTag,
#[error("The NFT field provided is not a supported")]
UnsupportedNftField,
#[error("The NFT behaviour provided is not a supported")]
UnsupportedNftBehaviour,
#[error("The Supply Policy provided is not a supported")]
UnsupportedSupply,
#[error("The Royalty Policy provided is not a supported")]
UnsupportedRoyalty,
}
1 change: 1 addition & 0 deletions crates/gutenberg/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod err;
pub mod models;
pub mod prelude;
pub mod schema;
pub mod types;
5 changes: 5 additions & 0 deletions crates/gutenberg/src/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod collection;
pub mod nft;

pub use collection::*;
pub use nft::*;
99 changes: 99 additions & 0 deletions crates/gutenberg/src/models/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//! Module containing the core logic to parse the `config.yaml` file into a
//! struct `Schema`, acting as an intermediate data structure, to write
//! the associated Move module and dump into a default or custom folder defined
//! by the caller.
use crate::err::GutenError;
use crate::types::Tag;

use serde::Deserialize;
use std::str::FromStr;

/// Contains the metadata fields of the collection
#[derive(Debug, Deserialize)]
pub struct Collection {
/// The name of the collection
pub name: String,
/// The description of the collection
pub description: String,
/// The symbol/ticker of the collection
pub symbol: String,
/// A set of strings that categorize the domain in which the NFT operates
pub tags: Vec<Tag>,
/// Field for extra data
pub url: Option<String>,
}

impl Collection {
pub fn new() -> Collection {
Collection {
name: String::new(),
description: String::new(),
symbol: String::new(),
tags: Vec::new(),
url: Option::None,
}
}

pub fn new_from(
name: String,
description: String,
symbol: String,
tags: Vec<Tag>,
url: String,
) -> Collection {
Collection {
name,
description,
symbol,
tags,
url: Option::Some(url),
}
}

pub fn set_name(&mut self, name: String) {
self.name = name;
}

pub fn set_description(&mut self, description: String) {
self.description = description;
}

pub fn set_symbol(&mut self, symbol: String) {
self.symbol = symbol;
}

pub fn set_url(&mut self, symbol: String) {
self.symbol = symbol;
}

pub fn set_tags(&mut self, tags: &Vec<String>) -> Result<(), GutenError> {
self.tags = tags
.iter()
.map(|string| {
Tag::from_str(string).map_err(|_| GutenError::UnsupportedTag)
})
.collect::<Result<Vec<Tag>, GutenError>>()?;

Ok(())
}

pub fn push_tag(&mut self, tag_string: String) -> Result<(), GutenError> {
let tag = Tag::from_str(tag_string.as_str())
.map_err(|_| GutenError::UnsupportedTag)?;

self.tags.push(tag);

Ok(())
}

// TODO
pub fn pop_tag(&mut self, _tag_string: String) {}

// pub fn set_royalty_fee_bps(&mut self, royalty_bps: String) {
// self.royalty_fee_bps = royalty_bps;
// }

// pub fn set_url(&mut self, royalty_bps: String) {
// self.royalty_fee_bps = royalty_bps;
// }
}
Loading