diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5e12621..3696a0a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,7 +5,7 @@ on: branches: ['**'] env: - SINGLE_ASSET_REWARD: "--manifest-path=src/contracts/single_asset_reward/Cargo.toml" + SINGLE_TOKEN: "--manifest-path=contracts/src/token/single/Cargo.toml" jobs: build: @@ -25,16 +25,16 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: ${{ env.SINGLE_ASSET_REWARD }} -- -D warnings + args: ${{ env.SINGLE_TOKEN }} -- -D warnings - name: Build uses: actions-rs/cargo@v1 with: command: build - args: ${{ env.SINGLE_ASSET_REWARD }} + args: ${{ env.SINGLE_TOKEN }} - name: Test uses: actions-rs/cargo@v1 with: command: test - args: ${{ env.SINGLE_ASSET_REWARD }} \ No newline at end of file + args: ${{ env.SINGLE_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..19375d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Ignore build artifacts from the local tests sub-crate. +target/ +debug/ + +# Ignore backup files creates by cargo fmt. +**/*.rs.bk + +# Remove Cargo.lock when creating an executable, leave it for libraries +# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock +Cargo.lock + +.DS_Store diff --git a/src/Cargo.toml b/Cargo.toml similarity index 64% rename from src/Cargo.toml rename to Cargo.toml index 3c43f0a..c9d75ed 100644 --- a/src/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,14 @@ version= "0.1.0" authors = ["Igor Papandinas", "Leandro Palazzolo"] edition = "2021" +license = "MIT" +readme = "README.md" +repository = "https://github.com/kudos-ink/contracts" +description = "Kudos Ink smart contracts for automated contribution rewards." +keywords = ["wasm", "smart-contracts", "blockchain", "ink"] +categories = ["no-std", "embedded"] +include = ["Cargo.toml", "src/**/*.rs"] + [dependencies] ink = { version = "4.3.0", default-features = false } @@ -13,9 +21,12 @@ scale-info = { version = "2.6", default-features = false, features = ["derive"], # OpenBrush dependency openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", version = "4.0.0-beta", default-features = false, features = ["ownable"] } +# These dependencies +kudos_ink_contracts = { path = "contracts", default-features = false } + [lib] name = "kudos_ink" -path = "lib.rs" +path = "src/lib.rs" crate-type = [ "rlib", ] diff --git a/src/.gitignore b/contracts/.gitignore similarity index 97% rename from src/.gitignore rename to contracts/.gitignore index ed66fb5..b217b8a 100755 --- a/src/.gitignore +++ b/contracts/.gitignore @@ -1,6 +1,5 @@ # Ignore build artifacts from the local tests sub-crate. target/ -debug/ # Ignore backup files creates by cargo fmt. **/*.rs.bk diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml new file mode 100644 index 0000000..eb7fe80 --- /dev/null +++ b/contracts/Cargo.toml @@ -0,0 +1,43 @@ +[workspace] +members = ["src/token/single"] + +[package] +name = "kudos_ink_contracts" +version= "0.1.0" +authors = ["Igor Papandinas", "Leandro Palazzolo"] +edition = "2021" + +license = "MIT" +readme = "README.md" +repository = "https://github.com/kudos-ink/contracts" +description = "Reusable implementations of reward contracts and traits." +keywords = ["wasm", "smart-contracts", "blockchain", "ink"] +categories = ["no-std", "embedded"] +include = ["Cargo.toml", "src/**/*.rs"] + +[dependencies] +ink = { version = "4.3.0", default-features = false } + +scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } +scale-info = { version = "2.6", default-features = false, features = ["derive"], optional = true } + +# OpenBrush dependency +openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", version = "4.0.0-beta", default-features = false, features = ["ownable"] } + +[lib] +name = "kudos_ink_contracts" +path = "src/lib.rs" +crate-type = [ + "rlib", +] + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", + # OpenBrush dependency + "openbrush/std", +] +single = [] \ No newline at end of file diff --git a/contracts/src/lib.rs b/contracts/src/lib.rs new file mode 100644 index 0000000..52b07a3 --- /dev/null +++ b/contracts/src/lib.rs @@ -0,0 +1,3 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +pub mod traits; diff --git a/src/contracts/single_asset_reward/Cargo.toml b/contracts/src/token/single/Cargo.toml similarity index 80% rename from src/contracts/single_asset_reward/Cargo.toml rename to contracts/src/token/single/Cargo.toml index 1370bb4..76f6d45 100755 --- a/src/contracts/single_asset_reward/Cargo.toml +++ b/contracts/src/token/single/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "single_asset_reward" +name = "single_token_contract" version = "0.1.0" authors = ["Igor Papandinas", "Leandro Palazzolo"] edition = "2021" @@ -13,10 +13,10 @@ scale-info = { version = "2.6", default-features = false, features = ["derive"], openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", version = "4.0.0-beta", default-features = false, features = ["ownable"] } # These dependencies -kudos_ink = { path = "../..", default-features = false } +kudos_ink_contracts = { git = "https://github.com/kudos-ink/contracts", branch = "next" } [lib] -name = "single_asset_reward" +name = "single_token_contract" path = "lib.rs" [features] @@ -27,6 +27,6 @@ std = [ "scale-info/std", # OpenBrush dependency "openbrush/std", - "kudos_ink/std", + "kudos_ink_contracts/std", ] ink-as-dependency = [] diff --git a/src/contracts/single_asset_reward/lib.rs b/contracts/src/token/single/lib.rs similarity index 93% rename from src/contracts/single_asset_reward/lib.rs rename to contracts/src/token/single/lib.rs index 0fc7e2c..340bf29 100755 --- a/src/contracts/single_asset_reward/lib.rs +++ b/contracts/src/token/single/lib.rs @@ -2,8 +2,8 @@ #[openbrush::implementation(Ownable)] #[openbrush::contract] -pub mod single_asset_reward { - use kudos_ink::traits::workflow::{WorkflowError, *}; +pub mod single_token { + use kudos_ink_contracts::traits::workflow::{WorkflowError, *}; use openbrush::{modifiers, traits::Storage}; use ink::env::hash::{HashOutput, Sha2x256}; @@ -27,7 +27,7 @@ pub mod single_asset_reward { #[ink(storage)] #[derive(Default, Storage)] - pub struct SingleAssetReward { + pub struct SingleToken { #[storage_field] ownable: ownable::Data, @@ -69,7 +69,7 @@ pub mod single_asset_reward { reward: Balance, } - impl Workflow for SingleAssetReward { + impl Workflow for SingleToken { /// Register the caller as an aspiring contributor. /// /// Constraint(s): @@ -121,7 +121,7 @@ pub mod single_asset_reward { } } - impl SingleAssetReward { + impl SingleToken { /// Constructor that initializes an asset reward for a given workflow #[ink(constructor)] pub fn new(workflow: HashValue, reward: Balance) -> Self { @@ -291,7 +291,7 @@ pub mod single_asset_reward { use super::*; use ink::env::test::EmittedEvent; - type Event = ::Type; + type Event = ::Type; /// We test if the constructor does its job. #[ink::test] @@ -306,7 +306,7 @@ pub mod single_asset_reward { fn register_identity_works() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let bob_identity = SingleAssetReward::hash("bobby".as_bytes()); + let bob_identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); assert_eq!( contract.register_identity(bob_identity), @@ -335,7 +335,7 @@ pub mod single_asset_reward { fn already_registered_identity_fails() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); assert_eq!( @@ -348,7 +348,7 @@ pub mod single_asset_reward { fn approve_works() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -381,7 +381,7 @@ pub mod single_asset_reward { fn only_contract_owner_can_approve() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -396,8 +396,8 @@ pub mod single_asset_reward { fn already_approved_contribution_fails() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); - let identity2 = SingleAssetReward::hash("bobby2".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); + let identity2 = SingleToken::hash("bobby2".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -415,8 +415,8 @@ pub mod single_asset_reward { fn approve_unknown_contributor_identity_fails() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); - let identity2 = SingleAssetReward::hash("bobby2".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); + let identity2 = SingleToken::hash("bobby2".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -432,7 +432,7 @@ pub mod single_asset_reward { fn can_claim_works() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -452,7 +452,7 @@ pub mod single_asset_reward { let accounts = default_accounts(); let single_reward = 1u128; let mut contract = create_contract(1u128, single_reward); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -504,7 +504,7 @@ pub mod single_asset_reward { fn cannot_claim_unknown_contribution() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -523,7 +523,7 @@ pub mod single_asset_reward { fn cannot_claim_if_not_contributor() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.eve); let _ = contract.register_identity(identity); @@ -542,7 +542,7 @@ pub mod single_asset_reward { fn cannot_claim_already_claimed_reward() { let accounts = default_accounts(); let mut contract = create_contract(1u128, 1u128); - let identity = SingleAssetReward::hash("bobby".as_bytes()); + let identity = SingleToken::hash("bobby".as_bytes()); set_next_caller(accounts.bob); let _ = contract.register_identity(identity); @@ -580,14 +580,14 @@ pub mod single_asset_reward { .expect("Cannot get account balance") } - /// Creates a new instance of `SingleAssetReward` with `initial_balance`. + /// Creates a new instance of `SingleToken` with `initial_balance`. /// /// Returns the `contract_instance`. - fn create_contract(initial_balance: Balance, reward: Balance) -> SingleAssetReward { + fn create_contract(initial_balance: Balance, reward: Balance) -> SingleToken { let accounts = default_accounts(); set_next_caller(accounts.alice); set_balance(contract_id(), initial_balance); - SingleAssetReward::new([0; 32], reward) + SingleToken::new([0; 32], reward) } fn decode_events(emittend_events: Vec) -> Vec { diff --git a/src/traits/mod.rs b/contracts/src/traits/mod.rs similarity index 100% rename from src/traits/mod.rs rename to contracts/src/traits/mod.rs diff --git a/src/traits/workflow.rs b/contracts/src/traits/workflow.rs similarity index 98% rename from src/traits/workflow.rs rename to contracts/src/traits/workflow.rs index 8190231..f66d21b 100644 --- a/src/traits/workflow.rs +++ b/contracts/src/traits/workflow.rs @@ -1,7 +1,5 @@ use openbrush::{contracts::traits::ownable::*, modifiers}; -#[cfg(feature = "std")] - /// Type alias for hashes. pub type HashValue = [u8; 32]; diff --git a/kudos-contracts.code-workspace b/kudos-contracts.code-workspace new file mode 100644 index 0000000..390b229 --- /dev/null +++ b/kudos-contracts.code-workspace @@ -0,0 +1,7 @@ +{ + "settings": { + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer" + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 52b07a3..8819f11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,3 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -pub mod traits; +pub use kudos_ink_contracts as contracts; \ No newline at end of file