Closed russellmorton closed 2 years ago
@jchenche some of the info I could find on complex storage values so far: Taquito page for reference: https://tezostaquito.io/docs/complex_parameters/ Contract collection: https://tezostaquito.io/docs/contracts_collection/ Minter contracts that Rick said could be useful for this: https://github.com/tqtezos/minter-sdk/tree/main/packages/minter-contracts/bin
Refer to https://github.com/ecadlabs/taqueria/issues/892
Some types are more popular than others, and therefore I've segmented the list of michelson types into priority buckets.
https://tezos.gitlab.io/michelson-reference/#type-bytes ~https://tezos.gitlab.io/michelson-reference/#type-contract~ https://tezos.gitlab.io/michelson-reference/#type-key https://tezos.gitlab.io/michelson-reference/#type-key_hash https://tezos.gitlab.io/michelson-reference/#type-lambda https://tezos.gitlab.io/michelson-reference/#type-list https://tezos.gitlab.io/michelson-reference/#type-never ~https://tezos.gitlab.io/michelson-reference/#type-operation~ https://tezos.gitlab.io/michelson-reference/#type-option https://tezos.gitlab.io/michelson-reference/#type-or https://tezos.gitlab.io/michelson-reference/#type-set https://tezos.gitlab.io/michelson-reference/#type-signature https://tezos.gitlab.io/michelson-reference/#type-unit https://tezos.gitlab.io/michelson-reference/#type-timestamp
https://tezos.gitlab.io/michelson-reference/#type-chain_id https://tezos.gitlab.io/michelson-reference/#type-sapling_state https://tezos.gitlab.io/michelson-reference/#type-sapling_transaction https://tezos.gitlab.io/michelson-reference/#type-ticket
https://tezos.gitlab.io/michelson-reference/#type-bls12_381_fr https://tezos.gitlab.io/michelson-reference/#type-bls12_381_g1 https://tezos.gitlab.io/michelson-reference/#type-bls12_381_g2
Also note, JSON has very few types:
string
number
boolean
null
object
array
Compiled hashlock.mligo
(below) with LIGO and then deployed the Michelson contract with the storage (in config.json
) at the bottom, successfully.
type commit = {
date : timestamp;
salted_hash : bytes;
}
type commit_set = (address, commit) big_map
type storage = {
hashed : bytes;
unused : bool;
commits : commit_set
}
type reveal = {
hashable : bytes;
message : unit -> operation list
}
type parameter =
Commit of bytes
| Reveal of reveal
type return = operation list * storage
(* We use hash-commit so that a baker can not steal *)
let commit (p, s : bytes * storage) : return =
let commit : commit =
{date = Tezos.get_now () + 86_400; salted_hash = p} in
let updated_map: commit_set =
Big_map.update (Tezos.get_sender ()) (Some commit) s.commits in
let s = {s with commits = updated_map}
in ([] : operation list), s
let reveal (p, s : reveal * storage) : return =
if not s.unused
then
(failwith "This contract has already been used." : return)
else
let commit : commit =
match Big_map.find_opt (Tezos.get_sender ()) s.commits with
| Some c -> c
| None ->
(failwith "You have not made a commitment to hash against yet."
: commit)
in
if Tezos.get_now () < commit.date
then
(failwith "It has not been 24 hours since your commit yet.": return)
else
let salted =
Crypto.sha256 (Bytes.concat p.hashable (Bytes.pack (Tezos.get_sender ()))) in
if salted <> commit.salted_hash
then
(failwith "This reveal does not match your commitment.": return)
else
if s.hashed = Crypto.sha256 p.hashable
then
let s : storage = {s with unused = false}
in p.message (), s
else (failwith "Your commitment did not match the storage hash."
: return)
let main (p, s : parameter * storage) : return =
match p with
| Commit c -> commit (c,s)
| Reveal r -> reveal (r,s)
"storage": {
"hashlock.tz": {
"commits": {
"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": {
"date": "2020-05-29T11:22:33Z",
"salted_hash": "0e2ab5866b0ec701a0204881645dc50e1d60668f1433a385e999f0af1b6cd8ce"
}
},
"hashed": "0e2ab5866b0ec701a0204881645dc50e1d60668f1433a385e999f0af1b6cd8ce",
"unused": true
}
}
Deployed counter.tz
(first contract) with storage value 2
and got back an address ("KT1UmYh9CnT8qFuVWLMtGkRSGqJhw5ERTY6d"
), which I used to specify as storage for countercaller.tz
(second contract) and deployed that, successfully.
parameter (or (int %decrement) (int %increment)) ;
storage int ;
code { DUP ;
CDR ;
SWAP ;
CAR ;
IF_LEFT { SWAP ; SUB } { ADD } ;
NIL operation ;
PAIR }
parameter (or int int);
storage address;
code {
DUP;
DUP;
CDR;
CONTRACT (or int int);
IF_NONE
{DROP; NIL operation }
{
SWAP;
CAR;
DIP {PUSH mutez 0};
TRANSFER_TOKENS;
DIP {NIL operation;};
CONS;
};
DIP { CDR };
PAIR }
As a Taqueria user I want to open, compile, test and deploy advanced sample smart contracts so that I can use more complex contracts in my project.
Definition of a advanced contract in relation to this issue
A single file smart contract with a complex initial storage or complex entrypoints
Acceptance Criteria