@lucid-evolution/provider 0.1.45 → 0.1.46
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 +618 -684
- package/dist/index.d.cts +10 -53
- package/dist/index.d.ts +10 -53
- package/dist/index.js +608 -675
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
// src/core.ts
|
|
8
2
|
import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
9
3
|
|
|
10
|
-
// src/blockfrost
|
|
4
|
+
// src/blockfrost.ts
|
|
11
5
|
import { fromHex, sleep } from "@lucid-evolution/core-utils";
|
|
12
6
|
import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
|
|
13
7
|
|
|
14
8
|
// package.json
|
|
15
9
|
var package_default = {
|
|
16
10
|
name: "@lucid-evolution/provider",
|
|
17
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.46",
|
|
18
12
|
description: "",
|
|
19
13
|
main: "./dist/index.js",
|
|
20
14
|
types: "./dist/index.d.ts",
|
|
@@ -62,8 +56,48 @@ var package_default = {
|
|
|
62
56
|
}
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
// src/
|
|
59
|
+
// src/internal/blockfrost.ts
|
|
66
60
|
import { pipe, Record } from "effect";
|
|
61
|
+
var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
|
|
62
|
+
{
|
|
63
|
+
txId: utxo.txHash,
|
|
64
|
+
index: utxo.outputIndex
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
address: utxo.address,
|
|
68
|
+
value: {
|
|
69
|
+
coins: Number(utxo.assets["lovelace"]),
|
|
70
|
+
assets: fromAssets(utxo.assets)
|
|
71
|
+
},
|
|
72
|
+
datumHash: utxo.datumHash,
|
|
73
|
+
datum: utxo.datum,
|
|
74
|
+
script: toTxOutScript(utxo.scriptRef)
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
var toTxOutScript = (scriptRef) => {
|
|
78
|
+
if (scriptRef) {
|
|
79
|
+
switch (scriptRef.type) {
|
|
80
|
+
case "PlutusV1":
|
|
81
|
+
return { "plutus:v1": scriptRef.script };
|
|
82
|
+
case "PlutusV2":
|
|
83
|
+
return { "plutus:v2": scriptRef.script };
|
|
84
|
+
case "PlutusV3":
|
|
85
|
+
return { "plutus:v3": scriptRef.script };
|
|
86
|
+
default:
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var fromAssets = (assets) => pipe(
|
|
92
|
+
Record.remove(assets, "lovelace"),
|
|
93
|
+
Record.mapEntries((amount, unit) => [
|
|
94
|
+
unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
|
|
95
|
+
Number(amount)
|
|
96
|
+
]),
|
|
97
|
+
(r) => Record.isEmptyRecord(r) ? void 0 : r
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// src/blockfrost.ts
|
|
67
101
|
var Blockfrost = class {
|
|
68
102
|
url;
|
|
69
103
|
projectId;
|
|
@@ -341,42 +375,6 @@ var Blockfrost = class {
|
|
|
341
375
|
return evalRedeemers;
|
|
342
376
|
}
|
|
343
377
|
};
|
|
344
|
-
function datumJsonToCbor(json) {
|
|
345
|
-
const convert = (json2) => {
|
|
346
|
-
if (!isNaN(json2.int)) {
|
|
347
|
-
return CML.PlutusData.new_integer(
|
|
348
|
-
CML.BigInteger.from_str(json2.int.toString())
|
|
349
|
-
);
|
|
350
|
-
} else if (json2.bytes || !isNaN(Number(json2.bytes))) {
|
|
351
|
-
return CML.PlutusData.new_bytes(fromHex(json2.bytes));
|
|
352
|
-
} else if (json2.map) {
|
|
353
|
-
const m = CML.PlutusMap.new();
|
|
354
|
-
json2.map.forEach(({ k, v }) => {
|
|
355
|
-
m.set(convert(k), convert(v));
|
|
356
|
-
});
|
|
357
|
-
return CML.PlutusData.new_map(m);
|
|
358
|
-
} else if (json2.list) {
|
|
359
|
-
const l = CML.PlutusDataList.new();
|
|
360
|
-
json2.list.forEach((v) => {
|
|
361
|
-
l.add(convert(v));
|
|
362
|
-
});
|
|
363
|
-
return CML.PlutusData.new_list(l);
|
|
364
|
-
} else if (!isNaN(json2.constructor)) {
|
|
365
|
-
const l = CML.PlutusDataList.new();
|
|
366
|
-
json2.fields.forEach((v) => {
|
|
367
|
-
l.add(convert(v));
|
|
368
|
-
});
|
|
369
|
-
return CML.PlutusData.new_constr_plutus_data(
|
|
370
|
-
CML.ConstrPlutusData.new(
|
|
371
|
-
CML.BigInteger.from_str(json2.constructor.toString()).as_u64(),
|
|
372
|
-
l
|
|
373
|
-
)
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
throw new Error("Unsupported type");
|
|
377
|
-
};
|
|
378
|
-
return convert(json).to_cbor_hex();
|
|
379
|
-
}
|
|
380
378
|
var handleRateLimit = async (count) => {
|
|
381
379
|
if (count % 100 === 0) {
|
|
382
380
|
await sleep(5e3);
|
|
@@ -385,52 +383,21 @@ var handleRateLimit = async (count) => {
|
|
|
385
383
|
}
|
|
386
384
|
};
|
|
387
385
|
var lucid = package_default.version;
|
|
388
|
-
var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
|
|
389
|
-
{
|
|
390
|
-
txId: utxo.txHash,
|
|
391
|
-
index: utxo.outputIndex
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
address: utxo.address,
|
|
395
|
-
value: {
|
|
396
|
-
coins: Number(utxo.assets["lovelace"]),
|
|
397
|
-
assets: fromAssets(utxo.assets)
|
|
398
|
-
},
|
|
399
|
-
datumHash: utxo.datumHash,
|
|
400
|
-
datum: utxo.datum,
|
|
401
|
-
script: toTxOutScript(utxo.scriptRef)
|
|
402
|
-
}
|
|
403
|
-
]);
|
|
404
|
-
var toTxOutScript = (scriptRef) => {
|
|
405
|
-
if (scriptRef) {
|
|
406
|
-
switch (scriptRef.type) {
|
|
407
|
-
case "PlutusV1":
|
|
408
|
-
return { "plutus:v1": scriptRef.script };
|
|
409
|
-
case "PlutusV2":
|
|
410
|
-
return { "plutus:v2": scriptRef.script };
|
|
411
|
-
case "PlutusV3":
|
|
412
|
-
return { "plutus:v3": scriptRef.script };
|
|
413
|
-
default:
|
|
414
|
-
return void 0;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
var fromAssets = (assets) => pipe(
|
|
419
|
-
Record.remove(assets, "lovelace"),
|
|
420
|
-
Record.mapEntries((amount, unit) => [
|
|
421
|
-
unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
|
|
422
|
-
Number(amount)
|
|
423
|
-
]),
|
|
424
|
-
(r) => Record.isEmptyRecord(r) ? void 0 : r
|
|
425
|
-
);
|
|
426
386
|
|
|
427
|
-
// src/kupmios
|
|
428
|
-
import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit } from "@lucid-evolution/utils";
|
|
429
|
-
import * as
|
|
387
|
+
// src/kupmios.ts
|
|
388
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
|
|
389
|
+
import * as S3 from "@effect/schema/Schema";
|
|
430
390
|
import { Effect, pipe as pipe2, Array as _Array, Schedule, Data } from "effect";
|
|
391
|
+
import {
|
|
392
|
+
HttpClient,
|
|
393
|
+
HttpClientRequest,
|
|
394
|
+
HttpClientResponse
|
|
395
|
+
} from "@effect/platform";
|
|
396
|
+
import { ArrayFormatter } from "@effect/schema";
|
|
431
397
|
|
|
432
|
-
// src/
|
|
398
|
+
// src/internal/ogmios.ts
|
|
433
399
|
import * as S from "@effect/schema/Schema";
|
|
400
|
+
import { fromUnit } from "@lucid-evolution/utils";
|
|
434
401
|
var JSONRPCSchema = (schema) => S.extend(
|
|
435
402
|
S.Struct({
|
|
436
403
|
jsonrpc: S.String,
|
|
@@ -526,63 +493,118 @@ var ProtocolParametersSchema = S.Struct({
|
|
|
526
493
|
maxCollateralInputs: S.Number,
|
|
527
494
|
version: S.Struct({ major: S.Number, minor: S.Number })
|
|
528
495
|
});
|
|
529
|
-
var
|
|
530
|
-
|
|
531
|
-
|
|
496
|
+
var Delegation = S.NullOr(
|
|
497
|
+
S.Record(
|
|
498
|
+
S.String,
|
|
499
|
+
S.Struct({
|
|
500
|
+
delegate: S.Struct({ id: S.String }),
|
|
501
|
+
rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
|
|
502
|
+
deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
|
|
503
|
+
})
|
|
504
|
+
)
|
|
505
|
+
);
|
|
506
|
+
var RedeemerSchema = S.Struct({
|
|
507
|
+
validator: S.Struct({
|
|
508
|
+
purpose: S.String,
|
|
509
|
+
index: S.Int
|
|
510
|
+
}),
|
|
511
|
+
budget: S.Struct({
|
|
512
|
+
memory: S.Int,
|
|
513
|
+
cpu: S.Int
|
|
514
|
+
})
|
|
515
|
+
});
|
|
516
|
+
var toOgmiosUTxOs = (utxos) => {
|
|
517
|
+
const toOgmiosScript = (scriptRef) => {
|
|
518
|
+
if (scriptRef) {
|
|
519
|
+
switch (scriptRef.type) {
|
|
520
|
+
case "PlutusV1":
|
|
521
|
+
return { language: "plutus:v1", cbor: scriptRef.script };
|
|
522
|
+
case "PlutusV2":
|
|
523
|
+
return { language: "plutus:v2", cbor: scriptRef.script };
|
|
524
|
+
case "PlutusV3":
|
|
525
|
+
return { language: "plutus:v3", cbor: scriptRef.script };
|
|
526
|
+
default:
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const toOgmiosAssets = (assets) => {
|
|
532
|
+
const newAssets = {};
|
|
533
|
+
Object.entries(assets).map(([unit, amount]) => {
|
|
534
|
+
if (unit == "lovelace") return;
|
|
535
|
+
const { policyId, assetName } = fromUnit(unit);
|
|
536
|
+
newAssets[policyId][assetName ? assetName : ""] = Number(amount);
|
|
537
|
+
});
|
|
538
|
+
return newAssets;
|
|
539
|
+
};
|
|
540
|
+
return (utxos || []).map(
|
|
541
|
+
(utxo) => ({
|
|
542
|
+
transaction: {
|
|
543
|
+
id: utxo.txHash
|
|
544
|
+
},
|
|
545
|
+
index: utxo.outputIndex,
|
|
546
|
+
address: utxo.address,
|
|
547
|
+
value: {
|
|
548
|
+
ada: { lovelace: Number(utxo.assets["lovelace"]) },
|
|
549
|
+
...toOgmiosAssets(utxo.assets)
|
|
550
|
+
},
|
|
551
|
+
datumHash: utxo.datumHash,
|
|
552
|
+
datum: utxo.datum,
|
|
553
|
+
script: toOgmiosScript(utxo.scriptRef)
|
|
554
|
+
})
|
|
555
|
+
);
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/internal/kupo.ts
|
|
559
|
+
import * as S2 from "@effect/schema/Schema";
|
|
560
|
+
var ValueSchema = S2.Struct({
|
|
561
|
+
coins: S2.Number,
|
|
562
|
+
assets: S2.Record(S2.String, S2.Number)
|
|
532
563
|
});
|
|
533
|
-
var
|
|
534
|
-
transaction_index:
|
|
535
|
-
transaction_id:
|
|
536
|
-
output_index:
|
|
537
|
-
address:
|
|
538
|
-
value:
|
|
539
|
-
datum_hash:
|
|
540
|
-
datum_type:
|
|
541
|
-
script_hash:
|
|
542
|
-
created_at:
|
|
543
|
-
slot_no:
|
|
544
|
-
header_hash:
|
|
564
|
+
var UTxOSchema = S2.Struct({
|
|
565
|
+
transaction_index: S2.Number,
|
|
566
|
+
transaction_id: S2.String,
|
|
567
|
+
output_index: S2.Number,
|
|
568
|
+
address: S2.String,
|
|
569
|
+
value: ValueSchema,
|
|
570
|
+
datum_hash: S2.NullOr(S2.String),
|
|
571
|
+
datum_type: S2.optional(S2.Literal("hash", "inline")),
|
|
572
|
+
script_hash: S2.NullOr(S2.String),
|
|
573
|
+
created_at: S2.Struct({
|
|
574
|
+
slot_no: S2.Number,
|
|
575
|
+
header_hash: S2.String
|
|
545
576
|
}),
|
|
546
|
-
spent_at:
|
|
547
|
-
|
|
548
|
-
slot_no:
|
|
549
|
-
header_hash:
|
|
577
|
+
spent_at: S2.NullOr(
|
|
578
|
+
S2.Struct({
|
|
579
|
+
slot_no: S2.Number,
|
|
580
|
+
header_hash: S2.String
|
|
550
581
|
})
|
|
551
582
|
)
|
|
552
583
|
});
|
|
553
|
-
var
|
|
554
|
-
|
|
555
|
-
language:
|
|
556
|
-
script:
|
|
584
|
+
var ScriptSchema = S2.NullOr(
|
|
585
|
+
S2.Struct({
|
|
586
|
+
language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
|
|
587
|
+
script: S2.String
|
|
557
588
|
})
|
|
558
589
|
);
|
|
559
|
-
var
|
|
560
|
-
var
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
delegate:
|
|
565
|
-
rewards:
|
|
566
|
-
deposit:
|
|
590
|
+
var DatumSchema = S2.NullOr(S2.Struct({ datum: S2.String }));
|
|
591
|
+
var DelegationSchema = S2.NullOr(
|
|
592
|
+
S2.Record(
|
|
593
|
+
S2.String,
|
|
594
|
+
S2.Struct({
|
|
595
|
+
delegate: S2.Struct({ id: S2.String }),
|
|
596
|
+
rewards: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) }),
|
|
597
|
+
deposit: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) })
|
|
567
598
|
})
|
|
568
599
|
)
|
|
569
600
|
);
|
|
570
601
|
|
|
571
|
-
// src/kupmios
|
|
572
|
-
import {
|
|
573
|
-
HttpClient,
|
|
574
|
-
HttpClientRequest,
|
|
575
|
-
HttpClientResponse
|
|
576
|
-
} from "@effect/platform";
|
|
577
|
-
import { ArrayFormatter } from "@effect/schema";
|
|
602
|
+
// src/kupmios.ts
|
|
578
603
|
var KupmiosError = class extends Data.TaggedError("KupmiosError") {
|
|
579
604
|
get message() {
|
|
580
|
-
return `${this.cause}`;
|
|
605
|
+
return `${JSON.stringify(this.cause)}`;
|
|
581
606
|
}
|
|
582
607
|
};
|
|
583
|
-
var kupmiosError = (cause) => new KupmiosError({
|
|
584
|
-
cause: JSON.stringify(cause)
|
|
585
|
-
});
|
|
586
608
|
var Kupmios = class {
|
|
587
609
|
kupoUrl;
|
|
588
610
|
ogmiosUrl;
|
|
@@ -601,15 +623,13 @@ var Kupmios = class {
|
|
|
601
623
|
params: {},
|
|
602
624
|
id: null
|
|
603
625
|
};
|
|
604
|
-
const schema = JSONRPCSchema(
|
|
605
|
-
ProtocolParametersSchema
|
|
606
|
-
);
|
|
626
|
+
const schema = JSONRPCSchema(ProtocolParametersSchema);
|
|
607
627
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
608
628
|
Effect.flatMap(
|
|
609
|
-
(response) => "error" in response ?
|
|
629
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response.result)
|
|
610
630
|
),
|
|
611
631
|
Effect.timeout(1e4),
|
|
612
|
-
Effect.catchAll(
|
|
632
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
613
633
|
);
|
|
614
634
|
const result = await Effect.runPromise(program);
|
|
615
635
|
return toProtocolParameters(result);
|
|
@@ -618,11 +638,11 @@ var Kupmios = class {
|
|
|
618
638
|
const isAddress = typeof addressOrCredential === "string";
|
|
619
639
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
620
640
|
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
|
|
621
|
-
const schema =
|
|
641
|
+
const schema = S3.Array(UTxOSchema);
|
|
622
642
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
623
643
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
624
644
|
Effect.timeout(1e4),
|
|
625
|
-
Effect.catchAll(
|
|
645
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
626
646
|
);
|
|
627
647
|
const utxos = await Effect.runPromise(program);
|
|
628
648
|
return utxos;
|
|
@@ -630,25 +650,25 @@ var Kupmios = class {
|
|
|
630
650
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
631
651
|
const isAddress = typeof addressOrCredential === "string";
|
|
632
652
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
633
|
-
const { policyId, assetName } =
|
|
653
|
+
const { policyId, assetName } = fromUnit2(unit);
|
|
634
654
|
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
|
|
635
|
-
const schema =
|
|
655
|
+
const schema = S3.Array(UTxOSchema);
|
|
636
656
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
637
657
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
638
658
|
Effect.timeout(1e4),
|
|
639
|
-
Effect.catchAll(
|
|
659
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
640
660
|
);
|
|
641
661
|
const utxos = await Effect.runPromise(program);
|
|
642
662
|
return utxos;
|
|
643
663
|
}
|
|
644
664
|
async getUtxoByUnit(unit) {
|
|
645
|
-
const { policyId, assetName } =
|
|
665
|
+
const { policyId, assetName } = fromUnit2(unit);
|
|
646
666
|
const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
|
|
647
|
-
const schema =
|
|
667
|
+
const schema = S3.Array(UTxOSchema);
|
|
648
668
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
649
669
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
650
670
|
Effect.timeout(1e4),
|
|
651
|
-
Effect.catchAll(
|
|
671
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
652
672
|
);
|
|
653
673
|
const utxos = await Effect.runPromise(program);
|
|
654
674
|
if (utxos.length > 1) {
|
|
@@ -661,13 +681,13 @@ var Kupmios = class {
|
|
|
661
681
|
...new Set(outRefs.map((outRef) => outRef.txHash))
|
|
662
682
|
];
|
|
663
683
|
const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
664
|
-
const schema =
|
|
684
|
+
const schema = S3.Array(UTxOSchema);
|
|
665
685
|
const program = Effect.forEach(
|
|
666
686
|
queryHashes,
|
|
667
687
|
(txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
|
|
668
688
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
669
689
|
Effect.timeout(1e4),
|
|
670
|
-
Effect.catchAll(
|
|
690
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
671
691
|
)
|
|
672
692
|
);
|
|
673
693
|
const utxos = await Effect.runPromise(program);
|
|
@@ -684,13 +704,13 @@ var Kupmios = class {
|
|
|
684
704
|
params: { keys: [rewardAddress] },
|
|
685
705
|
id: null
|
|
686
706
|
};
|
|
687
|
-
const schema = JSONRPCSchema(
|
|
707
|
+
const schema = JSONRPCSchema(Delegation);
|
|
688
708
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
689
709
|
Effect.flatMap(
|
|
690
|
-
(response) => "error" in response ?
|
|
710
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response.result)
|
|
691
711
|
),
|
|
692
712
|
Effect.timeout(1e4),
|
|
693
|
-
Effect.catchAll(
|
|
713
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
694
714
|
);
|
|
695
715
|
const result = await Effect.runPromise(program);
|
|
696
716
|
const delegation = result ? Object.values(result)[0] : null;
|
|
@@ -701,18 +721,18 @@ var Kupmios = class {
|
|
|
701
721
|
}
|
|
702
722
|
async getDatum(datumHash) {
|
|
703
723
|
const pattern = `${this.kupoUrl}/datums/${datumHash}`;
|
|
704
|
-
const schema =
|
|
724
|
+
const schema = DatumSchema;
|
|
705
725
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
706
726
|
Effect.timeout(1e4),
|
|
707
727
|
Effect.flatMap(Effect.fromNullable),
|
|
708
|
-
Effect.catchAll(
|
|
728
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
709
729
|
);
|
|
710
730
|
const result = await Effect.runPromise(program);
|
|
711
731
|
return result.datum;
|
|
712
732
|
}
|
|
713
733
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
714
734
|
const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
|
|
715
|
-
const schema =
|
|
735
|
+
const schema = S3.Array(UTxOSchema).annotations({
|
|
716
736
|
identifier: "Array<KupmiosSchema.KupoUTxO>"
|
|
717
737
|
});
|
|
718
738
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
@@ -721,7 +741,7 @@ var Kupmios = class {
|
|
|
721
741
|
until: (result) => result.length > 0
|
|
722
742
|
}),
|
|
723
743
|
Effect.timeout(16e4),
|
|
724
|
-
Effect.catchAll(
|
|
744
|
+
Effect.catchAll((cause) => new KupmiosError({ cause })),
|
|
725
745
|
Effect.as(true)
|
|
726
746
|
);
|
|
727
747
|
return await Effect.runPromise(program);
|
|
@@ -736,70 +756,39 @@ var Kupmios = class {
|
|
|
736
756
|
id: null
|
|
737
757
|
};
|
|
738
758
|
const schema = JSONRPCSchema(
|
|
739
|
-
|
|
740
|
-
transaction:
|
|
741
|
-
id:
|
|
759
|
+
S3.Struct({
|
|
760
|
+
transaction: S3.Struct({
|
|
761
|
+
id: S3.String
|
|
742
762
|
})
|
|
743
763
|
})
|
|
744
764
|
);
|
|
745
765
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
746
766
|
Effect.flatMap(
|
|
747
|
-
(response) => "error" in response ? Effect.fail(response
|
|
767
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response)
|
|
748
768
|
),
|
|
749
769
|
Effect.timeout(1e4),
|
|
750
|
-
Effect.catchAll(
|
|
770
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
751
771
|
);
|
|
752
772
|
const { result } = await Effect.runPromise(program);
|
|
753
773
|
return result.transaction.id;
|
|
754
774
|
}
|
|
755
775
|
async evaluateTx(tx, additionalUTxOs) {
|
|
756
|
-
const utxos = (additionalUTxOs || []).map((utxo) => {
|
|
757
|
-
const script = utxo.scriptRef ? {
|
|
758
|
-
language: utxo.scriptRef.type,
|
|
759
|
-
cbor: utxo.scriptRef.script
|
|
760
|
-
} : void 0;
|
|
761
|
-
return [
|
|
762
|
-
{
|
|
763
|
-
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
764
|
-
},
|
|
765
|
-
{
|
|
766
|
-
address: utxo.address,
|
|
767
|
-
value: {
|
|
768
|
-
coins: utxo.assets.lovelace,
|
|
769
|
-
assets: utxo.assets.restAssets
|
|
770
|
-
},
|
|
771
|
-
datumHash: utxo.datumHash,
|
|
772
|
-
datum: utxo.datum,
|
|
773
|
-
script
|
|
774
|
-
}
|
|
775
|
-
];
|
|
776
|
-
});
|
|
777
776
|
const data = {
|
|
778
777
|
jsonrpc: "2.0",
|
|
779
778
|
method: "evaluateTransaction",
|
|
780
|
-
params: {
|
|
779
|
+
params: {
|
|
780
|
+
transaction: { cbor: tx },
|
|
781
|
+
additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
|
|
782
|
+
},
|
|
781
783
|
id: null
|
|
782
784
|
};
|
|
783
|
-
const schema = JSONRPCSchema(
|
|
784
|
-
S2.Array(
|
|
785
|
-
S2.Struct({
|
|
786
|
-
validator: S2.Struct({
|
|
787
|
-
purpose: S2.String,
|
|
788
|
-
index: S2.Int
|
|
789
|
-
}),
|
|
790
|
-
budget: S2.Struct({
|
|
791
|
-
memory: S2.Int,
|
|
792
|
-
cpu: S2.Int
|
|
793
|
-
})
|
|
794
|
-
})
|
|
795
|
-
)
|
|
796
|
-
);
|
|
785
|
+
const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
|
|
797
786
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
798
787
|
Effect.flatMap(
|
|
799
|
-
(response) => "error" in response ?
|
|
788
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response.result)
|
|
800
789
|
),
|
|
801
790
|
Effect.timeout(1e4),
|
|
802
|
-
Effect.catchAll(
|
|
791
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
803
792
|
);
|
|
804
793
|
const result = await Effect.runPromise(program);
|
|
805
794
|
const evalRedeemers = result.map((item) => ({
|
|
@@ -816,7 +805,7 @@ var Kupmios = class {
|
|
|
816
805
|
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* () {
|
|
817
806
|
if (datum_type === "inline" && datum_hash) {
|
|
818
807
|
const pattern = `${kupoUrl}/datums/${datum_hash}`;
|
|
819
|
-
const schema =
|
|
808
|
+
const schema = DatumSchema;
|
|
820
809
|
return yield* fetchKupoParse(pattern, schema).pipe(
|
|
821
810
|
Effect.flatMap(Effect.fromNullable),
|
|
822
811
|
Effect.map((result) => result.datum),
|
|
@@ -827,7 +816,7 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* (
|
|
|
827
816
|
var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
|
|
828
817
|
if (script_hash) {
|
|
829
818
|
const pattern = `${kupoUrl}/scripts/${script_hash}`;
|
|
830
|
-
const schema =
|
|
819
|
+
const schema = ScriptSchema;
|
|
831
820
|
return yield* pipe2(
|
|
832
821
|
fetchKupoParse(pattern, schema),
|
|
833
822
|
Effect.flatMap(Effect.fromNullable),
|
|
@@ -846,6 +835,11 @@ var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
|
|
|
846
835
|
type: "PlutusV2",
|
|
847
836
|
script: applyDoubleCborEncoding2(script)
|
|
848
837
|
};
|
|
838
|
+
case "plutus:v3":
|
|
839
|
+
return {
|
|
840
|
+
type: "PlutusV3",
|
|
841
|
+
script: applyDoubleCborEncoding2(script)
|
|
842
|
+
};
|
|
849
843
|
}
|
|
850
844
|
})
|
|
851
845
|
);
|
|
@@ -905,9 +899,7 @@ var fetchOgmiosParse = (url, data, schema) => pipe2(
|
|
|
905
899
|
HttpClientRequest.jsonBody(data),
|
|
906
900
|
Effect.flatMap(HttpClient.fetch),
|
|
907
901
|
HttpClientResponse.json,
|
|
908
|
-
Effect.flatMap(
|
|
909
|
-
S2.decodeUnknown(schema, { onExcessProperty: "error", errors: "first" })
|
|
910
|
-
),
|
|
902
|
+
Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
|
|
911
903
|
Effect.catchTag(
|
|
912
904
|
"ParseError",
|
|
913
905
|
(e) => Effect.fail(ArrayFormatter.formatErrorSync(e))
|
|
@@ -918,7 +910,7 @@ var fetchKupoParse = (url, schema) => pipe2(
|
|
|
918
910
|
HttpClientRequest.get(url),
|
|
919
911
|
HttpClient.fetchOk,
|
|
920
912
|
HttpClientResponse.json,
|
|
921
|
-
Effect.flatMap(
|
|
913
|
+
Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
|
|
922
914
|
Effect.catchTag(
|
|
923
915
|
"ParseError",
|
|
924
916
|
(e) => Effect.fail(ArrayFormatter.formatErrorSync(e))
|
|
@@ -1949,13 +1941,13 @@ var Maestro = class {
|
|
|
1949
1941
|
}
|
|
1950
1942
|
async evaluateTx(tx, additionalUTxOs) {
|
|
1951
1943
|
const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
|
|
1952
|
-
index: utxo.outputIndex,
|
|
1953
1944
|
tx_hash: utxo.txHash,
|
|
1954
|
-
|
|
1945
|
+
index: utxo.outputIndex,
|
|
1946
|
+
txout_cbor: utxoToCore(utxo).output().to_cbor_hex()
|
|
1955
1947
|
}));
|
|
1956
1948
|
const payload = {
|
|
1957
1949
|
cbor: tx,
|
|
1958
|
-
additionalMaestroUTxOs
|
|
1950
|
+
additional_utxos: additionalMaestroUTxOs
|
|
1959
1951
|
};
|
|
1960
1952
|
const res = await fetch(`${this.url}/transactions/evaluate`, {
|
|
1961
1953
|
method: "POST",
|
|
@@ -2000,211 +1992,218 @@ var toScriptRef = (reference_script) => {
|
|
|
2000
1992
|
};
|
|
2001
1993
|
var lucid2 = package_default.version;
|
|
2002
1994
|
|
|
2003
|
-
// src/koios
|
|
2004
|
-
import * as
|
|
1995
|
+
// src/koios.ts
|
|
1996
|
+
import * as S5 from "@effect/schema/Schema";
|
|
2005
1997
|
import { fromHex as fromHex4 } from "@lucid-evolution/core-utils";
|
|
2006
|
-
import {
|
|
1998
|
+
import { fromUnit as fromUnit3 } from "@lucid-evolution/utils";
|
|
2007
1999
|
|
|
2008
|
-
// src/koios
|
|
2009
|
-
import
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2000
|
+
// src/internal/koios.ts
|
|
2001
|
+
import {
|
|
2002
|
+
HttpClient as HttpClient2,
|
|
2003
|
+
HttpClientRequest as HttpClientRequest2,
|
|
2004
|
+
HttpClientResponse as HttpClientResponse2
|
|
2005
|
+
} from "@effect/platform";
|
|
2006
|
+
import * as S4 from "@effect/schema/Schema";
|
|
2007
|
+
import { Effect as Effect2, pipe as pipe3 } from "effect";
|
|
2008
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding4 } from "@lucid-evolution/utils";
|
|
2009
|
+
var ProtocolParametersSchema2 = S4.Struct({
|
|
2010
|
+
pvt_motion_no_confidence: S4.Number,
|
|
2011
|
+
pvt_committee_normal: S4.Number,
|
|
2012
|
+
pvt_committee_no_confidence: S4.Number,
|
|
2013
|
+
pvt_hard_fork_initiation: S4.Number,
|
|
2014
|
+
pvtpp_security_group: S4.Number,
|
|
2015
|
+
dvt_motion_no_confidence: S4.Number,
|
|
2016
|
+
dvt_committee_normal: S4.Number,
|
|
2017
|
+
dvt_committee_no_confidence: S4.Number,
|
|
2018
|
+
dvt_update_to_constitution: S4.Number,
|
|
2019
|
+
dvt_hard_fork_initiation: S4.Number,
|
|
2020
|
+
dvt_p_p_network_group: S4.Number,
|
|
2021
|
+
dvt_p_p_economic_group: S4.Number,
|
|
2022
|
+
dvt_p_p_technical_group: S4.Number,
|
|
2023
|
+
dvt_p_p_gov_group: S4.Number,
|
|
2024
|
+
dvt_treasury_withdrawal: S4.Number,
|
|
2025
|
+
committee_min_size: S4.Number,
|
|
2026
|
+
committee_max_term_length: S4.Number,
|
|
2027
|
+
gov_action_lifetime: S4.Number,
|
|
2028
|
+
gov_action_deposit: S4.NumberFromString,
|
|
2029
|
+
drep_deposit: S4.NumberFromString,
|
|
2030
|
+
drep_activity: S4.Number,
|
|
2031
|
+
min_fee_ref_script_cost_per_byte: S4.Number,
|
|
2032
|
+
epoch_no: S4.Number,
|
|
2033
|
+
min_fee_a: S4.Number,
|
|
2034
|
+
min_fee_b: S4.Number,
|
|
2035
|
+
max_block_size: S4.Number,
|
|
2036
|
+
max_tx_size: S4.Number,
|
|
2037
|
+
max_bh_size: S4.Number,
|
|
2038
|
+
key_deposit: S4.BigInt,
|
|
2039
|
+
pool_deposit: S4.BigInt,
|
|
2040
|
+
max_epoch: S4.Number,
|
|
2041
|
+
optimal_pool_count: S4.Number,
|
|
2042
|
+
influence: S4.Number,
|
|
2043
|
+
monetary_expand_rate: S4.Number,
|
|
2044
|
+
treasury_growth_rate: S4.Number,
|
|
2045
|
+
decentralisation: S4.Number,
|
|
2046
|
+
extra_entropy: S4.NullOr(S4.String),
|
|
2047
|
+
protocol_major: S4.Number,
|
|
2048
|
+
protocol_minor: S4.Number,
|
|
2049
|
+
min_utxo_value: S4.String,
|
|
2050
|
+
min_pool_cost: S4.String,
|
|
2051
|
+
nonce: S4.String,
|
|
2052
|
+
block_hash: S4.NullOr(S4.String),
|
|
2053
|
+
cost_models: S4.Struct({
|
|
2054
|
+
PlutusV1: S4.Array(S4.Number),
|
|
2055
|
+
PlutusV2: S4.Array(S4.Number),
|
|
2056
|
+
PlutusV3: S4.Array(S4.Number)
|
|
2058
2057
|
}),
|
|
2059
|
-
price_mem:
|
|
2060
|
-
price_step:
|
|
2061
|
-
max_tx_ex_mem:
|
|
2062
|
-
max_tx_ex_steps:
|
|
2063
|
-
max_block_ex_mem:
|
|
2064
|
-
max_block_ex_steps:
|
|
2065
|
-
max_val_size:
|
|
2066
|
-
collateral_percent:
|
|
2067
|
-
max_collateral_inputs:
|
|
2068
|
-
coins_per_utxo_size:
|
|
2058
|
+
price_mem: S4.Number,
|
|
2059
|
+
price_step: S4.Number,
|
|
2060
|
+
max_tx_ex_mem: S4.BigIntFromNumber,
|
|
2061
|
+
max_tx_ex_steps: S4.BigIntFromNumber,
|
|
2062
|
+
max_block_ex_mem: S4.Number,
|
|
2063
|
+
max_block_ex_steps: S4.Number,
|
|
2064
|
+
max_val_size: S4.Number,
|
|
2065
|
+
collateral_percent: S4.Number,
|
|
2066
|
+
max_collateral_inputs: S4.Number,
|
|
2067
|
+
coins_per_utxo_size: S4.BigInt
|
|
2069
2068
|
});
|
|
2070
|
-
var
|
|
2071
|
-
policy_id:
|
|
2072
|
-
asset_name:
|
|
2073
|
-
fingerprint:
|
|
2074
|
-
decimals:
|
|
2075
|
-
quantity:
|
|
2069
|
+
var AssetSchema = S4.Struct({
|
|
2070
|
+
policy_id: S4.String,
|
|
2071
|
+
asset_name: S4.NullOr(S4.String),
|
|
2072
|
+
fingerprint: S4.String,
|
|
2073
|
+
decimals: S4.Number,
|
|
2074
|
+
quantity: S4.String
|
|
2076
2075
|
});
|
|
2077
|
-
var ReferenceScriptSchema =
|
|
2078
|
-
hash:
|
|
2079
|
-
size:
|
|
2080
|
-
type:
|
|
2081
|
-
bytes:
|
|
2082
|
-
value:
|
|
2076
|
+
var ReferenceScriptSchema = S4.Struct({
|
|
2077
|
+
hash: S4.NullOr(S4.String),
|
|
2078
|
+
size: S4.NullOr(S4.Number),
|
|
2079
|
+
type: S4.NullOr(S4.String),
|
|
2080
|
+
bytes: S4.NullOr(S4.String),
|
|
2081
|
+
value: S4.NullOr(S4.Object)
|
|
2083
2082
|
});
|
|
2084
|
-
var
|
|
2085
|
-
tx_hash:
|
|
2086
|
-
tx_index:
|
|
2087
|
-
block_time:
|
|
2088
|
-
block_height:
|
|
2089
|
-
value:
|
|
2090
|
-
datum_hash:
|
|
2091
|
-
inline_datum:
|
|
2092
|
-
|
|
2093
|
-
bytes:
|
|
2094
|
-
value:
|
|
2083
|
+
var UTxOSchema2 = S4.Struct({
|
|
2084
|
+
tx_hash: S4.String,
|
|
2085
|
+
tx_index: S4.Number,
|
|
2086
|
+
block_time: S4.Number,
|
|
2087
|
+
block_height: S4.NullOr(S4.Number),
|
|
2088
|
+
value: S4.String,
|
|
2089
|
+
datum_hash: S4.NullOr(S4.String),
|
|
2090
|
+
inline_datum: S4.NullOr(
|
|
2091
|
+
S4.Struct({
|
|
2092
|
+
bytes: S4.String,
|
|
2093
|
+
value: S4.Object
|
|
2095
2094
|
})
|
|
2096
2095
|
),
|
|
2097
|
-
reference_script:
|
|
2098
|
-
asset_list:
|
|
2096
|
+
reference_script: S4.NullOr(ReferenceScriptSchema),
|
|
2097
|
+
asset_list: S4.NullOr(S4.Array(AssetSchema))
|
|
2099
2098
|
});
|
|
2100
|
-
var
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
address:
|
|
2104
|
-
balance:
|
|
2105
|
-
stake_address:
|
|
2106
|
-
script_address:
|
|
2107
|
-
utxo_set:
|
|
2099
|
+
var AddressInfoSchema = S4.Array(
|
|
2100
|
+
S4.NullishOr(
|
|
2101
|
+
S4.Struct({
|
|
2102
|
+
address: S4.String,
|
|
2103
|
+
balance: S4.String,
|
|
2104
|
+
stake_address: S4.NullOr(S4.String),
|
|
2105
|
+
script_address: S4.Boolean,
|
|
2106
|
+
utxo_set: S4.Array(UTxOSchema2)
|
|
2108
2107
|
})
|
|
2109
2108
|
)
|
|
2110
2109
|
);
|
|
2111
|
-
var
|
|
2112
|
-
payment_addr:
|
|
2113
|
-
bech32:
|
|
2114
|
-
cred:
|
|
2110
|
+
var InputOutputSchema = S4.Struct({
|
|
2111
|
+
payment_addr: S4.Struct({
|
|
2112
|
+
bech32: S4.String,
|
|
2113
|
+
cred: S4.String
|
|
2115
2114
|
}),
|
|
2116
|
-
stake_addr:
|
|
2117
|
-
tx_hash:
|
|
2118
|
-
tx_index:
|
|
2119
|
-
value:
|
|
2120
|
-
datum_hash:
|
|
2121
|
-
inline_datum:
|
|
2122
|
-
|
|
2123
|
-
bytes:
|
|
2124
|
-
value:
|
|
2115
|
+
stake_addr: S4.NullOr(S4.String),
|
|
2116
|
+
tx_hash: S4.String,
|
|
2117
|
+
tx_index: S4.Number,
|
|
2118
|
+
value: S4.String,
|
|
2119
|
+
datum_hash: S4.NullOr(S4.String),
|
|
2120
|
+
inline_datum: S4.NullOr(
|
|
2121
|
+
S4.Struct({
|
|
2122
|
+
bytes: S4.String,
|
|
2123
|
+
value: S4.Object
|
|
2125
2124
|
})
|
|
2126
2125
|
),
|
|
2127
|
-
reference_script:
|
|
2128
|
-
asset_list:
|
|
2126
|
+
reference_script: S4.NullOr(ReferenceScriptSchema),
|
|
2127
|
+
asset_list: S4.Array(AssetSchema)
|
|
2129
2128
|
});
|
|
2130
|
-
var
|
|
2131
|
-
tx_hash:
|
|
2132
|
-
block_hash:
|
|
2133
|
-
block_height:
|
|
2134
|
-
epoch_no:
|
|
2135
|
-
epoch_slot:
|
|
2136
|
-
absolute_slot:
|
|
2137
|
-
tx_timestamp:
|
|
2138
|
-
tx_block_index:
|
|
2139
|
-
tx_size:
|
|
2140
|
-
total_output:
|
|
2141
|
-
fee:
|
|
2142
|
-
treasury_donation:
|
|
2143
|
-
deposit:
|
|
2144
|
-
invalid_before:
|
|
2145
|
-
invalid_after:
|
|
2146
|
-
collateral_inputs:
|
|
2147
|
-
collateral_output:
|
|
2148
|
-
reference_inputs:
|
|
2149
|
-
inputs:
|
|
2150
|
-
outputs:
|
|
2151
|
-
withdrawals:
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
amount:
|
|
2155
|
-
stake_addr:
|
|
2129
|
+
var TxInfoSchema = S4.Struct({
|
|
2130
|
+
tx_hash: S4.String,
|
|
2131
|
+
block_hash: S4.String,
|
|
2132
|
+
block_height: S4.Number,
|
|
2133
|
+
epoch_no: S4.Number,
|
|
2134
|
+
epoch_slot: S4.Number,
|
|
2135
|
+
absolute_slot: S4.Number,
|
|
2136
|
+
tx_timestamp: S4.Number,
|
|
2137
|
+
tx_block_index: S4.Number,
|
|
2138
|
+
tx_size: S4.Number,
|
|
2139
|
+
total_output: S4.String,
|
|
2140
|
+
fee: S4.String,
|
|
2141
|
+
treasury_donation: S4.String,
|
|
2142
|
+
deposit: S4.String,
|
|
2143
|
+
invalid_before: S4.NullOr(S4.String),
|
|
2144
|
+
invalid_after: S4.NullOr(S4.String),
|
|
2145
|
+
collateral_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
|
|
2146
|
+
collateral_output: S4.NullOr(InputOutputSchema),
|
|
2147
|
+
reference_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
|
|
2148
|
+
inputs: S4.Array(InputOutputSchema),
|
|
2149
|
+
outputs: S4.Array(InputOutputSchema),
|
|
2150
|
+
withdrawals: S4.NullOr(
|
|
2151
|
+
S4.Array(
|
|
2152
|
+
S4.Struct({
|
|
2153
|
+
amount: S4.String,
|
|
2154
|
+
stake_addr: S4.String
|
|
2156
2155
|
})
|
|
2157
2156
|
)
|
|
2158
2157
|
),
|
|
2159
|
-
assets_minted:
|
|
2160
|
-
metadata:
|
|
2161
|
-
certificates:
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
index:
|
|
2165
|
-
type:
|
|
2166
|
-
info:
|
|
2158
|
+
assets_minted: S4.NullOr(S4.Array(AssetSchema)),
|
|
2159
|
+
metadata: S4.NullOr(S4.Object),
|
|
2160
|
+
certificates: S4.NullOr(
|
|
2161
|
+
S4.Array(
|
|
2162
|
+
S4.Struct({
|
|
2163
|
+
index: S4.Number,
|
|
2164
|
+
type: S4.String,
|
|
2165
|
+
info: S4.NullOr(S4.Object)
|
|
2167
2166
|
})
|
|
2168
2167
|
)
|
|
2169
2168
|
),
|
|
2170
|
-
native_scripts:
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
script_hash:
|
|
2174
|
-
script_json:
|
|
2169
|
+
native_scripts: S4.NullOr(
|
|
2170
|
+
S4.Array(
|
|
2171
|
+
S4.Struct({
|
|
2172
|
+
script_hash: S4.String,
|
|
2173
|
+
script_json: S4.Object
|
|
2175
2174
|
})
|
|
2176
2175
|
)
|
|
2177
2176
|
),
|
|
2178
|
-
plutus_contracts:
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
address:
|
|
2182
|
-
spends_input:
|
|
2183
|
-
|
|
2184
|
-
tx_hash:
|
|
2185
|
-
tx_index:
|
|
2177
|
+
plutus_contracts: S4.NullOr(
|
|
2178
|
+
S4.Array(
|
|
2179
|
+
S4.Struct({
|
|
2180
|
+
address: S4.String,
|
|
2181
|
+
spends_input: S4.NullOr(
|
|
2182
|
+
S4.Struct({
|
|
2183
|
+
tx_hash: S4.String,
|
|
2184
|
+
tx_index: S4.Number
|
|
2186
2185
|
})
|
|
2187
2186
|
),
|
|
2188
|
-
script_hash:
|
|
2189
|
-
bytecode:
|
|
2190
|
-
size:
|
|
2191
|
-
valid_contract:
|
|
2192
|
-
input:
|
|
2193
|
-
redeemer:
|
|
2194
|
-
purpose:
|
|
2195
|
-
fee:
|
|
2196
|
-
unit:
|
|
2197
|
-
steps:
|
|
2198
|
-
mem:
|
|
2187
|
+
script_hash: S4.String,
|
|
2188
|
+
bytecode: S4.String,
|
|
2189
|
+
size: S4.Number,
|
|
2190
|
+
valid_contract: S4.Boolean,
|
|
2191
|
+
input: S4.Struct({
|
|
2192
|
+
redeemer: S4.Struct({
|
|
2193
|
+
purpose: S4.Literal("spend", "mint", "cert", "reward"),
|
|
2194
|
+
fee: S4.String,
|
|
2195
|
+
unit: S4.Struct({
|
|
2196
|
+
steps: S4.String,
|
|
2197
|
+
mem: S4.String
|
|
2199
2198
|
}),
|
|
2200
|
-
datum:
|
|
2201
|
-
hash:
|
|
2202
|
-
value:
|
|
2199
|
+
datum: S4.Struct({
|
|
2200
|
+
hash: S4.NullOr(S4.String),
|
|
2201
|
+
value: S4.NullOr(S4.Object)
|
|
2203
2202
|
})
|
|
2204
2203
|
}),
|
|
2205
|
-
datum:
|
|
2206
|
-
hash:
|
|
2207
|
-
value:
|
|
2204
|
+
datum: S4.Struct({
|
|
2205
|
+
hash: S4.NullOr(S4.String),
|
|
2206
|
+
value: S4.NullOr(S4.Object)
|
|
2208
2207
|
})
|
|
2209
2208
|
})
|
|
2210
2209
|
})
|
|
@@ -2212,101 +2211,147 @@ var KoiosTxInfoSchema = S3.Struct({
|
|
|
2212
2211
|
),
|
|
2213
2212
|
//TODO: add S.Struct
|
|
2214
2213
|
// https://preprod.koios.rest/#post-/tx_info
|
|
2215
|
-
voting_procedures:
|
|
2214
|
+
voting_procedures: S4.Array(S4.Object),
|
|
2216
2215
|
//TODO: add S.Struct
|
|
2217
2216
|
// https://preprod.koios.rest/#post-/tx_info
|
|
2218
|
-
proposal_procedures:
|
|
2217
|
+
proposal_procedures: S4.Object
|
|
2219
2218
|
});
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
// src/fetch.ts
|
|
2226
|
-
var fetch_exports = {};
|
|
2227
|
-
__export(fetch_exports, {
|
|
2228
|
-
FetchError: () => FetchError,
|
|
2229
|
-
JsonError: () => JsonError,
|
|
2230
|
-
ResponseError: () => ResponseError,
|
|
2231
|
-
fetchEffect: () => fetchEffect
|
|
2219
|
+
var TxHashSchema = S4.String;
|
|
2220
|
+
var AssetAddressSchema = S4.Struct({
|
|
2221
|
+
payment_address: S4.String,
|
|
2222
|
+
stake_address: S4.NullOr(S4.String),
|
|
2223
|
+
quantity: S4.String
|
|
2232
2224
|
});
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2225
|
+
var AccountInfoSchema = S4.Struct({
|
|
2226
|
+
delegated_pool: S4.NullOr(S4.String),
|
|
2227
|
+
rewards_available: S4.NumberFromString
|
|
2228
|
+
});
|
|
2229
|
+
var DatumInfo = S4.Struct({
|
|
2230
|
+
bytes: S4.String
|
|
2231
|
+
});
|
|
2232
|
+
var postWithSchemaValidation = (url, data, schema) => pipe3(
|
|
2233
|
+
HttpClientRequest2.post(url),
|
|
2234
|
+
HttpClientRequest2.jsonBody(data),
|
|
2235
|
+
Effect2.flatMap(HttpClient2.fetchOk),
|
|
2236
|
+
HttpClientResponse2.json,
|
|
2237
|
+
Effect2.flatMap(S4.decodeUnknown(schema))
|
|
2238
|
+
// Effect.scoped
|
|
2239
|
+
);
|
|
2240
|
+
var getWithSchemaValidation = (url, schema) => pipe3(
|
|
2241
|
+
HttpClientRequest2.get(url),
|
|
2242
|
+
HttpClient2.fetchOk,
|
|
2243
|
+
HttpClientResponse2.json,
|
|
2244
|
+
Effect2.flatMap(S4.decodeUnknown(schema))
|
|
2245
|
+
);
|
|
2246
|
+
var toUTxO = (koiosUTxO, address) => ({
|
|
2247
|
+
txHash: koiosUTxO.tx_hash,
|
|
2248
|
+
outputIndex: koiosUTxO.tx_index,
|
|
2249
|
+
assets: (() => {
|
|
2250
|
+
const a = {};
|
|
2251
|
+
if (koiosUTxO.asset_list) {
|
|
2252
|
+
koiosUTxO.asset_list.forEach((am) => {
|
|
2253
|
+
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
2257
|
+
return a;
|
|
2258
|
+
})(),
|
|
2259
|
+
address,
|
|
2260
|
+
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
|
|
2261
|
+
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
2262
|
+
scriptRef: toScriptRef2(koiosUTxO.reference_script)
|
|
2263
|
+
});
|
|
2264
|
+
var toScriptRef2 = (reference_script) => {
|
|
2265
|
+
if (reference_script && reference_script.bytes && reference_script.type) {
|
|
2266
|
+
switch (reference_script.type) {
|
|
2267
|
+
case "plutusV1":
|
|
2268
|
+
return {
|
|
2269
|
+
type: "PlutusV1",
|
|
2270
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2271
|
+
};
|
|
2272
|
+
case "plutusV2":
|
|
2273
|
+
return {
|
|
2274
|
+
type: "PlutusV2",
|
|
2275
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2276
|
+
};
|
|
2277
|
+
case "plutusV3":
|
|
2278
|
+
return {
|
|
2279
|
+
type: "PlutusV3",
|
|
2280
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2281
|
+
};
|
|
2282
|
+
default:
|
|
2283
|
+
return void 0;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2237
2286
|
};
|
|
2238
|
-
var
|
|
2287
|
+
var getUtxosEffect = (baseUrl, addressOrCredential) => {
|
|
2288
|
+
const url = `${baseUrl}/address_info`;
|
|
2289
|
+
const body = {
|
|
2290
|
+
_addresses: [addressOrCredential]
|
|
2291
|
+
};
|
|
2292
|
+
const schema = AddressInfoSchema;
|
|
2293
|
+
const result = pipe3(
|
|
2294
|
+
Effect2.if(typeof addressOrCredential === "string", {
|
|
2295
|
+
onFalse: () => Effect2.fail("Credential Type is not supported in Koios yet."),
|
|
2296
|
+
onTrue: () => postWithSchemaValidation(url, body, schema)
|
|
2297
|
+
}),
|
|
2298
|
+
Effect2.map(
|
|
2299
|
+
([result2]) => result2 ? result2.utxo_set.map((koiosUtxo) => toUTxO(koiosUtxo, result2.address)) : []
|
|
2300
|
+
)
|
|
2301
|
+
);
|
|
2302
|
+
return result;
|
|
2239
2303
|
};
|
|
2240
|
-
var fetchEffect = (input, requestInit) => pipe3(
|
|
2241
|
-
Effect2.tryPromise({
|
|
2242
|
-
try: () => fetch(input, requestInit),
|
|
2243
|
-
catch: (error) => new FetchError({
|
|
2244
|
-
message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
|
|
2245
|
-
})
|
|
2246
|
-
}),
|
|
2247
|
-
Effect2.flatMap(
|
|
2248
|
-
(response) => !response.ok ? new ResponseError({
|
|
2249
|
-
message: `${response.status} ${response.statusText}`
|
|
2250
|
-
}) : Effect2.succeed(response)
|
|
2251
|
-
),
|
|
2252
|
-
Effect2.flatMap(
|
|
2253
|
-
(response) => Effect2.tryPromise({
|
|
2254
|
-
try: () => response.json(),
|
|
2255
|
-
catch: (error) => new JsonError({ message: String(error) })
|
|
2256
|
-
})
|
|
2257
|
-
)
|
|
2258
|
-
);
|
|
2259
2304
|
|
|
2260
|
-
// src/koios
|
|
2305
|
+
// src/koios.ts
|
|
2306
|
+
import { Data as Data2, Effect as Effect3, pipe as pipe4, Schedule as Schedule2 } from "effect";
|
|
2307
|
+
var KoiosError = class extends Data2.TaggedError("KoiosError") {
|
|
2308
|
+
get message() {
|
|
2309
|
+
return `${this.cause}`;
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2261
2312
|
var Koios = class {
|
|
2262
2313
|
baseUrl;
|
|
2263
2314
|
constructor(baseUrl) {
|
|
2264
2315
|
this.baseUrl = baseUrl;
|
|
2265
2316
|
}
|
|
2266
2317
|
async getProtocolParameters() {
|
|
2267
|
-
const
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
errors: "first"
|
|
2274
|
-
})(result[0]),
|
|
2275
|
-
Effect3.catchTag(
|
|
2276
|
-
"ParseError",
|
|
2277
|
-
(e) => Effect3.fail(ArrayFormatter2.formatErrorSync(e))
|
|
2278
|
-
),
|
|
2318
|
+
const url = `${this.baseUrl}/epoch_params?limit=1`;
|
|
2319
|
+
const schema = S5.Array(ProtocolParametersSchema2);
|
|
2320
|
+
const [result] = await pipe4(
|
|
2321
|
+
getWithSchemaValidation(url, schema),
|
|
2322
|
+
Effect3.timeout(1e4),
|
|
2323
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2279
2324
|
Effect3.runPromise
|
|
2280
2325
|
);
|
|
2281
2326
|
return {
|
|
2282
|
-
minFeeA:
|
|
2283
|
-
minFeeB:
|
|
2284
|
-
maxTxSize:
|
|
2285
|
-
maxValSize:
|
|
2286
|
-
keyDeposit:
|
|
2287
|
-
poolDeposit:
|
|
2288
|
-
priceMem:
|
|
2289
|
-
priceStep:
|
|
2290
|
-
maxTxExMem:
|
|
2291
|
-
maxTxExSteps:
|
|
2292
|
-
coinsPerUtxoByte:
|
|
2293
|
-
collateralPercentage:
|
|
2294
|
-
maxCollateralInputs:
|
|
2327
|
+
minFeeA: result.min_fee_a,
|
|
2328
|
+
minFeeB: result.min_fee_b,
|
|
2329
|
+
maxTxSize: result.max_tx_size,
|
|
2330
|
+
maxValSize: result.max_val_size,
|
|
2331
|
+
keyDeposit: result.key_deposit,
|
|
2332
|
+
poolDeposit: result.pool_deposit,
|
|
2333
|
+
priceMem: result.price_mem,
|
|
2334
|
+
priceStep: result.price_step,
|
|
2335
|
+
maxTxExMem: result.max_tx_ex_mem,
|
|
2336
|
+
maxTxExSteps: result.max_tx_ex_steps,
|
|
2337
|
+
coinsPerUtxoByte: result.coins_per_utxo_size,
|
|
2338
|
+
collateralPercentage: result.collateral_percent,
|
|
2339
|
+
maxCollateralInputs: result.max_collateral_inputs,
|
|
2295
2340
|
costModels: {
|
|
2296
2341
|
PlutusV1: Object.fromEntries(
|
|
2297
|
-
|
|
2342
|
+
result.cost_models.PlutusV1.map((value, index) => [
|
|
2298
2343
|
index.toString(),
|
|
2299
2344
|
value
|
|
2300
2345
|
])
|
|
2301
2346
|
),
|
|
2302
2347
|
PlutusV2: Object.fromEntries(
|
|
2303
|
-
|
|
2348
|
+
result.cost_models.PlutusV2.map((value, index) => [
|
|
2304
2349
|
index.toString(),
|
|
2305
2350
|
value
|
|
2306
2351
|
])
|
|
2307
2352
|
),
|
|
2308
2353
|
PlutusV3: Object.fromEntries(
|
|
2309
|
-
|
|
2354
|
+
result.cost_models.PlutusV3.map((value, index) => [
|
|
2310
2355
|
index.toString(),
|
|
2311
2356
|
value
|
|
2312
2357
|
])
|
|
@@ -2315,109 +2360,80 @@ var Koios = class {
|
|
|
2315
2360
|
};
|
|
2316
2361
|
}
|
|
2317
2362
|
async getUtxos(addressOrCredential) {
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
"Content-Type": "application/json"
|
|
2326
|
-
},
|
|
2327
|
-
method: "POST",
|
|
2328
|
-
body: JSON.stringify(body)
|
|
2329
|
-
}).then((res) => res.json());
|
|
2330
|
-
const [parsedResult] = await pipe4(
|
|
2331
|
-
S4.decodeUnknown(KoiosAddressInfoSchema, {
|
|
2332
|
-
onExcessProperty: "error",
|
|
2333
|
-
errors: "first"
|
|
2334
|
-
})(result),
|
|
2335
|
-
Effect3.catchTag(
|
|
2336
|
-
"ParseError",
|
|
2337
|
-
(e) => Effect3.fail(ArrayFormatter2.formatErrorSync(e))
|
|
2338
|
-
),
|
|
2339
|
-
Effect3.runPromise
|
|
2340
|
-
);
|
|
2341
|
-
return parsedResult ? parsedResult.utxo_set.map(
|
|
2342
|
-
(koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
|
|
2343
|
-
) : [];
|
|
2344
|
-
} else {
|
|
2345
|
-
throw Error("getUtxos by Credential Type is not supported in Koios yet.");
|
|
2346
|
-
}
|
|
2363
|
+
const result = await pipe4(
|
|
2364
|
+
getUtxosEffect(this.baseUrl, addressOrCredential),
|
|
2365
|
+
Effect3.timeout(1e4),
|
|
2366
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2367
|
+
Effect3.runPromise
|
|
2368
|
+
);
|
|
2369
|
+
return result;
|
|
2347
2370
|
}
|
|
2348
2371
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2372
|
+
const result = await pipe4(
|
|
2373
|
+
getUtxosEffect(this.baseUrl, addressOrCredential),
|
|
2374
|
+
Effect3.map(
|
|
2375
|
+
(utxos) => utxos.filter((utxo) => {
|
|
2353
2376
|
const keys = Object.keys(utxo.assets);
|
|
2354
2377
|
return keys.length > 0 && keys.includes(unit);
|
|
2355
|
-
})
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
);
|
|
2363
|
-
}
|
|
2378
|
+
})
|
|
2379
|
+
),
|
|
2380
|
+
Effect3.timeout(1e4),
|
|
2381
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2382
|
+
Effect3.runPromise
|
|
2383
|
+
);
|
|
2384
|
+
return result;
|
|
2364
2385
|
}
|
|
2365
2386
|
async getUtxoByUnit(unit) {
|
|
2366
|
-
let { policyId, assetName } =
|
|
2367
|
-
|
|
2368
|
-
const
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
+
let { policyId, assetName } = fromUnit3(unit);
|
|
2388
|
+
const url = `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`;
|
|
2389
|
+
const result = await pipe4(
|
|
2390
|
+
getWithSchemaValidation(url, S5.Array(AssetAddressSchema)),
|
|
2391
|
+
Effect3.flatMap(
|
|
2392
|
+
(adresses) => adresses.length === 0 ? Effect3.fail("Unit not found") : Effect3.succeed(adresses)
|
|
2393
|
+
),
|
|
2394
|
+
Effect3.flatMap(
|
|
2395
|
+
(adresses) => adresses.length > 1 ? Effect3.fail("Unit needs to be an NFT or only held by one address.") : Effect3.succeed(adresses[0])
|
|
2396
|
+
),
|
|
2397
|
+
Effect3.flatMap(
|
|
2398
|
+
(address) => getUtxosEffect(this.baseUrl, address.payment_address)
|
|
2399
|
+
),
|
|
2400
|
+
Effect3.map(
|
|
2401
|
+
(utxos) => utxos.filter((utxo) => {
|
|
2402
|
+
const keys = Object.keys(utxo.assets);
|
|
2403
|
+
return keys.length > 0 && keys.includes(unit);
|
|
2404
|
+
})
|
|
2405
|
+
),
|
|
2406
|
+
Effect3.flatMap(
|
|
2407
|
+
(utxos) => utxos.length > 1 ? Effect3.fail("Unit needs to be an NFT or only held by one address.") : Effect3.succeed(utxos[0])
|
|
2408
|
+
),
|
|
2409
|
+
Effect3.timeout(1e4),
|
|
2410
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2411
|
+
Effect3.runPromise
|
|
2412
|
+
);
|
|
2413
|
+
return result;
|
|
2387
2414
|
}
|
|
2388
2415
|
async getUtxosByOutRef(outRefs) {
|
|
2416
|
+
const url = `${this.baseUrl}/tx_info`;
|
|
2389
2417
|
const body = {
|
|
2390
2418
|
_tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))],
|
|
2391
2419
|
_assets: true,
|
|
2392
2420
|
_scripts: true
|
|
2393
2421
|
};
|
|
2394
|
-
const
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
},
|
|
2399
|
-
method: "POST",
|
|
2400
|
-
body: JSON.stringify(body)
|
|
2401
|
-
}).then((res) => res.json());
|
|
2402
|
-
const [parsedResult] = await pipe4(
|
|
2403
|
-
S4.decodeUnknown(S4.Array(KoiosTxInfoSchema), {
|
|
2404
|
-
onExcessProperty: "error",
|
|
2405
|
-
errors: "first"
|
|
2406
|
-
})(result),
|
|
2407
|
-
Effect3.catchTag(
|
|
2408
|
-
"ParseError",
|
|
2409
|
-
(e) => Effect3.fail(ArrayFormatter2.formatErrorSync(e))
|
|
2410
|
-
),
|
|
2422
|
+
const schema = S5.Array(TxInfoSchema);
|
|
2423
|
+
const [result] = await pipe4(
|
|
2424
|
+
postWithSchemaValidation(url, body, schema),
|
|
2425
|
+
Effect3.timeout(1e4),
|
|
2426
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2411
2427
|
Effect3.runPromise
|
|
2412
2428
|
);
|
|
2413
|
-
if (
|
|
2414
|
-
const utxos =
|
|
2429
|
+
if (result) {
|
|
2430
|
+
const utxos = result.outputs.map(
|
|
2415
2431
|
(koiosInputOutput) => toUTxO(
|
|
2416
2432
|
{
|
|
2417
2433
|
tx_hash: koiosInputOutput.tx_hash,
|
|
2418
2434
|
tx_index: koiosInputOutput.tx_index,
|
|
2419
2435
|
block_time: 0,
|
|
2420
|
-
block_height:
|
|
2436
|
+
block_height: result.block_height,
|
|
2421
2437
|
value: koiosInputOutput.value,
|
|
2422
2438
|
datum_hash: koiosInputOutput.datum_hash,
|
|
2423
2439
|
inline_datum: koiosInputOutput.inline_datum,
|
|
@@ -2440,135 +2456,94 @@ var Koios = class {
|
|
|
2440
2456
|
const body = {
|
|
2441
2457
|
_stake_addresses: [rewardAddress]
|
|
2442
2458
|
};
|
|
2443
|
-
const
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
+
const url = `${this.baseUrl}/account_info`;
|
|
2460
|
+
const result = await pipe4(
|
|
2461
|
+
postWithSchemaValidation(
|
|
2462
|
+
url,
|
|
2463
|
+
body,
|
|
2464
|
+
S5.Array(AccountInfoSchema)
|
|
2465
|
+
),
|
|
2466
|
+
Effect3.flatMap(
|
|
2467
|
+
(result2) => result2.length === 0 ? Effect3.fail("No Delegation Found by Reward Address") : Effect3.succeed(result2[0])
|
|
2468
|
+
),
|
|
2469
|
+
Effect3.timeout(1e4),
|
|
2470
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2471
|
+
Effect3.runPromise
|
|
2472
|
+
);
|
|
2473
|
+
return {
|
|
2474
|
+
poolId: result.delegated_pool || null,
|
|
2475
|
+
rewards: BigInt(result.rewards_available)
|
|
2476
|
+
};
|
|
2459
2477
|
}
|
|
2460
2478
|
async getDatum(datumHash) {
|
|
2479
|
+
const url = `${this.baseUrl}/datum_info`;
|
|
2461
2480
|
const body = {
|
|
2462
2481
|
_datum_hashes: [datumHash]
|
|
2463
2482
|
};
|
|
2464
|
-
const
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
"
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
} else {
|
|
2475
|
-
throw new Error("No Datum Found by Datum Hash");
|
|
2476
|
-
}
|
|
2483
|
+
const result = await pipe4(
|
|
2484
|
+
postWithSchemaValidation(url, body, S5.Array(DatumInfo)),
|
|
2485
|
+
Effect3.flatMap(
|
|
2486
|
+
(result2) => result2.length === 0 ? Effect3.fail("No Datum Found by Datum Hash") : Effect3.succeed(result2[0])
|
|
2487
|
+
),
|
|
2488
|
+
Effect3.timeout(1e4),
|
|
2489
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2490
|
+
Effect3.runPromise
|
|
2491
|
+
);
|
|
2492
|
+
return result.bytes;
|
|
2477
2493
|
}
|
|
2478
2494
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
2495
|
+
const url = `${this.baseUrl}/tx_info`;
|
|
2479
2496
|
const body = {
|
|
2480
2497
|
_tx_hashes: [txHash]
|
|
2481
2498
|
};
|
|
2482
|
-
const
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
"Content-Type": "application/json"
|
|
2486
|
-
},
|
|
2487
|
-
method: "POST",
|
|
2488
|
-
body: JSON.stringify(body)
|
|
2489
|
-
};
|
|
2490
|
-
const program = pipe4(
|
|
2491
|
-
fetchEffect(`${this.baseUrl}/tx_info`, request),
|
|
2492
|
-
Effect3.flatMap(
|
|
2493
|
-
(json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
|
|
2494
|
-
),
|
|
2495
|
-
Effect3.catchTag(
|
|
2496
|
-
"ParseError",
|
|
2497
|
-
(e) => Effect3.fail(ArrayFormatter2.formatErrorSync(e))
|
|
2498
|
-
),
|
|
2499
|
+
const schema = S5.Array(TxInfoSchema);
|
|
2500
|
+
const result = await pipe4(
|
|
2501
|
+
postWithSchemaValidation(url, body, schema),
|
|
2499
2502
|
Effect3.repeat({
|
|
2500
2503
|
schedule: Schedule2.exponential(checkInterval),
|
|
2501
|
-
until: (
|
|
2504
|
+
until: (result2) => result2.length > 0
|
|
2502
2505
|
}),
|
|
2503
2506
|
Effect3.timeout(16e4),
|
|
2504
2507
|
Effect3.orDie,
|
|
2505
|
-
Effect3.as(true)
|
|
2508
|
+
Effect3.as(true),
|
|
2509
|
+
Effect3.runPromise
|
|
2506
2510
|
);
|
|
2507
|
-
return
|
|
2511
|
+
return result;
|
|
2508
2512
|
}
|
|
2509
2513
|
async submitTx(tx) {
|
|
2510
|
-
const
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
const isTxHash = S4.is(TxHashSchema);
|
|
2520
|
-
if (!isTxHash(result)) {
|
|
2521
|
-
throw new Error(JSON.stringify(result));
|
|
2522
|
-
}
|
|
2514
|
+
const url = `${this.baseUrl}/submittx`;
|
|
2515
|
+
const body = fromHex4(tx);
|
|
2516
|
+
const schema = TxHashSchema;
|
|
2517
|
+
const result = await pipe4(
|
|
2518
|
+
postWithSchemaValidation(url, body, schema),
|
|
2519
|
+
Effect3.timeout(1e4),
|
|
2520
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2521
|
+
Effect3.runPromise
|
|
2522
|
+
);
|
|
2523
2523
|
return result;
|
|
2524
2524
|
}
|
|
2525
2525
|
async evaluateTx(tx, additionalUTxOs) {
|
|
2526
|
-
const
|
|
2527
|
-
|
|
2528
|
-
language: utxo.scriptRef.type,
|
|
2529
|
-
cbor: utxo.scriptRef.script
|
|
2530
|
-
} : void 0;
|
|
2531
|
-
return [
|
|
2532
|
-
{
|
|
2533
|
-
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
2534
|
-
},
|
|
2535
|
-
{
|
|
2536
|
-
address: utxo.address,
|
|
2537
|
-
value: {
|
|
2538
|
-
coins: utxo.assets.lovelace,
|
|
2539
|
-
assets: utxo.assets.restAssets
|
|
2540
|
-
},
|
|
2541
|
-
datumHash: utxo.datumHash,
|
|
2542
|
-
datum: utxo.datum,
|
|
2543
|
-
script
|
|
2544
|
-
}
|
|
2545
|
-
];
|
|
2546
|
-
});
|
|
2547
|
-
const data = {
|
|
2526
|
+
const url = `${this.baseUrl}/ogmios`;
|
|
2527
|
+
const body = {
|
|
2548
2528
|
jsonrpc: "2.0",
|
|
2549
2529
|
method: "evaluateTransaction",
|
|
2550
|
-
params: {
|
|
2530
|
+
params: {
|
|
2531
|
+
transaction: { cbor: tx },
|
|
2532
|
+
additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
|
|
2533
|
+
},
|
|
2551
2534
|
id: null
|
|
2552
2535
|
};
|
|
2553
|
-
const
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
if (!response.ok) {
|
|
2565
|
-
const errorBody = await response.text();
|
|
2566
|
-
throw new Error(
|
|
2567
|
-
`Request failed with status ${response.status}: ${errorBody}`
|
|
2568
|
-
);
|
|
2569
|
-
}
|
|
2570
|
-
const result = await response.json();
|
|
2571
|
-
const evalRedeemers = result.result.map((item) => ({
|
|
2536
|
+
const schema = JSONRPCSchema(S5.Array(RedeemerSchema));
|
|
2537
|
+
const result = await pipe4(
|
|
2538
|
+
postWithSchemaValidation(url, body, schema),
|
|
2539
|
+
Effect3.flatMap(
|
|
2540
|
+
(response) => "error" in response ? Effect3.fail(response) : Effect3.succeed(response.result)
|
|
2541
|
+
),
|
|
2542
|
+
Effect3.timeout(1e4),
|
|
2543
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2544
|
+
Effect3.runPromise
|
|
2545
|
+
);
|
|
2546
|
+
const evalRedeemers = result.map((item) => ({
|
|
2572
2547
|
ex_units: {
|
|
2573
2548
|
mem: item.budget.memory,
|
|
2574
2549
|
steps: item.budget.cpu
|
|
@@ -2579,55 +2554,13 @@ var Koios = class {
|
|
|
2579
2554
|
return evalRedeemers;
|
|
2580
2555
|
}
|
|
2581
2556
|
};
|
|
2582
|
-
var toUTxO = (koiosUTxO, address) => ({
|
|
2583
|
-
txHash: koiosUTxO.tx_hash,
|
|
2584
|
-
outputIndex: koiosUTxO.tx_index,
|
|
2585
|
-
assets: (() => {
|
|
2586
|
-
const a = {};
|
|
2587
|
-
if (koiosUTxO.asset_list) {
|
|
2588
|
-
koiosUTxO.asset_list.forEach((am) => {
|
|
2589
|
-
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
2590
|
-
});
|
|
2591
|
-
}
|
|
2592
|
-
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
2593
|
-
return a;
|
|
2594
|
-
})(),
|
|
2595
|
-
address,
|
|
2596
|
-
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
|
|
2597
|
-
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
2598
|
-
scriptRef: toScriptRef2(koiosUTxO.reference_script)
|
|
2599
|
-
});
|
|
2600
|
-
var toScriptRef2 = (reference_script) => {
|
|
2601
|
-
if (reference_script && reference_script.bytes && reference_script.type) {
|
|
2602
|
-
switch (reference_script.type) {
|
|
2603
|
-
case "plutusV1":
|
|
2604
|
-
return {
|
|
2605
|
-
type: "PlutusV1",
|
|
2606
|
-
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2607
|
-
};
|
|
2608
|
-
case "plutusV2":
|
|
2609
|
-
return {
|
|
2610
|
-
type: "PlutusV2",
|
|
2611
|
-
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2612
|
-
};
|
|
2613
|
-
case "plutusV3":
|
|
2614
|
-
return {
|
|
2615
|
-
type: "PlutusV3",
|
|
2616
|
-
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2617
|
-
};
|
|
2618
|
-
default:
|
|
2619
|
-
return void 0;
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
};
|
|
2623
2557
|
export {
|
|
2624
2558
|
Blockfrost,
|
|
2625
2559
|
Emulator,
|
|
2626
|
-
fetch_exports as FetchProvider,
|
|
2627
2560
|
Koios,
|
|
2561
|
+
KoiosError,
|
|
2628
2562
|
Kupmios,
|
|
2629
2563
|
KupmiosError,
|
|
2630
2564
|
Maestro,
|
|
2631
|
-
datumJsonToCbor,
|
|
2632
2565
|
generateEmulatorAccount
|
|
2633
2566
|
};
|