@lucid-evolution/provider 0.1.43 → 0.1.44
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 +140 -117
- package/dist/index.js +66 -43
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -45,14 +45,14 @@ module.exports = __toCommonJS(src_exports);
|
|
|
45
45
|
// src/core.ts
|
|
46
46
|
var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
|
|
47
47
|
|
|
48
|
-
// src/blockfrost.ts
|
|
48
|
+
// src/blockfrost/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.
|
|
55
|
+
version: "0.1.44",
|
|
56
56
|
description: "",
|
|
57
57
|
main: "./dist/index.js",
|
|
58
58
|
types: "./dist/index.d.ts",
|
|
@@ -100,7 +100,8 @@ var package_default = {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
// src/blockfrost.ts
|
|
103
|
+
// src/blockfrost/blockfrost.ts
|
|
104
|
+
var import_effect = require("effect");
|
|
104
105
|
var Blockfrost = class {
|
|
105
106
|
url;
|
|
106
107
|
projectId;
|
|
@@ -336,19 +337,9 @@ var Blockfrost = class {
|
|
|
336
337
|
return utxos;
|
|
337
338
|
}
|
|
338
339
|
async evaluateTx(tx, additionalUTxOs) {
|
|
339
|
-
const additionalUTxOSet = (additionalUTxOs || []).map((utxo) => [
|
|
340
|
-
{ txId: utxo.txHash, index: utxo.outputIndex },
|
|
341
|
-
{
|
|
342
|
-
address: utxo.address,
|
|
343
|
-
value: { coins: utxo.assets.lovelace, assets: utxo.assets.restAssets },
|
|
344
|
-
datum_hash: utxo.datumHash,
|
|
345
|
-
datum: utxo.datum,
|
|
346
|
-
script: utxo.scriptRef
|
|
347
|
-
}
|
|
348
|
-
]);
|
|
349
340
|
const payload = {
|
|
350
341
|
cbor: tx,
|
|
351
|
-
|
|
342
|
+
additionalUtxoSet: toAditionalUTXOs(additionalUTxOs)
|
|
352
343
|
};
|
|
353
344
|
const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
|
|
354
345
|
method: "POST",
|
|
@@ -357,10 +348,7 @@ var Blockfrost = class {
|
|
|
357
348
|
project_id: this.projectId,
|
|
358
349
|
lucid
|
|
359
350
|
},
|
|
360
|
-
body: JSON.stringify(
|
|
361
|
-
payload,
|
|
362
|
-
(_, value) => typeof value === "bigint" ? value.toString() : value
|
|
363
|
-
)
|
|
351
|
+
body: JSON.stringify(payload)
|
|
364
352
|
}).then((res2) => res2.json());
|
|
365
353
|
if (!res || res.error) {
|
|
366
354
|
const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}`;
|
|
@@ -424,17 +412,41 @@ function datumJsonToCbor(json) {
|
|
|
424
412
|
}
|
|
425
413
|
var handleRateLimit = async (count) => {
|
|
426
414
|
if (count % 100 === 0) {
|
|
427
|
-
await (0, import_core_utils.sleep)(
|
|
415
|
+
await (0, import_core_utils.sleep)(5e3);
|
|
428
416
|
} else if (count % 10 === 0) {
|
|
429
|
-
await (0, import_core_utils.sleep)(
|
|
417
|
+
await (0, import_core_utils.sleep)(500);
|
|
430
418
|
}
|
|
431
419
|
};
|
|
432
420
|
var lucid = package_default.version;
|
|
421
|
+
var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
|
|
422
|
+
{
|
|
423
|
+
txId: utxo.txHash,
|
|
424
|
+
index: utxo.outputIndex
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
address: utxo.address,
|
|
428
|
+
value: {
|
|
429
|
+
coins: Number(utxo.assets["lovelace"]),
|
|
430
|
+
assets: fromAssets(utxo.assets)
|
|
431
|
+
},
|
|
432
|
+
datumHash: utxo.datumHash,
|
|
433
|
+
datum: utxo.datum,
|
|
434
|
+
script: utxo.scriptRef ? utxo.scriptRef.type === "PlutusV1" ? { "plutus:v1": utxo.scriptRef.script } : { "plutus:v2": utxo.scriptRef.script } : void 0
|
|
435
|
+
}
|
|
436
|
+
]);
|
|
437
|
+
var fromAssets = (assets) => (0, import_effect.pipe)(
|
|
438
|
+
import_effect.Record.remove(assets, "lovelace"),
|
|
439
|
+
import_effect.Record.mapEntries((amount, unit) => [
|
|
440
|
+
unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
|
|
441
|
+
Number(amount)
|
|
442
|
+
]),
|
|
443
|
+
(r) => import_effect.Record.isEmptyRecord(r) ? void 0 : r
|
|
444
|
+
);
|
|
433
445
|
|
|
434
446
|
// src/kupmios/kupmios.ts
|
|
435
447
|
var import_utils2 = require("@lucid-evolution/utils");
|
|
436
448
|
var S2 = __toESM(require("@effect/schema/Schema"), 1);
|
|
437
|
-
var
|
|
449
|
+
var import_effect2 = require("effect");
|
|
438
450
|
|
|
439
451
|
// src/kupmios/schema.ts
|
|
440
452
|
var S = __toESM(require("@effect/schema/Schema"), 1);
|
|
@@ -504,7 +516,12 @@ var KupoUTxO = S.Struct({
|
|
|
504
516
|
slot_no: S.Number,
|
|
505
517
|
header_hash: S.String
|
|
506
518
|
}),
|
|
507
|
-
spent_at: S.NullOr(
|
|
519
|
+
spent_at: S.NullOr(
|
|
520
|
+
S.Struct({
|
|
521
|
+
slot_no: S.Number,
|
|
522
|
+
header_hash: S.String
|
|
523
|
+
})
|
|
524
|
+
)
|
|
508
525
|
});
|
|
509
526
|
var KupoScriptSchema = S.NullOr(
|
|
510
527
|
S.Struct({
|
|
@@ -526,7 +543,7 @@ var KupoDelegation = S.NullOr(
|
|
|
526
543
|
|
|
527
544
|
// src/kupmios/kupmios.ts
|
|
528
545
|
var import_platform = require("@effect/platform");
|
|
529
|
-
var KupmiosError = class extends
|
|
546
|
+
var KupmiosError = class extends import_effect2.Data.TaggedError("KupmiosError") {
|
|
530
547
|
get message() {
|
|
531
548
|
return `${this.cause}`;
|
|
532
549
|
}
|
|
@@ -556,13 +573,13 @@ var Kupmios = class {
|
|
|
556
573
|
ProtocolParametersSchema
|
|
557
574
|
);
|
|
558
575
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
559
|
-
|
|
560
|
-
(response) => "error" in response ? kupmiosError(response.error) :
|
|
576
|
+
import_effect2.Effect.flatMap(
|
|
577
|
+
(response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
|
|
561
578
|
),
|
|
562
|
-
|
|
563
|
-
|
|
579
|
+
import_effect2.Effect.timeout(1e4),
|
|
580
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
564
581
|
);
|
|
565
|
-
const result = await
|
|
582
|
+
const result = await import_effect2.Effect.runPromise(program);
|
|
566
583
|
return toProtocolParameters(result);
|
|
567
584
|
}
|
|
568
585
|
async getUtxos(addressOrCredential) {
|
|
@@ -571,11 +588,11 @@ var Kupmios = class {
|
|
|
571
588
|
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
|
|
572
589
|
const schema = S2.Array(KupoUTxO);
|
|
573
590
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
591
|
+
import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
592
|
+
import_effect2.Effect.timeout(1e4),
|
|
593
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
577
594
|
);
|
|
578
|
-
const utxos = await
|
|
595
|
+
const utxos = await import_effect2.Effect.runPromise(program);
|
|
579
596
|
return utxos;
|
|
580
597
|
}
|
|
581
598
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
@@ -585,11 +602,11 @@ var Kupmios = class {
|
|
|
585
602
|
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
|
|
586
603
|
const schema = S2.Array(KupoUTxO);
|
|
587
604
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
605
|
+
import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
606
|
+
import_effect2.Effect.timeout(1e4),
|
|
607
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
591
608
|
);
|
|
592
|
-
const utxos = await
|
|
609
|
+
const utxos = await import_effect2.Effect.runPromise(program);
|
|
593
610
|
return utxos;
|
|
594
611
|
}
|
|
595
612
|
async getUtxoByUnit(unit) {
|
|
@@ -597,11 +614,11 @@ var Kupmios = class {
|
|
|
597
614
|
const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
|
|
598
615
|
const schema = S2.Array(KupoUTxO);
|
|
599
616
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
617
|
+
import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
618
|
+
import_effect2.Effect.timeout(1e4),
|
|
619
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
603
620
|
);
|
|
604
|
-
const utxos = await
|
|
621
|
+
const utxos = await import_effect2.Effect.runPromise(program);
|
|
605
622
|
if (utxos.length > 1) {
|
|
606
623
|
throw new Error("Unit needs to be an NFT or only held by one address.");
|
|
607
624
|
}
|
|
@@ -613,16 +630,16 @@ var Kupmios = class {
|
|
|
613
630
|
];
|
|
614
631
|
const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
615
632
|
const schema = S2.Array(KupoUTxO);
|
|
616
|
-
const program =
|
|
633
|
+
const program = import_effect2.Effect.forEach(
|
|
617
634
|
queryHashes,
|
|
618
635
|
(txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
636
|
+
import_effect2.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
637
|
+
import_effect2.Effect.timeout(1e4),
|
|
638
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
622
639
|
)
|
|
623
640
|
);
|
|
624
|
-
const utxos = await
|
|
625
|
-
return
|
|
641
|
+
const utxos = await import_effect2.Effect.runPromise(program);
|
|
642
|
+
return import_effect2.Array.flatten(utxos).filter(
|
|
626
643
|
(utxo) => outRefs.some(
|
|
627
644
|
(outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
|
|
628
645
|
)
|
|
@@ -637,13 +654,13 @@ var Kupmios = class {
|
|
|
637
654
|
};
|
|
638
655
|
const schema = JSONRPCSchema(KupoDelegation);
|
|
639
656
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
640
|
-
|
|
641
|
-
(response) => "error" in response ? kupmiosError(response.error) :
|
|
657
|
+
import_effect2.Effect.flatMap(
|
|
658
|
+
(response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
|
|
642
659
|
),
|
|
643
|
-
|
|
644
|
-
|
|
660
|
+
import_effect2.Effect.timeout(1e4),
|
|
661
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
645
662
|
);
|
|
646
|
-
const result = await
|
|
663
|
+
const result = await import_effect2.Effect.runPromise(program);
|
|
647
664
|
const delegation = result ? Object.values(result)[0] : null;
|
|
648
665
|
return {
|
|
649
666
|
poolId: delegation?.delegate?.id || null,
|
|
@@ -654,28 +671,28 @@ var Kupmios = class {
|
|
|
654
671
|
const pattern = `${this.kupoUrl}/datums/${datumHash}`;
|
|
655
672
|
const schema = KupoDatumSchema;
|
|
656
673
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
674
|
+
import_effect2.Effect.timeout(1e4),
|
|
675
|
+
import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
|
|
676
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
660
677
|
);
|
|
661
|
-
const result = await
|
|
678
|
+
const result = await import_effect2.Effect.runPromise(program);
|
|
662
679
|
return result.datum;
|
|
663
680
|
}
|
|
664
681
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
665
|
-
const pattern = `${this.kupoUrl}/matches/*@${txHash}?
|
|
682
|
+
const pattern = `${this.kupoUrl}/matches/*@${txHash}?spent`;
|
|
666
683
|
const schema = S2.Array(KupoUTxO).annotations({
|
|
667
684
|
identifier: "Array<KupmiosSchema.KupoUTxO>"
|
|
668
685
|
});
|
|
669
686
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
670
|
-
|
|
671
|
-
schedule:
|
|
687
|
+
import_effect2.Effect.repeat({
|
|
688
|
+
schedule: import_effect2.Schedule.exponential(checkInterval),
|
|
672
689
|
until: (result) => result.length > 0
|
|
673
690
|
}),
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
691
|
+
import_effect2.Effect.timeout(16e4),
|
|
692
|
+
import_effect2.Effect.catchAll(kupmiosError),
|
|
693
|
+
import_effect2.Effect.as(true)
|
|
677
694
|
);
|
|
678
|
-
return await
|
|
695
|
+
return await import_effect2.Effect.runPromise(program);
|
|
679
696
|
}
|
|
680
697
|
async submitTx(cbor) {
|
|
681
698
|
const data = {
|
|
@@ -694,13 +711,13 @@ var Kupmios = class {
|
|
|
694
711
|
})
|
|
695
712
|
);
|
|
696
713
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
697
|
-
|
|
698
|
-
(response) => "error" in response ?
|
|
714
|
+
import_effect2.Effect.flatMap(
|
|
715
|
+
(response) => "error" in response ? import_effect2.Effect.fail(response.error) : import_effect2.Effect.succeed(response)
|
|
699
716
|
),
|
|
700
|
-
|
|
701
|
-
|
|
717
|
+
import_effect2.Effect.timeout(1e4),
|
|
718
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
702
719
|
);
|
|
703
|
-
const { result } = await
|
|
720
|
+
const { result } = await import_effect2.Effect.runPromise(program);
|
|
704
721
|
return result.transaction.id;
|
|
705
722
|
}
|
|
706
723
|
async evaluateTx(tx, additionalUTxOs) {
|
|
@@ -746,13 +763,13 @@ var Kupmios = class {
|
|
|
746
763
|
)
|
|
747
764
|
);
|
|
748
765
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
749
|
-
|
|
750
|
-
(response) => "error" in response ? kupmiosError(response.error) :
|
|
766
|
+
import_effect2.Effect.flatMap(
|
|
767
|
+
(response) => "error" in response ? kupmiosError(response.error) : import_effect2.Effect.succeed(response.result)
|
|
751
768
|
),
|
|
752
|
-
|
|
753
|
-
|
|
769
|
+
import_effect2.Effect.timeout(1e4),
|
|
770
|
+
import_effect2.Effect.catchAll(kupmiosError)
|
|
754
771
|
);
|
|
755
|
-
const result = await
|
|
772
|
+
const result = await import_effect2.Effect.runPromise(program);
|
|
756
773
|
const evalRedeemers = result.map((item) => ({
|
|
757
774
|
ex_units: {
|
|
758
775
|
mem: item.budget.memory,
|
|
@@ -764,37 +781,43 @@ var Kupmios = class {
|
|
|
764
781
|
return evalRedeemers;
|
|
765
782
|
}
|
|
766
783
|
};
|
|
767
|
-
var getDatumEffect = (kupoUrl, datum_type, datum_hash) =>
|
|
784
|
+
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect2.Effect.gen(function* () {
|
|
768
785
|
if (datum_type === "inline" && datum_hash) {
|
|
769
786
|
const pattern = `${kupoUrl}/datums/${datum_hash}`;
|
|
770
787
|
const schema = KupoDatumSchema;
|
|
771
788
|
return yield* fetchKupoParse(pattern, schema).pipe(
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
789
|
+
import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
|
|
790
|
+
import_effect2.Effect.map((result) => result.datum),
|
|
791
|
+
import_effect2.Effect.timeout(1e4)
|
|
775
792
|
);
|
|
776
|
-
} else return
|
|
793
|
+
} else return void 0;
|
|
777
794
|
});
|
|
778
|
-
var getScriptEffect = (kupoUrl, script_hash) =>
|
|
795
|
+
var getScriptEffect = (kupoUrl, script_hash) => import_effect2.Effect.gen(function* () {
|
|
779
796
|
if (script_hash) {
|
|
780
797
|
const pattern = `${kupoUrl}/scripts/${script_hash}`;
|
|
781
798
|
const schema = KupoScriptSchema;
|
|
782
|
-
return yield* (0,
|
|
799
|
+
return yield* (0, import_effect2.pipe)(
|
|
783
800
|
fetchKupoParse(pattern, schema),
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
801
|
+
import_effect2.Effect.flatMap(import_effect2.Effect.fromNullable),
|
|
802
|
+
import_effect2.Effect.timeout(1e4),
|
|
803
|
+
import_effect2.Effect.map(({ language, script }) => {
|
|
787
804
|
switch (language) {
|
|
788
805
|
case "native":
|
|
789
|
-
return
|
|
806
|
+
return void 0;
|
|
790
807
|
case "plutus:v1":
|
|
791
|
-
return {
|
|
808
|
+
return {
|
|
809
|
+
type: "PlutusV1",
|
|
810
|
+
script: (0, import_utils2.applyDoubleCborEncoding)(script)
|
|
811
|
+
};
|
|
792
812
|
case "plutus:v2":
|
|
793
|
-
return {
|
|
813
|
+
return {
|
|
814
|
+
type: "PlutusV2",
|
|
815
|
+
script: (0, import_utils2.applyDoubleCborEncoding)(script)
|
|
816
|
+
};
|
|
794
817
|
}
|
|
795
818
|
})
|
|
796
819
|
);
|
|
797
|
-
} else return
|
|
820
|
+
} else return void 0;
|
|
798
821
|
});
|
|
799
822
|
var toAssets = (value) => {
|
|
800
823
|
const assets = { lovelace: BigInt(value.coins) };
|
|
@@ -839,42 +862,42 @@ var toProtocolParameters = (result) => {
|
|
|
839
862
|
}
|
|
840
863
|
};
|
|
841
864
|
};
|
|
842
|
-
var fetchOgmiosParse = (url, data, schema) => (0,
|
|
865
|
+
var fetchOgmiosParse = (url, data, schema) => (0, import_effect2.pipe)(
|
|
843
866
|
import_platform.HttpClientRequest.post(url),
|
|
844
867
|
import_platform.HttpClientRequest.jsonBody(data),
|
|
845
|
-
|
|
868
|
+
import_effect2.Effect.flatMap(import_platform.HttpClient.fetch),
|
|
846
869
|
import_platform.HttpClientResponse.json,
|
|
847
|
-
|
|
870
|
+
import_effect2.Effect.flatMap(S2.decodeUnknown(schema))
|
|
848
871
|
// Effect.catchTag("ParseError", (e) =>
|
|
849
872
|
// Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
|
|
850
873
|
// ),
|
|
851
874
|
// Effect.scoped
|
|
852
875
|
);
|
|
853
|
-
var fetchKupoParse = (url, schema) => (0,
|
|
876
|
+
var fetchKupoParse = (url, schema) => (0, import_effect2.pipe)(
|
|
854
877
|
import_platform.HttpClientRequest.get(url),
|
|
855
878
|
import_platform.HttpClient.fetchOk,
|
|
856
879
|
import_platform.HttpClientResponse.json,
|
|
857
|
-
|
|
880
|
+
import_effect2.Effect.flatMap(S2.decodeUnknown(schema))
|
|
858
881
|
// Effect.catchTag("ParseError", (e) =>
|
|
859
882
|
// Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
|
|
860
883
|
// ),
|
|
861
884
|
// Effect.scoped
|
|
862
885
|
);
|
|
863
|
-
var kupmiosUtxosToUtxos = (kupoURL, utxos) =>
|
|
886
|
+
var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect2.Effect.forEach(
|
|
864
887
|
utxos,
|
|
865
888
|
(utxo) => {
|
|
866
|
-
return (0,
|
|
867
|
-
|
|
889
|
+
return (0, import_effect2.pipe)(
|
|
890
|
+
import_effect2.Effect.all([
|
|
868
891
|
getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
|
|
869
892
|
getScriptEffect(kupoURL, utxo.script_hash)
|
|
870
893
|
]),
|
|
871
|
-
|
|
894
|
+
import_effect2.Effect.map(
|
|
872
895
|
([datum, script]) => ({
|
|
873
896
|
txHash: utxo.transaction_id,
|
|
874
897
|
outputIndex: utxo.output_index,
|
|
875
898
|
address: utxo.address,
|
|
876
899
|
assets: toAssets(utxo.value),
|
|
877
|
-
datumHash: utxo.datum_type === "hash" ? utxo.datum_hash :
|
|
900
|
+
datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
|
|
878
901
|
datum,
|
|
879
902
|
scriptRef: script
|
|
880
903
|
})
|
|
@@ -2092,7 +2115,7 @@ var KoiosTxInfoSchema = S3.Struct({
|
|
|
2092
2115
|
});
|
|
2093
2116
|
|
|
2094
2117
|
// src/koios/koios.ts
|
|
2095
|
-
var
|
|
2118
|
+
var import_effect4 = require("effect");
|
|
2096
2119
|
var import_schema2 = require("@effect/schema");
|
|
2097
2120
|
|
|
2098
2121
|
// src/fetch.ts
|
|
@@ -2103,27 +2126,27 @@ __export(fetch_exports, {
|
|
|
2103
2126
|
ResponseError: () => ResponseError,
|
|
2104
2127
|
fetchEffect: () => fetchEffect
|
|
2105
2128
|
});
|
|
2106
|
-
var
|
|
2107
|
-
var FetchError = class extends
|
|
2129
|
+
var import_effect3 = require("effect");
|
|
2130
|
+
var FetchError = class extends import_effect3.Data.TaggedError("FetchError") {
|
|
2108
2131
|
};
|
|
2109
|
-
var ResponseError = class extends
|
|
2132
|
+
var ResponseError = class extends import_effect3.Data.TaggedError("ResponseError") {
|
|
2110
2133
|
};
|
|
2111
|
-
var JsonError = class extends
|
|
2134
|
+
var JsonError = class extends import_effect3.Data.TaggedError("JsonError") {
|
|
2112
2135
|
};
|
|
2113
|
-
var fetchEffect = (input, requestInit) => (0,
|
|
2114
|
-
|
|
2136
|
+
var fetchEffect = (input, requestInit) => (0, import_effect3.pipe)(
|
|
2137
|
+
import_effect3.Effect.tryPromise({
|
|
2115
2138
|
try: () => fetch(input, requestInit),
|
|
2116
2139
|
catch: (error) => new FetchError({
|
|
2117
2140
|
message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
|
|
2118
2141
|
})
|
|
2119
2142
|
}),
|
|
2120
|
-
|
|
2143
|
+
import_effect3.Effect.flatMap(
|
|
2121
2144
|
(response) => !response.ok ? new ResponseError({
|
|
2122
2145
|
message: `${response.status} ${response.statusText}`
|
|
2123
|
-
}) :
|
|
2146
|
+
}) : import_effect3.Effect.succeed(response)
|
|
2124
2147
|
),
|
|
2125
|
-
|
|
2126
|
-
(response) =>
|
|
2148
|
+
import_effect3.Effect.flatMap(
|
|
2149
|
+
(response) => import_effect3.Effect.tryPromise({
|
|
2127
2150
|
try: () => response.json(),
|
|
2128
2151
|
catch: (error) => new JsonError({ message: String(error) })
|
|
2129
2152
|
})
|
|
@@ -2322,24 +2345,24 @@ var Koios = class {
|
|
|
2322
2345
|
method: "POST",
|
|
2323
2346
|
body: JSON.stringify(body)
|
|
2324
2347
|
};
|
|
2325
|
-
const program = (0,
|
|
2348
|
+
const program = (0, import_effect4.pipe)(
|
|
2326
2349
|
fetchEffect(`${this.baseUrl}/tx_info`, request),
|
|
2327
|
-
|
|
2350
|
+
import_effect4.Effect.flatMap(
|
|
2328
2351
|
(json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
|
|
2329
2352
|
),
|
|
2330
|
-
|
|
2353
|
+
import_effect4.Effect.catchTag(
|
|
2331
2354
|
"ParseError",
|
|
2332
|
-
(e) =>
|
|
2355
|
+
(e) => import_effect4.Effect.fail(import_schema2.ArrayFormatter.formatErrorSync(e))
|
|
2333
2356
|
),
|
|
2334
|
-
|
|
2335
|
-
schedule:
|
|
2357
|
+
import_effect4.Effect.repeat({
|
|
2358
|
+
schedule: import_effect4.Schedule.exponential(checkInterval),
|
|
2336
2359
|
until: (result) => result.length > 0
|
|
2337
2360
|
}),
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2361
|
+
import_effect4.Effect.timeout(16e4),
|
|
2362
|
+
import_effect4.Effect.orDie,
|
|
2363
|
+
import_effect4.Effect.as(true)
|
|
2341
2364
|
);
|
|
2342
|
-
return
|
|
2365
|
+
return import_effect4.Effect.runPromise(program);
|
|
2343
2366
|
}
|
|
2344
2367
|
async submitTx(tx) {
|
|
2345
2368
|
const result = await fetch(`${this.baseUrl}/submittx`, {
|
package/dist/index.js
CHANGED
|
@@ -7,14 +7,14 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/core.ts
|
|
8
8
|
import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
9
9
|
|
|
10
|
-
// src/blockfrost.ts
|
|
10
|
+
// src/blockfrost/blockfrost.ts
|
|
11
11
|
import { fromHex, sleep } from "@lucid-evolution/core-utils";
|
|
12
12
|
import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
16
|
name: "@lucid-evolution/provider",
|
|
17
|
-
version: "0.1.
|
|
17
|
+
version: "0.1.44",
|
|
18
18
|
description: "",
|
|
19
19
|
main: "./dist/index.js",
|
|
20
20
|
types: "./dist/index.d.ts",
|
|
@@ -62,7 +62,8 @@ var package_default = {
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
// src/blockfrost.ts
|
|
65
|
+
// src/blockfrost/blockfrost.ts
|
|
66
|
+
import { pipe, Record } from "effect";
|
|
66
67
|
var Blockfrost = class {
|
|
67
68
|
url;
|
|
68
69
|
projectId;
|
|
@@ -298,19 +299,9 @@ var Blockfrost = class {
|
|
|
298
299
|
return utxos;
|
|
299
300
|
}
|
|
300
301
|
async evaluateTx(tx, additionalUTxOs) {
|
|
301
|
-
const additionalUTxOSet = (additionalUTxOs || []).map((utxo) => [
|
|
302
|
-
{ txId: utxo.txHash, index: utxo.outputIndex },
|
|
303
|
-
{
|
|
304
|
-
address: utxo.address,
|
|
305
|
-
value: { coins: utxo.assets.lovelace, assets: utxo.assets.restAssets },
|
|
306
|
-
datum_hash: utxo.datumHash,
|
|
307
|
-
datum: utxo.datum,
|
|
308
|
-
script: utxo.scriptRef
|
|
309
|
-
}
|
|
310
|
-
]);
|
|
311
302
|
const payload = {
|
|
312
303
|
cbor: tx,
|
|
313
|
-
|
|
304
|
+
additionalUtxoSet: toAditionalUTXOs(additionalUTxOs)
|
|
314
305
|
};
|
|
315
306
|
const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
|
|
316
307
|
method: "POST",
|
|
@@ -319,10 +310,7 @@ var Blockfrost = class {
|
|
|
319
310
|
project_id: this.projectId,
|
|
320
311
|
lucid
|
|
321
312
|
},
|
|
322
|
-
body: JSON.stringify(
|
|
323
|
-
payload,
|
|
324
|
-
(_, value) => typeof value === "bigint" ? value.toString() : value
|
|
325
|
-
)
|
|
313
|
+
body: JSON.stringify(payload)
|
|
326
314
|
}).then((res2) => res2.json());
|
|
327
315
|
if (!res || res.error) {
|
|
328
316
|
const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}`;
|
|
@@ -386,17 +374,41 @@ function datumJsonToCbor(json) {
|
|
|
386
374
|
}
|
|
387
375
|
var handleRateLimit = async (count) => {
|
|
388
376
|
if (count % 100 === 0) {
|
|
389
|
-
await sleep(
|
|
377
|
+
await sleep(5e3);
|
|
390
378
|
} else if (count % 10 === 0) {
|
|
391
|
-
await sleep(
|
|
379
|
+
await sleep(500);
|
|
392
380
|
}
|
|
393
381
|
};
|
|
394
382
|
var lucid = package_default.version;
|
|
383
|
+
var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
|
|
384
|
+
{
|
|
385
|
+
txId: utxo.txHash,
|
|
386
|
+
index: utxo.outputIndex
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
address: utxo.address,
|
|
390
|
+
value: {
|
|
391
|
+
coins: Number(utxo.assets["lovelace"]),
|
|
392
|
+
assets: fromAssets(utxo.assets)
|
|
393
|
+
},
|
|
394
|
+
datumHash: utxo.datumHash,
|
|
395
|
+
datum: utxo.datum,
|
|
396
|
+
script: utxo.scriptRef ? utxo.scriptRef.type === "PlutusV1" ? { "plutus:v1": utxo.scriptRef.script } : { "plutus:v2": utxo.scriptRef.script } : void 0
|
|
397
|
+
}
|
|
398
|
+
]);
|
|
399
|
+
var fromAssets = (assets) => pipe(
|
|
400
|
+
Record.remove(assets, "lovelace"),
|
|
401
|
+
Record.mapEntries((amount, unit) => [
|
|
402
|
+
unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
|
|
403
|
+
Number(amount)
|
|
404
|
+
]),
|
|
405
|
+
(r) => Record.isEmptyRecord(r) ? void 0 : r
|
|
406
|
+
);
|
|
395
407
|
|
|
396
408
|
// src/kupmios/kupmios.ts
|
|
397
|
-
import { fromUnit } from "@lucid-evolution/utils";
|
|
409
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit } from "@lucid-evolution/utils";
|
|
398
410
|
import * as S2 from "@effect/schema/Schema";
|
|
399
|
-
import { Effect, pipe, Array as _Array, Schedule, Data } from "effect";
|
|
411
|
+
import { Effect, pipe as pipe2, Array as _Array, Schedule, Data } from "effect";
|
|
400
412
|
|
|
401
413
|
// src/kupmios/schema.ts
|
|
402
414
|
import * as S from "@effect/schema/Schema";
|
|
@@ -466,7 +478,12 @@ var KupoUTxO = S.Struct({
|
|
|
466
478
|
slot_no: S.Number,
|
|
467
479
|
header_hash: S.String
|
|
468
480
|
}),
|
|
469
|
-
spent_at: S.NullOr(
|
|
481
|
+
spent_at: S.NullOr(
|
|
482
|
+
S.Struct({
|
|
483
|
+
slot_no: S.Number,
|
|
484
|
+
header_hash: S.String
|
|
485
|
+
})
|
|
486
|
+
)
|
|
470
487
|
});
|
|
471
488
|
var KupoScriptSchema = S.NullOr(
|
|
472
489
|
S.Struct({
|
|
@@ -628,7 +645,7 @@ var Kupmios = class {
|
|
|
628
645
|
return result.datum;
|
|
629
646
|
}
|
|
630
647
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
631
|
-
const pattern = `${this.kupoUrl}/matches/*@${txHash}?
|
|
648
|
+
const pattern = `${this.kupoUrl}/matches/*@${txHash}?spent`;
|
|
632
649
|
const schema = S2.Array(KupoUTxO).annotations({
|
|
633
650
|
identifier: "Array<KupmiosSchema.KupoUTxO>"
|
|
634
651
|
});
|
|
@@ -739,28 +756,34 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* (
|
|
|
739
756
|
Effect.map((result) => result.datum),
|
|
740
757
|
Effect.timeout(1e4)
|
|
741
758
|
);
|
|
742
|
-
} else return
|
|
759
|
+
} else return void 0;
|
|
743
760
|
});
|
|
744
761
|
var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
|
|
745
762
|
if (script_hash) {
|
|
746
763
|
const pattern = `${kupoUrl}/scripts/${script_hash}`;
|
|
747
764
|
const schema = KupoScriptSchema;
|
|
748
|
-
return yield*
|
|
765
|
+
return yield* pipe2(
|
|
749
766
|
fetchKupoParse(pattern, schema),
|
|
750
767
|
Effect.flatMap(Effect.fromNullable),
|
|
751
768
|
Effect.timeout(1e4),
|
|
752
769
|
Effect.map(({ language, script }) => {
|
|
753
770
|
switch (language) {
|
|
754
771
|
case "native":
|
|
755
|
-
return
|
|
772
|
+
return void 0;
|
|
756
773
|
case "plutus:v1":
|
|
757
|
-
return {
|
|
774
|
+
return {
|
|
775
|
+
type: "PlutusV1",
|
|
776
|
+
script: applyDoubleCborEncoding2(script)
|
|
777
|
+
};
|
|
758
778
|
case "plutus:v2":
|
|
759
|
-
return {
|
|
779
|
+
return {
|
|
780
|
+
type: "PlutusV2",
|
|
781
|
+
script: applyDoubleCborEncoding2(script)
|
|
782
|
+
};
|
|
760
783
|
}
|
|
761
784
|
})
|
|
762
785
|
);
|
|
763
|
-
} else return
|
|
786
|
+
} else return void 0;
|
|
764
787
|
});
|
|
765
788
|
var toAssets = (value) => {
|
|
766
789
|
const assets = { lovelace: BigInt(value.coins) };
|
|
@@ -805,7 +828,7 @@ var toProtocolParameters = (result) => {
|
|
|
805
828
|
}
|
|
806
829
|
};
|
|
807
830
|
};
|
|
808
|
-
var fetchOgmiosParse = (url, data, schema) =>
|
|
831
|
+
var fetchOgmiosParse = (url, data, schema) => pipe2(
|
|
809
832
|
HttpClientRequest.post(url),
|
|
810
833
|
HttpClientRequest.jsonBody(data),
|
|
811
834
|
Effect.flatMap(HttpClient.fetch),
|
|
@@ -816,7 +839,7 @@ var fetchOgmiosParse = (url, data, schema) => pipe(
|
|
|
816
839
|
// ),
|
|
817
840
|
// Effect.scoped
|
|
818
841
|
);
|
|
819
|
-
var fetchKupoParse = (url, schema) =>
|
|
842
|
+
var fetchKupoParse = (url, schema) => pipe2(
|
|
820
843
|
HttpClientRequest.get(url),
|
|
821
844
|
HttpClient.fetchOk,
|
|
822
845
|
HttpClientResponse.json,
|
|
@@ -829,7 +852,7 @@ var fetchKupoParse = (url, schema) => pipe(
|
|
|
829
852
|
var kupmiosUtxosToUtxos = (kupoURL, utxos) => Effect.forEach(
|
|
830
853
|
utxos,
|
|
831
854
|
(utxo) => {
|
|
832
|
-
return
|
|
855
|
+
return pipe2(
|
|
833
856
|
Effect.all([
|
|
834
857
|
getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
|
|
835
858
|
getScriptEffect(kupoURL, utxo.script_hash)
|
|
@@ -840,7 +863,7 @@ var kupmiosUtxosToUtxos = (kupoURL, utxos) => Effect.forEach(
|
|
|
840
863
|
outputIndex: utxo.output_index,
|
|
841
864
|
address: utxo.address,
|
|
842
865
|
assets: toAssets(utxo.value),
|
|
843
|
-
datumHash: utxo.datum_type === "hash" ? utxo.datum_hash :
|
|
866
|
+
datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : void 0,
|
|
844
867
|
datum,
|
|
845
868
|
scriptRef: script
|
|
846
869
|
})
|
|
@@ -1575,7 +1598,7 @@ function redeemerTagToString(tag) {
|
|
|
1575
1598
|
}
|
|
1576
1599
|
|
|
1577
1600
|
// src/maestro.ts
|
|
1578
|
-
import { applyDoubleCborEncoding as
|
|
1601
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding3, utxoToCore } from "@lucid-evolution/utils";
|
|
1579
1602
|
import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
|
|
1580
1603
|
var Maestro = class {
|
|
1581
1604
|
url;
|
|
@@ -1810,7 +1833,7 @@ var Maestro = class {
|
|
|
1810
1833
|
datum: result.datum?.bytes,
|
|
1811
1834
|
scriptRef: result.reference_script ? result.reference_script.type == "native" ? void 0 : {
|
|
1812
1835
|
type: result.reference_script.type == "plutusv1" ? "PlutusV1" : "PlutusV2",
|
|
1813
|
-
script:
|
|
1836
|
+
script: applyDoubleCborEncoding3(result.reference_script.bytes)
|
|
1814
1837
|
} : void 0
|
|
1815
1838
|
};
|
|
1816
1839
|
}
|
|
@@ -1867,7 +1890,7 @@ var lucid2 = package_default.version;
|
|
|
1867
1890
|
// src/koios/koios.ts
|
|
1868
1891
|
import * as S4 from "@effect/schema/Schema";
|
|
1869
1892
|
import { fromHex as fromHex4 } from "@lucid-evolution/core-utils";
|
|
1870
|
-
import { applyDoubleCborEncoding as
|
|
1893
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding4, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
|
|
1871
1894
|
|
|
1872
1895
|
// src/koios/schema.ts
|
|
1873
1896
|
import * as S3 from "@effect/schema/Schema";
|
|
@@ -2061,7 +2084,7 @@ var KoiosTxInfoSchema = S3.Struct({
|
|
|
2061
2084
|
});
|
|
2062
2085
|
|
|
2063
2086
|
// src/koios/koios.ts
|
|
2064
|
-
import { Effect as Effect3, pipe as
|
|
2087
|
+
import { Effect as Effect3, pipe as pipe4, Schedule as Schedule2 } from "effect";
|
|
2065
2088
|
import { ArrayFormatter } from "@effect/schema";
|
|
2066
2089
|
|
|
2067
2090
|
// src/fetch.ts
|
|
@@ -2072,14 +2095,14 @@ __export(fetch_exports, {
|
|
|
2072
2095
|
ResponseError: () => ResponseError,
|
|
2073
2096
|
fetchEffect: () => fetchEffect
|
|
2074
2097
|
});
|
|
2075
|
-
import { Data as Data2, Effect as Effect2, pipe as
|
|
2098
|
+
import { Data as Data2, Effect as Effect2, pipe as pipe3 } from "effect";
|
|
2076
2099
|
var FetchError = class extends Data2.TaggedError("FetchError") {
|
|
2077
2100
|
};
|
|
2078
2101
|
var ResponseError = class extends Data2.TaggedError("ResponseError") {
|
|
2079
2102
|
};
|
|
2080
2103
|
var JsonError = class extends Data2.TaggedError("JsonError") {
|
|
2081
2104
|
};
|
|
2082
|
-
var fetchEffect = (input, requestInit) =>
|
|
2105
|
+
var fetchEffect = (input, requestInit) => pipe3(
|
|
2083
2106
|
Effect2.tryPromise({
|
|
2084
2107
|
try: () => fetch(input, requestInit),
|
|
2085
2108
|
catch: (error) => new FetchError({
|
|
@@ -2291,7 +2314,7 @@ var Koios = class {
|
|
|
2291
2314
|
method: "POST",
|
|
2292
2315
|
body: JSON.stringify(body)
|
|
2293
2316
|
};
|
|
2294
|
-
const program =
|
|
2317
|
+
const program = pipe4(
|
|
2295
2318
|
fetchEffect(`${this.baseUrl}/tx_info`, request),
|
|
2296
2319
|
Effect3.flatMap(
|
|
2297
2320
|
(json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
|
|
@@ -2401,10 +2424,10 @@ var toUTxO = (koiosUTxO, address) => ({
|
|
|
2401
2424
|
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
2402
2425
|
scriptRef: koiosUTxO.reference_script ? koiosUTxO.reference_script.type == "plutusV1" ? {
|
|
2403
2426
|
type: "PlutusV1",
|
|
2404
|
-
script:
|
|
2427
|
+
script: applyDoubleCborEncoding4(koiosUTxO.reference_script.bytes)
|
|
2405
2428
|
} : {
|
|
2406
2429
|
type: "PlutusV2",
|
|
2407
|
-
script:
|
|
2430
|
+
script: applyDoubleCborEncoding4(koiosUTxO.reference_script.bytes)
|
|
2408
2431
|
} : void 0
|
|
2409
2432
|
});
|
|
2410
2433
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"effect": "^3.5.6",
|
|
33
33
|
"@lucid-evolution/core-types": "0.1.13",
|
|
34
34
|
"@lucid-evolution/core-utils": "0.1.13",
|
|
35
|
-
"@lucid-evolution/utils": "0.1.
|
|
36
|
-
"@lucid-evolution/wallet": "0.1.
|
|
35
|
+
"@lucid-evolution/utils": "0.1.35",
|
|
36
|
+
"@lucid-evolution/wallet": "0.1.39"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^20.12.8",
|