Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split translucent and blueprint.ts into distinct packages / First pass at monorepo setup #33

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ uplc/target
.env.*
seed.txt
package-lock.json
.vscode/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const translucent = await Translucent.new(
new Maestro({
network: "Mainnet",
apiKey: "<apikey>",
turboSubmit: true
turboSubmit: true,
}),
"Mainnet",
);
Expand Down
Binary file modified bun.lockb
Binary file not shown.
40 changes: 4 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
{
"name": "translucent-cardano",
"module": "index.ts",
"type": "module",
"version": "0.0.2",
"scripts": {
"build:wasm": "cd ./uplc && ./build.sh && rm pkg-node/.gitignore && rm pkg-web/.gitignore && cd .. && npm i"
},
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/sha256": "^0.2.2",
"bun-types": "latest",
"eslint": "^8.50.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"@cardano-ogmios/schema": "^6.0.0-rc6"
},
"dependencies": {
"@dcspark/cardano-multiplatform-lib-browser": "^3.1.2",
"@dcspark/cardano-multiplatform-lib-nodejs": "^3.1.2",
"@emurgo/cardano-message-signing-browser": "^1.0.1",
"@emurgo/cardano-message-signing-nodejs": "^1.0.1",
"@sinclair/typebox": "^0.31.28",
"fast-check": "^3.14.0",
"mathjs": "^12.2.1",
"prettier": "^3.1.1",
"sha256": "^0.2.0",
"uplc-node": "^0.0.2",
"uplc-web": "^0.0.2"
},
"browser": {
"./core/core.ts": "./core/core-browser.ts"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
"name": "translucent-monorepo",
"workspaces": [
"packages/*"
]
}
5 changes: 5 additions & 0 deletions packages/translucent-blueprint/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { parseBlueprint } from ".";

const args = Bun.argv.slice(2);

