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

Add batch calls for faster deployment #62

Merged
merged 9 commits into from
Apr 26, 2023
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
4 changes: 2 additions & 2 deletions crates/common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum RmrkError {
NotEquipped,
NotTokenOwner,
PartIsNotSlot,
SlotAlreayUsed,
SlotAlreadyUsed,
TargetAssetCannotReceiveSlot,
UnknownEquippableAsset,
UnknownPart,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl ToString for RmrkError {
RmrkError::NotEquipped => String::from("NotEquipped"),
RmrkError::NotTokenOwner => String::from("NotTokenOwner"),
RmrkError::PartIsNotSlot => String::from("PartIsNotSlot"),
RmrkError::SlotAlreayUsed => String::from("SlotAlreayUsed"),
RmrkError::SlotAlreadyUsed => String::from("SlotAlreadyUsed"),
RmrkError::TargetAssetCannotReceiveSlot => String::from("TargetAssetCannotReceiveSlot"),
RmrkError::UnknownEquippableAsset => String::from("UnknownEquippableAsset"),
RmrkError::UnknownPart => String::from("UnknownPart"),
Expand Down
2 changes: 1 addition & 1 deletion crates/equippable/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
.get((token_id, part_id)))
.is_some()
{
return Err(RmrkError::SlotAlreayUsed.into())
return Err(RmrkError::SlotAlreadyUsed.into())
}
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion crates/minting/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use rmrk_common::errors::Result;

use ink::prelude::string::String as PreludeString;

use openbrush::{
contracts::psp34::extensions::enumerable::*,
traits::{
Expand Down Expand Up @@ -49,7 +50,7 @@ pub trait MintingLazy {
#[ink(message, payable)]
fn mint(&mut self) -> Result<()>;

/// Purchas many tokens.
/// Purchase many tokens.
#[ink(message, payable)]
fn mint_many(&mut self, mint_amount: u64) -> Result<()>;

Expand Down
85 changes: 85 additions & 0 deletions crates/rmrk/src/batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#![allow(clippy::inline_fn_without_body)]

/// Batch calls for the RMRK contract.
/// Due to big POV size of this contract only a several Tx can be made per one block.
/// This trait allows to batch several calls into one Tx.
/// It is not mandatory to include this trait.
/// However it is possible to include it only if all crates are compiled.
use crate::{
storage::*,
traits::*,
};

use ink::prelude::vec::Vec;
use openbrush::{
contracts::{
access_control,
psp34::extensions::{
enumerable::*,
metadata::*,
},
reentrancy_guard::*,
},
traits::{
AccountId,
DefaultEnv,
Storage,
},
};
use rmrk_common::{
errors::Result,
types::*,
};
use rmrk_multiasset::MultiAssetData;
use rmrk_nesting::NestingData;

#[openbrush::wrapper]
pub type BatchCallsRef = dyn BatchCalls;

#[openbrush::trait_definition]
pub trait BatchCalls:
DefaultEnv
+ Nesting
+ MultiAsset
+ Minting
+ Storage<MultiAssetData>
+ Storage<NestingData>
+ Storage<MintingData>
+ Storage<reentrancy_guard::Data>
+ Storage<metadata::Data>
+ Storage<access_control::Data>
+ Storage<psp34::Data<enumerable::Balances>>
+ psp34::Internal
{
#[ink(message)]
fn add_asset_to_many_tokens(&mut self, tokens: Vec<Id>, asset_id: AssetId) -> Result<()> {
for token_id in tokens {
MultiAsset::add_asset_to_token(self, token_id.clone(), asset_id, None)?;
}
Ok(())
}

/// Add a list of parent-child token pairs. The child NFT is from a different collection.
#[ink(message)]
fn add_many_children(
&mut self,
child_contract: AccountId,
parent_child_pair: Vec<(Id, Id)>,
) -> Result<()> {
for (parent_id, child_id) in parent_child_pair {
Nesting::add_child(self, parent_id, (child_contract, child_id))?;
}

Ok(())
}

/// Transfer many tokens to specified addresses
#[ink(message)]
fn transfer_many(&mut self, token_to_destination: Vec<(Id, AccountId)>) -> Result<()> {
for (token_id, destination) in token_to_destination {
psp34::Internal::_transfer_token(self, destination, token_id, Vec::new())?;
}

Ok(())
}
}
5 changes: 3 additions & 2 deletions crates/rmrk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod batch;
pub mod config;
pub mod query;

Expand All @@ -11,17 +12,17 @@ pub use rmrk_common::{
};

pub mod storage {
pub use rmrk_catalog::*;
pub use rmrk_equippable::*;
pub use rmrk_minting::*;
pub use rmrk_multiasset::*;
pub use rmrk_nesting::*;
pub use rmrk_catalog::*;
}

pub mod traits {
pub use rmrk_catalog::traits::*;
pub use rmrk_equippable::traits::*;
pub use rmrk_minting::traits::*;
pub use rmrk_multiasset::traits::*;
pub use rmrk_nesting::traits::*;
pub use rmrk_catalog::traits::*;
}
3 changes: 3 additions & 0 deletions examples/equippable/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod rmrk_example_equippable {
};

use rmrk::{
batch::*,
config,
query::*,
storage::*,
Expand Down Expand Up @@ -229,6 +230,8 @@ pub mod rmrk_example_equippable {

impl Query for Rmrk {}

impl BatchCalls for Rmrk {}

impl Rmrk {
/// Instantiate new RMRK contract
#[allow(clippy::too_many_arguments)]
Expand Down
Loading