@lucid-evolution/provider 0.1.45 → 0.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +639 -687
- package/dist/index.d.cts +12 -53
- package/dist/index.d.ts +12 -53
- package/dist/index.js +627 -677
- 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.47",
|
|
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
|
+
})
|
|
532
515
|
});
|
|
533
|
-
var
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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)
|
|
563
|
+
});
|
|
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))
|
|
@@ -958,6 +950,21 @@ import { coreToUtxo, getAddressDetails } from "@lucid-evolution/utils";
|
|
|
958
950
|
import { fromHex as fromHex2 } from "@lucid-evolution/core-utils";
|
|
959
951
|
import { walletFromSeed } from "@lucid-evolution/wallet";
|
|
960
952
|
import { RedeemerTag } from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
953
|
+
async function generateEmulatorAccountFrommPrivateKey(assets) {
|
|
954
|
+
const privateKey = CML.PrivateKey.generate_ed25519().to_bech32();
|
|
955
|
+
const priv = CML.PrivateKey.from_bech32(privateKey);
|
|
956
|
+
const pubKeyHash = priv.to_public().hash();
|
|
957
|
+
const address = CML.EnterpriseAddress.new(
|
|
958
|
+
0,
|
|
959
|
+
CML.Credential.new_pub_key(pubKeyHash)
|
|
960
|
+
).to_address().to_bech32(void 0);
|
|
961
|
+
return {
|
|
962
|
+
seedPhrase: "",
|
|
963
|
+
address,
|
|
964
|
+
assets,
|
|
965
|
+
privateKey
|
|
966
|
+
};
|
|
967
|
+
}
|
|
961
968
|
function generateEmulatorAccount(assets) {
|
|
962
969
|
const seedPhrase = generateSeedPhrase();
|
|
963
970
|
return {
|
|
@@ -967,7 +974,8 @@ function generateEmulatorAccount(assets) {
|
|
|
967
974
|
accountIndex: 0,
|
|
968
975
|
network: "Custom"
|
|
969
976
|
}).address,
|
|
970
|
-
assets
|
|
977
|
+
assets,
|
|
978
|
+
privateKey: ""
|
|
971
979
|
};
|
|
972
980
|
}
|
|
973
981
|
var Emulator = class {
|
|
@@ -1949,13 +1957,13 @@ var Maestro = class {
|
|
|
1949
1957
|
}
|
|
1950
1958
|
async evaluateTx(tx, additionalUTxOs) {
|
|
1951
1959
|
const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
|
|
1952
|
-
index: utxo.outputIndex,
|
|
1953
1960
|
tx_hash: utxo.txHash,
|
|
1954
|
-
|
|
1961
|
+
index: utxo.outputIndex,
|
|
1962
|
+
txout_cbor: utxoToCore(utxo).output().to_cbor_hex()
|
|
1955
1963
|
}));
|
|
1956
1964
|
const payload = {
|
|
1957
1965
|
cbor: tx,
|
|
1958
|
-
additionalMaestroUTxOs
|
|
1966
|
+
additional_utxos: additionalMaestroUTxOs
|
|
1959
1967
|
};
|
|
1960
1968
|
const res = await fetch(`${this.url}/transactions/evaluate`, {
|
|
1961
1969
|
method: "POST",
|
|
@@ -2000,211 +2008,218 @@ var toScriptRef = (reference_script) => {
|
|
|
2000
2008
|
};
|
|
2001
2009
|
var lucid2 = package_default.version;
|
|
2002
2010
|
|
|
2003
|
-
// src/koios
|
|
2004
|
-
import * as
|
|
2011
|
+
// src/koios.ts
|
|
2012
|
+
import * as S5 from "@effect/schema/Schema";
|
|
2005
2013
|
import { fromHex as fromHex4 } from "@lucid-evolution/core-utils";
|
|
2006
|
-
import {
|
|
2014
|
+
import { fromUnit as fromUnit3 } from "@lucid-evolution/utils";
|
|
2007
2015
|
|
|
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
|
-
|
|
2016
|
+
// src/internal/koios.ts
|
|
2017
|
+
import {
|
|
2018
|
+
HttpClient as HttpClient2,
|
|
2019
|
+
HttpClientRequest as HttpClientRequest2,
|
|
2020
|
+
HttpClientResponse as HttpClientResponse2
|
|
2021
|
+
} from "@effect/platform";
|
|
2022
|
+
import * as S4 from "@effect/schema/Schema";
|
|
2023
|
+
import { Effect as Effect2, pipe as pipe3 } from "effect";
|
|
2024
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding4 } from "@lucid-evolution/utils";
|
|
2025
|
+
var ProtocolParametersSchema2 = S4.Struct({
|
|
2026
|
+
pvt_motion_no_confidence: S4.Number,
|
|
2027
|
+
pvt_committee_normal: S4.Number,
|
|
2028
|
+
pvt_committee_no_confidence: S4.Number,
|
|
2029
|
+
pvt_hard_fork_initiation: S4.Number,
|
|
2030
|
+
pvtpp_security_group: S4.Number,
|
|
2031
|
+
dvt_motion_no_confidence: S4.Number,
|
|
2032
|
+
dvt_committee_normal: S4.Number,
|
|
2033
|
+
dvt_committee_no_confidence: S4.Number,
|
|
2034
|
+
dvt_update_to_constitution: S4.Number,
|
|
2035
|
+
dvt_hard_fork_initiation: S4.Number,
|
|
2036
|
+
dvt_p_p_network_group: S4.Number,
|
|
2037
|
+
dvt_p_p_economic_group: S4.Number,
|
|
2038
|
+
dvt_p_p_technical_group: S4.Number,
|
|
2039
|
+
dvt_p_p_gov_group: S4.Number,
|
|
2040
|
+
dvt_treasury_withdrawal: S4.Number,
|
|
2041
|
+
committee_min_size: S4.Number,
|
|
2042
|
+
committee_max_term_length: S4.Number,
|
|
2043
|
+
gov_action_lifetime: S4.Number,
|
|
2044
|
+
gov_action_deposit: S4.NumberFromString,
|
|
2045
|
+
drep_deposit: S4.NumberFromString,
|
|
2046
|
+
drep_activity: S4.Number,
|
|
2047
|
+
min_fee_ref_script_cost_per_byte: S4.Number,
|
|
2048
|
+
epoch_no: S4.Number,
|
|
2049
|
+
min_fee_a: S4.Number,
|
|
2050
|
+
min_fee_b: S4.Number,
|
|
2051
|
+
max_block_size: S4.Number,
|
|
2052
|
+
max_tx_size: S4.Number,
|
|
2053
|
+
max_bh_size: S4.Number,
|
|
2054
|
+
key_deposit: S4.BigInt,
|
|
2055
|
+
pool_deposit: S4.BigInt,
|
|
2056
|
+
max_epoch: S4.Number,
|
|
2057
|
+
optimal_pool_count: S4.Number,
|
|
2058
|
+
influence: S4.Number,
|
|
2059
|
+
monetary_expand_rate: S4.Number,
|
|
2060
|
+
treasury_growth_rate: S4.Number,
|
|
2061
|
+
decentralisation: S4.Number,
|
|
2062
|
+
extra_entropy: S4.NullOr(S4.String),
|
|
2063
|
+
protocol_major: S4.Number,
|
|
2064
|
+
protocol_minor: S4.Number,
|
|
2065
|
+
min_utxo_value: S4.String,
|
|
2066
|
+
min_pool_cost: S4.String,
|
|
2067
|
+
nonce: S4.String,
|
|
2068
|
+
block_hash: S4.NullOr(S4.String),
|
|
2069
|
+
cost_models: S4.Struct({
|
|
2070
|
+
PlutusV1: S4.Array(S4.Number),
|
|
2071
|
+
PlutusV2: S4.Array(S4.Number),
|
|
2072
|
+
PlutusV3: S4.Array(S4.Number)
|
|
2058
2073
|
}),
|
|
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:
|
|
2074
|
+
price_mem: S4.Number,
|
|
2075
|
+
price_step: S4.Number,
|
|
2076
|
+
max_tx_ex_mem: S4.BigIntFromNumber,
|
|
2077
|
+
max_tx_ex_steps: S4.BigIntFromNumber,
|
|
2078
|
+
max_block_ex_mem: S4.Number,
|
|
2079
|
+
max_block_ex_steps: S4.Number,
|
|
2080
|
+
max_val_size: S4.Number,
|
|
2081
|
+
collateral_percent: S4.Number,
|
|
2082
|
+
max_collateral_inputs: S4.Number,
|
|
2083
|
+
coins_per_utxo_size: S4.BigInt
|
|
2069
2084
|
});
|
|
2070
|
-
var
|
|
2071
|
-
policy_id:
|
|
2072
|
-
asset_name:
|
|
2073
|
-
fingerprint:
|
|
2074
|
-
decimals:
|
|
2075
|
-
quantity:
|
|
2085
|
+
var AssetSchema = S4.Struct({
|
|
2086
|
+
policy_id: S4.String,
|
|
2087
|
+
asset_name: S4.NullOr(S4.String),
|
|
2088
|
+
fingerprint: S4.String,
|
|
2089
|
+
decimals: S4.Number,
|
|
2090
|
+
quantity: S4.String
|
|
2076
2091
|
});
|
|
2077
|
-
var ReferenceScriptSchema =
|
|
2078
|
-
hash:
|
|
2079
|
-
size:
|
|
2080
|
-
type:
|
|
2081
|
-
bytes:
|
|
2082
|
-
value:
|
|
2092
|
+
var ReferenceScriptSchema = S4.Struct({
|
|
2093
|
+
hash: S4.NullOr(S4.String),
|
|
2094
|
+
size: S4.NullOr(S4.Number),
|
|
2095
|
+
type: S4.NullOr(S4.String),
|
|
2096
|
+
bytes: S4.NullOr(S4.String),
|
|
2097
|
+
value: S4.NullOr(S4.Object)
|
|
2083
2098
|
});
|
|
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:
|
|
2099
|
+
var UTxOSchema2 = S4.Struct({
|
|
2100
|
+
tx_hash: S4.String,
|
|
2101
|
+
tx_index: S4.Number,
|
|
2102
|
+
block_time: S4.Number,
|
|
2103
|
+
block_height: S4.NullOr(S4.Number),
|
|
2104
|
+
value: S4.String,
|
|
2105
|
+
datum_hash: S4.NullOr(S4.String),
|
|
2106
|
+
inline_datum: S4.NullOr(
|
|
2107
|
+
S4.Struct({
|
|
2108
|
+
bytes: S4.String,
|
|
2109
|
+
value: S4.Object
|
|
2095
2110
|
})
|
|
2096
2111
|
),
|
|
2097
|
-
reference_script:
|
|
2098
|
-
asset_list:
|
|
2112
|
+
reference_script: S4.NullOr(ReferenceScriptSchema),
|
|
2113
|
+
asset_list: S4.NullOr(S4.Array(AssetSchema))
|
|
2099
2114
|
});
|
|
2100
|
-
var
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
address:
|
|
2104
|
-
balance:
|
|
2105
|
-
stake_address:
|
|
2106
|
-
script_address:
|
|
2107
|
-
utxo_set:
|
|
2115
|
+
var AddressInfoSchema = S4.Array(
|
|
2116
|
+
S4.NullishOr(
|
|
2117
|
+
S4.Struct({
|
|
2118
|
+
address: S4.String,
|
|
2119
|
+
balance: S4.String,
|
|
2120
|
+
stake_address: S4.NullOr(S4.String),
|
|
2121
|
+
script_address: S4.Boolean,
|
|
2122
|
+
utxo_set: S4.Array(UTxOSchema2)
|
|
2108
2123
|
})
|
|
2109
2124
|
)
|
|
2110
2125
|
);
|
|
2111
|
-
var
|
|
2112
|
-
payment_addr:
|
|
2113
|
-
bech32:
|
|
2114
|
-
cred:
|
|
2126
|
+
var InputOutputSchema = S4.Struct({
|
|
2127
|
+
payment_addr: S4.Struct({
|
|
2128
|
+
bech32: S4.String,
|
|
2129
|
+
cred: S4.String
|
|
2115
2130
|
}),
|
|
2116
|
-
stake_addr:
|
|
2117
|
-
tx_hash:
|
|
2118
|
-
tx_index:
|
|
2119
|
-
value:
|
|
2120
|
-
datum_hash:
|
|
2121
|
-
inline_datum:
|
|
2122
|
-
|
|
2123
|
-
bytes:
|
|
2124
|
-
value:
|
|
2131
|
+
stake_addr: S4.NullOr(S4.String),
|
|
2132
|
+
tx_hash: S4.String,
|
|
2133
|
+
tx_index: S4.Number,
|
|
2134
|
+
value: S4.String,
|
|
2135
|
+
datum_hash: S4.NullOr(S4.String),
|
|
2136
|
+
inline_datum: S4.NullOr(
|
|
2137
|
+
S4.Struct({
|
|
2138
|
+
bytes: S4.String,
|
|
2139
|
+
value: S4.Object
|
|
2125
2140
|
})
|
|
2126
2141
|
),
|
|
2127
|
-
reference_script:
|
|
2128
|
-
asset_list:
|
|
2142
|
+
reference_script: S4.NullOr(ReferenceScriptSchema),
|
|
2143
|
+
asset_list: S4.Array(AssetSchema)
|
|
2129
2144
|
});
|
|
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:
|
|
2145
|
+
var TxInfoSchema = S4.Struct({
|
|
2146
|
+
tx_hash: S4.String,
|
|
2147
|
+
block_hash: S4.String,
|
|
2148
|
+
block_height: S4.Number,
|
|
2149
|
+
epoch_no: S4.Number,
|
|
2150
|
+
epoch_slot: S4.Number,
|
|
2151
|
+
absolute_slot: S4.Number,
|
|
2152
|
+
tx_timestamp: S4.Number,
|
|
2153
|
+
tx_block_index: S4.Number,
|
|
2154
|
+
tx_size: S4.Number,
|
|
2155
|
+
total_output: S4.String,
|
|
2156
|
+
fee: S4.String,
|
|
2157
|
+
treasury_donation: S4.String,
|
|
2158
|
+
deposit: S4.String,
|
|
2159
|
+
invalid_before: S4.NullOr(S4.String),
|
|
2160
|
+
invalid_after: S4.NullOr(S4.String),
|
|
2161
|
+
collateral_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
|
|
2162
|
+
collateral_output: S4.NullOr(InputOutputSchema),
|
|
2163
|
+
reference_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
|
|
2164
|
+
inputs: S4.Array(InputOutputSchema),
|
|
2165
|
+
outputs: S4.Array(InputOutputSchema),
|
|
2166
|
+
withdrawals: S4.NullOr(
|
|
2167
|
+
S4.Array(
|
|
2168
|
+
S4.Struct({
|
|
2169
|
+
amount: S4.String,
|
|
2170
|
+
stake_addr: S4.String
|
|
2156
2171
|
})
|
|
2157
2172
|
)
|
|
2158
2173
|
),
|
|
2159
|
-
assets_minted:
|
|
2160
|
-
metadata:
|
|
2161
|
-
certificates:
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
index:
|
|
2165
|
-
type:
|
|
2166
|
-
info:
|
|
2174
|
+
assets_minted: S4.NullOr(S4.Array(AssetSchema)),
|
|
2175
|
+
metadata: S4.NullOr(S4.Object),
|
|
2176
|
+
certificates: S4.NullOr(
|
|
2177
|
+
S4.Array(
|
|
2178
|
+
S4.Struct({
|
|
2179
|
+
index: S4.Number,
|
|
2180
|
+
type: S4.String,
|
|
2181
|
+
info: S4.NullOr(S4.Object)
|
|
2167
2182
|
})
|
|
2168
2183
|
)
|
|
2169
2184
|
),
|
|
2170
|
-
native_scripts:
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
script_hash:
|
|
2174
|
-
script_json:
|
|
2185
|
+
native_scripts: S4.NullOr(
|
|
2186
|
+
S4.Array(
|
|
2187
|
+
S4.Struct({
|
|
2188
|
+
script_hash: S4.String,
|
|
2189
|
+
script_json: S4.Object
|
|
2175
2190
|
})
|
|
2176
2191
|
)
|
|
2177
2192
|
),
|
|
2178
|
-
plutus_contracts:
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
address:
|
|
2182
|
-
spends_input:
|
|
2183
|
-
|
|
2184
|
-
tx_hash:
|
|
2185
|
-
tx_index:
|
|
2193
|
+
plutus_contracts: S4.NullOr(
|
|
2194
|
+
S4.Array(
|
|
2195
|
+
S4.Struct({
|
|
2196
|
+
address: S4.String,
|
|
2197
|
+
spends_input: S4.NullOr(
|
|
2198
|
+
S4.Struct({
|
|
2199
|
+
tx_hash: S4.String,
|
|
2200
|
+
tx_index: S4.Number
|
|
2186
2201
|
})
|
|
2187
2202
|
),
|
|
2188
|
-
script_hash:
|
|
2189
|
-
bytecode:
|
|
2190
|
-
size:
|
|
2191
|
-
valid_contract:
|
|
2192
|
-
input:
|
|
2193
|
-
redeemer:
|
|
2194
|
-
purpose:
|
|
2195
|
-
fee:
|
|
2196
|
-
unit:
|
|
2197
|
-
steps:
|
|
2198
|
-
mem:
|
|
2203
|
+
script_hash: S4.String,
|
|
2204
|
+
bytecode: S4.String,
|
|
2205
|
+
size: S4.Number,
|
|
2206
|
+
valid_contract: S4.Boolean,
|
|
2207
|
+
input: S4.Struct({
|
|
2208
|
+
redeemer: S4.Struct({
|
|
2209
|
+
purpose: S4.Literal("spend", "mint", "cert", "reward"),
|
|
2210
|
+
fee: S4.String,
|
|
2211
|
+
unit: S4.Struct({
|
|
2212
|
+
steps: S4.String,
|
|
2213
|
+
mem: S4.String
|
|
2199
2214
|
}),
|
|
2200
|
-
datum:
|
|
2201
|
-
hash:
|
|
2202
|
-
value:
|
|
2215
|
+
datum: S4.Struct({
|
|
2216
|
+
hash: S4.NullOr(S4.String),
|
|
2217
|
+
value: S4.NullOr(S4.Object)
|
|
2203
2218
|
})
|
|
2204
2219
|
}),
|
|
2205
|
-
datum:
|
|
2206
|
-
hash:
|
|
2207
|
-
value:
|
|
2220
|
+
datum: S4.Struct({
|
|
2221
|
+
hash: S4.NullOr(S4.String),
|
|
2222
|
+
value: S4.NullOr(S4.Object)
|
|
2208
2223
|
})
|
|
2209
2224
|
})
|
|
2210
2225
|
})
|
|
@@ -2212,101 +2227,147 @@ var KoiosTxInfoSchema = S3.Struct({
|
|
|
2212
2227
|
),
|
|
2213
2228
|
//TODO: add S.Struct
|
|
2214
2229
|
// https://preprod.koios.rest/#post-/tx_info
|
|
2215
|
-
voting_procedures:
|
|
2230
|
+
voting_procedures: S4.Array(S4.Object),
|
|
2216
2231
|
//TODO: add S.Struct
|
|
2217
2232
|
// https://preprod.koios.rest/#post-/tx_info
|
|
2218
|
-
proposal_procedures:
|
|
2233
|
+
proposal_procedures: S4.Object
|
|
2219
2234
|
});
|
|
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
|
|
2235
|
+
var TxHashSchema = S4.String;
|
|
2236
|
+
var AssetAddressSchema = S4.Struct({
|
|
2237
|
+
payment_address: S4.String,
|
|
2238
|
+
stake_address: S4.NullOr(S4.String),
|
|
2239
|
+
quantity: S4.String
|
|
2232
2240
|
});
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2241
|
+
var AccountInfoSchema = S4.Struct({
|
|
2242
|
+
delegated_pool: S4.NullOr(S4.String),
|
|
2243
|
+
rewards_available: S4.NumberFromString
|
|
2244
|
+
});
|
|
2245
|
+
var DatumInfo = S4.Struct({
|
|
2246
|
+
bytes: S4.String
|
|
2247
|
+
});
|
|
2248
|
+
var postWithSchemaValidation = (url, data, schema) => pipe3(
|
|
2249
|
+
HttpClientRequest2.post(url),
|
|
2250
|
+
HttpClientRequest2.jsonBody(data),
|
|
2251
|
+
Effect2.flatMap(HttpClient2.fetchOk),
|
|
2252
|
+
HttpClientResponse2.json,
|
|
2253
|
+
Effect2.flatMap(S4.decodeUnknown(schema))
|
|
2254
|
+
// Effect.scoped
|
|
2255
|
+
);
|
|
2256
|
+
var getWithSchemaValidation = (url, schema) => pipe3(
|
|
2257
|
+
HttpClientRequest2.get(url),
|
|
2258
|
+
HttpClient2.fetchOk,
|
|
2259
|
+
HttpClientResponse2.json,
|
|
2260
|
+
Effect2.flatMap(S4.decodeUnknown(schema))
|
|
2261
|
+
);
|
|
2262
|
+
var toUTxO = (koiosUTxO, address) => ({
|
|
2263
|
+
txHash: koiosUTxO.tx_hash,
|
|
2264
|
+
outputIndex: koiosUTxO.tx_index,
|
|
2265
|
+
assets: (() => {
|
|
2266
|
+
const a = {};
|
|
2267
|
+
if (koiosUTxO.asset_list) {
|
|
2268
|
+
koiosUTxO.asset_list.forEach((am) => {
|
|
2269
|
+
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
2273
|
+
return a;
|
|
2274
|
+
})(),
|
|
2275
|
+
address,
|
|
2276
|
+
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
|
|
2277
|
+
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
2278
|
+
scriptRef: toScriptRef2(koiosUTxO.reference_script)
|
|
2279
|
+
});
|
|
2280
|
+
var toScriptRef2 = (reference_script) => {
|
|
2281
|
+
if (reference_script && reference_script.bytes && reference_script.type) {
|
|
2282
|
+
switch (reference_script.type) {
|
|
2283
|
+
case "plutusV1":
|
|
2284
|
+
return {
|
|
2285
|
+
type: "PlutusV1",
|
|
2286
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2287
|
+
};
|
|
2288
|
+
case "plutusV2":
|
|
2289
|
+
return {
|
|
2290
|
+
type: "PlutusV2",
|
|
2291
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2292
|
+
};
|
|
2293
|
+
case "plutusV3":
|
|
2294
|
+
return {
|
|
2295
|
+
type: "PlutusV3",
|
|
2296
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2297
|
+
};
|
|
2298
|
+
default:
|
|
2299
|
+
return void 0;
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2237
2302
|
};
|
|
2238
|
-
var
|
|
2303
|
+
var getUtxosEffect = (baseUrl, addressOrCredential) => {
|
|
2304
|
+
const url = `${baseUrl}/address_info`;
|
|
2305
|
+
const body = {
|
|
2306
|
+
_addresses: [addressOrCredential]
|
|
2307
|
+
};
|
|
2308
|
+
const schema = AddressInfoSchema;
|
|
2309
|
+
const result = pipe3(
|
|
2310
|
+
Effect2.if(typeof addressOrCredential === "string", {
|
|
2311
|
+
onFalse: () => Effect2.fail("Credential Type is not supported in Koios yet."),
|
|
2312
|
+
onTrue: () => postWithSchemaValidation(url, body, schema)
|
|
2313
|
+
}),
|
|
2314
|
+
Effect2.map(
|
|
2315
|
+
([result2]) => result2 ? result2.utxo_set.map((koiosUtxo) => toUTxO(koiosUtxo, result2.address)) : []
|
|
2316
|
+
)
|
|
2317
|
+
);
|
|
2318
|
+
return result;
|
|
2239
2319
|
};
|
|
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
2320
|
|
|
2260
|
-
// src/koios
|
|
2321
|
+
// src/koios.ts
|
|
2322
|
+
import { Data as Data2, Effect as Effect3, pipe as pipe4, Schedule as Schedule2 } from "effect";
|
|
2323
|
+
var KoiosError = class extends Data2.TaggedError("KoiosError") {
|
|
2324
|
+
get message() {
|
|
2325
|
+
return `${this.cause}`;
|
|
2326
|
+
}
|
|
2327
|
+
};
|
|
2261
2328
|
var Koios = class {
|
|
2262
2329
|
baseUrl;
|
|
2263
2330
|
constructor(baseUrl) {
|
|
2264
2331
|
this.baseUrl = baseUrl;
|
|
2265
2332
|
}
|
|
2266
2333
|
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
|
-
),
|
|
2334
|
+
const url = `${this.baseUrl}/epoch_params?limit=1`;
|
|
2335
|
+
const schema = S5.Array(ProtocolParametersSchema2);
|
|
2336
|
+
const [result] = await pipe4(
|
|
2337
|
+
getWithSchemaValidation(url, schema),
|
|
2338
|
+
Effect3.timeout(1e4),
|
|
2339
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2279
2340
|
Effect3.runPromise
|
|
2280
2341
|
);
|
|
2281
2342
|
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:
|
|
2343
|
+
minFeeA: result.min_fee_a,
|
|
2344
|
+
minFeeB: result.min_fee_b,
|
|
2345
|
+
maxTxSize: result.max_tx_size,
|
|
2346
|
+
maxValSize: result.max_val_size,
|
|
2347
|
+
keyDeposit: result.key_deposit,
|
|
2348
|
+
poolDeposit: result.pool_deposit,
|
|
2349
|
+
priceMem: result.price_mem,
|
|
2350
|
+
priceStep: result.price_step,
|
|
2351
|
+
maxTxExMem: result.max_tx_ex_mem,
|
|
2352
|
+
maxTxExSteps: result.max_tx_ex_steps,
|
|
2353
|
+
coinsPerUtxoByte: result.coins_per_utxo_size,
|
|
2354
|
+
collateralPercentage: result.collateral_percent,
|
|
2355
|
+
maxCollateralInputs: result.max_collateral_inputs,
|
|
2295
2356
|
costModels: {
|
|
2296
2357
|
PlutusV1: Object.fromEntries(
|
|
2297
|
-
|
|
2358
|
+
result.cost_models.PlutusV1.map((value, index) => [
|
|
2298
2359
|
index.toString(),
|
|
2299
2360
|
value
|
|
2300
2361
|
])
|
|
2301
2362
|
),
|
|
2302
2363
|
PlutusV2: Object.fromEntries(
|
|
2303
|
-
|
|
2364
|
+
result.cost_models.PlutusV2.map((value, index) => [
|
|
2304
2365
|
index.toString(),
|
|
2305
2366
|
value
|
|
2306
2367
|
])
|
|
2307
2368
|
),
|
|
2308
2369
|
PlutusV3: Object.fromEntries(
|
|
2309
|
-
|
|
2370
|
+
result.cost_models.PlutusV3.map((value, index) => [
|
|
2310
2371
|
index.toString(),
|
|
2311
2372
|
value
|
|
2312
2373
|
])
|
|
@@ -2315,109 +2376,80 @@ var Koios = class {
|
|
|
2315
2376
|
};
|
|
2316
2377
|
}
|
|
2317
2378
|
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
|
-
}
|
|
2379
|
+
const result = await pipe4(
|
|
2380
|
+
getUtxosEffect(this.baseUrl, addressOrCredential),
|
|
2381
|
+
Effect3.timeout(1e4),
|
|
2382
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2383
|
+
Effect3.runPromise
|
|
2384
|
+
);
|
|
2385
|
+
return result;
|
|
2347
2386
|
}
|
|
2348
2387
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2388
|
+
const result = await pipe4(
|
|
2389
|
+
getUtxosEffect(this.baseUrl, addressOrCredential),
|
|
2390
|
+
Effect3.map(
|
|
2391
|
+
(utxos) => utxos.filter((utxo) => {
|
|
2353
2392
|
const keys = Object.keys(utxo.assets);
|
|
2354
2393
|
return keys.length > 0 && keys.includes(unit);
|
|
2355
|
-
})
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
);
|
|
2363
|
-
}
|
|
2394
|
+
})
|
|
2395
|
+
),
|
|
2396
|
+
Effect3.timeout(1e4),
|
|
2397
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2398
|
+
Effect3.runPromise
|
|
2399
|
+
);
|
|
2400
|
+
return result;
|
|
2364
2401
|
}
|
|
2365
2402
|
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
|
-
|
|
2403
|
+
let { policyId, assetName } = fromUnit3(unit);
|
|
2404
|
+
const url = `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`;
|
|
2405
|
+
const result = await pipe4(
|
|
2406
|
+
getWithSchemaValidation(url, S5.Array(AssetAddressSchema)),
|
|
2407
|
+
Effect3.flatMap(
|
|
2408
|
+
(adresses) => adresses.length === 0 ? Effect3.fail("Unit not found") : Effect3.succeed(adresses)
|
|
2409
|
+
),
|
|
2410
|
+
Effect3.flatMap(
|
|
2411
|
+
(adresses) => adresses.length > 1 ? Effect3.fail("Unit needs to be an NFT or only held by one address.") : Effect3.succeed(adresses[0])
|
|
2412
|
+
),
|
|
2413
|
+
Effect3.flatMap(
|
|
2414
|
+
(address) => getUtxosEffect(this.baseUrl, address.payment_address)
|
|
2415
|
+
),
|
|
2416
|
+
Effect3.map(
|
|
2417
|
+
(utxos) => utxos.filter((utxo) => {
|
|
2418
|
+
const keys = Object.keys(utxo.assets);
|
|
2419
|
+
return keys.length > 0 && keys.includes(unit);
|
|
2420
|
+
})
|
|
2421
|
+
),
|
|
2422
|
+
Effect3.flatMap(
|
|
2423
|
+
(utxos) => utxos.length > 1 ? Effect3.fail("Unit needs to be an NFT or only held by one address.") : Effect3.succeed(utxos[0])
|
|
2424
|
+
),
|
|
2425
|
+
Effect3.timeout(1e4),
|
|
2426
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2427
|
+
Effect3.runPromise
|
|
2428
|
+
);
|
|
2429
|
+
return result;
|
|
2387
2430
|
}
|
|
2388
2431
|
async getUtxosByOutRef(outRefs) {
|
|
2432
|
+
const url = `${this.baseUrl}/tx_info`;
|
|
2389
2433
|
const body = {
|
|
2390
2434
|
_tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))],
|
|
2391
2435
|
_assets: true,
|
|
2392
2436
|
_scripts: true
|
|
2393
2437
|
};
|
|
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
|
-
),
|
|
2438
|
+
const schema = S5.Array(TxInfoSchema);
|
|
2439
|
+
const [result] = await pipe4(
|
|
2440
|
+
postWithSchemaValidation(url, body, schema),
|
|
2441
|
+
Effect3.timeout(1e4),
|
|
2442
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2411
2443
|
Effect3.runPromise
|
|
2412
2444
|
);
|
|
2413
|
-
if (
|
|
2414
|
-
const utxos =
|
|
2445
|
+
if (result) {
|
|
2446
|
+
const utxos = result.outputs.map(
|
|
2415
2447
|
(koiosInputOutput) => toUTxO(
|
|
2416
2448
|
{
|
|
2417
2449
|
tx_hash: koiosInputOutput.tx_hash,
|
|
2418
2450
|
tx_index: koiosInputOutput.tx_index,
|
|
2419
2451
|
block_time: 0,
|
|
2420
|
-
block_height:
|
|
2452
|
+
block_height: result.block_height,
|
|
2421
2453
|
value: koiosInputOutput.value,
|
|
2422
2454
|
datum_hash: koiosInputOutput.datum_hash,
|
|
2423
2455
|
inline_datum: koiosInputOutput.inline_datum,
|
|
@@ -2440,135 +2472,94 @@ var Koios = class {
|
|
|
2440
2472
|
const body = {
|
|
2441
2473
|
_stake_addresses: [rewardAddress]
|
|
2442
2474
|
};
|
|
2443
|
-
const
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2475
|
+
const url = `${this.baseUrl}/account_info`;
|
|
2476
|
+
const result = await pipe4(
|
|
2477
|
+
postWithSchemaValidation(
|
|
2478
|
+
url,
|
|
2479
|
+
body,
|
|
2480
|
+
S5.Array(AccountInfoSchema)
|
|
2481
|
+
),
|
|
2482
|
+
Effect3.flatMap(
|
|
2483
|
+
(result2) => result2.length === 0 ? Effect3.fail("No Delegation Found by Reward Address") : Effect3.succeed(result2[0])
|
|
2484
|
+
),
|
|
2485
|
+
Effect3.timeout(1e4),
|
|
2486
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2487
|
+
Effect3.runPromise
|
|
2488
|
+
);
|
|
2489
|
+
return {
|
|
2490
|
+
poolId: result.delegated_pool || null,
|
|
2491
|
+
rewards: BigInt(result.rewards_available)
|
|
2492
|
+
};
|
|
2459
2493
|
}
|
|
2460
2494
|
async getDatum(datumHash) {
|
|
2495
|
+
const url = `${this.baseUrl}/datum_info`;
|
|
2461
2496
|
const body = {
|
|
2462
2497
|
_datum_hashes: [datumHash]
|
|
2463
2498
|
};
|
|
2464
|
-
const
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
"
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
} else {
|
|
2475
|
-
throw new Error("No Datum Found by Datum Hash");
|
|
2476
|
-
}
|
|
2499
|
+
const result = await pipe4(
|
|
2500
|
+
postWithSchemaValidation(url, body, S5.Array(DatumInfo)),
|
|
2501
|
+
Effect3.flatMap(
|
|
2502
|
+
(result2) => result2.length === 0 ? Effect3.fail("No Datum Found by Datum Hash") : Effect3.succeed(result2[0])
|
|
2503
|
+
),
|
|
2504
|
+
Effect3.timeout(1e4),
|
|
2505
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2506
|
+
Effect3.runPromise
|
|
2507
|
+
);
|
|
2508
|
+
return result.bytes;
|
|
2477
2509
|
}
|
|
2478
2510
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
2511
|
+
const url = `${this.baseUrl}/tx_info`;
|
|
2479
2512
|
const body = {
|
|
2480
2513
|
_tx_hashes: [txHash]
|
|
2481
2514
|
};
|
|
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
|
-
),
|
|
2515
|
+
const schema = S5.Array(TxInfoSchema);
|
|
2516
|
+
const result = await pipe4(
|
|
2517
|
+
postWithSchemaValidation(url, body, schema),
|
|
2499
2518
|
Effect3.repeat({
|
|
2500
2519
|
schedule: Schedule2.exponential(checkInterval),
|
|
2501
|
-
until: (
|
|
2520
|
+
until: (result2) => result2.length > 0
|
|
2502
2521
|
}),
|
|
2503
2522
|
Effect3.timeout(16e4),
|
|
2504
2523
|
Effect3.orDie,
|
|
2505
|
-
Effect3.as(true)
|
|
2524
|
+
Effect3.as(true),
|
|
2525
|
+
Effect3.runPromise
|
|
2506
2526
|
);
|
|
2507
|
-
return
|
|
2527
|
+
return result;
|
|
2508
2528
|
}
|
|
2509
2529
|
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
|
-
}
|
|
2530
|
+
const url = `${this.baseUrl}/submittx`;
|
|
2531
|
+
const body = fromHex4(tx);
|
|
2532
|
+
const schema = TxHashSchema;
|
|
2533
|
+
const result = await pipe4(
|
|
2534
|
+
postWithSchemaValidation(url, body, schema),
|
|
2535
|
+
Effect3.timeout(1e4),
|
|
2536
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2537
|
+
Effect3.runPromise
|
|
2538
|
+
);
|
|
2523
2539
|
return result;
|
|
2524
2540
|
}
|
|
2525
2541
|
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 = {
|
|
2542
|
+
const url = `${this.baseUrl}/ogmios`;
|
|
2543
|
+
const body = {
|
|
2548
2544
|
jsonrpc: "2.0",
|
|
2549
2545
|
method: "evaluateTransaction",
|
|
2550
|
-
params: {
|
|
2546
|
+
params: {
|
|
2547
|
+
transaction: { cbor: tx },
|
|
2548
|
+
additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
|
|
2549
|
+
},
|
|
2551
2550
|
id: null
|
|
2552
2551
|
};
|
|
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) => ({
|
|
2552
|
+
const schema = JSONRPCSchema(S5.Array(RedeemerSchema));
|
|
2553
|
+
const result = await pipe4(
|
|
2554
|
+
postWithSchemaValidation(url, body, schema),
|
|
2555
|
+
Effect3.flatMap(
|
|
2556
|
+
(response) => "error" in response ? Effect3.fail(response) : Effect3.succeed(response.result)
|
|
2557
|
+
),
|
|
2558
|
+
Effect3.timeout(1e4),
|
|
2559
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2560
|
+
Effect3.runPromise
|
|
2561
|
+
);
|
|
2562
|
+
const evalRedeemers = result.map((item) => ({
|
|
2572
2563
|
ex_units: {
|
|
2573
2564
|
mem: item.budget.memory,
|
|
2574
2565
|
steps: item.budget.cpu
|
|
@@ -2579,55 +2570,14 @@ var Koios = class {
|
|
|
2579
2570
|
return evalRedeemers;
|
|
2580
2571
|
}
|
|
2581
2572
|
};
|
|
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
2573
|
export {
|
|
2624
2574
|
Blockfrost,
|
|
2625
2575
|
Emulator,
|
|
2626
|
-
fetch_exports as FetchProvider,
|
|
2627
2576
|
Koios,
|
|
2577
|
+
KoiosError,
|
|
2628
2578
|
Kupmios,
|
|
2629
2579
|
KupmiosError,
|
|
2630
2580
|
Maestro,
|
|
2631
|
-
|
|
2632
|
-
|
|
2581
|
+
generateEmulatorAccount,
|
|
2582
|
+
generateEmulatorAccountFrommPrivateKey
|
|
2633
2583
|
};
|