Skip to content

Commit

Permalink
Merge pull request #37 from ORIGYN-SA/0.1.2-1
Browse files Browse the repository at this point in the history
0.1.2 1
  • Loading branch information
skilesare authored Jan 9, 2023
2 parents 99b9460 + 41ef0da commit e4d9128
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 215 deletions.
2 changes: 1 addition & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"subnet_type": "system"
}
},
"dfx": "0.11.2",
"dfx": "0.12.1",
"networks": {
"local": {
"bind": "127.0.0.1:8000",
Expand Down
327 changes: 216 additions & 111 deletions src/origyn_nft_reference/market.mo

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions src/origyn_nft_reference/metadata.mo
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,61 @@ module {
};
};

//sets the owner on the nft
//this is not the only entity that has rights. use is_nft_owner to determine ownership rights
public func set_nft_owner(state: Types.State, token_id: Text, new_owner: Types.Account, caller: Principal) : Result.Result<CandyTypes.CandyValue, Types.OrigynError>{

let current_state = state.refresh_state();

//make sure we always have fresh meta data incase something has changed
var fresh_metadata = switch(get_metadata_for_token(current_state, token_id, caller, ?state.canister(), state.state.collection_data.owner)){
case(#err(err)){
return #err(Types.errors(#token_not_found, "set_nft_owner can't get metadata " # err.flag_point, ?caller));
};
case(#ok(val)){
val;
};
};

var temp_metadata : CandyTypes.CandyValue = switch(Properties.updateProperties(Conversions.valueToProperties(fresh_metadata), [
{
name = Types.metadata.owner;
mode = #Set(switch(new_owner){
case(#principal(buyer)){#Principal(buyer);};
case(#account_id(buyer)){#Text(buyer);};
case(#extensible(buyer)){buyer;};
case(#account(buyer)){#Array(#frozen([#Principal(buyer.owner), #Option(switch(buyer.sub_account){case(null){null}; case(?val){?#Blob(val);}})]))};
});
}
])){
case(#ok(props)){
#Class(props);
};
case(#err(err)){
return #err(Types.errors(#update_class_error, "set_nft_owner - error setting owner " # debug_show((token_id, new_owner, fresh_metadata)), ?caller));
};
};

Map.set(current_state.state.nft_metadata, Map.thash, token_id, temp_metadata);

#ok(temp_metadata);
};

public func is_nft_owner(metadata: CandyTypes.CandyValue, anAccount : Types.Account) : Result.Result<Bool, Types.OrigynError>{

let owner = switch(get_nft_owner(metadata)){
case(#err(err)){
return #err(Types.errors(err.error, "is_nft_owner check owner" # err.flag_point, null));
};
case(#ok(val)){
switch(val){
case(#extensible(ex)){
if(Conversions.valueToText(ex) == "trx in flight"){
return(#ok(false));
}
};
case(_){};
};
val;
};
};
Expand Down
34 changes: 16 additions & 18 deletions src/origyn_nft_reference/mint.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1066,23 +1066,16 @@ module {
};

var primary_royalties = switch(Properties.getClassProperty(collection, Types.metadata.primary_royalties_default)){
case(null){
#Array(#frozen([]));
};
case(?val){
val.value;
};
case(null) #Array(#frozen([]));
case(?val) val.value;
};

metadata := Metadata.set_system_var(metadata, Types.metadata.__system_primary_royalty, primary_royalties);


var secondary_royalties = switch(Properties.getClassProperty(collection, Types.metadata.secondary_royalties_default)){
case(null){
#Array(#frozen([]));
};
case(?val){
val.value;
};
case(null) #Array(#frozen([]));
case(?val) val.value;
};

metadata := Metadata.set_system_var(metadata, Types.metadata.__system_secondary_royalty, secondary_royalties);
Expand All @@ -1099,13 +1092,18 @@ module {

metadata := Metadata.set_system_var(metadata, Types.metadata.__system_node, node_principal);

var originator_principal = switch(Properties.getClassProperty(collection, Types.metadata.__system_originator)){
case(null){
#Principal(Principal.fromText("yfhhd-7eebr-axyvl-35zkt-z6mp7-hnz7a-xuiux-wo5jf-rslf7-65cqd-cae")); //dev fund
};
case(?val){
val.value;
var originator_principal = switch(Properties.getClassProperty(metadata, Types.metadata.originator_override)){
case(null){
switch(Properties.getClassProperty(collection, Types.metadata.__system_originator)){
case(null){
#Principal(Principal.fromText("yfhhd-7eebr-axyvl-35zkt-z6mp7-hnz7a-xuiux-wo5jf-rslf7-65cqd-cae")); //dev fund
};
case(?val){
val.value;
};
};
};
case(?val) val.value;
};

metadata := Metadata.set_system_var(metadata, Types.metadata.__system_originator, originator_principal);
Expand Down
3 changes: 2 additions & 1 deletion src/origyn_nft_reference/types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ module {
primary_port: Text;
primary_protocol: Text;
primary_royalties_default : Text;

originator_override : Text;
royalty_broker : Text;
royalty_node : Text;
royalty_originator : Text;
Expand Down Expand Up @@ -1161,6 +1161,7 @@ module {
primary_host = "primary_host";
primary_port = "primary_port";
primary_protocol = "primary_protocol";
originator_override = "com.origyn.originator.override";
royalty_broker = "com.origyn.royalty.broker";
royalty_node = "com.origyn.royalty.node";
royalty_originator = "com.origyn.royalty.originator";
Expand Down
10 changes: 5 additions & 5 deletions src/tests/test_runner_data.mo
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

let canister : Types.Service = actor(Principal.toText(newPrincipal));

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this));

//D.print("Minting");
let mint_attempt = await canister.mint_nft_origyn("1", #principal(Principal.fromActor(a_wallet)));
Expand Down Expand Up @@ -377,7 +377,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

let canister : Types.Service = actor(Principal.toText(newPrincipal));

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this));

//attempt to change the metadata of a library before mint

Expand Down Expand Up @@ -539,7 +539,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

let canister : Types.Service = actor(Principal.toText(newPrincipal));

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this));

//attempt to delete page before minting

Expand Down Expand Up @@ -694,7 +694,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

let canister : Types.Service = actor(Principal.toText(newPrincipal));

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this));

//attempt to delete page before minting

Expand All @@ -710,7 +710,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

D.print("deletePage:" # debug_show(deletePage));

//let stage = await canister.stage_nft_origyn(utils.standardNFT("1", Principal.fromActor(canister), Principal.fromActor(this), 1024, false));
//let stage = await canister.stage_nft_origyn(utils.standardNFT("1", Principal.fromActor(canister), Principal.fromActor(this), 1024, false, Principal.fromActor(this)));

let fileStage = await canister.stage_library_nft_origyn(utils.standardFileChunk("1","page","hello world replace larger", #Class([
{name = "library_id"; value=#Text("page"); immutable= true},
Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_runner_instant_transfer.mo
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ shared (deployer) actor class test_runner_instant_transfer(dfx_ledger: Principal
let canister_principal = Principal.fromActor(canister);

//stage unminted and minted NFTs
let stage_minted_nft = await utils.buildStandardNFT("first", canister, this_principal, 1024, false); //this sets the owner of the nft to the canister change later on mint
let stage_unminted_nft = await utils.buildStandardNFT("second", canister, this_principal, 1024, false); //this sets the owner of th nft to the canister
let stage_minted_nft = await utils.buildStandardNFT("first", canister, this_principal, 1024, false, Principal.fromActor(this)); //this sets the owner of the nft to the canister change later on mint
let stage_unminted_nft = await utils.buildStandardNFT("second", canister, this_principal, 1024, false, Principal.fromActor(this)); //this sets the owner of th nft to the canister

//mint first staged NFT
let mint_nft = await canister.mint_nft_origyn("first", #principal(this_principal));//changing owner of first to this
Expand Down Expand Up @@ -638,7 +638,7 @@ shared (deployer) actor class test_runner_instant_transfer(dfx_ledger: Principal
let canister_principal = Principal.fromActor(canister);

//stage unminted and minted NFTs
let stage_soulbound_nft = await utils.buildStandardNFT("soulbound", canister, this_principal, 1024, true);
let stage_soulbound_nft = await utils.buildStandardNFT("soulbound", canister, this_principal, 1024, true, Principal.fromActor(this));

let mint_nft = await canister.mint_nft_origyn("soulbound", #principal(this_principal));

Expand Down
34 changes: 17 additions & 17 deletions src/tests/test_runner_nft.mo
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

D.print("calling stage");

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false);
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false);
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));

//mint 2
let mint_attempt = await canister.mint_nft_origyn("2", #principal(Principal.fromActor(this)));
Expand Down Expand Up @@ -416,9 +416,9 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

D.print("calling stage");

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false);
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false);
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));

D.print("finished stage");
D.print(debug_show(standardStage.0));
Expand Down Expand Up @@ -890,7 +890,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
canister,
Principal.fromActor(canister),
Principal.fromActor(n_wallet),
Principal.fromActor(o_wallet),
Principal.fromActor(this),
2048000);

let updateNetwork = canister.collection_update_nft_origyn(#UpdateNetwork(?Principal.fromActor(net_wallet)));
Expand All @@ -899,9 +899,9 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
D.print("calling stage");


let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false);
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false);
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(o_wallet));
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(o_wallet));
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(o_wallet));

