@lucid-evolution/provider 0.1.45 → 0.1.47

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/index.cjs CHANGED
@@ -32,27 +32,27 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  Blockfrost: () => Blockfrost,
34
34
  Emulator: () => Emulator,
35
- FetchProvider: () => fetch_exports,
36
35
  Koios: () => Koios,
36
+ KoiosError: () => KoiosError,
37
37
  Kupmios: () => Kupmios,
38
38
  KupmiosError: () => KupmiosError,
39
39
  Maestro: () => Maestro,
40
- datumJsonToCbor: () => datumJsonToCbor,
41
- generateEmulatorAccount: () => generateEmulatorAccount
40
+ generateEmulatorAccount: () => generateEmulatorAccount,
41
+ generateEmulatorAccountFrommPrivateKey: () => generateEmulatorAccountFrommPrivateKey
42
42
  });
43
43
  module.exports = __toCommonJS(src_exports);
44
44
 
45
45
  // src/core.ts
46
46
  var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
47
47
 
48
- // src/blockfrost/blockfrost.ts
48
+ // src/blockfrost.ts
49
49
  var import_core_utils = require("@lucid-evolution/core-utils");
50
50
  var import_utils = require("@lucid-evolution/utils");
51
51
 
52
52
  // package.json
53
53
  var package_default = {
54
54
  name: "@lucid-evolution/provider",
55
- version: "0.1.45",
55
+ version: "0.1.47",
56
56
  description: "",
57
57
  main: "./dist/index.js",
58
58
  types: "./dist/index.d.ts",
@@ -100,8 +100,48 @@ var package_default = {
100
100
  }
101
101
  };
102
102
 
103
- // src/blockfrost/blockfrost.ts
103
+ // src/internal/blockfrost.ts
104
104
  var import_effect = require("effect");
