Skip to content

Commit

Permalink
Merge pull request #7 from MeshJS/feature/blueprint-utils
Browse files Browse the repository at this point in the history
feat: wip
  • Loading branch information
SIDANWhatever committed Apr 8, 2024
2 parents faf8df6 + a33cee2 commit 11361ae
Show file tree
Hide file tree
Showing 12 changed files with 1,191 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
- run: yarn ci
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@meshsdk/mesh-csl",
"description": "Cardano Off-chain Code APIs built on cardano-serialization-lib",
"version": "0.0.1-beta.2",
"version": "0.0.1-beta.3",
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down Expand Up @@ -44,12 +44,14 @@
"@sidan-lab/sidan-csl-rs-browser": "^0.2.6-beta3",
"@sidan-lab/sidan-csl-rs-nodejs": "^0.2.6-beta3",
"@types/node": "^18.16.3",
"blakejs": "^1.2.1"
"blakejs": "^1.2.1",
"json-bigint": "^1.0.0"
},
"devDependencies": {
"@commitlint/cli": "^17.4.3",
"@commitlint/config-conventional": "^17.4.3",
"@types/jest": "^29.5.1",
"@types/json-bigint": "^1.0.4",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"commitlint": "^17.4.3",
Expand Down
11 changes: 6 additions & 5 deletions src/core/type/blueprint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Plutus from './plutus';

/* eslint-disable @typescript-eslint/no-explicit-any */
export type PreambleType = {
title: string;
description: string;
Expand Down Expand Up @@ -36,6 +35,8 @@ export type BPValidator<D, R, P> = {
hash: string;
};

export type ByteArray = Plutus.BuiltinByteString;
export type Int = Plutus.Integer;
export type Constructor<N, T> = Plutus.ConStr<N, T>;
export type RawBlueprint = {
preamble: PreambleType;
validators: BPValidator<string, string, string>[];
definitions: any[];
};
8 changes: 4 additions & 4 deletions src/core/type/plutus.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-use-before-define */
/* eslint-disable @typescript-eslint/no-explicit-any */

export type ConStr<N, T> = { constructor: N; fields: T };
export type ConStr0<T> = ConStr<0, T>;
export type ConStr1<T> = ConStr<1, T>;
export type ConStr2<T> = ConStr<2, T>;
export type ConStr<N = any, T = any> = { constructor: N; fields: T };
export type ConStr0<T = any> = ConStr<0, T>;
export type ConStr1<T = any> = ConStr<1, T>;
export type ConStr2<T = any> = ConStr<2, T>;
export type Bool = ConStr0<[]> | ConStr1<[]>;
export type BuiltinByteString = { bytes: string };
export type Integer = { int: number };
Expand Down
11 changes: 11 additions & 0 deletions src/core/utils/aiken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ export const applyParamsToScript = (rawAikenScriptBlueprint: string, params: str
});
return csl.apply_params_to_script(cslParams, rawAikenScriptBlueprint);
};

export const applyObjParamsToScript = <T extends object>(
rawAikenScriptBlueprint: string,
params: T[],
): string => {
const cslParams = csl.JsVecString.new();
params.forEach((param) => {
cslParams.add(JSON.stringify(param));
});
return csl.apply_params_to_script(cslParams, rawAikenScriptBlueprint);
};
69 changes: 69 additions & 0 deletions src/core/utils/blueprint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable max-classes-per-file */

import { BuiltinByteString, ConStr, Integer } from '../type';

export class ByteArray {
public bytes: string = '';

constructor(bytes?: string) {
if (bytes) this.bytes = bytes;
}

public toObject(): BuiltinByteString {
return {
bytes: this.bytes,
};
}
}

export class Int {
public int: number = 0;

constructor(int?: number) {
if (int) this.int = int;
}

public toObject(): Integer {
return {
int: this.int,
};
}
}

export class Constructor {
public conStr: number = 0;

public fields: any[] = [];

constructor(conStr: number, fields: any[]) {
if (conStr) this.conStr = conStr;
if (fields) this.fields = fields;
}

public toObject(): ConStr {
return {
constructor: this.conStr,
fields: this.fields,
};
}
}

export type BlueprintDefinition = Constructor | ByteArray | Int;

export const parseBlueprintDefinition = (item: any, args = []): Constructor | ByteArray | Int => {
switch (item.dataType) {
case 'bytes':
return new ByteArray(...args);
case 'integer':
return new Int(...args);
// case 'constructor':
// return Constructor;
default:
throw new Error(`Unknown data type: ${item.dataType}`);
}
};

// export class MeshBlueprint {
// constructor() {}
// }
1 change: 1 addition & 0 deletions src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './credentials';
export * from './staking';
export * from './transaction';
export * from './aiken';
export * from './blueprint';

0 comments on commit 11361ae

Please sign in to comment.