let mint_attempt3 = await canister.mint_nft_origyn("2", #principal(Principal.fromActor(this)));
let mint_attempt4 = await canister.mint_nft_origyn("3", #principal(Principal.fromActor(this)));
Expand Down Expand Up @@ -1181,7 +1181,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

let canister : Types.Service = actor(Principal.toText(newPrincipal));

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));


let mint_attempt = await canister.mint_nft_origyn("1", #principal(Principal.fromActor(a_wallet)));
Expand Down Expand Up @@ -1275,8 +1275,8 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
let mode = canister.__set_time_mode(#test);
let atime = canister.__advance_time(Time.now());

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false); //for auctioning a minted item
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(this), 1024, false); //for auctioning an unminted item
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this)); //for auctioning a minted item
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this)); //for auctioning an unminted item

D.print("Minting");
let mint_attempt = await canister.mint_nft_origyn("1", #principal(Principal.fromActor(this))); //mint to the test account
Expand Down Expand Up @@ -2464,9 +2464,9 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

D.print("calling stage");

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false);
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false);
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let standardStage3 = await utils.buildStandardNFT("3", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));

D.print("finished stage");
D.print(debug_show(standardStage.0));
Expand Down Expand Up @@ -2854,7 +2854,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr

D.print("calling stage");

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(canister), 1024, false, Principal.fromActor(this));
let mint_attempt = await canister.mint_nft_origyn("1", #principal(Principal.fromActor(c_wallet))); //mint to c_wallet

D.print("finished stage");
Expand Down
12 changes: 6 additions & 6 deletions src/tests/test_runner_nft_2.mo
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
D.print("calling stage");

//MINT0007, MINT0008
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this));
D.print("finished stage");
D.print(debug_show(standardStage.0));

