Skip to content

Commit

Permalink
setter for config
Browse files Browse the repository at this point in the history
  • Loading branch information
christianschmitz committed Aug 4, 2023
1 parent f061516 commit c98875c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 15 deletions.
13 changes: 12 additions & 1 deletion helios-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ declare module "helios" {
/**
* Current version of the Helios library.
*/
export const VERSION: "0.15.1";
export const VERSION: "0.15.2";
/**
* A tab used for indenting of the IR.
* 2 spaces.
Expand All @@ -848,6 +848,17 @@ declare module "helios" {
*/
export const REAL_PRECISION: number;
export namespace config {
function set(props: {
DEBUG?: boolean;
STRICT_BABBAGE?: boolean;
IS_TESTNET?: boolean;
N_DUMMY_INPUTS?: number;
AUTO_SET_VALIDITY_RANGE?: boolean;
VALIDITY_RANGE_START_OFFSET?: number;
VALIDITY_RANGE_END_OFFSET?: number;
EXPERIMENTAL_CEK?: boolean;
IGNORE_UNEVALUATED_CONSTANTS?: boolean;
}): void;
const DEBUG: boolean;
const STRICT_BABBAGE: boolean;
const IS_TESTNET: boolean;
Expand Down
29 changes: 27 additions & 2 deletions helios.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,37 @@ export function highlight(src: string): Uint8Array;
/**
* Current version of the Helios library.
*/
export const VERSION: "0.15.1";
export const VERSION: "0.15.2";
/**
* Mutable global config variables.
* Mutable global config properties.
* @namespace
*/
export namespace config {
/**
* Modify the config properties
* @param {{
* DEBUG?: boolean
* STRICT_BABBAGE?: boolean
* IS_TESTNET?: boolean
* N_DUMMY_INPUTS?: number
* AUTO_SET_VALIDITY_RANGE?: boolean
* VALIDITY_RANGE_START_OFFSET?: number
* VALIDITY_RANGE_END_OFFSET?: number
* EXPERIMENTAL_CEK?: boolean
* IGNORE_UNEVALUATED_CONSTANTS?: boolean
* }} props
*/
function set(props: {
DEBUG?: boolean;
STRICT_BABBAGE?: boolean;
IS_TESTNET?: boolean;
N_DUMMY_INPUTS?: number;
AUTO_SET_VALIDITY_RANGE?: boolean;
VALIDITY_RANGE_START_OFFSET?: number;
VALIDITY_RANGE_END_OFFSET?: number;
EXPERIMENTAL_CEK?: boolean;
IGNORE_UNEVALUATED_CONSTANTS?: boolean;
}): void;
/**
* Global debug flag. Currently unused.
*
Expand Down
26 changes: 23 additions & 3 deletions helios.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Email: cschmitz398@gmail.com
// Website: https://www.hyperion-bt.org
// Repository: https://github.com/hyperion-bt/helios
// Version: 0.15.1
// Version: 0.15.2
// Last update: August 2023
// License type: BSD-3-Clause
//
Expand Down Expand Up @@ -298,7 +298,7 @@
/**
* Current version of the Helios library.
*/
export const VERSION = "0.15.1";
export const VERSION = "0.15.2";

/**
* A tab used for indenting of the IR.
Expand All @@ -316,10 +316,30 @@ export const TAB = " ";
export const REAL_PRECISION = 6;

/**
* Mutable global config variables.
* Mutable global config properties.
* @namespace
*/
export const config = {
/**
* Modify the config properties
* @param {{
* DEBUG?: boolean
* STRICT_BABBAGE?: boolean
* IS_TESTNET?: boolean
* N_DUMMY_INPUTS?: number
* AUTO_SET_VALIDITY_RANGE?: boolean
* VALIDITY_RANGE_START_OFFSET?: number
* VALIDITY_RANGE_END_OFFSET?: number
* EXPERIMENTAL_CEK?: boolean
* IGNORE_UNEVALUATED_CONSTANTS?: boolean
* }} props
*/
set: (props) => {
Object.keys(props).forEach(k => {
config[k] = props[k];
});
},

/**
* Global debug flag. Currently unused.
*
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hyperionbt/helios",
"type": "module",
"version": "0.15.1",
"version": "0.15.2",
"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.",
"main": "helios.js",
"types": "helios.d.ts",
Expand Down
22 changes: 21 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@ export const TAB = " ";
export const REAL_PRECISION = 6;

/**
* Mutable global config variables.
* Mutable global config properties.
* @namespace
*/
export const config = {
/**
* Modify the config properties
* @param {{
* DEBUG?: boolean
* STRICT_BABBAGE?: boolean
* IS_TESTNET?: boolean
* N_DUMMY_INPUTS?: number
* AUTO_SET_VALIDITY_RANGE?: boolean
* VALIDITY_RANGE_START_OFFSET?: number
* VALIDITY_RANGE_END_OFFSET?: number
* EXPERIMENTAL_CEK?: boolean
* IGNORE_UNEVALUATED_CONSTANTS?: boolean
* }} props
*/
set: (props) => {
Object.keys(props).forEach(k => {
config[k] = props[k];
});
},

/**
* Global debug flag. Currently unused.
*
Expand Down
4 changes: 2 additions & 2 deletions test/addresses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ async function scriptAddress() {
}

async function nonTestnetAddress() {
config.IS_TESTNET = false;
config.set({IS_TESTNET: false});

const addr = Address.fromHashes(new PubKeyHash("01020304050607080910111213141516171819202122232425262728"))

console.log(addr.toBech32());

assert(addr.toBech32().startsWith("addr1"));

config.IS_TESTNET = true;
config.set({IS_TESTNET: true});
}

async function addressInDatum() {
Expand Down
2 changes: 1 addition & 1 deletion test/example-scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
extractScriptPurposeAndName
} from "helios"

config.EXPERIMENTAL_CEK = true;
config.set({EXPERIMENTAL_CEK: true});

export default async function main() {
async function runTestScriptWithArgs(src, argNames, expectedResult, expectedMessages) {
Expand Down
2 changes: 1 addition & 1 deletion test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion utils/strip-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,22 +401,24 @@ function injectNamespaceDoclets(src, doclets) {
}
} else {
if (braceCount == 1 && l.trim().startsWith("const") || l.trim().startsWith("function")) {


const m = l.match(/^\s*const\s*([a-zA-Z_][a-zA-Z_0-9]*)\s*:/m)
if (m) {
const memberName = m[1]

if (namespaceName in doclets && memberName in doclets[namespaceName]) {
braceCount += countBraces(l)
return doclets[namespaceName][memberName] + "\n" + l
}
} else {

const m = l.match(/^\s*function\s*([a-zA-Z_][a-zA-Z_0-9]*)\s*\(/m)

if (m) {
const memberName = m[1]

if (namespaceName in doclets && memberName in doclets[namespaceName]) {
braceCount += countBraces(l)
return doclets[namespaceName][memberName] + "\n" + l
}
}
Expand Down

0 comments on commit c98875c

Please sign in to comment.