-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store path: /nix/store/myiv3b32cmbq17zkvq97z9y52n1w0py5-lambda-buffers-book
- Loading branch information
1 parent
65b0b60
commit 4f6b0a9
Showing
18 changed files
with
867 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extra-dependencies/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module MySchema | ||
|
||
import Plutus.V1 | ||
import Prelude (Eq, Json) | ||
|
||
sum Branchy a | ||
= Node PlutusData (Extended (Branchy a)) | ||
| Leaf a | ||
|
||
|
||
derive Json (Branchy a) | ||
derive Eq (Branchy a) | ||
derive PlutusData (Branchy a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
_: | ||
{ | ||
perSystem = { config, ... }: | ||
let | ||
tsFlake = | ||
config.lbf-nix.lbfPlutusTypescript { | ||
name = "lbf-plutus-sample-project"; | ||
src = ./.; | ||
files = [ "MySchema.lbf" ]; | ||
}; | ||
in | ||
{ | ||
packages = { | ||
inherit (tsFlake.packages) lbf-plutus-sample-project-typescript lbf-plutus-sample-project-typescript-tgz; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ inputs, ... }: | ||
{ | ||
imports = [ ./api/lbf/build.nix ]; | ||
|
||
perSystem = { config, system, ... }: | ||
let | ||
tsFlake = | ||
inputs.flake-lang.lib.${system}.typescriptFlake { | ||
name = "plutus-sample-project"; | ||
src = ./.; | ||
|
||
npmExtraDependencies = [ | ||
config.packages.lbf-plutus-sample-project-typescript-tgz | ||
]; | ||
|
||
devShellTools = config.settings.shell.tools; | ||
devShellHook = config.settings.shell.hook; | ||
}; | ||
in | ||
{ | ||
packages = { | ||
inherit (tsFlake.packages) plutus-sample-project-typescript plutus-sample-project-typescript-tgz; | ||
}; | ||
|
||
inherit (tsFlake) devShells checks; | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "lambda-buffers-prelude-sample-project", | ||
"version": "1.0.0", | ||
"description": "Sample project for LambdaBuffers", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/index.mjs", | ||
"./package.json": "./package.json" | ||
}, | ||
"scripts": { | ||
"build": "npx tsc -b src/", | ||
"test": ":" | ||
}, | ||
"author": "Jared Pon", | ||
"license": "ISC", | ||
"files": [ | ||
"./dist/**/*", | ||
"./.extra-dependencies/**/*" | ||
], | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
}, | ||
"dependencies": { | ||
"lbf-plutus": "file:.extra-dependencies/lbf-plutus-1.0.0.tgz", | ||
"lbf-plutus-sample-project": "file:.extra-dependencies/lbf-plutus-sample-project-1.0.0.tgz", | ||
"lbf-prelude": "file:.extra-dependencies/lbf-prelude-1.0.0.tgz", | ||
"lbr-plutus": "file:.extra-dependencies/lbr-plutus-1.0.0.tgz", | ||
"lbr-prelude": "file:.extra-dependencies/lbr-prelude-1.0.0.tgz", | ||
"plutus-ledger-api": "file:.extra-dependencies/plutus-ledger-api-1.0.0.tgz", | ||
"prelude": "file:.extra-dependencies/prelude-1.0.1.tgz" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Simple plutus sample project. | ||
// To run, type | ||
// ``` | ||
// npm run build && node ./dist/src/index.mjs | ||
// ``` | ||
import * as LbrPlutusV1 from "lbr-plutus/V1.js"; | ||
import * as LbrPlutusPd from "lbr-plutus/PlutusData.js"; | ||
import * as LbrPrelude from "lbr-prelude"; | ||
import * as Prelude from "prelude"; | ||
import * as MySchema from "lbf-plutus-sample-project/LambdaBuffers/MySchema.mjs"; | ||
|
||
const pubKeyHash: LbrPlutusV1.PubKeyHash = new Uint8Array([ | ||
0, | ||
0, | ||
]) as LbrPlutusV1.PubKeyHash; | ||
|
||
const cred: LbrPlutusV1.Credential = { | ||
name: "PubKeyCredential", | ||
fields: pubKeyHash, | ||
}; | ||
|
||
console.log(`Some samples of PubKeyHash and Credential`); | ||
console.log(pubKeyHash); | ||
console.log(cred); | ||
|
||
// Printing the leafy type | ||
console.log(`The Leaf constructor`); | ||
const leaf: MySchema.Branchy<LbrPlutusV1.Credential> = { | ||
name: "Leaf", | ||
fields: cred, | ||
}; | ||
const leafpd: LbrPlutusV1.PlutusData = LbrPlutusPd.IsPlutusData | ||
[MySchema.Branchy]( | ||
LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential], | ||
).toData(leaf); | ||
|
||
console.log(leafpd); | ||
console.log( | ||
`Prelude.Json: ${ | ||
Prelude.stringify( | ||
LbrPrelude.Json[MySchema.Branchy](LbrPrelude.Json[LbrPlutusV1.Credential]) | ||
.toJson(leaf), | ||
) | ||
}`, | ||
); | ||
console.log( | ||
`Prelude.Json: ${ | ||
Prelude.stringify(LbrPrelude.Json[LbrPlutusV1.PlutusData].toJson(leafpd)) | ||
}`, | ||
); | ||
|
||
console.log("fromData:"); | ||
console.log( | ||
LbrPlutusPd.IsPlutusData[MySchema.Branchy]( | ||
LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential], | ||
).fromData(leafpd), | ||
); | ||
|
||
// Printing the branchy | ||
console.log(`The Node constructor`); | ||
const branchy: MySchema.Branchy<LbrPlutusV1.Credential> = { | ||
name: "Node", | ||
fields: [leafpd, { name: "Finite", fields: leaf }], | ||
}; | ||
const branchypd: LbrPlutusV1.PlutusData = LbrPlutusPd.IsPlutusData | ||
[MySchema.Branchy](LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential]).toData( | ||
branchy, | ||
); | ||
|
||
console.log("toData:"); | ||
console.log(branchypd); | ||
|
||
console.log( | ||
`Prelude.Json: ${ | ||
Prelude.stringify( | ||
LbrPrelude.Json[MySchema.Branchy](LbrPrelude.Json[LbrPlutusV1.Credential]) | ||
.toJson(branchy), | ||
) | ||
}`, | ||
); | ||
console.log( | ||
`Prelude.Json: ${ | ||
Prelude.stringify(LbrPrelude.Json[LbrPlutusV1.PlutusData].toJson(branchypd)) | ||
}`, | ||
); | ||
|
||
console.log("fromData:"); | ||
console.log( | ||
LbrPlutusPd.IsPlutusData[MySchema.Branchy]( | ||
LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential], | ||
).fromData(branchypd), | ||
); | ||
|
||
// Printing the Eq | ||
console.log( | ||
`branchy is branchy: ${ | ||
LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).eq( | ||
branchy, | ||
branchy, | ||
) | ||
}`, | ||
); | ||
console.log( | ||
`branchy is not branchy: ${ | ||
LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).neq( | ||
branchy, | ||
branchy, | ||
) | ||
}`, | ||
); | ||
console.log( | ||
`branchy is leaf: ${ | ||
LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).eq( | ||
branchy, | ||
leaf, | ||
) | ||
}`, | ||
); | ||
console.log( | ||
`branchy is not leaf: ${ | ||
LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).neq( | ||
branchy, | ||
leaf, | ||
) | ||
}`, | ||
); |
Oops, something went wrong.