Expand Down Expand Up @@ -341,14 +341,14 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
case(#ok(res)){
switch(res.metadata){
case(#Class(data)){
if(data.size() ==12){ //check if a top level element was added to the structure
if(data.size() ==13){ //check if a top level element was added to the structure
"Ok";
} else {
D.print("testing size");
D.print(debug_show(test_metadata));
D.print(debug_show(data));
D.print(debug_show(data.size()));
"data elements don't match wanted 9 found " # debug_show(data.size());
"data elements don't match wanted 13 found " # debug_show(data.size());
}
};
case (_){
Expand Down Expand Up @@ -439,7 +439,7 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
D.print("a mint canister");
D.print(debug_show(Principal.fromActor(canister)));

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false);
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this));

let fileStage2 = await canister.stage_library_nft_origyn({
token_id = "1" : Text;
Expand Down Expand Up @@ -694,8 +694,8 @@ shared (deployer) actor class test_runner(dfx_ledger: Principal, dfx_ledger2: Pr
let mode = canister.__set_time_mode(#test);
let atime = canister.__advance_time(Time.now());

let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false); //for auctioning a minted item
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(this), 1024, false); //for auctioning an unminted item
let standardStage = await utils.buildStandardNFT("1", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this)); //for auctioning a minted item
let standardStage2 = await utils.buildStandardNFT("2", canister, Principal.fromActor(this), 1024, false, Principal.fromActor(this)); //for auctioning an unminted item

D.print("Minting");
let mint_attempt = await canister.mint_nft_origyn("1", #principal(Principal.fromActor(this))); //mint to the test account
Expand Down
Loading

0 comments on commit e4d9128

Please sign in to comment.