@helios-lang/effect 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Ledger/Address.js +14 -12
- package/dist/Ledger/Address.js.map +1 -1
- package/dist/Ledger/AssetClass.js +69 -0
- package/dist/Ledger/AssetClass.js.map +1 -0
- package/dist/Ledger/Assets.js +120 -0
- package/dist/Ledger/Assets.js.map +1 -0
- package/dist/Ledger/Credential.js +1 -1
- package/dist/Ledger/Credential.js.map +1 -1
- package/dist/Ledger/DatumHash.js +21 -0
- package/dist/Ledger/DatumHash.js.map +1 -0
- package/dist/Ledger/IsMainnet.js +4 -0
- package/dist/Ledger/IsMainnet.js.map +1 -0
- package/dist/Ledger/MintingPolicy.js +45 -0
- package/dist/Ledger/MintingPolicy.js.map +1 -0
- package/dist/Ledger/PubKeyHash.js +2 -2
- package/dist/Ledger/PubKeyHash.js.map +1 -1
- package/dist/Ledger/TxId.js +15 -0
- package/dist/Ledger/TxId.js.map +1 -0
- package/dist/Ledger/TxInput.js +51 -0
- package/dist/Ledger/TxInput.js.map +1 -0
- package/dist/Ledger/TxOutput.js +119 -0
- package/dist/Ledger/TxOutput.js.map +1 -0
- package/dist/Ledger/TxOutputDatum.js +41 -0
- package/dist/Ledger/TxOutputDatum.js.map +1 -0
- package/dist/Ledger/TxOutputId.js +39 -0
- package/dist/Ledger/TxOutputId.js.map +1 -0
- package/dist/Ledger/ValidatorHash.js +2 -2
- package/dist/Ledger/ValidatorHash.js.map +1 -1
- package/dist/Ledger/index.js +10 -0
- package/dist/Ledger/index.js.map +1 -1
- package/dist/Uplc/Data.js +24 -4
- package/dist/Uplc/Data.js.map +1 -1
- package/package.json +2 -1
- package/src/Ledger/Address.ts +27 -17
- package/src/Ledger/AssetClass.ts +90 -0
- package/src/Ledger/Assets.ts +164 -0
- package/src/Ledger/Credential.ts +1 -1
- package/src/Ledger/DatumHash.ts +36 -0
- package/src/Ledger/IsMainnet.ts +6 -0
- package/src/Ledger/MintingPolicy.ts +57 -0
- package/src/Ledger/PubKeyHash.ts +2 -2
- package/src/Ledger/TxId.ts +31 -0
- package/src/Ledger/TxInput.test.ts +21 -0
- package/src/Ledger/TxInput.ts +66 -0
- package/src/Ledger/TxOutput.ts +166 -0
- package/src/Ledger/TxOutputDatum.ts +64 -0
- package/src/Ledger/TxOutputId.ts +63 -0
- package/src/Ledger/ValidatorHash.ts +1 -1
- package/src/Ledger/index.ts +10 -0
- package/src/Uplc/Data.ts +28 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
|
+
import * as Bytes from "../internal/Bytes.js"
|
|
3
|
+
import * as Cbor from "../Cbor.js"
|
|
4
|
+
import * as TxId from "./TxId.js"
|
|
5
|
+
|
|
6
|
+
export function isValid(txOutputId: string): txOutputId is TxOutputId {
|
|
7
|
+
if (txOutputId.length < 65) {
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const txId = txOutputId.slice(0, 64)
|
|
12
|
+
|
|
13
|
+
const utxoIdx = parseInt(txOutputId.slice(64))
|
|
14
|
+
|
|
15
|
+
if (utxoIdx.toString() != txOutputId.slice(64)) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return /^[0-9a-fA-F]+$/.test(txId)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const TxOutputId = Schema.transform(
|
|
23
|
+
Schema.String,
|
|
24
|
+
Schema.String.pipe(
|
|
25
|
+
Schema.filter((id: string) => isValid(id) || "Invalid Cardano TxOutputId"),
|
|
26
|
+
Schema.brand("TxOutputId")
|
|
27
|
+
),
|
|
28
|
+
{
|
|
29
|
+
strict: false,
|
|
30
|
+
decode: (s) => s.split("#").join(""),
|
|
31
|
+
encode: (s) => s
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
export type TxOutputId = Schema.Schema.Type<typeof TxOutputId>
|
|
36
|
+
|
|
37
|
+
export function make(txId: TxId.TxId, utxoIdx: number | bigint): TxOutputId {
|
|
38
|
+
return (txId + utxoIdx.toString()) as TxOutputId
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const decode = (bytes: Bytes.BytesLike): Cbor.DecodeEffect<TxOutputId> =>
|
|
42
|
+
Cbor.decodeTuple([TxId.decode, Cbor.decodeInt])(bytes).pipe(
|
|
43
|
+
Effect.map(([txId, utxoIdx]) => make(txId, utxoIdx))
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
export function encode(txOutputId: TxOutputId): number[] {
|
|
47
|
+
return Cbor.encodeTuple([
|
|
48
|
+
TxId.encode(txId(txOutputId)),
|
|
49
|
+
Cbor.encodeInt(utxoIdx(txOutputId))
|
|
50
|
+
])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function pretty(txOutputId: TxOutputId): string {
|
|
54
|
+
return txId(txOutputId) + "#" + utxoIdx(txOutputId).toString()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function txId(txOutputId: TxOutputId): TxId.TxId {
|
|
58
|
+
return txOutputId.slice(0, 64) as TxId.TxId
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function utxoIdx(txOutputId: TxOutputId): number {
|
|
62
|
+
return parseInt(txOutputId.slice(64))
|
|
63
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Encoding, Schema } from "effect"
|
|
2
2
|
import * as Bytes from "../internal/Bytes.js"
|
|
3
3
|
import { decodeBytes, DecodeEffect, encodeBytes } from "../Cbor.js"
|
|
4
|
-
import { Data } from "../Uplc
|
|
4
|
+
import { Data } from "../Uplc"
|
|
5
5
|
|
|
6
6
|
export function isValid(vh: string): boolean {
|
|
7
7
|
return /^[0-9a-fA-F]+$/.test(vh) && vh.length == 56
|
package/src/Ledger/index.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export * as Address from "./Address.js"
|
|
2
|
+
export * as AssetClass from "./AssetClass.js"
|
|
3
|
+
export * as Assets from "./Assets.js"
|
|
2
4
|
export * as Credential from "./Credential.js"
|
|
5
|
+
export * as DatumHash from "./DatumHash.js"
|
|
6
|
+
export { IsMainnet } from "./IsMainnet.js"
|
|
7
|
+
export * as MintingPolicy from "./MintingPolicy.js"
|
|
3
8
|
export * as PubKeyHash from "./PubKeyHash.js"
|
|
9
|
+
export * as TxId from "./TxId.js"
|
|
10
|
+
export * as TxInput from "./TxInput.js"
|
|
11
|
+
export * as TxOutput from "./TxOutput.js"
|
|
12
|
+
export * as TxOutputDatum from "./TxOutputDatum.js"
|
|
13
|
+
export * as TxOutputId from "./TxOutputId.js"
|
|
4
14
|
export * as ValidatorHash from "./ValidatorHash.js"
|
package/src/Uplc/Data.ts
CHANGED
|
@@ -427,6 +427,31 @@ const Array$ = <ItemType>(
|
|
|
427
427
|
|
|
428
428
|
export { Array$ as Array }
|
|
429
429
|
|
|
430
|
+
export const PairArray = <KeyType, ValueType>(
|
|
431
|
+
keySchema: Schema.Schema<KeyType, Schema.Schema.Encoded<typeof Data>>,
|
|
432
|
+
valueSchema: Schema.Schema<ValueType, Schema.Schema.Encoded<typeof Data>>
|
|
433
|
+
) =>
|
|
434
|
+
Schema.transformOrFail(
|
|
435
|
+
Data,
|
|
436
|
+
Schema.Array(Schema.Tuple(keySchema, valueSchema)),
|
|
437
|
+
{
|
|
438
|
+
strict: true,
|
|
439
|
+
decode: (data) => {
|
|
440
|
+
if ("map" in data) {
|
|
441
|
+
return ParseResult.succeed(
|
|
442
|
+
data.map.map(({ k, v }) => [k, v] as const)
|
|
443
|
+
)
|
|
444
|
+
} else {
|
|
445
|
+
return ParseResult.fail(
|
|
446
|
+
new ParseResult.Unexpected(data, "expected MapData")
|
|
447
|
+
)
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
encode: (pairs) =>
|
|
451
|
+
ParseResult.succeed({ map: pairs.map(([k, v]) => ({ k, v })) })
|
|
452
|
+
}
|
|
453
|
+
)
|
|
454
|
+
|
|
430
455
|
export const Struct = <
|
|
431
456
|
FieldTypes extends { [fieldName: string]: Schema.Schema<any, Data> }
|
|
432
457
|
>(
|
|
@@ -617,7 +642,9 @@ export const Enum = <
|
|
|
617
642
|
encode: (value) => {
|
|
618
643
|
const variantName = value._tag
|
|
619
644
|
|
|
620
|
-
const tag = Object.keys(variants).indexOf(
|
|
645
|
+
const tag = Object.keys(variants).indexOf(
|
|
646
|
+
variantName as unknown as string
|
|
647
|
+
)
|
|
621
648
|
|
|
622
649
|
return ParseResult.succeed({
|
|
623
650
|
constructor: tag,
|