105
+ var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
106
+ {
107
+ txId: utxo.txHash,
108
+ index: utxo.outputIndex
109
+ },
110
+ {
111
+ address: utxo.address,
112
+ value: {
113
+ coins: Number(utxo.assets["lovelace"]),
114
+ assets: fromAssets(utxo.assets)
115
+ },
116
+ datumHash: utxo.datumHash,
117
+ datum: utxo.datum,
118
+ script: toTxOutScript(utxo.scriptRef)
119
+ }
120
+ ]);
121
+ var toTxOutScript = (scriptRef) => {
122
+ if (scriptRef) {
123
+ switch (scriptRef.type) {
124
+ case "PlutusV1":
125
+ return { "plutus:v1": scriptRef.script };
126
+ case "PlutusV2":
127
+ return { "plutus:v2": scriptRef.script };
128
+ case "PlutusV3":
129
+ return { "plutus:v3": scriptRef.script };
130
+ default:
131
+ return void 0;
132
+ }
133
+ }
134
+ };
135
+ var fromAssets = (assets) => (0, import_effect.pipe)(
136
+ import_effect.Record.remove(assets, "lovelace"),
137
+ import_effect.Record.mapEntries((amount, unit) => [
138
+ unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
139
+ Number(amount)
140
+ ]),
141
+ (r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
142
+ );
143
+
144
+ // src/blockfrost.ts
105
145
  var Blockfrost = class {
106
146
  url;
107
147
  projectId;
@@ -379,42 +419,6 @@ var Blockfrost = class {
379
419
  return evalRedeemers;
380
420
  }
381
421
  };
382
- function datumJsonToCbor(json) {
383
- const convert = (json2) => {
384
- if (!isNaN(json2.int)) {
385
- return CML.PlutusData.new_integer(
386
- CML.BigInteger.from_str(json2.int.toString())
387
- );
388
- } else if (json2.bytes || !isNaN(Number(json2.bytes))) {
389
- return CML.PlutusData.new_bytes((0, import_core_utils.fromHex)(json2.bytes));
390
- } else if (json2.map) {
391
- const m = CML.PlutusMap.new();
392
- json2.map.forEach(({ k, v }) => {
393
- m.set(convert(k), convert(v));
394
- });
395
- return CML.PlutusData.new_map(m);
396
- } else if (json2.list) {
397
- const l = CML.PlutusDataList.new();
398
- json2.list.forEach((v) => {
399
- l.add(convert(v));
400
- });
401
- return CML.PlutusData.new_list(l);
402
- } else if (!isNaN(json2.constructor)) {
403
- const l = CML.PlutusDataList.new();
404
- json2.fields.forEach((v) => {
405
- l.add(convert(v));
406
- });
407
- return CML.PlutusData.new_constr_plutus_data(
408
- CML.ConstrPlutusData.new(
409
- CML.BigInteger.from_str(json2.constructor.toString()).as_u64(),
410
- l
411
- )
412
- );
413
- }
414
- throw new Error("Unsupported type");
415
- };
416
- return convert(json).to_cbor_hex();
417
- }
418
422
  var handleRateLimit = async (count) => {
419
423
  if (count % 100 === 0) {
420
424
  await (0, import_core_utils.sleep)(5e3);
@@ -423,52 +427,17 @@ var handleRateLimit = async (count) => {
423
427
  }
424
428
  };
425
429
  var lucid = package_default.version;
426
- var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
427
- {
428
- txId: utxo.txHash,
429
- index: utxo.outputIndex
430
- },
431
- {
432
- address: utxo.address,
433
- value: {
434
- coins: Number(utxo.assets["lovelace"]),
435
- assets: fromAssets(utxo.assets)
436
- },
437
- datumHash: utxo.datumHash,
438
- datum: utxo.datum,
439
- script: toTxOutScript(utxo.scriptRef)
440
- }
441
- ]);
442
- var toTxOutScript = (scriptRef) => {
443
- if (scriptRef) {
444
- switch (scriptRef.type) {
445
- case "PlutusV1":
446
- return { "plutus:v1": scriptRef.script };
447
- case "PlutusV2":
448
- return { "plutus:v2": scriptRef.script };
449
- case "PlutusV3":
450
- return { "plutus:v3": scriptRef.script };
451
- default:
452
- return void 0;
453
- }
454
- }
455
- };
456
- var fromAssets = (assets) => (0, import_effect.pipe)(
457
- import_effect.Record.remove(assets, "lovelace"),
458
- import_effect.Record.mapEntries((amount, unit) => [
459
- unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
460
- Number(amount)
461
- ]),
462
- (r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
463
- );
464
430
 
465
- // src/kupmios/kupmios.ts
466
- var import_utils2 = require("@lucid-evolution/utils");
467
- var S2 = __toESM(require("@effect/schema/Schema"), 1);
431
+ // src/kupmios.ts
432
+ var import_utils3 = require("@lucid-evolution/utils");
433
+ var S3 = __toESM(require("@effect/schema/Schema"), 1);
468
434
  var import_effect2 = require("effect");
435
+ var import_platform = require("@effect/platform");
436
+ var import_schema = require("@effect/schema");
469
437
 
470
- // src/kupmios/schema.ts
438
+ // src/internal/ogmios.ts
471
439
  var S = __toESM(require("@effect/schema/Schema"), 1);
440
+ var import_utils2 = require("@lucid-evolution/utils");
472
441
  var JSONRPCSchema = (schema) => S.extend(
473
442
  S.Struct({
474
443
  jsonrpc: S.String,
@@ -564,59 +533,118 @@ var ProtocolParametersSchema = S.Struct({
564
533
  maxCollateralInputs: S.Number,
565
534
  version: S.Struct({ major: S.Number, minor: S.Number })
566
535
  });
567
- var KupoValueSchema = S.Struct({
568
- coins: S.Number,
569
- assets: S.Record(S.String, S.Number)
536
+ var Delegation = S.NullOr(
537
+ S.Record(
538
+ S.String,
539
+ S.Struct({
540
+ delegate: S.Struct({ id: S.String }),
541
+ rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
542
+ deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
543
+ })
544
+ )
545
+ );
546
+ var RedeemerSchema = S.Struct({
547
+ validator: S.Struct({
548
+ purpose: S.String,
549
+ index: S.Int
550
+ }),
551
+ budget: S.Struct({
552
+ memory: S.Int,
553
+ cpu: S.Int
554
+ })
570
555
  });
571
- var KupoUTxO = S.Struct({
572
- transaction_index: S.Number,
573
- transaction_id: S.String,
574
- output_index: S.Number,
575
- address: S.String,
576
- value: KupoValueSchema,
577
- datum_hash: S.NullOr(S.String),
578
- datum_type: S.optional(S.Literal("hash", "inline")),
579
- script_hash: S.NullOr(S.String),
580
- created_at: S.Struct({
581
- slot_no: S.Number,
582
- header_hash: S.String
556
+ var toOgmiosUTxOs = (utxos) => {
557
+ const toOgmiosScript = (scriptRef) => {
558
+ if (scriptRef) {
559
+ switch (scriptRef.type) {
560
+ case "PlutusV1":
561
+ return { language: "plutus:v1", cbor: scriptRef.script };
562
+ case "PlutusV2":
563
+ return { language: "plutus:v2", cbor: scriptRef.script };
564
+ case "PlutusV3":
565
+ return { language: "plutus:v3", cbor: scriptRef.script };
566
+ default:
567
+ return null;
568
+ }
569
+ }
570
+ };
571
+ const toOgmiosAssets = (assets) => {
572
+ const newAssets = {};
573
+ Object.entries(assets).map(([unit, amount]) => {
574
+ if (unit == "lovelace") return;
575
+ const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
576
+ newAssets[policyId][assetName ? assetName : ""] = Number(amount);
577
+ });
578
+ return newAssets;
579
+ };
580
+ return (utxos || []).map(
581
+ (utxo) => ({
582
+ transaction: {
583
+ id: utxo.txHash
584
+ },
585
+ index: utxo.outputIndex,
586
+ address: utxo.address,
587
+ value: {
588
+ ada: { lovelace: Number(utxo.assets["lovelace"]) },
589
+ ...toOgmiosAssets(utxo.assets)
590
+ },
591
+ datumHash: utxo.datumHash,
592
+ datum: utxo.datum,
593
+ script: toOgmiosScript(utxo.scriptRef)
594
+ })
595
+ );
596
+ };
597
+
598
+ // src/internal/kupo.ts
599
+ var S2 = __toESM(require("@effect/schema/Schema"), 1);
600
+ var ValueSchema = S2.Struct({
601
+ coins: S2.Number,
602
+ assets: S2.Record(S2.String, S2.Number)
603
+ });
604
+ var UTxOSchema = S2.Struct({
605
+ transaction_index: S2.Number,
606
+ transaction_id: S2.String,
607
+ output_index: S2.Number,
608
+ address: S2.String,
609
+ value: ValueSchema,
610
+ datum_hash: S2.NullOr(S2.String),
611
+ datum_type: S2.optional(S2.Literal("hash", "inline")),
612
+ script_hash: S2.NullOr(S2.String),
613
+ created_at: S2.Struct({
614
+ slot_no: S2.Number,
615
+ header_hash: S2.String
583
616
  }),
584
- spent_at: S.NullOr(
585
- S.Struct({
586
- slot_no: S.Number,
587
- header_hash: S.String
617
+ spent_at: S2.NullOr(
618
+ S2.Struct({
619
+ slot_no: S2.Number,
620
+ header_hash: S2.String
588
621
  })
589
622
  )
590
623
  });
591
- var KupoScriptSchema = S.NullOr(
592
- S.Struct({
593
- language: S.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
594
- script: S.String
624
+ var ScriptSchema = S2.NullOr(
625
+ S2.Struct({
626
+ language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
627
+ script: S2.String
595
628
  })
596
629
  );
597
- var KupoDatumSchema = S.NullOr(S.Struct({ datum: S.String }));
598
- var KupoDelegation = S.NullOr(
599
- S.Record(
600
- S.String,
601
- S.Struct({
602
- delegate: S.Struct({ id: S.String }),
603
- rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
604
- deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
630
+ var DatumSchema = S2.NullOr(S2.Struct({ datum: S2.String }));
631
+ var DelegationSchema = S2.NullOr(
632
+ S2.Record(
633
+ S2.String,
634
+ S2.Struct({
635
+ delegate: S2.Struct({ id: S2.String }),
636
+ rewards: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) }),
637
+ deposit: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) })
605
638
  })
606
639
  )
607
640
  );
608
641
 
609
- // src/kupmios/kupmios.ts
610
- var import_platform = require("@effect/platform");
611
- var import_schema = require("@effect/schema");
642
+ // src/kupmios.ts
612
643
  var KupmiosError = class extends import_effect2.Data.TaggedError("KupmiosError") {
613
644
  get message() {
614
- return `${this.cause}`;
645
+ return `${JSON.stringify(this.cause)}`;
615
646
  }
616
647
  };
617
- var kupmiosError = (cause) => new KupmiosError({
618
- cause: JSON.stringify(cause)
619
- });
620
648
  var Kupmios = class {
621
649
  kupoUrl;
622
650
  ogmiosUrl;
@@ -635,15 +663,13 @@ var Kupmios = class {
635
663
  params: {},
636
664
  id: null
637
665
  };
638
- const schema = JSONRPCSchema(
639
- ProtocolParametersSchema
640
- );
666
+ const schema = JSONRPCSchema(ProtocolParametersSchema);
641
667
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
642
668
  import_effect2.Effect.flatMap(
643
- (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
669
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
644
670
  ),
645
671
  import_effect2.Effect.timeout(1e4),
646
- import_effect2.Effect.catchAll(kupmiosError)
672
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
647
673
  );
648
674
  const result = await import_effect2.Effect.runPromise(program);
649
675
  return toProtocolParameters(result);
@@ -652,11 +678,11 @@ var Kupmios = class {
652
678
  const isAddress = typeof addressOrCredential === "string";
653
679
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
654
680
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
655
- const schema = S2.Array(KupoUTxO);
681
+ const schema = S3.Array(UTxOSchema);
656
682
  const program = fetchKupoParse(pattern, schema).pipe(
657
683
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
658
684
  import_effect2.Effect.timeout(1e4),
659
- import_effect2.Effect.catchAll(kupmiosError)
685
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
660
686
  );
661
687
  const utxos = await import_effect2.Effect.runPromise(program);
662
688
  return utxos;
@@ -664,25 +690,25 @@ var Kupmios = class {
664
690
  async getUtxosWithUnit(addressOrCredential, unit) {
665
691
  const isAddress = typeof addressOrCredential === "string";
666
692
  const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
667
- const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
693
+ const { policyId, assetName } = (0, import_utils3.fromUnit)(unit);
668
694
  const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
669
- const schema = S2.Array(KupoUTxO);
695
+ const schema = S3.Array(UTxOSchema);
670
696
  const program = fetchKupoParse(pattern, schema).pipe(
671
697
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
672
698
  import_effect2.Effect.timeout(1e4),
673
- import_effect2.Effect.catchAll(kupmiosError)
699
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
674
700
  );
675
701
  const utxos = await import_effect2.Effect.runPromise(program);
676
702
  return utxos;
677
703
  }
678
704
  async getUtxoByUnit(unit) {
679
- const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
705
+ const { policyId, assetName } = (0, import_utils3.fromUnit)(unit);
680
706
  const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
681
- const schema = S2.Array(KupoUTxO);
707
+ const schema = S3.Array(UTxOSchema);
682
708
  const program = fetchKupoParse(pattern, schema).pipe(
683
709
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
684
710
  import_effect2.Effect.timeout(1e4),
685
- import_effect2.Effect.catchAll(kupmiosError)
711
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
686
712
  );
687
713
  const utxos = await import_effect2.Effect.runPromise(program);
688
714
  if (utxos.length > 1) {
@@ -695,13 +721,13 @@ var Kupmios = class {
695
721
  ...new Set(outRefs.map((outRef) => outRef.txHash))
696
722
  ];
697
723
  const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
698
- const schema = S2.Array(KupoUTxO);
724
+ const schema = S3.Array(UTxOSchema);
699
725
  const program = import_effect2.Effect.forEach(
700
726
  queryHashes,
701
727
  (txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
702
728
  import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
703
729
  import_effect2.Effect.timeout(1e4),
704
- import_effect2.Effect.catchAll(kupmiosError)
730
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
705
731
  )
706
732
  );
707
733
  const utxos = await import_effect2.Effect.runPromise(program);
@@ -718,13 +744,13 @@ var Kupmios = class {
718
744
  params: { keys: [rewardAddress] },
719
745
  id: null
720
746
  };
721
- const schema = JSONRPCSchema(KupoDelegation);
747
+ const schema = JSONRPCSchema(Delegation);
722
748
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
723
749
  import_effect2.Effect.flatMap(
724
- (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
750
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
725
751
  ),
726
752
  import_effect2.Effect.timeout(1e4),
727
- import_effect2.Effect.catchAll(kupmiosError)
753
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
728
754
  );
729
755
  const result = await import_effect2.Effect.runPromise(program);
730
756
  const delegation = result ? Object.values(result)[0] : null;
@@ -735,18 +761,18 @@ var Kupmios = class {
735
761
  }
736
762
  async getDatum(datumHash) {
737
763
  const pattern = `${this.kupoUrl}/datums/${datumHash}`;
738
- const schema = KupoDatumSchema;
764
+ const schema = DatumSchema;
739
765
  const program = fetchKupoParse(pattern, schema).pipe(
740
766
  import_effect2.Effect.timeout(1e4),
741
767
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
742
- import_effect2.Effect.catchAll(kupmiosError)
768
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
743
769
  );
744
770
  const result = await import_effect2.Effect.runPromise(program);
745
771
  return result.datum;
746
772
  }
747
773
  async awaitTx(txHash, checkInterval = 2e4) {
748
774
  const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
749
- const schema = S2.Array(KupoUTxO).annotations({
775
+ const schema = S3.Array(UTxOSchema).annotations({
750
776
  identifier: "Array<KupmiosSchema.KupoUTxO>"
751
777
  });
752
778
  const program = fetchKupoParse(pattern, schema).pipe(
@@ -755,7 +781,7 @@ var Kupmios = class {
755
781
  until: (result) => result.length > 0
756
782
  }),
757
783
  import_effect2.Effect.timeout(16e4),
758
- import_effect2.Effect.catchAll(kupmiosError),
784
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause })),
759
785
  import_effect2.Effect.as(true)
760
786
  );
761
787
  return await import_effect2.Effect.runPromise(program);
@@ -770,70 +796,39 @@ var Kupmios = class {
770
796
  id: null
771
797
  };
772
798
  const schema = JSONRPCSchema(
773
- S2.Struct({
774
- transaction: S2.Struct({
775
- id: S2.String
799
+ S3.Struct({
800
+ transaction: S3.Struct({
801
+ id: S3.String
776
802
  })
777
803
  })
778
804
  );
779
805
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
780
806
  import_effect2.Effect.flatMap(
781
- (response) => "error" in response ? import_effect2.Effect.fail(response.error) : import_effect2.Effect.succeed(response)
807
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response)
782
808
  ),
783
809
  import_effect2.Effect.timeout(1e4),
784
- import_effect2.Effect.catchAll(kupmiosError)
810
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
785
811
  );
786
812
  const { result } = await import_effect2.Effect.runPromise(program);
787
813
  return result.transaction.id;
788
814
  }
789
815
  async evaluateTx(tx, additionalUTxOs) {
790
- const utxos = (additionalUTxOs || []).map((utxo) => {
791
- const script = utxo.scriptRef ? {
792
- language: utxo.scriptRef.type,
793
- cbor: utxo.scriptRef.script
794
- } : void 0;
795
- return [
796
- {
797
- transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
798
- },
799
- {
800
- address: utxo.address,
801
- value: {
802
- coins: utxo.assets.lovelace,
803
- assets: utxo.assets.restAssets
804
- },
805
- datumHash: utxo.datumHash,
806
- datum: utxo.datum,
807
- script
808
- }
809
- ];
810
- });
811
816
  const data = {
812
817
  jsonrpc: "2.0",
813
818
  method: "evaluateTransaction",
814
- params: { transaction: { cbor: tx }, additionalUTxO: utxos },
819
+ params: {
820
+ transaction: { cbor: tx },
821
+ additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
822
+ },
815
823
  id: null
816
824
  };
817
- const schema = JSONRPCSchema(
818
- S2.Array(
819
- S2.Struct({
820
- validator: S2.Struct({
821
- purpose: S2.String,
822
- index: S2.Int
823
- }),
824
- budget: S2.Struct({
825
- memory: S2.Int,
826
- cpu: S2.Int
827
- })
828
- })
829
- )
830
- );
825
+ const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
831
826
  const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
832
827
  import_effect2.Effect.flatMap(
833
- (response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
828
+ (response) => "error" in response ? import_effect2.Effect.fail(response) : import_effect2.Effect.succeed(response.result)
834
829
  ),
835
830
  import_effect2.Effect.timeout(1e4),
836
- import_effect2.Effect.catchAll(kupmiosError)
831
+ import_effect2.Effect.catchAll((cause) => new KupmiosError({ cause }))
837
832
  );
838
833
  const result = await import_effect2.Effect.runPromise(program);
839
834
  const evalRedeemers = result.map((item) => ({
@@ -850,7 +845,7 @@ var Kupmios = class {
850
845
  var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.gen(function* () {
851
846
  if (datum_type === "inline" && datum_hash) {
852
847
  const pattern = `${kupoUrl}/datums/${datum_hash}`;
853
- const schema = KupoDatumSchema;
848
+ const schema = DatumSchema;
854
849
  return yield* fetchKupoParse(pattern, schema).pipe(
855
850
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
856
851
  import_effect2.Effect.map((result) => result.datum),
@@ -861,7 +856,7 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.
861
856
  var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(function* () {
862
857
  if (script_hash) {
863
858
  const pattern = `${kupoUrl}/scripts/${script_hash}`;
864
- const schema = KupoScriptSchema;
859
+ const schema = ScriptSchema;
865
860
  return yield* (0, import_effect2.pipe)(
866
861
  fetchKupoParse(pattern, schema),
867
862
  import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
@@ -873,12 +868,17 @@ var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(functi
873
868
  case "plutus:v1":
874
869
  return {
875
870
  type: "PlutusV1",
876
- script: (0, import_utils2.applyDoubleCborEncoding)(script)
871
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
877
872
  };
878
873
  case "plutus:v2":
879
874
  return {
880
875
  type: "PlutusV2",
881
- script: (0, import_utils2.applyDoubleCborEncoding)(script)
876
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
877
+ };
878
+ case "plutus:v3":
879
+ return {
880
+ type: "PlutusV3",
881
+ script: (0, import_utils3.applyDoubleCborEncoding)(script)
882
882
  };
883
883
  }
884
884
  })
@@ -939,9 +939,7 @@ var fetchOgmiosParse = (url, data, schema) => (0, import_effect2.pipe)(
939
939
  import_platform.HttpClientRequest.jsonBody(data),
940
940
  import_effect2.Effect.flatMap(import_platform.HttpClient.fetch),
941
941
  import_platform.HttpClientResponse.json,
942
- import_effect2.Effect.flatMap(
943
- S2.decodeUnknown(schema, { onExcessProperty: "error", errors: "first" })
944
- ),
942
+ import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
945
943
  import_effect2.Effect.catchTag(
946
944
  "ParseError",
947
945
  (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
@@ -952,7 +950,7 @@ var fetchKupoParse = (url, schema) => (0, import_effect2.pipe)(
952
950
  import_platform.HttpClientRequest.get(url),
953
951
  import_platform.HttpClient.fetchOk,
954
952
  import_platform.HttpClientResponse.json,
955
- import_effect2.Effect.flatMap(S2.decodeUnknown(schema, { onExcessProperty: "error" })),
953
+ import_effect2.Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
956
954
  import_effect2.Effect.catchTag(
957
955
  "ParseError",
958
956
  (e) => import_effect2.Effect.fail(import_schema.ArrayFormatter.formatErrorSync(e))
@@ -984,13 +982,28 @@ var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
984
982
  );
985
983
 
986
984
  // src/emulator.ts
987
- var import_utils3 = require("@lucid-evolution/utils");
988
985
  var import_utils4 = require("@lucid-evolution/utils");
986
+ var import_utils5 = require("@lucid-evolution/utils");
989
987
  var import_core_utils2 = require("@lucid-evolution/core-utils");
990
988
  var import_wallet = require("@lucid-evolution/wallet");
991
989
  var import_cardano_multiplatform_lib_nodejs = require("@anastasia-labs/cardano-multiplatform-lib-nodejs");
990
+ async function generateEmulatorAccountFrommPrivateKey(assets) {
991
+ const privateKey = CML.PrivateKey.generate_ed25519().to_bech32();
992
+ const priv = CML.PrivateKey.from_bech32(privateKey);
993
+ const pubKeyHash = priv.to_public().hash();
994
+ const address = CML.EnterpriseAddress.new(
995
+ 0,
996
+ CML.Credential.new_pub_key(pubKeyHash)
997
+ ).to_address().to_bech32(void 0);
998
+ return {
999
+ seedPhrase: "",
1000
+ address,
1001
+ assets,
1002
+ privateKey
1003
+ };
1004
+ }
992
1005
  function generateEmulatorAccount(assets) {
993
- const seedPhrase = (0, import_utils3.generateSeedPhrase)();
1006
+ const seedPhrase = (0, import_utils4.generateSeedPhrase)();
994
1007
  return {
995
1008
  seedPhrase,
996
1009
  address: (0, import_wallet.walletFromSeed)(seedPhrase, {
@@ -998,7 +1011,8 @@ function generateEmulatorAccount(assets) {
998
1011
  accountIndex: 0,
999
1012
  network: "Custom"
1000
1013
  }).address,
1001
- assets
1014
+ assets,
1015
+ privateKey: ""
1002
1016
  };
1003
1017
  }
1004
1018
  var Emulator = class {
@@ -1014,7 +1028,7 @@ var Emulator = class {
1014
1028
  time;
1015
1029
  protocolParameters;
1016
1030
  datumTable = {};
1017
- constructor(accounts, protocolParameters = import_utils3.PROTOCOL_PARAMETERS_DEFAULT) {
1031
+ constructor(accounts, protocolParameters = import_utils4.PROTOCOL_PARAMETERS_DEFAULT) {
1018
1032
  const GENESIS_HASH = "00".repeat(32);
1019
1033
  this.blockHeight = 0;
1020
1034
  this.slot = 0;
@@ -1080,7 +1094,7 @@ var Emulator = class {
1080
1094
  if (typeof addressOrCredential === "string") {
1081
1095
  return addressOrCredential === utxo.address ? utxo : [];
1082
1096
  } else {
1083
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1097
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1084
1098
  return paymentCredential?.hash === addressOrCredential.hash ? utxo : [];
1085
1099
  }
1086
1100
  });
@@ -1097,7 +1111,7 @@ var Emulator = class {
1097
1111
  if (typeof addressOrCredential === "string") {
1098
1112
  return addressOrCredential === utxo.address && utxo.assets[unit] > 0n ? utxo : [];
1099
1113
  } else {
1100
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1114
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1101
1115
  return paymentCredential?.hash === addressOrCredential.hash && utxo.assets[unit] > 0n ? utxo : [];
1102
1116
  }
1103
1117
  });
@@ -1411,7 +1425,7 @@ It does not exist or was already spent.`
1411
1425
  It does not exist or was already spent.`
1412
1426
  );
1413
1427
  }
1414
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(entry.utxo.address);
1428
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(entry.utxo.address);
1415
1429
  if (paymentCredential?.type === "Script") {
1416
1430
  throw new Error("Collateral inputs can only contain vkeys.");
1417
1431
  }
@@ -1432,7 +1446,7 @@ It does not exist or was already spent.`
1432
1446
  body.withdrawals().get(rawAddress).toString()
1433
1447
  );
1434
1448
  const rewardAddress = rawAddress.to_address().to_bech32(void 0);
1435
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1449
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1436
1450
  checkAndConsumeHash(stakeCredential, "Reward", index);
1437
1451
  if (this.chain[rewardAddress]?.delegation.rewards !== withdrawal) {
1438
1452
  throw new Error(
@@ -1465,7 +1479,7 @@ It does not exist or was already spent.`
1465
1479
  CML.NetworkInfo.testnet().network_id(),
1466
1480
  deregistration.stake_credential()
1467
1481
  ).to_address().to_bech32(void 0);
1468
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1482
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1469
1483
  checkAndConsumeHash(stakeCredential, "Cert", index);
1470
1484
  if (!this.chain[rewardAddress]?.registeredStake) {
1471
1485
  throw new Error(
@@ -1482,7 +1496,7 @@ It does not exist or was already spent.`
1482
1496
  delegation.stake_credential()
1483
1497
  ).to_address().to_bech32(void 0);
1484
1498
  const poolId = delegation.pool().to_bech32("pool");
1485
- const { stakeCredential } = (0, import_utils4.getAddressDetails)(rewardAddress);
1499
+ const { stakeCredential } = (0, import_utils5.getAddressDetails)(rewardAddress);
1486
1500
  checkAndConsumeHash(stakeCredential, "Cert", index);
1487
1501
  if (!this.chain[rewardAddress]?.registeredStake && !certRequests.find(
1488
1502
  (request) => request.type === "Registration" && request.rewardAddress === rewardAddress
@@ -1497,7 +1511,7 @@ It does not exist or was already spent.`
1497
1511
  }
1498
1512
  }
1499
1513
  resolvedInputs.forEach(({ entry: { utxo } }, index) => {
1500
- const { paymentCredential } = (0, import_utils4.getAddressDetails)(utxo.address);
1514
+ const { paymentCredential } = (0, import_utils5.getAddressDetails)(utxo.address);
1501
1515
  checkAndConsumeHash(paymentCredential, "Spend", index);
1502
1516
  });
1503
1517
  const outputs = (() => {
@@ -1511,7 +1525,7 @@ It does not exist or was already spent.`
1511
1525
  ),
1512
1526
  output
1513
1527
  );
1514
- const utxo = (0, import_utils4.coreToUtxo)(unspentOutput);
1528
+ const utxo = (0, import_utils5.coreToUtxo)(unspentOutput);
1515
1529
  if (utxo.datumHash) consumedHashes.add(utxo.datumHash);
1516
1530
  collected.push({
1517
1531
  utxo,
@@ -1720,7 +1734,7 @@ function redeemerTagToString(tag) {
1720
1734
  }
1721
1735
 
1722
1736
  // src/maestro.ts
1723
- var import_utils5 = require("@lucid-evolution/utils");
1737
+ var import_utils6 = require("@lucid-evolution/utils");
1724
1738
  var import_core_utils3 = require("@lucid-evolution/core-utils");
1725
1739
  var Maestro = class {
1726
1740
  url;
@@ -1980,13 +1994,13 @@ var Maestro = class {
1980
1994
  }
1981
1995
  async evaluateTx(tx, additionalUTxOs) {
1982
1996
  const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
1983
- index: utxo.outputIndex,
1984
1997
  tx_hash: utxo.txHash,
1985
- tx_cbor: (0, import_utils5.utxoToCore)(utxo).to_cbor_hex
1998
+ index: utxo.outputIndex,
1999
+ txout_cbor: (0, import_utils6.utxoToCore)(utxo).output().to_cbor_hex()
1986
2000
  }));
1987
2001
  const payload = {
1988
2002
  cbor: tx,
1989
- additionalMaestroUTxOs
2003
+ additional_utxos: additionalMaestroUTxOs
1990
2004
  };
1991
2005
  const res = await fetch(`${this.url}/transactions/evaluate`, {
1992
2006
  method: "POST",
@@ -2012,17 +2026,17 @@ var toScriptRef = (reference_script) => {
2012
2026
  case "plutusv1":
2013
2027
  return {
2014
2028
  type: "PlutusV1",
2015
- script: (0, import_utils5.applyDoubleCborEncoding)(reference_script.bytes)
2029
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2016
2030
  };
2017
2031
  case "plutusv2":
2018
2032
  return {
2019
2033
  type: "PlutusV2",
2020
- script: (0, import_utils5.applyDoubleCborEncoding)(reference_script.bytes)
2034
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2021
2035
  };
2022
2036
  case "plutusv3":
2023
2037
  return {
2024
2038
  type: "PlutusV3",
2025
- script: (0, import_utils5.applyDoubleCborEncoding)(reference_script.bytes)
2039
+ script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2026
2040
  };
2027
2041
  default:
2028
2042
  return void 0;
@@ -2031,211 +2045,214 @@ var toScriptRef = (reference_script) => {
2031
2045
  };
2032
2046
  var lucid2 = package_default.version;
2033
2047
 
2034
- // src/koios/koios.ts
2035
- var S4 = __toESM(require("@effect/schema/Schema"), 1);
2048
+ // src/koios.ts
2049
+ var S5 = __toESM(require("@effect/schema/Schema"), 1);
2036
2050
  var import_core_utils4 = require("@lucid-evolution/core-utils");
2037
- var import_utils6 = require("@lucid-evolution/utils");
2051
+ var import_utils8 = require("@lucid-evolution/utils");
2038
2052
 
2039
- // src/koios/schema.ts
2040
- var S3 = __toESM(require("@effect/schema/Schema"), 1);
2041
- var ProtocolParametersSchema2 = S3.Struct({
2042
- pvt_motion_no_confidence: S3.Number,
2043
- pvt_committee_normal: S3.Number,
2044
- pvt_committee_no_confidence: S3.Number,
2045
- pvt_hard_fork_initiation: S3.Number,
2046
- pvtpp_security_group: S3.Number,
2047
- dvt_motion_no_confidence: S3.Number,
2048
- dvt_committee_normal: S3.Number,
2049
- dvt_committee_no_confidence: S3.Number,
2050
- dvt_update_to_constitution: S3.Number,
2051
- dvt_hard_fork_initiation: S3.Number,
2052
- dvt_p_p_network_group: S3.Number,
2053
- dvt_p_p_economic_group: S3.Number,
2054
- dvt_p_p_technical_group: S3.Number,
2055
- dvt_p_p_gov_group: S3.Number,
2056
- dvt_treasury_withdrawal: S3.Number,
2057
- committee_min_size: S3.Number,
2058
- committee_max_term_length: S3.Number,
2059
- gov_action_lifetime: S3.Number,
2060
- gov_action_deposit: S3.NumberFromString,
2061
- drep_deposit: S3.NumberFromString,
2062
- drep_activity: S3.Number,
2063
- min_fee_ref_script_cost_per_byte: S3.Number,
2064
- epoch_no: S3.Number,
2065
- min_fee_a: S3.Number,
2066
- min_fee_b: S3.Number,
2067
- max_block_size: S3.Number,
2068
- max_tx_size: S3.Number,
2069
- max_bh_size: S3.Number,
2070
- key_deposit: S3.BigInt,
2071
- pool_deposit: S3.BigInt,
2072
- max_epoch: S3.Number,
2073
- optimal_pool_count: S3.Number,
2074
- influence: S3.Number,
2075
- monetary_expand_rate: S3.Number,
2076
- treasury_growth_rate: S3.Number,
2077
- decentralisation: S3.Number,
2078
- extra_entropy: S3.NullOr(S3.String),
2079
- protocol_major: S3.Number,
2080
- protocol_minor: S3.Number,
2081
- min_utxo_value: S3.String,
2082
- min_pool_cost: S3.String,
2083
- nonce: S3.String,
2084
- block_hash: S3.NullOr(S3.String),
2085
- cost_models: S3.Struct({
2086
- PlutusV1: S3.Array(S3.Number),
2087
- PlutusV2: S3.Array(S3.Number),
2088
- PlutusV3: S3.Array(S3.Number)
2053
+ // src/internal/koios.ts
2054
+ var import_platform2 = require("@effect/platform");
2055
+ var S4 = __toESM(require("@effect/schema/Schema"), 1);
2056
+ var import_effect3 = require("effect");
2057
+ var import_utils7 = require("@lucid-evolution/utils");
2058
+ var ProtocolParametersSchema2 = S4.Struct({
2059
+ pvt_motion_no_confidence: S4.Number,
2060
+ pvt_committee_normal: S4.Number,
2061
+ pvt_committee_no_confidence: S4.Number,
2062
+ pvt_hard_fork_initiation: S4.Number,
2063
+ pvtpp_security_group: S4.Number,
2064
+ dvt_motion_no_confidence: S4.Number,
2065
+ dvt_committee_normal: S4.Number,
2066
+ dvt_committee_no_confidence: S4.Number,
2067
+ dvt_update_to_constitution: S4.Number,
2068
+ dvt_hard_fork_initiation: S4.Number,
2069
+ dvt_p_p_network_group: S4.Number,
2070
+ dvt_p_p_economic_group: S4.Number,
2071
+ dvt_p_p_technical_group: S4.Number,
2072
+ dvt_p_p_gov_group: S4.Number,
2073
+ dvt_treasury_withdrawal: S4.Number,
2074
+ committee_min_size: S4.Number,
2075
+ committee_max_term_length: S4.Number,
2076
+ gov_action_lifetime: S4.Number,
2077
+ gov_action_deposit: S4.NumberFromString,
2078
+ drep_deposit: S4.NumberFromString,
2079
+ drep_activity: S4.Number,
2080
+ min_fee_ref_script_cost_per_byte: S4.Number,
2081
+ epoch_no: S4.Number,
2082
+ min_fee_a: S4.Number,
2083
+ min_fee_b: S4.Number,
2084
+ max_block_size: S4.Number,
2085
+ max_tx_size: S4.Number,
2086
+ max_bh_size: S4.Number,
2087
+ key_deposit: S4.BigInt,
2088
+ pool_deposit: S4.BigInt,
2089
+ max_epoch: S4.Number,
2090
+ optimal_pool_count: S4.Number,
2091
+ influence: S4.Number,
2092
+ monetary_expand_rate: S4.Number,
2093
+ treasury_growth_rate: S4.Number,
2094
+ decentralisation: S4.Number,
2095
+ extra_entropy: S4.NullOr(S4.String),
2096
+ protocol_major: S4.Number,
2097
+ protocol_minor: S4.Number,
2098
+ min_utxo_value: S4.String,
2099
+ min_pool_cost: S4.String,
2100
+ nonce: S4.String,
2101
+ block_hash: S4.NullOr(S4.String),
2102
+ cost_models: S4.Struct({
2103
+ PlutusV1: S4.Array(S4.Number),
2104
+ PlutusV2: S4.Array(S4.Number),
2105
+ PlutusV3: S4.Array(S4.Number)
2089
2106
  }),
2090
- price_mem: S3.Number,
2091
- price_step: S3.Number,
2092
- max_tx_ex_mem: S3.BigIntFromNumber,
2093
- max_tx_ex_steps: S3.BigIntFromNumber,
2094
- max_block_ex_mem: S3.Number,
2095
- max_block_ex_steps: S3.Number,
2096
- max_val_size: S3.Number,
2097
- collateral_percent: S3.Number,
2098
- max_collateral_inputs: S3.Number,
2099
- coins_per_utxo_size: S3.BigInt
2107
+ price_mem: S4.Number,
2108
+ price_step: S4.Number,
2109
+ max_tx_ex_mem: S4.BigIntFromNumber,
2110
+ max_tx_ex_steps: S4.BigIntFromNumber,
2111
+ max_block_ex_mem: S4.Number,
2112
+ max_block_ex_steps: S4.Number,
2113
+ max_val_size: S4.Number,
2114
+ collateral_percent: S4.Number,
2115
+ max_collateral_inputs: S4.Number,
2116
+ coins_per_utxo_size: S4.BigInt
2100
2117
  });
2101
- var KoiosAssetSchema = S3.Struct({
2102
- policy_id: S3.String,
2103
- asset_name: S3.NullOr(S3.String),
2104
- fingerprint: S3.String,
2105
- decimals: S3.Number,
2106
- quantity: S3.String
2118
+ var AssetSchema = S4.Struct({
2119
+ policy_id: S4.String,
2120
+ asset_name: S4.NullOr(S4.String),
2121
+ fingerprint: S4.String,
2122
+ decimals: S4.Number,
2123
+ quantity: S4.String
2107
2124
  });
2108
- var ReferenceScriptSchema = S3.Struct({
2109
- hash: S3.NullOr(S3.String),
2110
- size: S3.NullOr(S3.Number),
2111
- type: S3.NullOr(S3.String),
2112
- bytes: S3.NullOr(S3.String),
2113
- value: S3.NullOr(S3.Object)
2125
+ var ReferenceScriptSchema = S4.Struct({
2126
+ hash: S4.NullOr(S4.String),
2127
+ size: S4.NullOr(S4.Number),
2128
+ type: S4.NullOr(S4.String),
2129
+ bytes: S4.NullOr(S4.String),
2130
+ value: S4.NullOr(S4.Object)
2114
2131
  });
2115
- var KoiosUTxOSchema = S3.Struct({
2116
- tx_hash: S3.String,
2117
- tx_index: S3.Number,
2118
- block_time: S3.Number,
2119
- block_height: S3.NullOr(S3.Number),
2120
- value: S3.String,
2121
- datum_hash: S3.NullOr(S3.String),
2122
- inline_datum: S3.NullOr(
2123
- S3.Struct({
2124
- bytes: S3.String,
2125
- value: S3.Object
2132
+ var UTxOSchema2 = S4.Struct({
2133
+ tx_hash: S4.String,
2134
+ tx_index: S4.Number,
2135
+ block_time: S4.Number,
2136
+ block_height: S4.NullOr(S4.Number),
2137
+ value: S4.String,
2138
+ datum_hash: S4.NullOr(S4.String),
2139
+ inline_datum: S4.NullOr(
2140
+ S4.Struct({
2141
+ bytes: S4.String,
2142
+ value: S4.Object
2126
2143
  })
2127
2144
  ),
2128
- reference_script: S3.NullOr(ReferenceScriptSchema),
2129
- asset_list: S3.NullOr(S3.Array(KoiosAssetSchema))
2145
+ reference_script: S4.NullOr(ReferenceScriptSchema),
2146
+ asset_list: S4.NullOr(S4.Array(AssetSchema))
2130
2147
  });
2131
- var KoiosAddressInfoSchema = S3.Array(
2132
- S3.NullishOr(
2133
- S3.Struct({
2134
- address: S3.String,
2135
- balance: S3.String,
2136
- stake_address: S3.NullOr(S3.String),
2137
- script_address: S3.Boolean,
2138
- utxo_set: S3.Array(KoiosUTxOSchema)
2148
+ var AddressInfoSchema = S4.Array(
2149
+ S4.NullishOr(
2150
+ S4.Struct({
2151
+ address: S4.String,
2152
+ balance: S4.String,
2153
+ stake_address: S4.NullOr(S4.String),
2154
+ script_address: S4.Boolean,
2155
+ utxo_set: S4.Array(UTxOSchema2)
2139
2156
  })
2140
2157
  )
2141
2158
  );
2142
- var KoiosInputOutputSchema = S3.Struct({
2143
- payment_addr: S3.Struct({
2144
- bech32: S3.String,
2145
- cred: S3.String
2159
+ var InputOutputSchema = S4.Struct({
2160
+ payment_addr: S4.Struct({
2161
+ bech32: S4.String,
2162
+ cred: S4.String
2146
2163
  }),
2147
- stake_addr: S3.NullOr(S3.String),
2148
- tx_hash: S3.String,
2149
- tx_index: S3.Number,
2150
- value: S3.String,
2151
- datum_hash: S3.NullOr(S3.String),
2152
- inline_datum: S3.NullOr(
2153
- S3.Struct({
2154
- bytes: S3.String,
2155
- value: S3.Object
2164
+ stake_addr: S4.NullOr(S4.String),
2165
+ tx_hash: S4.String,
2166
+ tx_index: S4.Number,
2167
+ value: S4.String,
2168
+ datum_hash: S4.NullOr(S4.String),
2169
+ inline_datum: S4.NullOr(
2170
+ S4.Struct({
2171
+ bytes: S4.String,
2172
+ value: S4.Object
2156
2173
  })
2157
2174
  ),
2158
- reference_script: S3.NullOr(ReferenceScriptSchema),
2159
- asset_list: S3.Array(KoiosAssetSchema)
2175
+ reference_script: S4.NullOr(ReferenceScriptSchema),
2176
+ asset_list: S4.Array(AssetSchema)
2160
2177
  });
2161
- var KoiosTxInfoSchema = S3.Struct({
2162
- tx_hash: S3.String,
2163
- block_hash: S3.String,
2164
- block_height: S3.Number,
2165
- epoch_no: S3.Number,
2166
- epoch_slot: S3.Number,
2167
- absolute_slot: S3.Number,
2168
- tx_timestamp: S3.Number,
2169
- tx_block_index: S3.Number,
2170
- tx_size: S3.Number,
2171
- total_output: S3.String,
2172
- fee: S3.String,
2173
- treasury_donation: S3.String,
2174
- deposit: S3.String,
2175
- invalid_before: S3.NullOr(S3.String),
2176
- invalid_after: S3.NullOr(S3.String),
2177
- collateral_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
2178
- collateral_output: S3.NullOr(KoiosInputOutputSchema),
2179
- reference_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
2180
- inputs: S3.Array(KoiosInputOutputSchema),
2181
- outputs: S3.Array(KoiosInputOutputSchema),
2182
- withdrawals: S3.NullOr(
2183
- S3.Array(
2184
- S3.Struct({
2185
- amount: S3.String,
2186
- stake_addr: S3.String
2178
+ var TxInfoSchema = S4.Struct({
2179
+ tx_hash: S4.String,
2180
+ block_hash: S4.String,
2181
+ block_height: S4.Number,
2182
+ epoch_no: S4.Number,
2183
+ epoch_slot: S4.Number,
2184
+ absolute_slot: S4.Number,
2185
+ tx_timestamp: S4.Number,
2186
+ tx_block_index: S4.Number,
2187
+ tx_size: S4.Number,
2188
+ total_output: S4.String,
2189
+ fee: S4.String,
2190
+ treasury_donation: S4.String,
2191
+ deposit: S4.String,
2192
+ invalid_before: S4.NullOr(S4.String),
2193
+ invalid_after: S4.NullOr(S4.String),
2194
+ collateral_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
2195
+ collateral_output: S4.NullOr(InputOutputSchema),
2196
+ reference_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
2197
+ inputs: S4.Array(InputOutputSchema),
2198
+ outputs: S4.Array(InputOutputSchema),
2199
+ withdrawals: S4.NullOr(
2200
+ S4.Array(
2201
+ S4.Struct({
2202
+ amount: S4.String,
2203
+ stake_addr: S4.String
2187
2204
  })
2188
2205
  )
2189
2206
  ),
2190
- assets_minted: S3.NullOr(S3.Array(KoiosAssetSchema)),
2191
- metadata: S3.NullOr(S3.Object),
2192
- certificates: S3.NullOr(
2193
- S3.Array(
2194
- S3.Struct({
2195
- index: S3.Number,
2196
- type: S3.String,
2197
- info: S3.NullOr(S3.Object)
2207
+ assets_minted: S4.NullOr(S4.Array(AssetSchema)),
2208
+ metadata: S4.NullOr(S4.Object),
2209
+ certificates: S4.NullOr(
2210
+ S4.Array(
2211
+ S4.Struct({
2212
+ index: S4.Number,
2213
+ type: S4.String,
2214
+ info: S4.NullOr(S4.Object)
2198
2215
  })
2199
2216
  )
2200
2217
  ),
2201
- native_scripts: S3.NullOr(
2202
- S3.Array(
2203
- S3.Struct({
2204
- script_hash: S3.String,
2205
- script_json: S3.Object
2218
+ native_scripts: S4.NullOr(
2219
+ S4.Array(
2220
+ S4.Struct({
2221
+ script_hash: S4.String,
2222
+ script_json: S4.Object
2206
2223
  })
2207
2224
  )
2208
2225
  ),
2209
- plutus_contracts: S3.NullOr(
2210
- S3.Array(
2211
- S3.Struct({
2212
- address: S3.String,
2213
- spends_input: S3.NullOr(
2214
- S3.Struct({
2215
- tx_hash: S3.String,
2216
- tx_index: S3.Number
2226
+ plutus_contracts: S4.NullOr(
2227
+ S4.Array(
2228
+ S4.Struct({
2229
+ address: S4.String,
2230
+ spends_input: S4.NullOr(
2231
+ S4.Struct({
2232
+ tx_hash: S4.String,
2233
+ tx_index: S4.Number
2217
2234
  })
2218
2235
  ),
2219
- script_hash: S3.String,
2220
- bytecode: S3.String,
2221
- size: S3.Number,
2222
- valid_contract: S3.Boolean,
2223
- input: S3.Struct({
2224
- redeemer: S3.Struct({
2225
- purpose: S3.Literal("spend", "mint", "cert", "reward"),
2226
- fee: S3.String,
2227
- unit: S3.Struct({
2228
- steps: S3.String,
2229
- mem: S3.String
2236
+ script_hash: S4.String,
2237
+ bytecode: S4.String,
2238
+ size: S4.Number,
2239
+ valid_contract: S4.Boolean,
2240
+ input: S4.Struct({
2241
+ redeemer: S4.Struct({
2242
+ purpose: S4.Literal("spend", "mint", "cert", "reward"),
2243
+ fee: S4.String,
2244
+ unit: S4.Struct({
2245
+ steps: S4.String,
2246
+ mem: S4.String
2230
2247
  }),
2231
- datum: S3.Struct({
2232
- hash: S3.NullOr(S3.String),
2233
- value: S3.NullOr(S3.Object)
2248
+ datum: S4.Struct({
2249
+ hash: S4.NullOr(S4.String),
2250
+ value: S4.NullOr(S4.Object)
2234
2251
  })
2235
2252
  }),
2236
- datum: S3.Struct({
2237
- hash: S3.NullOr(S3.String),
2238
- value: S3.NullOr(S3.Object)
2253
+ datum: S4.Struct({
2254
+ hash: S4.NullOr(S4.String),
2255
+ value: S4.NullOr(S4.Object)
2239
2256
  })
2240
2257
  })
2241
2258
  })
@@ -2243,101 +2260,147 @@ var KoiosTxInfoSchema = S3.Struct({
2243
2260
  ),
2244
2261
  //TODO: add S.Struct
2245
2262
  // https://preprod.koios.rest/#post-/tx_info
2246
- voting_procedures: S3.Array(S3.Object),
2263
+ voting_procedures: S4.Array(S4.Object),
2247
2264
  //TODO: add S.Struct
2248
2265
  // https://preprod.koios.rest/#post-/tx_info
2249
- proposal_procedures: S3.Object
2266
+ proposal_procedures: S4.Object
2250
2267
  });
2251
-
2252
- // src/koios/koios.ts
2253
- var import_effect4 = require("effect");
2254
- var import_schema3 = require("@effect/schema");
2255
-
2256
- // src/fetch.ts
2257
- var fetch_exports = {};
2258
- __export(fetch_exports, {
2259
- FetchError: () => FetchError,
2260
- JsonError: () => JsonError,
2261
- ResponseError: () => ResponseError,
2262
- fetchEffect: () => fetchEffect
2268
+ var TxHashSchema = S4.String;
2269
+ var AssetAddressSchema = S4.Struct({
2270
+ payment_address: S4.String,
2271
+ stake_address: S4.NullOr(S4.String),
2272
+ quantity: S4.String
2263
2273
  });
2264
- var import_effect3 = require("effect");
2265
- var FetchError = class extends import_effect3.Data.TaggedError("FetchError") {
2266
- };
2267
- var ResponseError = class extends import_effect3.Data.TaggedError("ResponseError") {
2274
+ var AccountInfoSchema = S4.Struct({
2275
+ delegated_pool: S4.NullOr(S4.String),
2276
+ rewards_available: S4.NumberFromString
2277
+ });
2278
+ var DatumInfo = S4.Struct({
2279
+ bytes: S4.String
2280
+ });
2281
+ var postWithSchemaValidation = (url, data, schema) => (0, import_effect3.pipe)(
2282
+ import_platform2.HttpClientRequest.post(url),
2283
+ import_platform2.HttpClientRequest.jsonBody(data),
2284
+ import_effect3.Effect.flatMap(import_platform2.HttpClient.fetchOk),
2285
+ import_platform2.HttpClientResponse.json,
2286
+ import_effect3.Effect.flatMap(S4.decodeUnknown(schema))
2287
+ // Effect.scoped
2288
+ );
2289
+ var getWithSchemaValidation = (url, schema) => (0, import_effect3.pipe)(
2290
+ import_platform2.HttpClientRequest.get(url),
2291
+ import_platform2.HttpClient.fetchOk,
2292
+ import_platform2.HttpClientResponse.json,
2293
+ import_effect3.Effect.flatMap(S4.decodeUnknown(schema))
2294
+ );
2295
+ var toUTxO = (koiosUTxO, address) => ({
2296
+ txHash: koiosUTxO.tx_hash,
2297
+ outputIndex: koiosUTxO.tx_index,
2298
+ assets: (() => {
2299
+ const a = {};
2300
+ if (koiosUTxO.asset_list) {
2301
+ koiosUTxO.asset_list.forEach((am) => {
2302
+ a[am.policy_id + am.asset_name] = BigInt(am.quantity);
2303
+ });
2304
+ }
2305
+ a["lovelace"] = BigInt(koiosUTxO.value);
2306
+ return a;
2307
+ })(),
2308
+ address,
2309
+ datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
2310
+ datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
2311
+ scriptRef: toScriptRef2(koiosUTxO.reference_script)
2312
+ });
2313
+ var toScriptRef2 = (reference_script) => {
2314
+ if (reference_script && reference_script.bytes && reference_script.type) {
2315
+ switch (reference_script.type) {
2316
+ case "plutusV1":
2317
+ return {
2318
+ type: "PlutusV1",
2319
+ script: (0, import_utils7.applyDoubleCborEncoding)(reference_script.bytes)
2320
+ };
2321
+ case "plutusV2":
2322
+ return {
2323
+ type: "PlutusV2",
2324
+ script: (0, import_utils7.applyDoubleCborEncoding)(reference_script.bytes)
2325
+ };
2326
+ case "plutusV3":
2327
+ return {
2328
+ type: "PlutusV3",
2329
+ script: (0, import_utils7.applyDoubleCborEncoding)(reference_script.bytes)
2330
+ };
2331
+ default:
2332
+ return void 0;
2333
+ }
2334
+ }
2268
2335
  };
2269
- var JsonError = class extends import_effect3.Data.TaggedError("JsonError") {
2336
+ var getUtxosEffect = (baseUrl, addressOrCredential) => {
2337
+ const url = `${baseUrl}/address_info`;
2338
+ const body = {
2339
+ _addresses: [addressOrCredential]
2340
+ };
2341
+ const schema = AddressInfoSchema;
2342
+ const result = (0, import_effect3.pipe)(
2343
+ import_effect3.Effect.if(typeof addressOrCredential === "string", {
2344
+ onFalse: () => import_effect3.Effect.fail("Credential Type is not supported in Koios yet."),
2345
+ onTrue: () => postWithSchemaValidation(url, body, schema)
2346
+ }),
2347
+ import_effect3.Effect.map(
2348
+ ([result2]) => result2 ? result2.utxo_set.map((koiosUtxo) => toUTxO(koiosUtxo, result2.address)) : []
2349
+ )
2350
+ );
2351
+ return result;
2270
2352
  };
2271
- var fetchEffect = (input, requestInit) => (0, import_effect3.pipe)(
2272
- import_effect3.Effect.tryPromise({
2273
- try: () => fetch(input, requestInit),
2274
- catch: (error) => new FetchError({
2275
- message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
2276
- })
2277
- }),
2278
- import_effect3.Effect.flatMap(
2279
- (response) => !response.ok ? new ResponseError({
2280
- message: `${response.status} ${response.statusText}`
2281
- }) : import_effect3.Effect.succeed(response)
2282
- ),
2283
- import_effect3.Effect.flatMap(
2284
- (response) => import_effect3.Effect.tryPromise({
2285
- try: () => response.json(),
2286
- catch: (error) => new JsonError({ message: String(error) })
2287
- })
2288
- )
2289
- );
2290
2353
 
2291
- // src/koios/koios.ts
2354
+ // src/koios.ts
2355
+ var import_effect4 = require("effect");
2356
+ var KoiosError = class extends import_effect4.Data.TaggedError("KoiosError") {
2357
+ get message() {
2358
+ return `${this.cause}`;
2359
+ }
2360
+ };
2292
2361
  var Koios = class {
2293
2362
  baseUrl;
2294
2363
  constructor(baseUrl) {
2295
2364
  this.baseUrl = baseUrl;
2296
2365
  }
2297
2366
  async getProtocolParameters() {
2298
- const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
2299
- (res) => res.json()
2300
- );
2301
- const param = await (0, import_effect4.pipe)(
2302
- S4.decodeUnknown(ProtocolParametersSchema2, {
2303
- onExcessProperty: "error",
2304
- errors: "first"
2305
- })(result[0]),
2306
- import_effect4.Effect.catchTag(
2307
- "ParseError",
2308
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2309
- ),
2367
+ const url = `${this.baseUrl}/epoch_params?limit=1`;
2368
+ const schema = S5.Array(ProtocolParametersSchema2);
2369
+ const [result] = await (0, import_effect4.pipe)(
2370
+ getWithSchemaValidation(url, schema),
2371
+ import_effect4.Effect.timeout(1e4),
2372
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2310
2373
  import_effect4.Effect.runPromise
2311
2374
  );
2312
2375
  return {
2313
- minFeeA: param.min_fee_a,
2314
- minFeeB: param.min_fee_b,
2315
- maxTxSize: param.max_tx_size,
2316
- maxValSize: param.max_val_size,
2317
- keyDeposit: param.key_deposit,
2318
- poolDeposit: param.pool_deposit,
2319
- priceMem: param.price_mem,
2320
- priceStep: param.price_step,
2321
- maxTxExMem: param.max_tx_ex_mem,
2322
- maxTxExSteps: param.max_tx_ex_steps,
2323
- coinsPerUtxoByte: param.coins_per_utxo_size,
2324
- collateralPercentage: param.collateral_percent,
2325
- maxCollateralInputs: param.max_collateral_inputs,
2376
+ minFeeA: result.min_fee_a,
2377
+ minFeeB: result.min_fee_b,
2378
+ maxTxSize: result.max_tx_size,
2379
+ maxValSize: result.max_val_size,
2380
+ keyDeposit: result.key_deposit,
2381
+ poolDeposit: result.pool_deposit,
2382
+ priceMem: result.price_mem,
2383
+ priceStep: result.price_step,
2384
+ maxTxExMem: result.max_tx_ex_mem,
2385
+ maxTxExSteps: result.max_tx_ex_steps,
2386
+ coinsPerUtxoByte: result.coins_per_utxo_size,
2387
+ collateralPercentage: result.collateral_percent,
2388
+ maxCollateralInputs: result.max_collateral_inputs,
2326
2389
  costModels: {
2327
2390
  PlutusV1: Object.fromEntries(
2328
- param.cost_models.PlutusV1.map((value, index) => [
2391
+ result.cost_models.PlutusV1.map((value, index) => [
2329
2392
  index.toString(),
2330
2393
  value
2331
2394
  ])
2332
2395
  ),
2333
2396
  PlutusV2: Object.fromEntries(
2334
- param.cost_models.PlutusV2.map((value, index) => [
2397
+ result.cost_models.PlutusV2.map((value, index) => [
2335
2398
  index.toString(),
2336
2399
  value
2337
2400
  ])
2338
2401
  ),
2339
2402
  PlutusV3: Object.fromEntries(
2340
- param.cost_models.PlutusV3.map((value, index) => [
2403
+ result.cost_models.PlutusV3.map((value, index) => [
2341
2404
  index.toString(),
2342
2405
  value
2343
2406
  ])
@@ -2346,109 +2409,80 @@ var Koios = class {
2346
2409
  };
2347
2410
  }
2348
2411
  async getUtxos(addressOrCredential) {
2349
- if (typeof addressOrCredential === "string") {
2350
- const body = {
2351
- _addresses: [addressOrCredential]
2352
- };
2353
- const result = await fetch(`${this.baseUrl}/address_info`, {
2354
- headers: {
2355
- Accept: "application/json",
2356
- "Content-Type": "application/json"
2357
- },
2358
- method: "POST",
2359
- body: JSON.stringify(body)
2360
- }).then((res) => res.json());
2361
- const [parsedResult] = await (0, import_effect4.pipe)(
2362
- S4.decodeUnknown(KoiosAddressInfoSchema, {
2363
- onExcessProperty: "error",
2364
- errors: "first"
2365
- })(result),
2366
- import_effect4.Effect.catchTag(
2367
- "ParseError",
2368
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2369
- ),
2370
- import_effect4.Effect.runPromise
2371
- );
2372
- return parsedResult ? parsedResult.utxo_set.map(
2373
- (koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
2374
- ) : [];
2375
- } else {
2376
- throw Error("getUtxos by Credential Type is not supported in Koios yet.");
2377
- }
2412
+ const result = await (0, import_effect4.pipe)(
2413
+ getUtxosEffect(this.baseUrl, addressOrCredential),
2414
+ import_effect4.Effect.timeout(1e4),
2415
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2416
+ import_effect4.Effect.runPromise
2417
+ );
2418
+ return result;
2378
2419
  }
2379
2420
  async getUtxosWithUnit(addressOrCredential, unit) {
2380
- if (typeof addressOrCredential === "string") {
2381
- const utxos = await this.getUtxos(addressOrCredential);
2382
- if (utxos && utxos.length > 0) {
2383
- return utxos.filter((utxo) => {
2421
+ const result = await (0, import_effect4.pipe)(
2422
+ getUtxosEffect(this.baseUrl, addressOrCredential),
2423
+ import_effect4.Effect.map(
2424
+ (utxos) => utxos.filter((utxo) => {
2384
2425
  const keys = Object.keys(utxo.assets);
2385
2426
  return keys.length > 0 && keys.includes(unit);
2386
- });
2387
- } else {
2388
- return [];
2389
- }
2390
- } else {
2391
- throw Error(
2392
- "getUtxosWithUnit by Credential Type is not supported in Koios yet."
2393
- );
2394
- }
2427
+ })
2428
+ ),
2429
+ import_effect4.Effect.timeout(1e4),
2430
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2431
+ import_effect4.Effect.runPromise
2432
+ );
2433
+ return result;
2395
2434
  }
2396
2435
  async getUtxoByUnit(unit) {
2397
- let { policyId, assetName } = (0, import_utils6.fromUnit)(unit);
2398
- assetName = String(assetName);
2399
- const assetAddresses = await fetch(
2400
- `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`
2401
- ).then((res) => res.json());
2402
- if (Array.isArray(assetAddresses) && assetAddresses.length > 0) {
2403
- if (assetAddresses.length > 1) {
2404
- throw new Error("Unit needs to be an NFT or only held by one address.");
2405
- }
2406
- const utxos = await this.getUtxos(
2407
- assetAddresses[0].payment_address
2408
- );
2409
- const result = utxos.find((utxo) => {
2410
- const keys = Object.keys(utxo.assets);
2411
- return keys.length > 0 && keys.includes(unit);
2412
- });
2413
- if (result) {
2414
- return result;
2415
- }
2416
- }
2417
- throw new Error("Unit not found.");
2436
+ let { policyId, assetName } = (0, import_utils8.fromUnit)(unit);
2437
+ const url = `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`;
2438
+ const result = await (0, import_effect4.pipe)(
2439
+ getWithSchemaValidation(url, S5.Array(AssetAddressSchema)),
2440
+ import_effect4.Effect.flatMap(
2441
+ (adresses) => adresses.length === 0 ? import_effect4.Effect.fail("Unit not found") : import_effect4.Effect.succeed(adresses)
2442
+ ),
2443
+ import_effect4.Effect.flatMap(
2444
+ (adresses) => adresses.length > 1 ? import_effect4.Effect.fail("Unit needs to be an NFT or only held by one address.") : import_effect4.Effect.succeed(adresses[0])
2445
+ ),
2446
+ import_effect4.Effect.flatMap(
2447
+ (address) => getUtxosEffect(this.baseUrl, address.payment_address)
2448
+ ),
2449
+ import_effect4.Effect.map(
2450
+ (utxos) => utxos.filter((utxo) => {
2451
+ const keys = Object.keys(utxo.assets);
2452
+ return keys.length > 0 && keys.includes(unit);
2453
+ })
2454
+ ),
2455
+ import_effect4.Effect.flatMap(
2456
+ (utxos) => utxos.length > 1 ? import_effect4.Effect.fail("Unit needs to be an NFT or only held by one address.") : import_effect4.Effect.succeed(utxos[0])
2457
+ ),
2458
+ import_effect4.Effect.timeout(1e4),
2459
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2460
+ import_effect4.Effect.runPromise
2461
+ );
2462
+ return result;
2418
2463
  }
2419
2464
  async getUtxosByOutRef(outRefs) {
2465
+ const url = `${this.baseUrl}/tx_info`;
2420
2466
  const body = {
2421
2467
  _tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))],
2422
2468
  _assets: true,
2423
2469
  _scripts: true
2424
2470
  };
2425
- const result = await fetch(`${this.baseUrl}/tx_info`, {
2426
- headers: {
2427
- Accept: "application/json",
2428
- "Content-Type": "application/json"
2429
- },
2430
- method: "POST",
2431
- body: JSON.stringify(body)
2432
- }).then((res) => res.json());
2433
- const [parsedResult] = await (0, import_effect4.pipe)(
2434
- S4.decodeUnknown(S4.Array(KoiosTxInfoSchema), {
2435
- onExcessProperty: "error",
2436
- errors: "first"
2437
- })(result),
2438
- import_effect4.Effect.catchTag(
2439
- "ParseError",
2440
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2441
- ),
2471
+ const schema = S5.Array(TxInfoSchema);
2472
+ const [result] = await (0, import_effect4.pipe)(
2473
+ postWithSchemaValidation(url, body, schema),
2474
+ import_effect4.Effect.timeout(1e4),
2475
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2442
2476
  import_effect4.Effect.runPromise
2443
2477
  );
2444
- if (parsedResult) {
2445
- const utxos = parsedResult.outputs.map(
2478
+ if (result) {
2479
+ const utxos = result.outputs.map(
2446
2480
  (koiosInputOutput) => toUTxO(
2447
2481
  {
2448
2482
  tx_hash: koiosInputOutput.tx_hash,
2449
2483
  tx_index: koiosInputOutput.tx_index,
2450
2484
  block_time: 0,
2451
- block_height: parsedResult.block_height,
2485
+ block_height: result.block_height,
2452
2486
  value: koiosInputOutput.value,
2453
2487
  datum_hash: koiosInputOutput.datum_hash,
2454
2488
  inline_datum: koiosInputOutput.inline_datum,
@@ -2471,135 +2505,94 @@ var Koios = class {
2471
2505
  const body = {
2472
2506
  _stake_addresses: [rewardAddress]
2473
2507
  };
2474
- const result = await fetch(`${this.baseUrl}/account_info`, {
2475
- headers: {
2476
- Accept: "application/json",
2477
- "Content-Type": "application/json"
2478
- },
2479
- method: "POST",
2480
- body: JSON.stringify(body)
2481
- }).then((res) => res.json());
2482
- if (Array.isArray(result) && result.length > 0) {
2483
- return {
2484
- poolId: result[0].delegated_pool || null,
2485
- rewards: BigInt(result[0].rewards_available)
2486
- };
2487
- } else {
2488
- throw new Error("No Delegation Found by Reward Address");
2489
- }
2508
+ const url = `${this.baseUrl}/account_info`;
2509
+ const result = await (0, import_effect4.pipe)(
2510
+ postWithSchemaValidation(
2511
+ url,
2512
+ body,
2513
+ S5.Array(AccountInfoSchema)
2514
+ ),
2515
+ import_effect4.Effect.flatMap(
2516
+ (result2) => result2.length === 0 ? import_effect4.Effect.fail("No Delegation Found by Reward Address") : import_effect4.Effect.succeed(result2[0])
2517
+ ),
2518
+ import_effect4.Effect.timeout(1e4),
2519
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2520
+ import_effect4.Effect.runPromise
2521
+ );
2522
+ return {
2523
+ poolId: result.delegated_pool || null,
2524
+ rewards: BigInt(result.rewards_available)
2525
+ };
2490
2526
  }
2491
2527
  async getDatum(datumHash) {
2528
+ const url = `${this.baseUrl}/datum_info`;
2492
2529
  const body = {
2493
2530
  _datum_hashes: [datumHash]
2494
2531
  };
2495
- const datum = await fetch(`${this.baseUrl}/datum_info`, {
2496
- headers: {
2497
- Accept: "application/json",
2498
- "Content-Type": "application/json"
2499
- },
2500
- method: "POST",
2501
- body: JSON.stringify(body)
2502
- }).then((res) => res.json());
2503
- if (Array.isArray(datum) && datum.length > 0) {
2504
- return datum[0].bytes;
2505
- } else {
2506
- throw new Error("No Datum Found by Datum Hash");
2507
- }
2532
+ const result = await (0, import_effect4.pipe)(
2533
+ postWithSchemaValidation(url, body, S5.Array(DatumInfo)),
2534
+ import_effect4.Effect.flatMap(
2535
+ (result2) => result2.length === 0 ? import_effect4.Effect.fail("No Datum Found by Datum Hash") : import_effect4.Effect.succeed(result2[0])
2536
+ ),
2537
+ import_effect4.Effect.timeout(1e4),
2538
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2539
+ import_effect4.Effect.runPromise
2540
+ );
2541
+ return result.bytes;
2508
2542
  }
2509
2543
  async awaitTx(txHash, checkInterval = 2e4) {
2544
+ const url = `${this.baseUrl}/tx_info`;
2510
2545
  const body = {
2511
2546
  _tx_hashes: [txHash]
2512
2547
  };
2513
- const request = {
2514
- headers: {
2515
- Accept: "application/json",
2516
- "Content-Type": "application/json"
2517
- },
2518
- method: "POST",
2519
- body: JSON.stringify(body)
2520
- };
2521
- const program = (0, import_effect4.pipe)(
2522
- fetchEffect(`${this.baseUrl}/tx_info`, request),
2523
- import_effect4.Effect.flatMap(
2524
- (json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
2525
- ),
2526
- import_effect4.Effect.catchTag(
2527
- "ParseError",
2528
- (e) => import_effect4.Effect.fail(import_schema3.ArrayFormatter.formatErrorSync(e))
2529
- ),
2548
+ const schema = S5.Array(TxInfoSchema);
2549
+ const result = await (0, import_effect4.pipe)(
2550
+ postWithSchemaValidation(url, body, schema),
2530
2551
  import_effect4.Effect.repeat({
2531
2552
  schedule: import_effect4.Schedule.exponential(checkInterval),
2532
- until: (result) => result.length > 0
2553
+ until: (result2) => result2.length > 0
2533
2554
  }),
2534
2555
  import_effect4.Effect.timeout(16e4),
2535
2556
  import_effect4.Effect.orDie,
2536
- import_effect4.Effect.as(true)
2557
+ import_effect4.Effect.as(true),
2558
+ import_effect4.Effect.runPromise
2537
2559
  );
2538
- return import_effect4.Effect.runPromise(program);
2560
+ return result;
2539
2561
  }
2540
2562
  async submitTx(tx) {
2541
- const result = await fetch(`${this.baseUrl}/submittx`, {
2542
- headers: {
2543
- Accept: "application/json",
2544
- "Content-Type": "application/cbor"
2545
- },
2546
- method: "POST",
2547
- body: (0, import_core_utils4.fromHex)(tx)
2548
- }).then((res) => res.json());
2549
- const TxHashSchema = S4.String;
2550
- const isTxHash = S4.is(TxHashSchema);
2551
- if (!isTxHash(result)) {
2552
- throw new Error(JSON.stringify(result));
2553
- }
2563
+ const url = `${this.baseUrl}/submittx`;
2564
+ const body = (0, import_core_utils4.fromHex)(tx);
2565
+ const schema = TxHashSchema;
2566
+ const result = await (0, import_effect4.pipe)(
2567
+ postWithSchemaValidation(url, body, schema),
2568
+ import_effect4.Effect.timeout(1e4),
2569
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2570
+ import_effect4.Effect.runPromise
2571
+ );
2554
2572
  return result;
2555
2573
  }
2556
2574
  async evaluateTx(tx, additionalUTxOs) {
2557
- const utxos = (additionalUTxOs || []).map((utxo) => {
2558
- const script = utxo.scriptRef ? {
2559
- language: utxo.scriptRef.type,
2560
- cbor: utxo.scriptRef.script
2561
- } : void 0;
2562
- return [
2563
- {
2564
- transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
2565
- },
2566
- {
2567
- address: utxo.address,
2568
- value: {
2569
- coins: utxo.assets.lovelace,
2570
- assets: utxo.assets.restAssets
2571
- },
2572
- datumHash: utxo.datumHash,
2573
- datum: utxo.datum,
2574
- script
2575
- }
2576
- ];
2577
- });
2578
- const data = {
2575
+ const url = `${this.baseUrl}/ogmios`;
2576
+ const body = {
2579
2577
  jsonrpc: "2.0",
2580
2578
  method: "evaluateTransaction",
2581
- params: { transaction: { cbor: tx }, additionalUTxO: utxos },
2579
+ params: {
2580
+ transaction: { cbor: tx },
2581
+ additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
2582
+ },
2582
2583
  id: null
2583
2584
  };
2584
- const response = await fetch(`${this.baseUrl}/ogmios`, {
2585
- headers: {
2586
- Accept: "application/json",
2587
- "Content-Type": "application/json"
2588
- },
2589
- method: "POST",
2590
- body: JSON.stringify(
2591
- data,
2592
- (_, value) => typeof value === "bigint" ? value.toString() : value
2593
- )
2594
- });
2595
- if (!response.ok) {
2596
- const errorBody = await response.text();
2597
- throw new Error(
2598
- `Request failed with status ${response.status}: ${errorBody}`
2599
- );
2600
- }
2601
- const result = await response.json();
2602
- const evalRedeemers = result.result.map((item) => ({
2585
+ const schema = JSONRPCSchema(S5.Array(RedeemerSchema));
2586
+ const result = await (0, import_effect4.pipe)(
2587
+ postWithSchemaValidation(url, body, schema),
2588
+ import_effect4.Effect.flatMap(
2589
+ (response) => "error" in response ? import_effect4.Effect.fail(response) : import_effect4.Effect.succeed(response.result)
2590
+ ),
2591
+ import_effect4.Effect.timeout(1e4),
2592
+ import_effect4.Effect.catchAllCause((cause) => new KoiosError({ cause })),
2593
+ import_effect4.Effect.runPromise
2594
+ );
2595
+ const evalRedeemers = result.map((item) => ({
2603
2596
  ex_units: {
2604
2597
  mem: item.budget.memory,
2605
2598
  steps: item.budget.cpu
@@ -2610,56 +2603,15 @@ var Koios = class {
2610
2603
  return evalRedeemers;
2611
2604
  }
2612
2605
  };
2613
- var toUTxO = (koiosUTxO, address) => ({
2614
- txHash: koiosUTxO.tx_hash,
2615
- outputIndex: koiosUTxO.tx_index,
2616
- assets: (() => {
2617
- const a = {};
2618
- if (koiosUTxO.asset_list) {
2619
- koiosUTxO.asset_list.forEach((am) => {
2620
- a[am.policy_id + am.asset_name] = BigInt(am.quantity);
2621
- });
2622
- }
2623
- a["lovelace"] = BigInt(koiosUTxO.value);
2624
- return a;
2625
- })(),
2626
- address,
2627
- datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
2628
- datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
2629
- scriptRef: toScriptRef2(koiosUTxO.reference_script)
2630
- });
2631
- var toScriptRef2 = (reference_script) => {
2632
- if (reference_script && reference_script.bytes && reference_script.type) {
2633
- switch (reference_script.type) {
2634
- case "plutusV1":
2635
- return {
2636
- type: "PlutusV1",
2637
- script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2638
- };
2639
- case "plutusV2":
2640
- return {
2641
- type: "PlutusV2",
2642
- script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2643
- };
2644
- case "plutusV3":
2645
- return {
2646
- type: "PlutusV3",
2647
- script: (0, import_utils6.applyDoubleCborEncoding)(reference_script.bytes)
2648
- };
2649
- default:
2650
- return void 0;
2651
- }
2652
- }
2653
- };
2654
2606
  // Annotate the CommonJS export names for ESM import in node:
2655
2607
  0 && (module.exports = {
2656
2608
  Blockfrost,
2657
2609
  Emulator,
2658
- FetchProvider,
2659
2610
  Koios,
2611
+ KoiosError,
2660
2612
  Kupmios,
2661
2613
  KupmiosError,
2662
2614
  Maestro,
2663
- datumJsonToCbor,
2664
- generateEmulatorAccount
2615
+ generateEmulatorAccount,
2616
+ generateEmulatorAccountFrommPrivateKey
2665
2617
  });