I just pushed a documentation update to
(and a couple of other related documentation pages) reflecting some significant changes in SimplicityHL 0.7.0: type inference in witness parsing and enum types.
You can see these in action in my prize claim contract where I declare
enum Action {
Update,
Claim(u64, u64),
}
and later on do
match witness::ACTION {
Action::Update => update(dest_addr_script_hash),
Action::Claim(p: u64, q: u64) => claim(dest_addr_script_hash, p, q),
}
… much cleaner than the historical Left() and Right() branches that we would have to use to match on an Either<> type in the witness.
The corresponding .wit files now look like
{
"DEST_ADDR_SCRIPT_HASH": "0xbcfbe70502021903755bb406a7c4681817be317affc7d1120de2041a9e06cfc5",
"ACTION": "Action::Claim(17041427052385644731, 18305655359241496139)"
}
and
{
"DEST_ADDR_SCRIPT_HASH": "0xbcfbe70502021903755bb406a7c4681817be317affc7d1120de2041a9e06cfc5",
"ACTION": "Action::Update"
}
so they’re also more concise and readable both due to type inference and the enum feature.
The last_will.simf example covenant has also been updated to use these features.
enum Action {
Inherit(Signature),
ColdSpend(Signature),
HotSpend(Signature),
}
fn main() {
match witness::ACTION {
Action::Inherit(sig: Signature) => inherit_spend(sig),
Action::ColdSpend(sig: Signature) => cold_spend(sig),
Action::HotSpend(sig: Signature) => refresh_spend(sig),
}
}
with the witness simplified to just
{
"ACTION": "Action::Inherit(0x755201bb62b0a8b8d18fd12fc02951ea3998ba42bfc6664daaf8a0d2298cad43cdc21358c7c82f37654275dc2fea8c858adbe97bac92828b498a5a237004db6f)"
}
Anyway, hopefully it will be fairly clear from these examples how to use these new features to write much more concise and readable contracts (you currently need SimplicityHL 0.7.0 and need to compile with -Z enums). The exact details are all up on the documentation site.