|
| 1 | +// Simple plutus sample project. |
| 2 | +// To run, type |
| 3 | +// ``` |
| 4 | +// npm run build && node ./dist/src/index.mjs |
| 5 | +// ``` |
| 6 | +import * as LbrPlutusV1 from "lbr-plutus/V1.js"; |
| 7 | +import * as LbrPlutusPd from "lbr-plutus/PlutusData.js"; |
| 8 | +import * as LbrPrelude from "lbr-prelude"; |
| 9 | +import * as Prelude from "prelude"; |
| 10 | +import * as MySchema from "lbf-plutus-sample-project/LambdaBuffers/MySchema.mjs"; |
| 11 | + |
| 12 | +const pubKeyHash: LbrPlutusV1.PubKeyHash = new Uint8Array([ |
| 13 | + 0, |
| 14 | + 0, |
| 15 | +]) as LbrPlutusV1.PubKeyHash; |
| 16 | + |
| 17 | +const cred: LbrPlutusV1.Credential = { |
| 18 | + name: "PubKeyCredential", |
| 19 | + fields: pubKeyHash, |
| 20 | +}; |
| 21 | + |
| 22 | +console.log(`Some samples of PubKeyHash and Credential`); |
| 23 | +console.log(pubKeyHash); |
| 24 | +console.log(cred); |
| 25 | + |
| 26 | +// Printing the leafy type |
| 27 | +console.log(`The Leaf constructor`); |
| 28 | +const leaf: MySchema.Branchy<LbrPlutusV1.Credential> = { |
| 29 | + name: "Leaf", |
| 30 | + fields: cred, |
| 31 | +}; |
| 32 | +const leafpd: LbrPlutusV1.PlutusData = LbrPlutusPd.IsPlutusData |
| 33 | + [MySchema.Branchy]( |
| 34 | + LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential], |
| 35 | + ).toData(leaf); |
| 36 | + |
| 37 | +console.log(leafpd); |
| 38 | +console.log( |
| 39 | + `Prelude.Json: ${ |
| 40 | + Prelude.stringify( |
| 41 | + LbrPrelude.Json[MySchema.Branchy](LbrPrelude.Json[LbrPlutusV1.Credential]) |
| 42 | + .toJson(leaf), |
| 43 | + ) |
| 44 | + }`, |
| 45 | +); |
| 46 | +console.log( |
| 47 | + `Prelude.Json: ${ |
| 48 | + Prelude.stringify(LbrPrelude.Json[LbrPlutusV1.PlutusData].toJson(leafpd)) |
| 49 | + }`, |
| 50 | +); |
| 51 | + |
| 52 | +console.log("fromData:"); |
| 53 | +console.log( |
| 54 | + LbrPlutusPd.IsPlutusData[MySchema.Branchy]( |
| 55 | + LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential], |
| 56 | + ).fromData(leafpd), |
| 57 | +); |
| 58 | + |
| 59 | +// Printing the branchy |
| 60 | +console.log(`The Node constructor`); |
| 61 | +const branchy: MySchema.Branchy<LbrPlutusV1.Credential> = { |
| 62 | + name: "Node", |
| 63 | + fields: [leafpd, { name: "Finite", fields: leaf }], |
| 64 | +}; |
| 65 | +const branchypd: LbrPlutusV1.PlutusData = LbrPlutusPd.IsPlutusData |
| 66 | + [MySchema.Branchy](LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential]).toData( |
| 67 | + branchy, |
| 68 | + ); |
| 69 | + |
| 70 | +console.log("toData:"); |
| 71 | +console.log(branchypd); |
| 72 | + |
| 73 | +console.log( |
| 74 | + `Prelude.Json: ${ |
| 75 | + Prelude.stringify( |
| 76 | + LbrPrelude.Json[MySchema.Branchy](LbrPrelude.Json[LbrPlutusV1.Credential]) |
| 77 | + .toJson(branchy), |
| 78 | + ) |
| 79 | + }`, |
| 80 | +); |
| 81 | +console.log( |
| 82 | + `Prelude.Json: ${ |
| 83 | + Prelude.stringify(LbrPrelude.Json[LbrPlutusV1.PlutusData].toJson(branchypd)) |
| 84 | + }`, |
| 85 | +); |
| 86 | + |
| 87 | +console.log("fromData:"); |
| 88 | +console.log( |
| 89 | + LbrPlutusPd.IsPlutusData[MySchema.Branchy]( |
| 90 | + LbrPlutusPd.IsPlutusData[LbrPlutusV1.Credential], |
| 91 | + ).fromData(branchypd), |
| 92 | +); |
| 93 | + |
| 94 | +// Printing the Eq |
| 95 | +console.log( |
| 96 | + `branchy is branchy: ${ |
| 97 | + LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).eq( |
| 98 | + branchy, |
| 99 | + branchy, |
| 100 | + ) |
| 101 | + }`, |
| 102 | +); |
| 103 | +console.log( |
| 104 | + `branchy is not branchy: ${ |
| 105 | + LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).neq( |
| 106 | + branchy, |
| 107 | + branchy, |
| 108 | + ) |
| 109 | + }`, |
| 110 | +); |
| 111 | +console.log( |
| 112 | + `branchy is leaf: ${ |
| 113 | + LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).eq( |
| 114 | + branchy, |
| 115 | + leaf, |
| 116 | + ) |
| 117 | + }`, |
| 118 | +); |
| 119 | +console.log( |
| 120 | + `branchy is not leaf: ${ |
| 121 | + LbrPrelude.Eq[MySchema.Branchy](LbrPrelude.Eq[LbrPlutusV1.Credential]).neq( |
| 122 | + branchy, |
| 123 | + leaf, |
| 124 | + ) |
| 125 | + }`, |
| 126 | +); |
0 commit comments