parseBlueprint(args[0], args[1]);
1 change: 1 addition & 0 deletions packages/translucent-blueprint/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src/blueprint";
9 changes: 9 additions & 0 deletions packages/translucent-blueprint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "translucent-blueprint",
"module": "index.ts",
"bin": {
"translucent-blueprint": "cli.ts"
},
"type": "module",
"version": "0.0.2"
}
2 changes: 0 additions & 2 deletions blueprint.ts → ...es/translucent-blueprint/src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,3 @@ import { applyParamsToScript, Data, Validator } from "../translucent/index.ts"`;
);
}
}

parseBlueprint("../../../on-chain/aiken/plutus.json", "plutus.ts");
26 changes: 26 additions & 0 deletions packages/translucent-blueprint/test/blueprint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { parseBlueprint } from "../src/blueprint";
import path from "path";
import expectedResult from "./fixtures/plutus-vesting.ts.txt";

jest.spyOn(Bun, "write").mockImplementation((path, data) => {
return Promise.resolve(data.toString().length);
});

it("should successfully parse any plutus.json", async () => {
const TARGET_FILENAME = "plutus.ts";

const plutusLocation = path.join(
import.meta.dir,
"./fixtures/plutus-vesting.json",
);
await parseBlueprint(plutusLocation, TARGET_FILENAME);

const writeMock = Bun.write as jest.MockedFunction<typeof Bun.write>;

expect(writeMock).toHaveBeenCalled();

const [writePath, writeData] = writeMock.mock.calls[0];

expect(writePath).toContain(TARGET_FILENAME);
expect(writeData).toEqual(expectedResult);
});
72 changes: 72 additions & 0 deletions packages/translucent-blueprint/test/fixtures/plutus-vesting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"preamble": {
"title": "aiken-lang/vesting",
"description": "Aiken contracts for project 'aiken-lang/vesting'",
"version": "0.0.0",
"plutusVersion": "v2",
"license": "Apache-2.0"
},
"validators": [
{
"title": "vesting.vesting",
"datum": {
"title": "datum",
"schema": {
"$ref": "#/definitions/vesting~1Datum"
}
},
"redeemer": {
"title": "_redeemer",
"schema": {
"$ref": "#/definitions/Void"
}
},
"compiledCode": "59020c01000032323232323232323232322223253330093232533300b3370e900100089919918008009129998088008a5013232533301000214a2266008008002602a00466e1d2002300f375460260026464646602666601e6600266016601a01090001bae3300b300d0074800930103d87a80004c0103d87980003301333300f332300100122533301400114a226464a6660260042660080080022940c060008cdc3a400460246ea8c058004cc04cccc03ccc004cc02cc0340212000375c66016601a00e900226103d87a80004c0103d87980003301333300f3322323253330133370e90010008991919b89005001375a603200260220042940c044004cc034c03ccc034c03c009200048000cc02cc034cc02cc034021200048038dd6998059806803a400098103d87a80004c0103d87980004bd7026103d87a80004c0103d87980004bd7011198019bac3300c300e00248040004c0040048894ccc04800852809919299980899b8f00200314a2266600a00a002006602c0066eb8c050008c0240085281804800998029803801240042930b1900219299980499b87480000044c8c8c8c8c8c94ccc048c05400852616375c602600260260046eb8c044004c044008dd6980780098038020b180380199800800a40004444666600e66e1c00400c0308cccc014014cdc000224004601c0020040044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881",
"hash": "9955364493da365b0e972b6bd28e20970b509a8f4d31016ee8976274"
}
],
"definitions": {
"ByteArray": {
"dataType": "bytes"
},
"Int": {
"dataType": "integer"
},
"Void": {
"title": "Unit",
"description": "The nullary constructor.",
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
},
"vesting/Datum": {
"title": "Datum",
"anyOf": [
{
"title": "Datum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "lock_until",
"description": "POSIX time in second, e.g. 1672843961000",
"$ref": "#/definitions/Int"
},
{
"title": "owner",
"$ref": "#/definitions/ByteArray"
},
{
"title": "beneficiary",
"$ref": "#/definitions/ByteArray"
}
]
}
]
}
}
}
14 changes: 14 additions & 0 deletions packages/translucent-blueprint/test/fixtures/plutus-vesting.ts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import { applyParamsToScript, Data, Validator } from "../translucent/index.ts"

export interface VestingVesting {
new (): Validator;
datum: {lockUntil:bigint;owner:string;beneficiary:string};
_redeemer: undefined;
};

export const VestingVesting = Object.assign(
function () {return {type: "PlutusV2", script: "59020c01000032323232323232323232322223253330093232533300b3370e900100089919918008009129998088008a5013232533301000214a2266008008002602a00466e1d2002300f375460260026464646602666601e6600266016601a01090001bae3300b300d0074800930103d87a80004c0103d87980003301333300f332300100122533301400114a226464a6660260042660080080022940c060008cdc3a400460246ea8c058004cc04cccc03ccc004cc02cc0340212000375c66016601a00e900226103d87a80004c0103d87980003301333300f3322323253330133370e90010008991919b89005001375a603200260220042940c044004cc034c03ccc034c03c009200048000cc02cc034cc02cc034021200048038dd6998059806803a400098103d87a80004c0103d87980004bd7026103d87a80004c0103d87980004bd7011198019bac3300c300e00248040004c0040048894ccc04800852809919299980899b8f00200314a2266600a00a002006602c0066eb8c050008c0240085281804800998029803801240042930b1900219299980499b87480000044c8c8c8c8c8c94ccc048c05400852616375c602600260260046eb8c044004c044008dd6980780098038020b180380199800800a40004444666600e66e1c00400c0308cccc014014cdc000224004601c0020040044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881"};},
{datum: {"title":"Datum","anyOf":[{"title":"Datum","dataType":"constructor","index":0,"fields":[{"dataType":"integer","title":"lockUntil"},{"dataType":"bytes","title":"owner"},{"dataType":"bytes","title":"beneficiary"}]}]}},
{_redeemer: {"title":"Unit","description":"The nullary constructor.","anyOf":[{"dataType":"constructor","index":0,"fields":[]}]}},
) as unknown as VestingVesting;
File renamed without changes.
38 changes: 38 additions & 0 deletions packages/translucent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "translucent-cardano",
"module": "index.ts",
"type": "module",
"version": "0.0.2",
"scripts": {
"build:wasm": "cd ./uplc && ./build.sh && rm pkg-node/.gitignore && rm pkg-web/.gitignore && cd .. && npm i"
},
"devDependencies": {
"@types/jest": "^29.5.5",
"@types/sha256": "^0.2.2",
"bun-types": "latest",
"eslint": "^8.50.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"@cardano-ogmios/schema": "^6.0.0-rc6"
},
"dependencies": {
"@dcspark/cardano-multiplatform-lib-browser": "^3.1.2",
"@dcspark/cardano-multiplatform-lib-nodejs": "^3.1.2",
"@emurgo/cardano-message-signing-browser": "^1.0.1",
"@emurgo/cardano-message-signing-nodejs": "^1.0.1",
"@sinclair/typebox": "^0.31.28",
"fast-check": "^3.14.0",
"mathjs": "^12.2.1",
"prettier": "^3.1.1",
"sha256": "^0.2.0",
"uplc-node": "^0.0.2",
"uplc-web": "^0.0.2"
},
"browser": {
"./core/core.ts": "./core/core-browser.ts"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class Maestro implements Provider {
method: "POST",
headers: {
"Content-Type": "application/json",
...(this.requireAmountsAsStrings(this.commonHeaders())),
...this.requireAmountsAsStrings(this.commonHeaders()),
},
body: body,
}),
Expand Down Expand Up @@ -280,7 +280,10 @@ export class Maestro implements Provider {
return { "api-key": this.apiKey, translucent: packageJson.version };
}

private requireAmountsAsStrings(obj: { "api-key": string; translucent: string }) {
private requireAmountsAsStrings(obj: {
"api-key": string;
translucent: string;
}) {
return { ...obj, "amounts-as-strings": "true" };
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"esModuleInterop": true
},
"exclude": ["node_modules"],
"include": ["src/**/*.ts", "tests/**/*.ts", "*.json"]
"include": ["packages/**/*.ts", "*.json"]
}
Loading