Skip to content

Commit

Permalink
Scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
wraitii committed Aug 23, 2023
1 parent a6dff0a commit 8f1ca58
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 221 deletions.
54 changes: 30 additions & 24 deletions src/attributes/attributes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ struct AttributeRemoveData {
}

#[derive(Drop, Serde)]
enum AttributeHandlerData
{
enum AttributeHandlerData {
Assign: AttributeAssignData,
Remove: AttributeRemoveData,
}
Expand All @@ -65,52 +64,58 @@ fn assign_attributes(
shape: @Array<PackedShapeItem>,
fts: @Array<FTSpec>,
) {
assert(set_owner.is_non_zero(), 'Bad input');
assert(set_token_id != 0, 'Bad input');
loop {
if (attributes.len() == 0) {
break ();
}
assign_attribute(ctx, set_owner, set_token_id, attributes.pop_front().unwrap(), shape, fts);
inner_attribute_assign(
ctx, set_owner, set_token_id, attributes.pop_front().unwrap(), shape, fts
);
}

// Update the cumulative balance
let balance = get!(
ctx.world, (CUM_BALANCE_TOKEN(), CB_ATTRIBUTES, set_token_id), ERC1155Balance
)
.amount;
assert(balance < balance + 1, 'Balance overflow');
set!(
ctx.world, ERC1155Balance {
token: CUM_BALANCE_TOKEN(),
token_id: CB_ATTRIBUTES,
account: set_token_id.try_into().unwrap(),
amount: balance + attributes.len()
}
);
}

fn assign_attribute(
fn inner_attribute_assign(
ctx: Context,
set_owner: ContractAddress,
set_token_id: felt252,
attribute_id: felt252,
shape: @Array<PackedShapeItem>,
fts: @Array<FTSpec>,
) {
assert(set_owner.is_non_zero(), 'Bad input');
assert(set_token_id != 0, 'Bad input');
assert(attribute_id != 0, 'Bad input');

let collection_id = get_collection_id(attribute_id);
let (admin, system) = get!(ctx.world, (collection_id), Collection).get_admin_or_system();
if admin.is_some() {
//library_erc1155::transferability::Transferability::_transfer_burnable(0, set_token_id, attribute_id, 1);
assert(0 == 1, 'TODO');
} else {
let mut calldata: Array<felt252> = ArrayTrait::new();
AttributeHandlerData::Assign(AttributeAssignData { set_owner, set_token_id, attribute_id, shape: shape.clone(), fts: fts.clone() }).serialize(ref calldata);
AttributeHandlerData::Assign(
AttributeAssignData {
set_owner, set_token_id, attribute_id, shape: shape.clone(), fts: fts.clone()
}
)
.serialize(ref calldata);
ctx.world.execute(system.unwrap().into(), calldata);
}
emit!(ctx.world, AttributeAssigned { set_token_id: set_token_id.into(), attribute_id });

// Update the cumulative balance
let balance = get!(
ctx.world, (CUM_BALANCE_TOKEN(), CB_ATTRIBUTES, set_token_id), ERC1155Balance
)
.amount;
assert(balance < balance + 1, 'Balance overflow');
set!(
ctx.world, ERC1155Balance {
token: CUM_BALANCE_TOKEN(),
token_id: CB_ATTRIBUTES,
account: set_token_id.try_into().unwrap(),
amount: balance + 1
}
);
}

fn remove_attributes(
Expand Down Expand Up @@ -138,7 +143,8 @@ fn remove_attribute(
assert(0 == 1, 'TODO');
} else {
let mut calldata: Array<felt252> = ArrayTrait::new();
AttributeHandlerData::Remove(AttributeRemoveData { set_owner, set_token_id, attribute_id }).serialize(ref calldata);
AttributeHandlerData::Remove(AttributeRemoveData { set_owner, set_token_id, attribute_id })
.serialize(ref calldata);
ctx.world.execute(system.unwrap().into(), calldata);
}

Expand Down
2 changes: 0 additions & 2 deletions src/set_nft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,4 @@ mod SetNft {
use briq_protocol::set_nft::systems::DisassemblySystemData;

use briq_protocol::types::{FTSpec, ShapeItem};


}
24 changes: 11 additions & 13 deletions src/shape_verifier.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ struct ShapeVerifier {
class_hash: ClassHash,
}

trait ShapeVerifierTrait
{
trait ShapeVerifierTrait {
fn assign_attribute(
self: @ShapeVerifier,
world: IWorldDispatcher,
Expand All @@ -45,14 +44,14 @@ trait ShapeVerifierTrait
shape: @Array<PackedShapeItem>,
fts: @Array<FTSpec>,
);

fn remove_attribute(
self: @ShapeVerifier,
world: IWorldDispatcher,
set_owner: ContractAddress,
set_token_id: felt252,
attribute_id: felt252,
);
);
}

impl ShapeVerifierImpl of ShapeVerifierTrait {
Expand Down Expand Up @@ -128,27 +127,26 @@ mod register_shape_verifier {
mod shape_verifier_system {
use dojo::world::Context;
use briq_protocol::world_config::{SYSTEM_CONFIG_ID, WorldConfig, AdminTrait};

use super::{ShapeVerifier, ShapeVerifierTrait};
use briq_protocol::attributes::attributes::{
AttributeHandlerData,
AttributeAssignData,
AttributeRemoveData,
AttributeHandlerData, AttributeAssignData, AttributeRemoveData,
};

fn execute(ctx: Context, data: AttributeHandlerData) {
match data {
AttributeHandlerData::Assign(d) => {
let AttributeAssignData { set_owner, set_token_id, attribute_id, shape, fts } = d;
let AttributeAssignData{set_owner, set_token_id, attribute_id, shape, fts } = d;
let shape_verifier = get!(ctx.world, (attribute_id), ShapeVerifier);
shape_verifier
.assign_attribute(ctx.world, set_owner, set_token_id, attribute_id, @shape, @fts);
.assign_attribute(
ctx.world, set_owner, set_token_id, attribute_id, @shape, @fts
);
},
AttributeHandlerData::Remove(d) => {
let AttributeRemoveData { set_owner, set_token_id, attribute_id } = d;
let AttributeRemoveData{set_owner, set_token_id, attribute_id } = d;
let shape_verifier = get!(ctx.world, (attribute_id), ShapeVerifier);
shape_verifier
.remove_attribute(ctx.world, set_owner, set_token_id, attribute_id);
shape_verifier.remove_attribute(ctx.world, set_owner, set_token_id, attribute_id);
},
}
}
Expand Down
Loading

0 comments on commit 8f1ca58

Please sign in to comment.