@hyperionbt/helios
Advanced tools
Comparing version 0.13.29 to 0.13.30
This Changelog only applies to notable changes of language related features in `helios.js` on the main branch. | ||
# 2023/04/29 | ||
* `List.drop`, `.take`, `.drop_end` and `.take_end` implemented | ||
# 2023/04/27 | ||
@@ -4,0 +7,0 @@ * `Real` fixed point number type with most basic math operators |
@@ -217,3 +217,4 @@ # Overview | ||
getters: length, head, tail | ||
methods: serialize, is_empty, get, prepend, any, all, find, find_safe, filter, fold, fold_lazy, map, sort, for_each, get_singleton | ||
methods: serialize, is_empty, get, prepend, any, all, find, find_safe, filter, fold, fold_lazy, | ||
map, sort, for_each, get_singleton, drop, take, drop_end, take_end | ||
internal ns: __helios__list | ||
@@ -220,0 +221,0 @@ ``` |
{ | ||
"name": "@hyperionbt/helios", | ||
"type": "module", | ||
"version": "0.13.29", | ||
"version": "0.13.30", | ||
"description": "Helios is a Domain Specific Language that compiles to Plutus-Core (i.e. Cardano on-chain validator scripts). Helios is a non-Haskell alternative to Plutus. With this library you can compile Helios scripts and build Cardano transactions, all you need to build 100% client-side dApps for Cardano.", | ||
@@ -6,0 +6,0 @@ "main": "helios.js", |
@@ -61,5 +61,5 @@ //@ts-check | ||
*/ | ||
AUTO_SET_VALIDITY_RANGE: true, | ||
AUTO_SET_VALIDITY_RANGE: false, | ||
VALIDITY_RANGE_START_OFFSET: 60, // seconds | ||
VALIDITY_RANGE_END_OFFSET: 300 // seconds | ||
} |
@@ -32,103 +32,209 @@ #!/usr/bin/env node | ||
const MULTI_NFT = ` | ||
minting multi_nft | ||
async function test1() { | ||
const src = ` | ||
minting multi_nft | ||
// a single transaction allows multiple minting policies to be used | ||
// PREC_NFT is empty for the base multi_nft minting policy, | ||
// but can be set to the minting policy hash of the base multi_nft minting policy, and so forth, | ||
// if you want to mint multiple batches of the tokens (each batch having a different minting policy hash of course) | ||
const PREC_NFT = # | ||
// a single transaction allows multiple minting policies to be used | ||
// PREC_NFT is empty for the base multi_nft minting policy, | ||
// but can be set to the minting policy hash of the base multi_nft minting policy, and so forth, | ||
// if you want to mint multiple batches of the tokens (each batch having a different minting policy hash of course) | ||
const PREC_NFT = # | ||
enum Redeemer { | ||
Mint { | ||
ref: TxOutputId | ||
enum Redeemer { | ||
Mint { | ||
ref: TxOutputId | ||
} | ||
Burn | ||
} | ||
Burn | ||
} | ||
func main(redeemer: Redeemer, ctx: ScriptContext) -> Bool { | ||
tx: Tx = ctx.tx; | ||
func main(redeemer: Redeemer, ctx: ScriptContext) -> Bool { | ||
tx: Tx = ctx.tx; | ||
mph: MintingPolicyHash = ctx.get_current_minting_policy_hash(); | ||
mph: MintingPolicyHash = ctx.get_current_minting_policy_hash(); | ||
redeemer.switch { | ||
Burn => { | ||
tx.minted.get_policy(mph).all((_, qty: Int) -> Bool { | ||
qty == -1 | ||
}) | ||
}, | ||
m: Mint => { | ||
token_name_suffix: ByteArray = m.ref.serialize().sha3().slice(1, -1); | ||
redeemer.switch { | ||
Burn => { | ||
tx.minted.get_policy(mph).all((_, qty: Int) -> Bool { | ||
qty == -1 | ||
}) | ||
}, | ||
m: Mint => { | ||
token_name_suffix: ByteArray = m.ref.serialize().sha3().slice(1, -1); | ||
// value.get_policy() returns a map of tokens in value | ||
mint_map: Map[ByteArray]Int = tx.minted.get_policy(mph); | ||
// value.get_policy() returns a map of tokens in value | ||
mint_map: Map[ByteArray]Int = tx.minted.get_policy(mph); | ||
// check that all minted tokens have the required suffix | ||
mint_map.all((k: ByteArray, qty: Int) -> Bool { | ||
qty == 1 && k.ends_with(token_name_suffix) | ||
}) && (PREC_NFT == # || mint_map == tx.minted.get_policy(MintingPolicyHash::new(PREC_NFT))) && ( | ||
tx.inputs.any((input: TxInput) -> Bool { | ||
input.output_id == m.ref | ||
}) | ||
) | ||
} | ||
} | ||
} | ||
// check that all minted tokens have the required suffix | ||
mint_map.all((k: ByteArray, qty: Int) -> Bool { | ||
qty == 1 && k.ends_with(token_name_suffix) | ||
}) && (PREC_NFT == # || mint_map == tx.minted.get_policy(MintingPolicyHash::new(PREC_NFT))) && ( | ||
tx.inputs.any((input: TxInput) -> Bool { | ||
input.output_id == m.ref | ||
}) | ||
) | ||
} | ||
} | ||
} | ||
// const for reference profiling | ||
// const for reference profiling | ||
const PKH: PubKeyHash = PubKeyHash::new(#01234567890123456789012345678901234567890123456789012345) | ||
const PKH: PubKeyHash = PubKeyHash::new(#01234567890123456789012345678901234567890123456789012345) | ||
const ADDRESS: Address = Address::new(Credential::new_pubkey(PKH), Option[StakingCredential]::None) | ||
const ADDRESS: Address = Address::new(Credential::new_pubkey(PKH), Option[StakingCredential]::None) | ||
const IN_VALUE: Value = Value::lovelace(1000000) | ||
const IN_VALUE: Value = Value::lovelace(1000000) | ||
const REF_ID: TxOutputId = TxOutputId::new(TxId::new(#0123456789012345678901234567890123456789012345678901234567891234), 0) | ||
const REF_ID: TxOutputId = TxOutputId::new(TxId::new(#0123456789012345678901234567890123456789012345678901234567891234), 0) | ||
const MINTED: Value = Value::new(AssetClass::new(MintingPolicyHash::CURRENT, #01 + REF_ID.serialize().sha3().slice(1, -1)), 1) | ||
const MINTED: Value = Value::new(AssetClass::new(MintingPolicyHash::CURRENT, #01 + REF_ID.serialize().sha3().slice(1, -1)), 1) | ||
const OUT_VALUE: Value = IN_VALUE + MINTED | ||
const OUT_VALUE: Value = IN_VALUE + MINTED | ||
const NEW_ID: TxOutputId = TxOutputId::new(TxId::new(#1123456789012345678901234567890123456789012345678901234567891234), 0) | ||
const NEW_ID: TxOutputId = TxOutputId::new(TxId::new(#1123456789012345678901234567890123456789012345678901234567891234), 0) | ||
const REDEEMER = Redeemer::Mint{REF_ID} | ||
const REDEEMER = Redeemer::Mint{REF_ID} | ||
struct Datum { | ||
a: Int | ||
struct Datum { | ||
a: Int | ||
} | ||
const SCRIPT_CONTEXT: ScriptContext = ScriptContext::new_minting(Tx::new( | ||
[]TxInput{TxInput::new(REF_ID, TxOutput::new(ADDRESS, IN_VALUE, OutputDatum::new_none()))}, | ||
[]TxInput{}, | ||
[]TxOutput{TxOutput::new(ADDRESS, OUT_VALUE, OutputDatum::new_none())}, | ||
Value::lovelace(160000), | ||
MINTED, | ||
[]DCert{}, | ||
Map[StakingCredential]Int{}, | ||
TimeRange::ALWAYS, | ||
[]PubKeyHash{}, | ||
Map[ScriptPurpose]Int{}, | ||
Map[DatumHash]Data{} | ||
), MintingPolicyHash::CURRENT)`; | ||
await profile(src, ["REDEEMER", "SCRIPT_CONTEXT"]); | ||
} | ||
const SCRIPT_CONTEXT: ScriptContext = ScriptContext::new_minting(Tx::new( | ||
[]TxInput{TxInput::new(REF_ID, TxOutput::new(ADDRESS, IN_VALUE, OutputDatum::new_none()))}, | ||
[]TxInput{}, | ||
[]TxOutput{TxOutput::new(ADDRESS, OUT_VALUE, OutputDatum::new_none())}, | ||
Value::lovelace(160000), | ||
MINTED, | ||
[]DCert{}, | ||
Map[StakingCredential]Int{}, | ||
TimeRange::ALWAYS, | ||
[]PubKeyHash{}, | ||
Map[ScriptPurpose]Int{}, | ||
Map[DatumHash]Data{} | ||
), MintingPolicyHash::CURRENT)`; | ||
async function test2() { | ||
const src = ` | ||
spending single_datum | ||
struct Datum { | ||
int: Int | ||
} | ||
func main(datum: Datum, _, _) -> Bool { | ||
print(datum.int.show()); | ||
true | ||
} | ||
const DATUM = Datum{10} | ||
` | ||
const SINGLE_DATUM = ` | ||
spending single_datum | ||
struct Datum { | ||
int: Int | ||
await profile(src, ["DATUM"]); | ||
} | ||
func main(datum: Datum, _, _) -> Bool { | ||
print(datum.int.show()); | ||
true | ||
async function test3() { | ||
const LIST = `[]Int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}`; | ||
console.log("profiling list.length"); | ||
await profile(` | ||
testing list_length | ||
func main(list: []Int) -> Int { | ||
list.length | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
console.log("profiling list.drop"); | ||
await profile(` | ||
testing list_drop | ||
func main(list: []Int) -> []Int { | ||
list.drop(2) | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
console.log("profiling list.take"); | ||
await profile(` | ||
testing list_take | ||
func main(list: []Int) -> []Int { | ||
list.take(2) | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
console.log("profiling list.take combined with list.length"); | ||
await profile(` | ||
testing list_length_and_take | ||
func main(list: []Int) -> []Int { | ||
n: Int = list.length; | ||
list.take(n-2) | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
console.log("profiling list.drop_end"); | ||
await profile(` | ||
testing list_drop_end | ||
func main(list: []Int) -> []Int { | ||
list.drop_end(2) | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
console.log("profiling list.drop with list.length"); | ||
await profile(` | ||
testing list_length_and_drop | ||
func main(list: []Int) -> []Int { | ||
n: Int = list.length; | ||
list.drop(n-2) | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
console.log("profiling list.take_end"); | ||
await profile(` | ||
testing list_take_end | ||
func main(list: []Int) -> []Int { | ||
list.take_end(2) | ||
} | ||
const LIST = ${LIST} | ||
`, ["LIST"]); | ||
} | ||
const DATUM = Datum{10} | ||
` | ||
export default async function main() { | ||
await profile(MULTI_NFT, ["REDEEMER", "SCRIPT_CONTEXT"]); | ||
await test1(); | ||
await profile(SINGLE_DATUM, ["DATUM"]); | ||
await test2(); | ||
await test3(); | ||
// exbudget/size used to be: {mem: 51795n, cpu: 31933326n, size: 367} (when get_policy().all_values(...) was being used). TODO: become that good again | ||
@@ -135,0 +241,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4978635
97055