From 7158a9ce70987b7da5da5b87c62febcc38b8568e Mon Sep 17 00:00:00 2001 From: Felipe Cardozo Date: Wed, 17 May 2023 21:07:02 -0300 Subject: [PATCH 1/3] make it compile --- Samples~/Contracts/FA2/balance_of.jsligo | 4 +- Samples~/Contracts/FA2/ledger.jsligo | 6 +- Samples~/Contracts/FA2/metadata.jsligo | 4 +- Samples~/Contracts/FA2/operators.jsligo | 14 ++-- Samples~/Contracts/FA2/storage.jsligo | 5 +- Samples~/Contracts/FA2/transfer.jsligo | 27 +++---- Samples~/Contracts/FA2/update_ops.jsligo | 8 +- Samples~/Contracts/_Misc/config.sh | 48 ++++++------ Samples~/Contracts/_Misc/incrementer.jsligo | 8 +- Samples~/Contracts/_Misc/jakartanet.json | 24 ------ Samples~/Contracts/_Misc/jakartanet.json.meta | 7 -- Samples~/Contracts/login.jsligo | 4 +- Samples~/Contracts/main.jsligo | 74 +++++++++---------- 13 files changed, 99 insertions(+), 134 deletions(-) delete mode 100644 Samples~/Contracts/_Misc/jakartanet.json delete mode 100644 Samples~/Contracts/_Misc/jakartanet.json.meta diff --git a/Samples~/Contracts/FA2/balance_of.jsligo b/Samples~/Contracts/FA2/balance_of.jsligo index f3cbee6b..b9474d00 100644 --- a/Samples~/Contracts/FA2/balance_of.jsligo +++ b/Samples~/Contracts/FA2/balance_of.jsligo @@ -47,9 +47,9 @@ const balance_of = ([b, s] : [balance_of_param, storage]): [list, sto // let balance_ = 0 as nat; // if (Storage.is_owner_of (s, owner, token_id)) balance_ = 1 as nat; - ({request:request,balance:balance_}) + return ({request:request,balance:balance_}); }; const callback_param = List.map (get_balance_info, requests); const operation = Tezos.transaction (callback_param, (0 as tez), callback); - [list([operation]),s] + return [list([operation]),s]; }; diff --git a/Samples~/Contracts/FA2/ledger.jsligo b/Samples~/Contracts/FA2/ledger.jsligo index 214faec2..9fc996ce 100644 --- a/Samples~/Contracts/FA2/ledger.jsligo +++ b/Samples~/Contracts/FA2/ledger.jsligo @@ -12,7 +12,7 @@ export type token_map = map; export type t = big_map; // returns the amount of items per requester [user, ID] -export const get_for_user = ([ledger, owner, token_id]: [t, owner, token_id]) : nat => +export const get_for_user = (ledger: t, owner: owner, token_id: token_id) : nat => match (Big_map.find_opt (owner, ledger), { Some: (m: token_map) => match (Map.find_opt(token_id, m), { Some: (a : nat) => a, @@ -22,7 +22,7 @@ export const get_for_user = ([ledger, owner, token_id]: [t, owner, token_id]) : }); // sets the amount for ID on that user and returns the new ledger -const set_for_user = ([ledger, owner, token_id, amount_]: [t, owner, token_id, amount_]) : t => +const set_for_user = (ledger: t, owner: owner, token_id: token_id, amount_: amount_) : t => { let oldMap = match(Big_map.find_opt(owner, ledger), { Some: (m : token_map) => m, @@ -34,7 +34,7 @@ const set_for_user = ([ledger, owner, token_id, amount_]: [t, owner, token_id, a }; // decreases the amount of items on the given user -const decrease_token_amount_for_user = ([ledger, from_, token_id, amount_]: [t, owner, token_id, amount_]) : t => { +const decrease_token_amount_for_user = (ledger: t , from_: owner, token_id: token_id, amount_: amount_) : t => { let balance_ = get_for_user (ledger, from_, token_id); assert_with_error ((balance_ >= amount_), Errors.ins_balance); balance_ = abs(balance_ - amount_); diff --git a/Samples~/Contracts/FA2/metadata.jsligo b/Samples~/Contracts/FA2/metadata.jsligo index a1caedbd..fb3b15e4 100644 --- a/Samples~/Contracts/FA2/metadata.jsligo +++ b/Samples~/Contracts/FA2/metadata.jsligo @@ -36,8 +36,8 @@ export const set_token_metadata = ([meta, tm] : [data, t]) : t => Big_map.update(meta.token_id, Some(meta), tm); // checks if the ID has ever been minted -export const assert_token_exist = ([m, token_id]: [t, nat]) : unit => { +export const assert_token_exist = (m:t, token_id:nat) : unit => { const _ = Option.unopt_with_error ( Big_map.find_opt (token_id, m), Errors.undefined_token); -}; \ No newline at end of file +}; diff --git a/Samples~/Contracts/FA2/operators.jsligo b/Samples~/Contracts/FA2/operators.jsligo index 556afa3e..ca0bde94 100644 --- a/Samples~/Contracts/FA2/operators.jsligo +++ b/Samples~/Contracts/FA2/operators.jsligo @@ -36,15 +36,13 @@ const assert_update_permission = (owner : owner) : unit => // added extra from: // https://gitlab.com/ligolang/contract-catalogue/-/blob/main/lib/fa2/nft/NFT.jsligo - export const is_operator = ([operators, owner, operator, token_id] : [t , address , address , nat]) : bool => { - - const authorized = - match (Big_map.find_opt ([owner, operator], operators), { - Some: (a : set) => a , - None : () => Set.empty - }); +export const is_operator = ([operators, owner, operator, token_id] : [t , address , address , nat]) : bool => { + const authorized = match (Big_map.find_opt ([owner, operator], operators), { + Some: (a : set) => a , + None : () => Set.empty + }); - (Set.mem (token_id, authorized) || owner == operator) + return (Set.mem (token_id, authorized) || owner == operator); }; // add a new operator to the list diff --git a/Samples~/Contracts/FA2/storage.jsligo b/Samples~/Contracts/FA2/storage.jsligo index e1a02ca8..0878c636 100644 --- a/Samples~/Contracts/FA2/storage.jsligo +++ b/Samples~/Contracts/FA2/storage.jsligo @@ -18,10 +18,9 @@ export type t = { }; // returns the amount of tokens for the provided user and ID -export const get_balance = ([s, owner, token_id] : [t, address, nat]) : nat => { +export const get_balance = (s:t, owner:address, token_id:nat) : nat => { TokenMetadata.assert_token_exist (s.token_metadata, token_id); - - return Ledger.get_for_user([s.ledger, owner, token_id]); + return Ledger.get_for_user(s.ledger, owner, token_id); }; // helper: makes a new storage with a new ledger instance diff --git a/Samples~/Contracts/FA2/transfer.jsligo b/Samples~/Contracts/FA2/transfer.jsligo index 39e5f117..262d12e0 100644 --- a/Samples~/Contracts/FA2/transfer.jsligo +++ b/Samples~/Contracts/FA2/transfer.jsligo @@ -39,7 +39,7 @@ export type transfer_param = list; const atomic_transfer_new_ledger = (l: Ledger.t, from_: address, to_ : address, token_id : nat, token_amount : nat) : Ledger.t => { let ledger = Ledger.decrease_token_amount_for_user (l, from_, token_id, token_amount); - ledger = Ledger.increase_token_amount_for_user (ledger, to_, token_id, token_amount); + ledger = Ledger.increase_token_amount_for_user ([ledger, to_, token_id, token_amount]); return ledger; } @@ -52,33 +52,28 @@ const transfer = ([t, s]: [transfer_param, storage]): [list, storage] const transfer_new_storage = (t : transfer_param, s : storage) : storage => { // This function process the "tx" list. Since all transfer share the same "from_" address, we use a se - const process_atomic_transfer = (from_ : address) : (s: storage, t: atomic_trans) => storage => { - return (s: storage, t: atomic_trans) : storage => - { + const process_atomic_transfer = (from_ : address) => ([s, t]: [storage, atomic_trans]) => { //const {to_,token_id,token_amount} = t; const to_ = t.to_; const token_id = t.token_id; const token_amount = t.token_amount; TokenMetadata.assert_token_exist (s.token_metadata, token_id); - Operators.assert_authorisation (s.operators, from_, token_id); + Operators.assert_authorisation ([s.operators, from_, token_id]); let new_marketplace = s.marketplace; - if(Marketplace.is_item_on_market([from_, token_id], s.marketplace)) + if(Marketplace.is_item_on_market([[from_, token_id], s.marketplace])) new_marketplace = Marketplace.remove_from_market([from_, token_id], s.marketplace); let new_ledger = atomic_transfer_new_ledger(s.ledger, from_, to_, token_id, token_amount); return ({...s, marketplace : new_marketplace, ledger: new_ledger}); - }; }; - const process_single_transfer = ([s, t]: [storage, transfer_from]) : storage => { - //const {from_,tx} = t; - const from_ = t.from_; - const tx = t.tx; - - return List.fold_left (process_atomic_transfer (from_), s, tx); + const process_single_transfer = ([s, t]: [storage, transfer_from]) => { + const {from_,tx} = t; + const ledger = List.fold_left (process_atomic_transfer (from_), s, tx); + return ledger }; return List.fold_left (process_single_transfer, s, t); @@ -105,13 +100,13 @@ const marketplace_buy = ([p, s]: [buy_param, storage]): [list, storag let caller = Tezos.get_sender(); // check if enough coins - let currency_balance = Storage.get_balance([s, caller, currency]); + let currency_balance = Storage.get_balance(s, caller, currency); if(currency_balance < price) { return failwith("Insufficient funds"); }; - let item_balance = Storage.get_balance([s, owner, token_id]); + let item_balance = Storage.get_balance(s, owner, token_id); if(item_balance <= (0 as nat)) { return failwith("Negative balance"); @@ -130,4 +125,4 @@ const marketplace_buy = ([p, s]: [buy_param, storage]): [list, storag let new_marketplace = Marketplace.remove_from_market([owner, token_id], s.marketplace); return [list ([]), ({...s, ledger: new_ledger, marketplace : new_marketplace})]; -} \ No newline at end of file +} diff --git a/Samples~/Contracts/FA2/update_ops.jsligo b/Samples~/Contracts/FA2/update_ops.jsligo index 6e837820..cdf92c5e 100644 --- a/Samples~/Contracts/FA2/update_ops.jsligo +++ b/Samples~/Contracts/FA2/update_ops.jsligo @@ -18,13 +18,13 @@ export type update_operators_param = list; const update_ops = ([updates, s]: [update_operators_param, storage]): [list, storage] => { const update_operator = ([operators,update] : [Operators.t, unit_update]) : Operators.t => match (update, - { Add_operator : (operator: operator) => Operators.add_operator (operators, operator.owner, operator.operator, operator.token_id) - , Remove_operator : (operator: operator) => Operators.remove_operator (operators, operator.owner, operator.operator, operator.token_id) + { Add_operator : (operator: operator) => Operators.add_operator ([operators, operator.owner, operator.operator, operator.token_id]) + , Remove_operator : (operator: operator) => Operators.remove_operator ([operators, operator.owner, operator.operator, operator.token_id]) }); let operators = Storage.get_operators (s); operators = List.fold_left (update_operator, operators, updates); - const s = Storage.set_operators (s, operators); - [list([]),s] + const s = Storage.set_operators ([s, operators]); + return [list([]),s]; }; // If transfer_policy is No_transfer or Owner_transfer diff --git a/Samples~/Contracts/_Misc/config.sh b/Samples~/Contracts/_Misc/config.sh index c8f96868..c2a67a5e 100644 --- a/Samples~/Contracts/_Misc/config.sh +++ b/Samples~/Contracts/_Misc/config.sh @@ -1,27 +1,34 @@ -alias ligo="docker run --rm -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:0.51.0" -export TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER=yes -tezos-client --endpoint https://rpc.tzkt.io/jakartanet config update -tezos-client --endpoint https://rpc.ghostnet.teztnets.xyz/ config update -tezos-client --endpoint https://jakartanet.tezos.marigold.dev/ config update -tezos-client activate account alice with 'NFT_myRepo/_Misc/jakartanet.json' -tezos-client get balance for alice -tezos-client --wait none transfer 0 from alice to KT1DCcniV9tatQFVLnPv15i4kGYNgpdE6GhS --arg '4' --burn-cap '1.0' -ligo compile parameter 'main.jsligo' '{val1:"str1",val2:"str2"}' -tezos-client --wait none transfer 0 from alice to KT1E4xgc9iniojkZqs1BDs117bzaYfMHZcPs --arg '(Pair "str1" "str2")' --burn-cap '1.0' -ligo compile storage 'NFT_myRepo/incrementer.jsligo' '{inventories:Big_map.empty as big_map, viewerContract:"KT1KvDaiC7sn6sdYyWncaYFUoivwHoK1pJM7" as address}' -tezos-client originate contract MINTER transferring 0 from alice running incrementer.tz --init 'Pair {} "KT1KvDaiC7sn6sdYyWncaYFUoivwHoK1pJM7"' --burn-cap 1.0 +alias ligo="docker run --rm -v "$PWD":"$PWD" -w "$PWD" ligolang/ligo:0.65.0" +export OCTEZ_CLIENT_UNSAFE_DISABLE_DISCLAIMER=yes +# octez-client --endpoint https://rpc.tzkt.io/jakartanet config update +# octez-client --endpoint https://rpc.ghostnet.teztnets.xyz/ config update +octez-client --endpoint https://ghostnet.tezos.marigold.dev/ config update +octez-client import secret key holder unencrypted:edsk3oRzLs4nUp4TrqsSJxqX9yMN1Jd6h2dx1SJf9DDWgr4tXbkRqm --force +octez-client get balance for holder +octez-client --wait none transfer 0 from holder to KT1DCcniV9tatQFVLnPv15i4kGYNgpdE6GhS --arg '4' --burn-cap '1.0' +ligo compile parameter '../main.jsligo' '{val1:"str1",val2:"str2"}' +octez-client --wait none transfer 0 from holder to KT1E4xgc9iniojkZqs1BDs117bzaYfMHZcPs --arg '(Pair "str1" "str2")' --burn-cap '1.0' +ligo compile storage 'incrementer.jsligo' '{inventories:Big_map.empty as big_map, viewerContract:"KT1KvDaiC7sn6sdYyWncaYFUoivwHoK1pJM7" as address}' +octez-client originate contract MINTER transferring 0 from holder running incrementer.tz --init 'Pair {} "KT1KvDaiC7sn6sdYyWncaYFUoivwHoK1pJM7"' --burn-cap 1.0 -tezos-client gen keys alice -tezos-client list known addresses -tezos-client show address alice -S +octez-client gen keys holder +octez-client list known addresses +octez-client show address holder -S -ligo compile contract 'NFT_myRepo/main.jsligo' > 'FA2.tz' -ligo compile storage 'NFT_myRepo/main.jsligo' '{ ledger: Big_map.empty as big_map>, marketplace: Big_map.empty as big_map<[address,nat], [nat, nat]>, operators: Big_map.empty as big_map<[address, address], set>, token_counter:(1 as nat), token_metadata: Big_map.empty as big_map}>}' -tezos-client originate contract FA2 transferring 0 from alice running FA2.tz --init '(Pair (Pair (Pair {} {}) {} 1) {})' --burn-cap 5.0 +ligo compile contract '../main.jsligo' > 'FA2.tz' +ligo compile storage '../main.jsligo' '{ + ledger: Big_map.empty as big_map>, + token_metadata: Big_map.empty as big_map}>, + operators: Big_map.empty as big_map<[address, address], set>, + marketplace: Big_map.empty as big_map<[address, nat], [nat, nat]>, + token_counter:(1 as nat) +}' +octez-client originate contract FA2 transferring 0 from holder running FA2.tz --init '(Pair (Pair (Pair {} {}) {} 1) {})' --burn-cap 5.0 -ligo compile parameter 'NFT_myRepo/main.jsligo' 'SetMeta({token_id:0 as nat, token_info:Map.literal( list([ + +ligo compile parameter '../main.jsligo' 'SetMeta({token_id:0 as nat, token_info:Map.literal( list([ ["item", Bytes.pack( {itemType:0, damage:0,armor:0,attackSpeed:0,healthPoints:0,manaPoints:0} )], ["name", Bytes.pack("Example Coin")], @@ -32,7 +39,6 @@ ligo compile parameter 'NFT_myRepo/main.jsligo' 'SetMeta({token_id:0 as nat, tok ["artifactUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["displayUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["thumbnailUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], - ["description", Bytes.pack("Unity Tezos Example Project coins used as soft currency")], ["minter", Bytes.pack(Tezos.get_sender())], ["creators", Bytes.pack(["https://assetstore.unity.com/packages/essentials/tutorial-projects/ui-toolkit-sample-dragon-crashers-231178"])], @@ -43,7 +49,7 @@ ligo compile parameter 'NFT_myRepo/main.jsligo' 'SetMeta({token_id:0 as nat, tok ]) )})' // as one line: -ligo compile parameter 'NFT_myRepo/main.jsligo' 'SetMeta({token_id:0 as nat, token_info:Map.literal( list([ ["item", Bytes.pack( {itemType:0, damage:0,armor:0,attackSpeed:0,healthPoints:0,manaPoints:0} )], ["name", Bytes.pack("Example Coin")], ["symbol", Bytes.pack("UnityTezos")], ["decimals", Bytes.pack(0)], ["image", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["artifactUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["displayUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["thumbnailUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["description", Bytes.pack("Unity Tezos Example Project coins used as soft currency")], ["minter", Bytes.pack(Tezos.get_sender())], ["creators", Bytes.pack(["https://assetstore.unity.com/packages/essentials/tutorial-projects/ui-toolkit-sample-dragon-crashers-231178"])], ["isBooleanAmount", Bytes.pack(false)], ["date", Bytes.pack(Tezos.get_now())]]) )})' +ligo compile parameter '../main.jsligo' 'SetMeta({token_id:0 as nat, token_info:Map.literal( list([ ["item", Bytes.pack( {itemType:0, damage:0,armor:0,attackSpeed:0,healthPoints:0,manaPoints:0} )], ["name", Bytes.pack("Example Coin")], ["symbol", Bytes.pack("UnityTezos")], ["decimals", Bytes.pack(0)], ["image", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["artifactUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["displayUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["thumbnailUri", Bytes.pack("ipfs://bafybeian23odhsho6gufacrcpcr65ft6bpqavzk36pt22lhcjoxy45mqpa")], ["description", Bytes.pack("Unity Tezos Example Project coins used as soft currency")], ["minter", Bytes.pack(Tezos.get_sender())], ["creators", Bytes.pack(["https://assetstore.unity.com/packages/essentials/tutorial-projects/ui-toolkit-sample-dragon-crashers-231178"])], ["isBooleanAmount", Bytes.pack(false)], ["date", Bytes.pack(Tezos.get_now())]]) )})' //result: (Right diff --git a/Samples~/Contracts/_Misc/incrementer.jsligo b/Samples~/Contracts/_Misc/incrementer.jsligo index 07da378f..58310237 100644 --- a/Samples~/Contracts/_Misc/incrementer.jsligo +++ b/Samples~/Contracts/_Misc/incrementer.jsligo @@ -53,7 +53,7 @@ type return_ = [listOfOps, storage]; // @view -let view_inventory_of = ([addr , s]: [address , storage]) : itemSet => +const view_inventory_of = ([addr , s]: [address , storage]) : itemSet => { let inv : inventory = match( Big_map.find_opt(addr, s.inventories) as option, { @@ -85,7 +85,7 @@ let sendToCallback = (addr : address, s : storage) : listOfOps => { }; */ -let mint = (seed: int, store: storage) : storage => { +const mint = (seed: int, store: storage) : storage => { let dmg = (seed * 13) % 9 + 1; let arm = (seed / 13) % (9) + 1; @@ -147,7 +147,7 @@ let mint = (seed: int, store: storage) : storage => { return new_store; }; -let main = ([action, store]: [parameter, storage]) : return_ => { +const main = ([action, store]: [parameter, storage]) : return_ => { let noop : listOfOps = list([]); match(action, { @@ -171,4 +171,4 @@ let main = ([action, store]: [parameter, storage]) : return_ => { return [noop, newStorage]; } }); -}; \ No newline at end of file +}; diff --git a/Samples~/Contracts/_Misc/jakartanet.json b/Samples~/Contracts/_Misc/jakartanet.json deleted file mode 100644 index 31378da6..00000000 --- a/Samples~/Contracts/_Misc/jakartanet.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "pkh": "tz1P5cETFVTcyXmi1oChsrewsAthuJZmjaRB", - "mnemonic": [ - "width", - "fruit", - "neck", - "enhance", - "orient", - "giraffe", - "maid", - "child", - "lottery", - "thank", - "limb", - "monster", - "era", - "invite", - "young" - ], - "email": "xdlughts.dgmriuab@teztnets.xyz", - "password": "31PnbWgMC1", - "amount": "32335372505", - "activation_code": "3c681fa7cf6eac6687125f2856c884ab823d67ca" -} \ No newline at end of file diff --git a/Samples~/Contracts/_Misc/jakartanet.json.meta b/Samples~/Contracts/_Misc/jakartanet.json.meta deleted file mode 100644 index c4d3b5a9..00000000 --- a/Samples~/Contracts/_Misc/jakartanet.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 44affac142b094850828e99ae17f79a5 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Samples~/Contracts/login.jsligo b/Samples~/Contracts/login.jsligo index 68b21735..7366b3e7 100644 --- a/Samples~/Contracts/login.jsligo +++ b/Samples~/Contracts/login.jsligo @@ -31,7 +31,7 @@ const login = (p: login_param, s: storage) : [list , storage] => let amount_ = 1000 as nat; // modifying the ledger (giving 1000 coins to the new user) - let new_ledger = Ledger.set_for_user([s.ledger, sender, token_id, amount_]); + let new_ledger = Ledger.set_for_user(s.ledger, sender, token_id, amount_); // the old metadata cached let new_metadata = s.token_metadata; @@ -67,4 +67,4 @@ const login = (p: login_param, s: storage) : [list , storage] => } return result; -}; \ No newline at end of file +}; diff --git a/Samples~/Contracts/main.jsligo b/Samples~/Contracts/main.jsligo index 3b9abc42..b01fc87f 100644 --- a/Samples~/Contracts/main.jsligo +++ b/Samples~/Contracts/main.jsligo @@ -99,11 +99,11 @@ const main = ([p, s]: [parameter, storage]) : [list, storage] => matc let caller = Tezos.get_sender(); TokenMetadata.assert_token_exist (s.token_metadata, p.token_id); - Operators.assert_authorisation (s.operators, caller, p.token_id); + Operators.assert_authorisation ([s.operators, caller, p.token_id]); let new_marketplace = Marketplace.add_to_market(p, s.marketplace); - let new_storage = Storage.set_marketplace (s, new_marketplace); - [list([]), new_storage] + let new_storage = Storage.set_marketplace ([s, new_marketplace]); + return [list([]), new_storage]; } , RemoveFromMarket : (p : remove_from_market_param ) => @@ -113,21 +113,21 @@ const main = ([p, s]: [parameter, storage]) : [list, storage] => matc const [_, token_id] = p; TokenMetadata.assert_token_exist (s.token_metadata, token_id); - Operators.assert_authorisation (s.operators, caller, token_id); + Operators.assert_authorisation ([s.operators, caller, token_id]); let new_marketplace = Marketplace.remove_from_market(p, s.marketplace); - let new_storage = Storage.set_marketplace (s, new_marketplace); - [list([]), new_storage] + let new_storage = Storage.set_marketplace ([s, new_marketplace]); + return [list([]), new_storage]; } , - Buy : (p : buy_param ) => Transfer.marketplace_buy(p, s), + Buy : (p : buy_param ) => Transfer.marketplace_buy([p, s]), - Transfer : (p : transfer_param ) => Transfer.transfer (p, s) , - Balance_of : (p : balance_of_param ) => BalanceOf.balance_of (p, s) , - Update_operators : (p : update_operators_param) => UpdateOps.update_ops (p, s), + Transfer : (p : transfer_param ) => Transfer.transfer ([p, s]) , + Balance_of : (p : balance_of_param ) => BalanceOf.balance_of ([p, s]) , + Update_operators : (p : update_operators_param) => UpdateOps.update_ops ([p, s]), // utility - SetMeta: (p : set_meta_param ) => Storage.set_token_metadata(p, s) , // to be removed for security + SetMeta: (p : set_meta_param ) => Storage.set_token_metadata([p, s]) , // to be removed for security // Humanize utility function do not need to execute any code, because they are never actually called HumanizeItem: (_p : item ) => failwith("Netezos use only"), @@ -141,22 +141,22 @@ const main = ([p, s]: [parameter, storage]) : [list, storage] => matc // @view const get_balance = ([p, s] : [[address , nat] , storage]) : nat => { const [owner, token_id] = p; - Storage.get_balance (s, owner, token_id); + return Storage.get_balance (s, owner, token_id); }; // @view const is_operator = ([op, s] : [Operators.operator_info , storage]) : bool => - Operators.is_operator (s.operators, op.owner, op.operator, op.token_id); + Operators.is_operator ([s.operators, op.owner, op.operator, op.token_id]); // @view const total_supply = ([token_id, s] : [nat , storage]) : nat => { TokenMetadata.assert_token_exist (s.token_metadata, token_id); - (1 as nat) + return (1 as nat); }; // @view const token_metadata = ([p, s] : [nat, storage]) : TokenMetadata.data => - TokenMetadata.get_token_metadata(p, s.token_metadata); + TokenMetadata.get_token_metadata([p, s.token_metadata]); // @view const view_item_meta = ([token_id , s]: [nat , storage]) : item => @@ -182,7 +182,7 @@ const view_item_meta = ([token_id , s]: [nat , storage]) : item => }; // @view -let view_items_of = ([owner , s]: [address , storage]) : set => +const view_items_of = ([owner , s]: [address , storage]) : set => { let inv = match( Big_map.find_opt(owner, s.ledger), { @@ -190,8 +190,8 @@ let view_items_of = ([owner , s]: [address , storage]) : set Map.empty }); - Map.fold( - (acc: set, [token_id, amount]: [token_id, amount]) => + return Map.fold( + ([acc, [token_id, amount]]: [set, [token_id, amount]]) => { if(amount > (0 as nat)) { @@ -230,25 +230,23 @@ let view_items_of = ([owner , s]: [address , storage]) : set => +const view_items_on_market = ([_p, s] : [unit, storage]) : set => { - Map.fold( - (acc: set, [marketToken, marketPrice]: [marketToken, marketPrice]) => + return Map.fold( + ([acc, [marketToken, marketPrice]]: [set, [marketToken, marketPrice]]) => { const [owner, token_id] = marketToken; const [currency, price] = marketPrice; - let meta = - match (Big_map.find_opt (token_id, s.token_metadata), { - Some : (data : data) => data, - None : () => failwith ("Meta not found") - }); + let meta = match (Big_map.find_opt (token_id, s.token_metadata), { + Some : (data : data) => data, + None : () => failwith ("Meta not found") + }); - let info = - match(Map.find_opt ("item", meta.token_info), { - Some : (info : bytes) => info, - None : () => failwith ("Property not found") - }); + let info = match(Map.find_opt ("item", meta.token_info), { + Some : (info : bytes) => info, + None : () => failwith ("Property not found") + }); let item = match( Bytes.unpack(info) as option, { Some: (it : item) => it, @@ -265,7 +263,7 @@ let view_items_on_market = ([_p, s] : [unit, storage]) : set Map.mem(p, s.marketplace); +const is_item_on_market = ([p, s] : [[address, nat], storage]) : bool => Map.mem(p, s.marketplace); // @view -let is_items_on_market = ([p, s] : [[address, list], storage]) : set<[nat, bool]> => - List.fold( - (acc: set<[nat, bool]>, token_id : nat) => { +const is_items_on_market = ([p, s] : [[address, list], storage]) : set<[nat, bool]> => + List.fold( + ([acc, token_id] : [set<[nat, bool]>, nat]) => { let is_present = Map.mem([p[0], token_id], s.marketplace); - Set.add([token_id, is_present], acc); + return Set.add([token_id, is_present], acc); }, p[1], Set.empty @@ -293,4 +291,4 @@ let is_items_on_market = ([p, s] : [[address, list], storage]) : set<[nat, // token_metadata(p, s).token_info["item"]; // @ view -//const all_tokens = ([_, s] : [unit , storage]) : list => s.token_ids; \ No newline at end of file +//const all_tokens = ([_, s] : [unit , storage]) : list => s.token_ids; From ef85bb10ba356e6f07ec08f44e0b21300e408967 Mon Sep 17 00:00:00 2001 From: Felipe Cardozo Date: Mon, 22 May 2023 13:36:50 -0300 Subject: [PATCH 2/3] contracts compatible with ligo 0.65.0 --- Samples~/Contracts/FA2/ledger.jsligo | 6 ++---- Samples~/Contracts/FA2/operators.jsligo | 4 ++-- Samples~/Contracts/FA2/update_ops.jsligo | 4 ++-- Samples~/Contracts/_Misc/config.sh | 2 +- Samples~/Contracts/main.jsligo | 6 +++--- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Samples~/Contracts/FA2/ledger.jsligo b/Samples~/Contracts/FA2/ledger.jsligo index 9fc996ce..d076a386 100644 --- a/Samples~/Contracts/FA2/ledger.jsligo +++ b/Samples~/Contracts/FA2/ledger.jsligo @@ -38,14 +38,12 @@ const decrease_token_amount_for_user = (ledger: t , from_: owner, token_id: toke let balance_ = get_for_user (ledger, from_, token_id); assert_with_error ((balance_ >= amount_), Errors.ins_balance); balance_ = abs(balance_ - amount_); - const ledger = set_for_user(ledger, from_, token_id, balance_); - return ledger; + return set_for_user(ledger, from_, token_id, balance_); }; // increases the amount of items on the given user const increase_token_amount_for_user = ([ledger, to_, token_id, amount_]: [t, owner, token_id, amount_]) : t => { let balance_ = get_for_user (ledger, to_, token_id); balance_ = balance_ + amount_; - const ledger = set_for_user(ledger, to_, token_id, balance_); - return ledger; + return set_for_user(ledger, to_, token_id, balance_); }; diff --git a/Samples~/Contracts/FA2/operators.jsligo b/Samples~/Contracts/FA2/operators.jsligo index ca0bde94..bacd4f3c 100644 --- a/Samples~/Contracts/FA2/operators.jsligo +++ b/Samples~/Contracts/FA2/operators.jsligo @@ -64,8 +64,8 @@ export const remove_operator = ([operators,owner,operator,token_id]: [t, owner, assert_update_permission (owner); const auth_tokens : option> = match (Big_map.find_opt ([owner,operator], operators), {Some : (ts : set) => { - const ts = Set.remove (token_id, ts); - if (Set.cardinal (ts) == (0 as nat)) { return None ()} else { return Some (ts)}; + const ts_result = Set.remove (token_id, ts); + if (Set.cardinal (ts_result) == (0 as nat)) { return None ()} else { return Some (ts_result)}; }, None : () => None () }); diff --git a/Samples~/Contracts/FA2/update_ops.jsligo b/Samples~/Contracts/FA2/update_ops.jsligo index cdf92c5e..2a09cfae 100644 --- a/Samples~/Contracts/FA2/update_ops.jsligo +++ b/Samples~/Contracts/FA2/update_ops.jsligo @@ -23,8 +23,8 @@ const update_ops = ([updates, s]: [update_operators_param, storage]): [list { let meta = match (Big_map.find_opt (token_id, s.token_metadata), { - Some : (data : data) => data, + Some : (data) => data, None : () => failwith ("Meta not found") }); @@ -197,7 +197,7 @@ const view_items_of = ([owner , s]: [address , storage]) : set data, + Some : (data) => data, None : () => failwith ("Meta not found") }); @@ -239,7 +239,7 @@ const view_items_on_market = ([_p, s] : [unit, storage]) : set data, + Some : (data) => data, None : () => failwith ("Meta not found") }); From 597d2b0ccb4bc168f44a7172a0931da9ed69472f Mon Sep 17 00:00:00 2001 From: Felipe Cardozo Date: Wed, 24 May 2023 19:50:00 -0300 Subject: [PATCH 3/3] Changelog updated --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08686503..a8c16568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [Bug](https://github.com/trilitech/tezos-unity-sdk/issues/57) with BeaconConnectorWebGl - [Bug](https://github.com/trilitech/tezos-unity-sdk/issues/63), updated Netezos to `v2.8.0` +- [Bug](https://github.com/trilitech/tezos-unity-sdk/issues/61) fix contracts compilation on Ligo `0.65.0` ### Added - Better [coroutine error handling](https://github.com/trilitech/tezos-unity-sdk/issues/39)