@lucid-evolution/provider 0.1.29 → 0.1.31
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 +557 -361
- package/dist/index.d.cts +47 -4
- package/dist/index.d.ts +47 -4
- package/dist/index.js +565 -361
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -31,8 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Blockfrost: () => Blockfrost,
|
|
34
|
+
FetchProvider: () => fetch_exports,
|
|
34
35
|
Koios: () => Koios,
|
|
35
36
|
Kupmios: () => Kupmios,
|
|
37
|
+
KupmiosError: () => KupmiosError,
|
|
36
38
|
Maestro: () => Maestro,
|
|
37
39
|
datumJsonToCbor: () => datumJsonToCbor
|
|
38
40
|
});
|
|
@@ -48,7 +50,7 @@ var import_utils = require("@lucid-evolution/utils");
|
|
|
48
50
|
// package.json
|
|
49
51
|
var package_default = {
|
|
50
52
|
name: "@lucid-evolution/provider",
|
|
51
|
-
version: "0.1.
|
|
53
|
+
version: "0.1.31",
|
|
52
54
|
description: "",
|
|
53
55
|
main: "./dist/index.js",
|
|
54
56
|
types: "./dist/index.d.ts",
|
|
@@ -80,17 +82,18 @@ var package_default = {
|
|
|
80
82
|
dependencies: {
|
|
81
83
|
"@anastasia-labs/cardano-multiplatform-lib-browser": "^5.3.1-2",
|
|
82
84
|
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "^5.3.1-2",
|
|
83
|
-
"@effect/
|
|
85
|
+
"@effect/platform": "^0.59.2",
|
|
86
|
+
"@effect/schema": "^0.68.26",
|
|
84
87
|
"@lucid-evolution/core-types": "workspace:*",
|
|
85
88
|
"@lucid-evolution/core-utils": "workspace:*",
|
|
86
89
|
"@lucid-evolution/utils": "workspace:*",
|
|
87
|
-
effect: "^3.
|
|
90
|
+
effect: "^3.5.6"
|
|
88
91
|
},
|
|
89
92
|
devDependencies: {
|
|
90
93
|
"@types/node": "^20.12.8",
|
|
91
94
|
tsup: "^8.0.2",
|
|
92
95
|
typescript: "^5.4.5",
|
|
93
|
-
vitest: "^
|
|
96
|
+
vitest: "^2.0.4"
|
|
94
97
|
}
|
|
95
98
|
};
|
|
96
99
|
|
|
@@ -349,232 +352,398 @@ function datumJsonToCbor(json) {
|
|
|
349
352
|
}
|
|
350
353
|
var lucid = package_default.version;
|
|
351
354
|
|
|
352
|
-
// src/kupmios.ts
|
|
355
|
+
// src/kupmios/kupmios.ts
|
|
353
356
|
var import_utils2 = require("@lucid-evolution/utils");
|
|
357
|
+
var S2 = __toESM(require("@effect/schema/Schema"), 1);
|
|
358
|
+
var import_effect = require("effect");
|
|
359
|
+
|
|
360
|
+
// src/kupmios/schema.ts
|
|
361
|
+
var S = __toESM(require("@effect/schema/Schema"), 1);
|
|
362
|
+
var JSONRPCSchema = (schema) => S.extend(
|
|
363
|
+
S.Struct({
|
|
364
|
+
jsonrpc: S.String,
|
|
365
|
+
method: S.String,
|
|
366
|
+
id: S.NullOr(S.Number)
|
|
367
|
+
}),
|
|
368
|
+
S.Union(S.Struct({ result: schema }), S.Struct({ error: S.Object }))
|
|
369
|
+
);
|
|
370
|
+
var LovelaceAsset = S.Struct({
|
|
371
|
+
lovelace: S.Number
|
|
372
|
+
});
|
|
373
|
+
var TupleNumberFromString = S.compose(
|
|
374
|
+
S.split("/"),
|
|
375
|
+
S.Array(S.NumberFromString)
|
|
376
|
+
);
|
|
377
|
+
var ProtocolParametersSchema = S.Struct({
|
|
378
|
+
minFeeCoefficient: S.Number,
|
|
379
|
+
minFeeConstant: S.Struct({ ada: LovelaceAsset }),
|
|
380
|
+
maxBlockBodySize: S.Struct({ bytes: S.Number }),
|
|
381
|
+
maxBlockHeaderSize: S.Struct({ bytes: S.Number }),
|
|
382
|
+
maxTransactionSize: S.Struct({ bytes: S.Number }),
|
|
383
|
+
stakeCredentialDeposit: S.Struct({ ada: LovelaceAsset }),
|
|
384
|
+
stakePoolDeposit: S.Struct({ ada: LovelaceAsset }),
|
|
385
|
+
stakePoolRetirementEpochBound: S.Number,
|
|
386
|
+
desiredNumberOfStakePools: S.Number,
|
|
387
|
+
stakePoolPledgeInfluence: TupleNumberFromString,
|
|
388
|
+
monetaryExpansion: TupleNumberFromString,
|
|
389
|
+
treasuryExpansion: TupleNumberFromString,
|
|
390
|
+
minStakePoolCost: S.Struct({ ada: LovelaceAsset }),
|
|
391
|
+
minUtxoDepositConstant: S.Struct({ ada: LovelaceAsset }),
|
|
392
|
+
minUtxoDepositCoefficient: S.Number,
|
|
393
|
+
plutusCostModels: S.Struct({
|
|
394
|
+
"plutus:v1": S.Array(S.Number),
|
|
395
|
+
"plutus:v2": S.Array(S.Number)
|
|
396
|
+
}),
|
|
397
|
+
scriptExecutionPrices: S.Struct({
|
|
398
|
+
memory: TupleNumberFromString,
|
|
399
|
+
cpu: TupleNumberFromString
|
|
400
|
+
}),
|
|
401
|
+
maxExecutionUnitsPerTransaction: S.Struct({
|
|
402
|
+
memory: S.Number,
|
|
403
|
+
cpu: S.Number
|
|
404
|
+
}),
|
|
405
|
+
maxExecutionUnitsPerBlock: S.Struct({ memory: S.Number, cpu: S.Number }),
|
|
406
|
+
maxValueSize: S.Struct({ bytes: S.Number }),
|
|
407
|
+
collateralPercentage: S.Number,
|
|
408
|
+
maxCollateralInputs: S.Number,
|
|
409
|
+
version: S.Struct({ major: S.Number, minor: S.Number })
|
|
410
|
+
});
|
|
411
|
+
var KupoValueSchema = S.Struct({
|
|
412
|
+
coins: S.Number,
|
|
413
|
+
assets: S.Record(S.String, S.Number)
|
|
414
|
+
});
|
|
415
|
+
var KupoUTxO = S.Struct({
|
|
416
|
+
transaction_index: S.Number,
|
|
417
|
+
transaction_id: S.String,
|
|
418
|
+
output_index: S.Number,
|
|
419
|
+
address: S.String,
|
|
420
|
+
value: KupoValueSchema,
|
|
421
|
+
datum_hash: S.NullOr(S.String),
|
|
422
|
+
datum_type: S.optional(S.Literal("hash", "inline")),
|
|
423
|
+
script_hash: S.NullOr(S.String),
|
|
424
|
+
created_at: S.Struct({
|
|
425
|
+
slot_no: S.Number,
|
|
426
|
+
header_hash: S.String
|
|
427
|
+
}),
|
|
428
|
+
spent_at: S.NullOr(S.Number)
|
|
429
|
+
});
|
|
430
|
+
var KupoScriptSchema = S.NullOr(
|
|
431
|
+
S.Struct({
|
|
432
|
+
language: S.Literal("native", "plutus:v1", "plutus:v2"),
|
|
433
|
+
script: S.String
|
|
434
|
+
})
|
|
435
|
+
);
|
|
436
|
+
var KupoDatumSchema = S.NullOr(S.Struct({ datum: S.String }));
|
|
437
|
+
var KupoDelegation = S.NullOr(
|
|
438
|
+
S.Record(
|
|
439
|
+
S.String,
|
|
440
|
+
S.Struct({
|
|
441
|
+
delegate: S.Struct({ id: S.String }),
|
|
442
|
+
rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
|
|
443
|
+
deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
|
|
444
|
+
})
|
|
445
|
+
)
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
// src/kupmios/kupmios.ts
|
|
449
|
+
var import_platform = require("@effect/platform");
|
|
450
|
+
var KupmiosError = class extends import_effect.Data.TaggedError("KupmiosError") {
|
|
451
|
+
get message() {
|
|
452
|
+
return `${this.cause}`;
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
var kupmiosError = (cause) => new KupmiosError({
|
|
456
|
+
cause: JSON.stringify(cause)
|
|
457
|
+
});
|
|
354
458
|
var Kupmios = class {
|
|
355
459
|
kupoUrl;
|
|
356
460
|
ogmiosUrl;
|
|
357
461
|
/**
|
|
358
462
|
* @param kupoUrl: http(s)://localhost:1442
|
|
359
|
-
* @param ogmiosUrl:
|
|
463
|
+
* @param ogmiosUrl: http(s)://localhost:1337
|
|
360
464
|
*/
|
|
361
465
|
constructor(kupoUrl, ogmiosUrl) {
|
|
362
466
|
this.kupoUrl = kupoUrl;
|
|
363
467
|
this.ogmiosUrl = ogmiosUrl;
|
|
364
468
|
}
|
|
365
469
|
async getProtocolParameters() {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
maxTxSize: parseInt(result.maxTransactionSize.bytes),
|
|
385
|
-
maxValSize: parseInt(result.maxValueSize.bytes),
|
|
386
|
-
keyDeposit: BigInt(result.stakeCredentialDeposit.ada.lovelace),
|
|
387
|
-
poolDeposit: BigInt(result.stakePoolDeposit.ada.lovelace),
|
|
388
|
-
priceMem: parseInt(memNum) / parseInt(memDenom),
|
|
389
|
-
priceStep: parseInt(stepsNum) / parseInt(stepsDenom),
|
|
390
|
-
maxTxExMem: BigInt(result.maxExecutionUnitsPerTransaction.memory),
|
|
391
|
-
maxTxExSteps: BigInt(result.maxExecutionUnitsPerTransaction.cpu),
|
|
392
|
-
// NOTE: coinsPerUtxoByte is now called utxoCostPerByte:
|
|
393
|
-
// https://github.com/IntersectMBO/cardano-node/pull/4141
|
|
394
|
-
// Ogmios v6.x calls it minUtxoDepositCoefficient according to the following
|
|
395
|
-
// documentation from its protocol parameters data model:
|
|
396
|
-
// https://github.com/CardanoSolutions/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md#protocol-parameters
|
|
397
|
-
coinsPerUtxoByte: BigInt(result.minUtxoDepositCoefficient),
|
|
398
|
-
collateralPercentage: parseInt(result.collateralPercentage),
|
|
399
|
-
maxCollateralInputs: parseInt(result.maxCollateralInputs),
|
|
400
|
-
costModels
|
|
401
|
-
});
|
|
402
|
-
client.close();
|
|
403
|
-
} catch (e) {
|
|
404
|
-
rej(e);
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
{ once: true }
|
|
408
|
-
);
|
|
409
|
-
});
|
|
470
|
+
const data = {
|
|
471
|
+
jsonrpc: "2.0",
|
|
472
|
+
method: "queryLedgerState/protocolParameters",
|
|
473
|
+
params: {},
|
|
474
|
+
id: null
|
|
475
|
+
};
|
|
476
|
+
const schema = JSONRPCSchema(
|
|
477
|
+
ProtocolParametersSchema
|
|
478
|
+
);
|
|
479
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
480
|
+
import_effect.Effect.flatMap(
|
|
481
|
+
(response) => "error" in response ? kupmiosError(response.error) : import_effect.Effect.succeed(response.result)
|
|
482
|
+
),
|
|
483
|
+
import_effect.Effect.timeout(1e4),
|
|
484
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
485
|
+
);
|
|
486
|
+
const result = await import_effect.Effect.runPromise(program);
|
|
487
|
+
return toProtocolParameters(result);
|
|
410
488
|
}
|
|
411
489
|
async getUtxos(addressOrCredential) {
|
|
412
490
|
const isAddress = typeof addressOrCredential === "string";
|
|
413
491
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
492
|
+
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
|
|
493
|
+
const schema = S2.Array(KupoUTxO);
|
|
494
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
495
|
+
import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
496
|
+
import_effect.Effect.timeout(1e4),
|
|
497
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
498
|
+
);
|
|
499
|
+
const utxos = await import_effect.Effect.runPromise(program);
|
|
500
|
+
return utxos;
|
|
418
501
|
}
|
|
419
502
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
420
503
|
const isAddress = typeof addressOrCredential === "string";
|
|
421
504
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
422
505
|
const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
506
|
+
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
|
|
507
|
+
const schema = S2.Array(KupoUTxO);
|
|
508
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
509
|
+
import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
510
|
+
import_effect.Effect.timeout(1e4),
|
|
511
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
512
|
+
);
|
|
513
|
+
const utxos = await import_effect.Effect.runPromise(program);
|
|
514
|
+
return utxos;
|
|
427
515
|
}
|
|
428
516
|
async getUtxoByUnit(unit) {
|
|
429
517
|
const { policyId, assetName } = (0, import_utils2.fromUnit)(unit);
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
518
|
+
const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
|
|
519
|
+
const schema = S2.Array(KupoUTxO);
|
|
520
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
521
|
+
import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
522
|
+
import_effect.Effect.timeout(1e4),
|
|
523
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
524
|
+
);
|
|
525
|
+
const utxos = await import_effect.Effect.runPromise(program);
|
|
434
526
|
if (utxos.length > 1) {
|
|
435
527
|
throw new Error("Unit needs to be an NFT or only held by one address.");
|
|
436
528
|
}
|
|
437
529
|
return utxos[0];
|
|
438
530
|
}
|
|
439
531
|
async getUtxosByOutRef(outRefs) {
|
|
440
|
-
const queryHashes = [
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
532
|
+
const queryHashes = [
|
|
533
|
+
...new Set(outRefs.map((outRef) => outRef.txHash))
|
|
534
|
+
];
|
|
535
|
+
const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
536
|
+
const schema = S2.Array(KupoUTxO);
|
|
537
|
+
const program = import_effect.Effect.forEach(
|
|
538
|
+
queryHashes,
|
|
539
|
+
(txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
|
|
540
|
+
import_effect.Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
541
|
+
import_effect.Effect.timeout(1e4),
|
|
542
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
543
|
+
)
|
|
448
544
|
);
|
|
449
|
-
|
|
545
|
+
const utxos = await import_effect.Effect.runPromise(program);
|
|
546
|
+
return import_effect.Array.flatten(utxos).filter(
|
|
450
547
|
(utxo) => outRefs.some(
|
|
451
548
|
(outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
|
|
452
549
|
)
|
|
453
550
|
);
|
|
454
551
|
}
|
|
455
552
|
async getDelegation(rewardAddress) {
|
|
456
|
-
const
|
|
457
|
-
"
|
|
458
|
-
|
|
553
|
+
const data = {
|
|
554
|
+
jsonrpc: "2.0",
|
|
555
|
+
method: "queryLedgerState/rewardAccountSummaries",
|
|
556
|
+
params: { keys: [rewardAddress] },
|
|
557
|
+
id: null
|
|
558
|
+
};
|
|
559
|
+
const schema = JSONRPCSchema(KupoDelegation);
|
|
560
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
561
|
+
import_effect.Effect.flatMap(
|
|
562
|
+
(response) => "error" in response ? kupmiosError(response.error) : import_effect.Effect.succeed(response.result)
|
|
563
|
+
),
|
|
564
|
+
import_effect.Effect.timeout(1e4),
|
|
565
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
459
566
|
);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const delegation = result ? Object.values(result)[0] : {};
|
|
467
|
-
res({
|
|
468
|
-
poolId: delegation?.delegate?.id || null,
|
|
469
|
-
rewards: BigInt(delegation?.rewards?.ada?.lovelace || 0)
|
|
470
|
-
});
|
|
471
|
-
client.close();
|
|
472
|
-
} catch (e) {
|
|
473
|
-
rej(e);
|
|
474
|
-
}
|
|
475
|
-
},
|
|
476
|
-
{ once: true }
|
|
477
|
-
);
|
|
478
|
-
});
|
|
567
|
+
const result = await import_effect.Effect.runPromise(program);
|
|
568
|
+
const delegation = result ? Object.values(result)[0] : null;
|
|
569
|
+
return {
|
|
570
|
+
poolId: delegation?.delegate?.id || null,
|
|
571
|
+
rewards: BigInt(delegation?.rewards?.ada?.lovelace || 0)
|
|
572
|
+
};
|
|
479
573
|
}
|
|
480
574
|
async getDatum(datumHash) {
|
|
481
|
-
const
|
|
482
|
-
|
|
575
|
+
const pattern = `${this.kupoUrl}/datums/${datumHash}`;
|
|
576
|
+
const schema = KupoDatumSchema;
|
|
577
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
578
|
+
import_effect.Effect.timeout(1e4),
|
|
579
|
+
import_effect.Effect.flatMap(import_effect.Effect.fromNullable),
|
|
580
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
483
581
|
);
|
|
484
|
-
|
|
485
|
-
throw new Error(`No datum found for datum hash: ${datumHash}`);
|
|
486
|
-
}
|
|
582
|
+
const result = await import_effect.Effect.runPromise(program);
|
|
487
583
|
return result.datum;
|
|
488
584
|
}
|
|
489
|
-
awaitTx(txHash, checkInterval =
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
`${this.kupoUrl}/matches/*@${txHash}?unspent`
|
|
494
|
-
).then((res2) => res2.json());
|
|
495
|
-
if (isConfirmed && isConfirmed.length > 0) {
|
|
496
|
-
clearInterval(confirmation);
|
|
497
|
-
await new Promise((res2) => setTimeout(() => res2(1), 1e3));
|
|
498
|
-
return res(true);
|
|
499
|
-
}
|
|
500
|
-
}, checkInterval);
|
|
585
|
+
async awaitTx(txHash, checkInterval = 2e4) {
|
|
586
|
+
const pattern = `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
587
|
+
const schema = S2.Array(KupoUTxO).annotations({
|
|
588
|
+
identifier: "Array<KupmiosSchema.KupoUTxO>"
|
|
501
589
|
});
|
|
590
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
591
|
+
import_effect.Effect.repeat({
|
|
592
|
+
schedule: import_effect.Schedule.exponential(checkInterval),
|
|
593
|
+
until: (result) => result.length > 0
|
|
594
|
+
}),
|
|
595
|
+
import_effect.Effect.timeout(16e4),
|
|
596
|
+
import_effect.Effect.catchAll(kupmiosError),
|
|
597
|
+
import_effect.Effect.as(true)
|
|
598
|
+
);
|
|
599
|
+
return await import_effect.Effect.runPromise(program);
|
|
502
600
|
}
|
|
503
601
|
async submitTx(cbor) {
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
rej(e);
|
|
518
|
-
}
|
|
519
|
-
},
|
|
520
|
-
{ once: true }
|
|
521
|
-
);
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
kupmiosUtxosToUtxos(utxos) {
|
|
525
|
-
return Promise.all(
|
|
526
|
-
utxos.map(async (utxo) => {
|
|
527
|
-
return {
|
|
528
|
-
txHash: utxo.transaction_id,
|
|
529
|
-
outputIndex: parseInt(utxo.output_index),
|
|
530
|
-
address: utxo.address,
|
|
531
|
-
assets: (() => {
|
|
532
|
-
const a = { lovelace: BigInt(utxo.value.coins) };
|
|
533
|
-
Object.keys(utxo.value.assets).forEach((unit) => {
|
|
534
|
-
a[unit.replace(".", "")] = BigInt(utxo.value.assets[unit]);
|
|
535
|
-
});
|
|
536
|
-
return a;
|
|
537
|
-
})(),
|
|
538
|
-
datumHash: utxo?.datum_type === "hash" ? utxo.datum_hash : null,
|
|
539
|
-
datum: utxo?.datum_type === "inline" ? await this.getDatum(utxo.datum_hash) : null,
|
|
540
|
-
scriptRef: utxo.script_hash && await (async () => {
|
|
541
|
-
const { script, language } = await fetch(
|
|
542
|
-
`${this.kupoUrl}/scripts/${utxo.script_hash}`
|
|
543
|
-
).then((res) => res.json());
|
|
544
|
-
if (language === "native") {
|
|
545
|
-
return { type: "Native", script };
|
|
546
|
-
} else if (language === "plutus:v1") {
|
|
547
|
-
return {
|
|
548
|
-
type: "PlutusV1",
|
|
549
|
-
script: CML.PlutusV1Script.from_cbor_hex(script).to_cbor_hex()
|
|
550
|
-
};
|
|
551
|
-
} else if (language === "plutus:v2") {
|
|
552
|
-
return {
|
|
553
|
-
type: "PlutusV2",
|
|
554
|
-
script: CML.PlutusV2Script.from_cbor_hex(script).to_cbor_hex()
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
})()
|
|
558
|
-
};
|
|
602
|
+
const data = {
|
|
603
|
+
jsonrpc: "2.0",
|
|
604
|
+
method: "submitTransaction",
|
|
605
|
+
params: {
|
|
606
|
+
transaction: { cbor }
|
|
607
|
+
},
|
|
608
|
+
id: null
|
|
609
|
+
};
|
|
610
|
+
const schema = JSONRPCSchema(
|
|
611
|
+
S2.Struct({
|
|
612
|
+
transaction: S2.Struct({
|
|
613
|
+
id: S2.String
|
|
614
|
+
})
|
|
559
615
|
})
|
|
560
616
|
);
|
|
617
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
618
|
+
import_effect.Effect.flatMap(
|
|
619
|
+
(response) => "error" in response ? import_effect.Effect.fail(response.error) : import_effect.Effect.succeed(response)
|
|
620
|
+
),
|
|
621
|
+
import_effect.Effect.timeout(1e4),
|
|
622
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
623
|
+
);
|
|
624
|
+
const { result } = await import_effect.Effect.runPromise(program);
|
|
625
|
+
return result.transaction.id;
|
|
561
626
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
627
|
+
};
|
|
628
|
+
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect.Effect.gen(function* () {
|
|
629
|
+
if (datum_type === "inline" && datum_hash) {
|
|
630
|
+
const pattern = `${kupoUrl}/datums/${datum_hash}`;
|
|
631
|
+
const schema = KupoDatumSchema;
|
|
632
|
+
return yield* fetchKupoParse(pattern, schema).pipe(
|
|
633
|
+
import_effect.Effect.flatMap(import_effect.Effect.fromNullable),
|
|
634
|
+
import_effect.Effect.map((result) => result.datum),
|
|
635
|
+
import_effect.Effect.timeout(1e4)
|
|
636
|
+
);
|
|
637
|
+
} else return null;
|
|
638
|
+
});
|
|
639
|
+
var getScriptEffect = (kupoUrl, script_hash) => import_effect.Effect.gen(function* () {
|
|
640
|
+
if (script_hash) {
|
|
641
|
+
const pattern = `${kupoUrl}/scripts/${script_hash}`;
|
|
642
|
+
const schema = KupoScriptSchema;
|
|
643
|
+
return yield* (0, import_effect.pipe)(
|
|
644
|
+
fetchKupoParse(pattern, schema),
|
|
645
|
+
import_effect.Effect.flatMap(import_effect.Effect.fromNullable),
|
|
646
|
+
import_effect.Effect.timeout(1e4),
|
|
647
|
+
import_effect.Effect.map(({ language, script }) => {
|
|
648
|
+
switch (language) {
|
|
649
|
+
case "native":
|
|
650
|
+
return { type: "Native", script };
|
|
651
|
+
case "plutus:v1":
|
|
652
|
+
return { type: "PlutusV1", script };
|
|
653
|
+
case "plutus:v2":
|
|
654
|
+
return { type: "PlutusV2", script };
|
|
655
|
+
}
|
|
573
656
|
})
|
|
574
657
|
);
|
|
575
|
-
|
|
658
|
+
} else return null;
|
|
659
|
+
});
|
|
660
|
+
var toAssets = (value) => {
|
|
661
|
+
const assets = { lovelace: BigInt(value.coins) };
|
|
662
|
+
for (const unit of Object.keys(value.assets)) {
|
|
663
|
+
assets[unit.replace(".", "")] = BigInt(value.assets[unit]);
|
|
576
664
|
}
|
|
665
|
+
return assets;
|
|
666
|
+
};
|
|
667
|
+
var toProtocolParameters = (result) => {
|
|
668
|
+
return {
|
|
669
|
+
minFeeA: result.minFeeCoefficient,
|
|
670
|
+
minFeeB: result.minFeeConstant.ada.lovelace,
|
|
671
|
+
maxTxSize: result.maxTransactionSize.bytes,
|
|
672
|
+
maxValSize: result.maxValueSize.bytes,
|
|
673
|
+
keyDeposit: BigInt(result.stakeCredentialDeposit.ada.lovelace),
|
|
674
|
+
poolDeposit: BigInt(result.stakePoolDeposit.ada.lovelace),
|
|
675
|
+
priceMem: result.scriptExecutionPrices.memory[0] / result.scriptExecutionPrices.memory[1],
|
|
676
|
+
priceStep: result.scriptExecutionPrices.cpu[0] / result.scriptExecutionPrices.cpu[1],
|
|
677
|
+
maxTxExMem: BigInt(result.maxExecutionUnitsPerTransaction.memory),
|
|
678
|
+
maxTxExSteps: BigInt(result.maxExecutionUnitsPerTransaction.cpu),
|
|
679
|
+
// NOTE: coinsPerUtxoByte is now called utxoCostPerByte:
|
|
680
|
+
// https://github.com/IntersectMBO/cardano-node/pull/4141
|
|
681
|
+
// Ogmios v6.x calls it minUtxoDepositCoefficient according to the following
|
|
682
|
+
// documentation from its protocol parameters data model:
|
|
683
|
+
// https://github.com/CardanoSolutions/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md#protocol-parameters
|
|
684
|
+
coinsPerUtxoByte: BigInt(result.minUtxoDepositCoefficient),
|
|
685
|
+
collateralPercentage: result.collateralPercentage,
|
|
686
|
+
maxCollateralInputs: result.maxCollateralInputs,
|
|
687
|
+
costModels: {
|
|
688
|
+
PlutusV1: Object.fromEntries(
|
|
689
|
+
result.plutusCostModels["plutus:v1"].map((value, index) => [
|
|
690
|
+
index.toString(),
|
|
691
|
+
value
|
|
692
|
+
])
|
|
693
|
+
),
|
|
694
|
+
PlutusV2: Object.fromEntries(
|
|
695
|
+
result.plutusCostModels["plutus:v2"].map((value, index) => [
|
|
696
|
+
index.toString(),
|
|
697
|
+
value
|
|
698
|
+
])
|
|
699
|
+
)
|
|
700
|
+
}
|
|
701
|
+
};
|
|
577
702
|
};
|
|
703
|
+
var fetchOgmiosParse = (url, data, schema) => (0, import_effect.pipe)(
|
|
704
|
+
import_platform.HttpClientRequest.post(url),
|
|
705
|
+
import_platform.HttpClientRequest.jsonBody(data),
|
|
706
|
+
import_effect.Effect.flatMap(import_platform.HttpClient.fetch),
|
|
707
|
+
import_platform.HttpClientResponse.json,
|
|
708
|
+
import_effect.Effect.flatMap(S2.decodeUnknown(schema))
|
|
709
|
+
// Effect.catchTag("ParseError", (e) =>
|
|
710
|
+
// Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
|
|
711
|
+
// ),
|
|
712
|
+
// Effect.scoped
|
|
713
|
+
);
|
|
714
|
+
var fetchKupoParse = (url, schema) => (0, import_effect.pipe)(
|
|
715
|
+
import_platform.HttpClientRequest.get(url),
|
|
716
|
+
import_platform.HttpClient.fetchOk,
|
|
717
|
+
import_platform.HttpClientResponse.json,
|
|
718
|
+
import_effect.Effect.flatMap(S2.decodeUnknown(schema))
|
|
719
|
+
// Effect.catchTag("ParseError", (e) =>
|
|
720
|
+
// Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
|
|
721
|
+
// ),
|
|
722
|
+
// Effect.scoped
|
|
723
|
+
);
|
|
724
|
+
var kupmiosUtxosToUtxos = (kupoURL, utxos) => import_effect.Effect.forEach(
|
|
725
|
+
utxos,
|
|
726
|
+
(utxo) => {
|
|
727
|
+
return (0, import_effect.pipe)(
|
|
728
|
+
import_effect.Effect.all([
|
|
729
|
+
getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
|
|
730
|
+
getScriptEffect(kupoURL, utxo.script_hash)
|
|
731
|
+
]),
|
|
732
|
+
import_effect.Effect.map(
|
|
733
|
+
([datum, script]) => ({
|
|
734
|
+
txHash: utxo.transaction_id,
|
|
735
|
+
outputIndex: utxo.output_index,
|
|
736
|
+
address: utxo.address,
|
|
737
|
+
assets: toAssets(utxo.value),
|
|
738
|
+
datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : null,
|
|
739
|
+
datum,
|
|
740
|
+
scriptRef: script
|
|
741
|
+
})
|
|
742
|
+
)
|
|
743
|
+
);
|
|
744
|
+
},
|
|
745
|
+
{ concurrency: "unbounded" }
|
|
746
|
+
);
|
|
578
747
|
|
|
579
748
|
// src/maestro.ts
|
|
580
749
|
var import_utils3 = require("@lucid-evolution/utils");
|
|
@@ -840,194 +1009,194 @@ var Maestro = class {
|
|
|
840
1009
|
var lucid2 = package_default.version;
|
|
841
1010
|
|
|
842
1011
|
// src/koios/koios.ts
|
|
843
|
-
var
|
|
1012
|
+
var S4 = __toESM(require("@effect/schema/Schema"), 1);
|
|
844
1013
|
var import_core_utils3 = require("@lucid-evolution/core-utils");
|
|
845
1014
|
var import_utils4 = require("@lucid-evolution/utils");
|
|
846
1015
|
|
|
847
1016
|
// src/koios/schema.ts
|
|
848
|
-
var
|
|
849
|
-
var
|
|
850
|
-
epoch_no:
|
|
851
|
-
min_fee_a:
|
|
852
|
-
min_fee_b:
|
|
853
|
-
max_block_size:
|
|
854
|
-
max_tx_size:
|
|
855
|
-
max_bh_size:
|
|
856
|
-
key_deposit:
|
|
857
|
-
pool_deposit:
|
|
858
|
-
max_epoch:
|
|
859
|
-
optimal_pool_count:
|
|
860
|
-
influence:
|
|
861
|
-
monetary_expand_rate:
|
|
862
|
-
treasury_growth_rate:
|
|
863
|
-
decentralisation:
|
|
864
|
-
extra_entropy:
|
|
865
|
-
protocol_major:
|
|
866
|
-
protocol_minor:
|
|
867
|
-
min_utxo_value:
|
|
868
|
-
min_pool_cost:
|
|
869
|
-
nonce:
|
|
870
|
-
block_hash:
|
|
871
|
-
cost_models:
|
|
872
|
-
PlutusV1:
|
|
873
|
-
PlutusV2:
|
|
1017
|
+
var S3 = __toESM(require("@effect/schema/Schema"), 1);
|
|
1018
|
+
var ProtocolParametersSchema2 = S3.Struct({
|
|
1019
|
+
epoch_no: S3.Number,
|
|
1020
|
+
min_fee_a: S3.Number,
|
|
1021
|
+
min_fee_b: S3.Number,
|
|
1022
|
+
max_block_size: S3.Number,
|
|
1023
|
+
max_tx_size: S3.Number,
|
|
1024
|
+
max_bh_size: S3.Number,
|
|
1025
|
+
key_deposit: S3.BigInt,
|
|
1026
|
+
pool_deposit: S3.BigInt,
|
|
1027
|
+
max_epoch: S3.Number,
|
|
1028
|
+
optimal_pool_count: S3.Number,
|
|
1029
|
+
influence: S3.Number,
|
|
1030
|
+
monetary_expand_rate: S3.Number,
|
|
1031
|
+
treasury_growth_rate: S3.Number,
|
|
1032
|
+
decentralisation: S3.Number,
|
|
1033
|
+
extra_entropy: S3.NullOr(S3.String),
|
|
1034
|
+
protocol_major: S3.Number,
|
|
1035
|
+
protocol_minor: S3.Number,
|
|
1036
|
+
min_utxo_value: S3.String,
|
|
1037
|
+
min_pool_cost: S3.String,
|
|
1038
|
+
nonce: S3.String,
|
|
1039
|
+
block_hash: S3.NullOr(S3.String),
|
|
1040
|
+
cost_models: S3.Struct({
|
|
1041
|
+
PlutusV1: S3.Array(S3.Number),
|
|
1042
|
+
PlutusV2: S3.Array(S3.Number)
|
|
874
1043
|
}),
|
|
875
|
-
price_mem:
|
|
876
|
-
price_step:
|
|
877
|
-
max_tx_ex_mem:
|
|
878
|
-
max_tx_ex_steps:
|
|
879
|
-
max_block_ex_mem:
|
|
880
|
-
max_block_ex_steps:
|
|
881
|
-
max_val_size:
|
|
882
|
-
collateral_percent:
|
|
883
|
-
max_collateral_inputs:
|
|
884
|
-
coins_per_utxo_size:
|
|
1044
|
+
price_mem: S3.Number,
|
|
1045
|
+
price_step: S3.Number,
|
|
1046
|
+
max_tx_ex_mem: S3.BigIntFromNumber,
|
|
1047
|
+
max_tx_ex_steps: S3.BigIntFromNumber,
|
|
1048
|
+
max_block_ex_mem: S3.Number,
|
|
1049
|
+
max_block_ex_steps: S3.Number,
|
|
1050
|
+
max_val_size: S3.Number,
|
|
1051
|
+
collateral_percent: S3.Number,
|
|
1052
|
+
max_collateral_inputs: S3.Number,
|
|
1053
|
+
coins_per_utxo_size: S3.BigInt
|
|
885
1054
|
});
|
|
886
|
-
var KoiosAssetSchema =
|
|
887
|
-
policy_id:
|
|
888
|
-
asset_name:
|
|
889
|
-
fingerprint:
|
|
890
|
-
decimals:
|
|
891
|
-
quantity:
|
|
1055
|
+
var KoiosAssetSchema = S3.Struct({
|
|
1056
|
+
policy_id: S3.String,
|
|
1057
|
+
asset_name: S3.NullOr(S3.String),
|
|
1058
|
+
fingerprint: S3.String,
|
|
1059
|
+
decimals: S3.Number,
|
|
1060
|
+
quantity: S3.String
|
|
892
1061
|
});
|
|
893
|
-
var KoiosUTxOSchema =
|
|
894
|
-
tx_hash:
|
|
895
|
-
tx_index:
|
|
896
|
-
block_height:
|
|
897
|
-
value:
|
|
898
|
-
datum_hash:
|
|
899
|
-
inline_datum:
|
|
900
|
-
|
|
901
|
-
bytes:
|
|
902
|
-
value:
|
|
1062
|
+
var KoiosUTxOSchema = S3.Struct({
|
|
1063
|
+
tx_hash: S3.String,
|
|
1064
|
+
tx_index: S3.Number,
|
|
1065
|
+
block_height: S3.NullOr(S3.Number),
|
|
1066
|
+
value: S3.String,
|
|
1067
|
+
datum_hash: S3.NullOr(S3.String),
|
|
1068
|
+
inline_datum: S3.NullOr(
|
|
1069
|
+
S3.Struct({
|
|
1070
|
+
bytes: S3.String,
|
|
1071
|
+
value: S3.Object
|
|
903
1072
|
})
|
|
904
1073
|
),
|
|
905
|
-
reference_script:
|
|
906
|
-
|
|
907
|
-
hash:
|
|
908
|
-
size:
|
|
909
|
-
type:
|
|
910
|
-
bytes:
|
|
911
|
-
value:
|
|
1074
|
+
reference_script: S3.NullOr(
|
|
1075
|
+
S3.Struct({
|
|
1076
|
+
hash: S3.String,
|
|
1077
|
+
size: S3.Number,
|
|
1078
|
+
type: S3.String,
|
|
1079
|
+
bytes: S3.String,
|
|
1080
|
+
value: S3.NullOr(S3.Object)
|
|
912
1081
|
})
|
|
913
1082
|
),
|
|
914
|
-
asset_list:
|
|
1083
|
+
asset_list: S3.NullOr(S3.Array(KoiosAssetSchema))
|
|
915
1084
|
});
|
|
916
|
-
var KoiosAddressInfoSchema =
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
address:
|
|
920
|
-
balance:
|
|
921
|
-
stake_address:
|
|
922
|
-
script_address:
|
|
923
|
-
utxo_set:
|
|
1085
|
+
var KoiosAddressInfoSchema = S3.Array(
|
|
1086
|
+
S3.NullishOr(
|
|
1087
|
+
S3.Struct({
|
|
1088
|
+
address: S3.String,
|
|
1089
|
+
balance: S3.String,
|
|
1090
|
+
stake_address: S3.NullOr(S3.String),
|
|
1091
|
+
script_address: S3.Boolean,
|
|
1092
|
+
utxo_set: S3.Array(KoiosUTxOSchema)
|
|
924
1093
|
})
|
|
925
1094
|
)
|
|
926
1095
|
);
|
|
927
|
-
var KoiosInputOutputSchema =
|
|
928
|
-
payment_addr:
|
|
929
|
-
bech32:
|
|
930
|
-
cred:
|
|
1096
|
+
var KoiosInputOutputSchema = S3.Struct({
|
|
1097
|
+
payment_addr: S3.Struct({
|
|
1098
|
+
bech32: S3.String,
|
|
1099
|
+
cred: S3.String
|
|
931
1100
|
}),
|
|
932
|
-
stake_addr:
|
|
933
|
-
tx_hash:
|
|
934
|
-
tx_index:
|
|
935
|
-
value:
|
|
936
|
-
datum_hash:
|
|
937
|
-
inline_datum:
|
|
938
|
-
|
|
939
|
-
bytes:
|
|
940
|
-
value:
|
|
1101
|
+
stake_addr: S3.NullOr(S3.String),
|
|
1102
|
+
tx_hash: S3.String,
|
|
1103
|
+
tx_index: S3.Number,
|
|
1104
|
+
value: S3.String,
|
|
1105
|
+
datum_hash: S3.NullOr(S3.String),
|
|
1106
|
+
inline_datum: S3.NullOr(
|
|
1107
|
+
S3.Struct({
|
|
1108
|
+
bytes: S3.String,
|
|
1109
|
+
value: S3.Object
|
|
941
1110
|
})
|
|
942
1111
|
),
|
|
943
|
-
reference_script:
|
|
944
|
-
|
|
945
|
-
hash:
|
|
946
|
-
size:
|
|
947
|
-
type:
|
|
948
|
-
bytes:
|
|
949
|
-
value:
|
|
1112
|
+
reference_script: S3.NullOr(
|
|
1113
|
+
S3.Struct({
|
|
1114
|
+
hash: S3.String,
|
|
1115
|
+
size: S3.Number,
|
|
1116
|
+
type: S3.String,
|
|
1117
|
+
bytes: S3.String,
|
|
1118
|
+
value: S3.NullOr(S3.Object)
|
|
950
1119
|
})
|
|
951
1120
|
),
|
|
952
|
-
asset_list:
|
|
1121
|
+
asset_list: S3.Union(S3.Array(KoiosAssetSchema), S3.String)
|
|
953
1122
|
});
|
|
954
|
-
var KoiosTxInfoSchema =
|
|
955
|
-
tx_hash:
|
|
956
|
-
block_hash:
|
|
957
|
-
block_height:
|
|
958
|
-
epoch_no:
|
|
959
|
-
epoch_slot:
|
|
960
|
-
absolute_slot:
|
|
961
|
-
tx_timestamp:
|
|
962
|
-
tx_block_index:
|
|
963
|
-
tx_size:
|
|
964
|
-
total_output:
|
|
965
|
-
fee:
|
|
966
|
-
deposit:
|
|
967
|
-
invalid_before:
|
|
968
|
-
invalid_after:
|
|
969
|
-
collateral_inputs:
|
|
970
|
-
collateral_output:
|
|
971
|
-
reference_inputs:
|
|
972
|
-
inputs:
|
|
973
|
-
outputs:
|
|
974
|
-
withdrawals:
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
amount:
|
|
978
|
-
stake_addr:
|
|
1123
|
+
var KoiosTxInfoSchema = S3.Struct({
|
|
1124
|
+
tx_hash: S3.String,
|
|
1125
|
+
block_hash: S3.String,
|
|
1126
|
+
block_height: S3.Number,
|
|
1127
|
+
epoch_no: S3.Number,
|
|
1128
|
+
epoch_slot: S3.Number,
|
|
1129
|
+
absolute_slot: S3.Number,
|
|
1130
|
+
tx_timestamp: S3.Number,
|
|
1131
|
+
tx_block_index: S3.Number,
|
|
1132
|
+
tx_size: S3.Number,
|
|
1133
|
+
total_output: S3.String,
|
|
1134
|
+
fee: S3.String,
|
|
1135
|
+
deposit: S3.String,
|
|
1136
|
+
invalid_before: S3.NullOr(S3.String),
|
|
1137
|
+
invalid_after: S3.NullOr(S3.String),
|
|
1138
|
+
collateral_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
|
|
1139
|
+
collateral_output: S3.NullOr(KoiosInputOutputSchema),
|
|
1140
|
+
reference_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
|
|
1141
|
+
inputs: S3.Array(KoiosInputOutputSchema),
|
|
1142
|
+
outputs: S3.Array(KoiosInputOutputSchema),
|
|
1143
|
+
withdrawals: S3.NullOr(
|
|
1144
|
+
S3.Array(
|
|
1145
|
+
S3.Struct({
|
|
1146
|
+
amount: S3.String,
|
|
1147
|
+
stake_addr: S3.String
|
|
979
1148
|
})
|
|
980
1149
|
)
|
|
981
1150
|
),
|
|
982
|
-
assets_minted:
|
|
983
|
-
metadata:
|
|
984
|
-
certificates:
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
index:
|
|
988
|
-
type:
|
|
989
|
-
info:
|
|
1151
|
+
assets_minted: S3.NullOr(S3.Array(KoiosAssetSchema)),
|
|
1152
|
+
metadata: S3.NullOr(S3.Object),
|
|
1153
|
+
certificates: S3.NullOr(
|
|
1154
|
+
S3.Array(
|
|
1155
|
+
S3.Struct({
|
|
1156
|
+
index: S3.Number,
|
|
1157
|
+
type: S3.String,
|
|
1158
|
+
info: S3.NullOr(S3.Object)
|
|
990
1159
|
})
|
|
991
1160
|
)
|
|
992
1161
|
),
|
|
993
|
-
native_scripts:
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
script_hash:
|
|
997
|
-
script_json:
|
|
1162
|
+
native_scripts: S3.NullOr(
|
|
1163
|
+
S3.Array(
|
|
1164
|
+
S3.Struct({
|
|
1165
|
+
script_hash: S3.String,
|
|
1166
|
+
script_json: S3.Object
|
|
998
1167
|
})
|
|
999
1168
|
)
|
|
1000
1169
|
),
|
|
1001
|
-
plutus_contracts:
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
address:
|
|
1005
|
-
spends_input:
|
|
1006
|
-
|
|
1007
|
-
tx_hash:
|
|
1008
|
-
tx_index:
|
|
1170
|
+
plutus_contracts: S3.NullOr(
|
|
1171
|
+
S3.Array(
|
|
1172
|
+
S3.Struct({
|
|
1173
|
+
address: S3.String,
|
|
1174
|
+
spends_input: S3.NullOr(
|
|
1175
|
+
S3.Struct({
|
|
1176
|
+
tx_hash: S3.String,
|
|
1177
|
+
tx_index: S3.Number
|
|
1009
1178
|
})
|
|
1010
1179
|
),
|
|
1011
|
-
script_hash:
|
|
1012
|
-
bytecode:
|
|
1013
|
-
size:
|
|
1014
|
-
valid_contract:
|
|
1015
|
-
input:
|
|
1016
|
-
redeemer:
|
|
1017
|
-
purpose:
|
|
1018
|
-
fee:
|
|
1019
|
-
unit:
|
|
1020
|
-
steps:
|
|
1021
|
-
mem:
|
|
1180
|
+
script_hash: S3.String,
|
|
1181
|
+
bytecode: S3.String,
|
|
1182
|
+
size: S3.Number,
|
|
1183
|
+
valid_contract: S3.Boolean,
|
|
1184
|
+
input: S3.Struct({
|
|
1185
|
+
redeemer: S3.Struct({
|
|
1186
|
+
purpose: S3.Literal("spend", "mint", "cert", "reward"),
|
|
1187
|
+
fee: S3.String,
|
|
1188
|
+
unit: S3.Struct({
|
|
1189
|
+
steps: S3.String,
|
|
1190
|
+
mem: S3.String
|
|
1022
1191
|
}),
|
|
1023
|
-
datum:
|
|
1024
|
-
hash:
|
|
1025
|
-
value:
|
|
1192
|
+
datum: S3.Struct({
|
|
1193
|
+
hash: S3.NullOr(S3.String),
|
|
1194
|
+
value: S3.NullOr(S3.Object)
|
|
1026
1195
|
})
|
|
1027
1196
|
}),
|
|
1028
|
-
datum:
|
|
1029
|
-
hash:
|
|
1030
|
-
value:
|
|
1197
|
+
datum: S3.Struct({
|
|
1198
|
+
hash: S3.NullOr(S3.String),
|
|
1199
|
+
value: S3.NullOr(S3.Object)
|
|
1031
1200
|
})
|
|
1032
1201
|
})
|
|
1033
1202
|
})
|
|
@@ -1036,8 +1205,45 @@ var KoiosTxInfoSchema = S.Struct({
|
|
|
1036
1205
|
});
|
|
1037
1206
|
|
|
1038
1207
|
// src/koios/koios.ts
|
|
1039
|
-
var
|
|
1208
|
+
var import_effect3 = require("effect");
|
|
1040
1209
|
var import_schema2 = require("@effect/schema");
|
|
1210
|
+
|
|
1211
|
+
// src/fetch.ts
|
|
1212
|
+
var fetch_exports = {};
|
|
1213
|
+
__export(fetch_exports, {
|
|
1214
|
+
FetchError: () => FetchError,
|
|
1215
|
+
JsonError: () => JsonError,
|
|
1216
|
+
ResponseError: () => ResponseError,
|
|
1217
|
+
fetchEffect: () => fetchEffect
|
|
1218
|
+
});
|
|
1219
|
+
var import_effect2 = require("effect");
|
|
1220
|
+
var FetchError = class extends import_effect2.Data.TaggedError("FetchError") {
|
|
1221
|
+
};
|
|
1222
|
+
var ResponseError = class extends import_effect2.Data.TaggedError("ResponseError") {
|
|
1223
|
+
};
|
|
1224
|
+
var JsonError = class extends import_effect2.Data.TaggedError("JsonError") {
|
|
1225
|
+
};
|
|
1226
|
+
var fetchEffect = (input, requestInit) => (0, import_effect2.pipe)(
|
|
1227
|
+
import_effect2.Effect.tryPromise({
|
|
1228
|
+
try: () => fetch(input, requestInit),
|
|
1229
|
+
catch: (error) => new FetchError({
|
|
1230
|
+
message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
|
|
1231
|
+
})
|
|
1232
|
+
}),
|
|
1233
|
+
import_effect2.Effect.flatMap(
|
|
1234
|
+
(response) => !response.ok ? new ResponseError({
|
|
1235
|
+
message: `${response.status} ${response.statusText}`
|
|
1236
|
+
}) : import_effect2.Effect.succeed(response)
|
|
1237
|
+
),
|
|
1238
|
+
import_effect2.Effect.flatMap(
|
|
1239
|
+
(response) => import_effect2.Effect.tryPromise({
|
|
1240
|
+
try: () => response.json(),
|
|
1241
|
+
catch: (error) => new JsonError({ message: String(error) })
|
|
1242
|
+
})
|
|
1243
|
+
)
|
|
1244
|
+
);
|
|
1245
|
+
|
|
1246
|
+
// src/koios/koios.ts
|
|
1041
1247
|
var Koios = class {
|
|
1042
1248
|
baseUrl;
|
|
1043
1249
|
constructor(baseUrl) {
|
|
@@ -1047,7 +1253,7 @@ var Koios = class {
|
|
|
1047
1253
|
const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
|
|
1048
1254
|
(res) => res.json()
|
|
1049
1255
|
);
|
|
1050
|
-
const param =
|
|
1256
|
+
const param = S4.decodeUnknownSync(ProtocolParametersSchema2)(result[0]);
|
|
1051
1257
|
return {
|
|
1052
1258
|
minFeeA: param.min_fee_a,
|
|
1053
1259
|
minFeeB: param.min_fee_b,
|
|
@@ -1091,7 +1297,7 @@ var Koios = class {
|
|
|
1091
1297
|
method: "POST",
|
|
1092
1298
|
body: JSON.stringify(body)
|
|
1093
1299
|
}).then((res) => res.json());
|
|
1094
|
-
const parsedResult =
|
|
1300
|
+
const parsedResult = S4.decodeUnknownSync(KoiosAddressInfoSchema)(
|
|
1095
1301
|
result
|
|
1096
1302
|
)[0];
|
|
1097
1303
|
return parsedResult ? parsedResult.utxo_set.map(
|
|
@@ -1154,7 +1360,7 @@ var Koios = class {
|
|
|
1154
1360
|
method: "POST",
|
|
1155
1361
|
body: JSON.stringify(body)
|
|
1156
1362
|
}).then((res) => res.json());
|
|
1157
|
-
const parsedResult =
|
|
1363
|
+
const parsedResult = S4.decodeUnknownSync(S4.Array(KoiosTxInfoSchema))(
|
|
1158
1364
|
result
|
|
1159
1365
|
)[0];
|
|
1160
1366
|
if (parsedResult) {
|
|
@@ -1217,7 +1423,7 @@ var Koios = class {
|
|
|
1217
1423
|
throw new Error("No Datum Found by Datum Hash");
|
|
1218
1424
|
}
|
|
1219
1425
|
}
|
|
1220
|
-
awaitTx(txHash, checkInterval = 2e4) {
|
|
1426
|
+
async awaitTx(txHash, checkInterval = 2e4) {
|
|
1221
1427
|
const body = {
|
|
1222
1428
|
_tx_hashes: [txHash]
|
|
1223
1429
|
};
|
|
@@ -1229,36 +1435,24 @@ var Koios = class {
|
|
|
1229
1435
|
method: "POST",
|
|
1230
1436
|
body: JSON.stringify(body)
|
|
1231
1437
|
};
|
|
1232
|
-
const program = (0,
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
catch: (error) => new Error(String(error))
|
|
1237
|
-
}),
|
|
1238
|
-
import_effect.Effect.flatMap(
|
|
1239
|
-
(response) => !response.ok ? import_effect.Effect.fail(new Error(`${response.status} ${response.statusText}`)) : import_effect.Effect.succeed(response)
|
|
1438
|
+
const program = (0, import_effect3.pipe)(
|
|
1439
|
+
fetchEffect(`${this.baseUrl}/tx_info`, request),
|
|
1440
|
+
import_effect3.Effect.flatMap(
|
|
1441
|
+
(json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
|
|
1240
1442
|
),
|
|
1241
|
-
|
|
1242
|
-
(response) => import_effect.Effect.tryPromise({
|
|
1243
|
-
try: () => response.json(),
|
|
1244
|
-
catch: (error) => new Error(String(error))
|
|
1245
|
-
})
|
|
1246
|
-
),
|
|
1247
|
-
import_effect.Effect.flatMap(
|
|
1248
|
-
(json) => S2.decodeUnknown(S2.Array(KoiosTxInfoSchema), { errors: "first" })(json)
|
|
1249
|
-
),
|
|
1250
|
-
import_effect.Effect.catchTag(
|
|
1443
|
+
import_effect3.Effect.catchTag(
|
|
1251
1444
|
"ParseError",
|
|
1252
|
-
(e) =>
|
|
1445
|
+
(e) => import_effect3.Effect.fail(import_schema2.ArrayFormatter.formatErrorSync(e))
|
|
1253
1446
|
),
|
|
1254
|
-
|
|
1255
|
-
schedule:
|
|
1447
|
+
import_effect3.Effect.repeat({
|
|
1448
|
+
schedule: import_effect3.Schedule.exponential(checkInterval),
|
|
1256
1449
|
until: (result) => result.length > 0
|
|
1257
1450
|
}),
|
|
1258
|
-
|
|
1259
|
-
|
|
1451
|
+
import_effect3.Effect.timeout(16e4),
|
|
1452
|
+
import_effect3.Effect.orDie,
|
|
1453
|
+
import_effect3.Effect.as(true)
|
|
1260
1454
|
);
|
|
1261
|
-
return
|
|
1455
|
+
return import_effect3.Effect.runPromise(program);
|
|
1262
1456
|
}
|
|
1263
1457
|
async submitTx(tx) {
|
|
1264
1458
|
const result = await fetch(`${this.baseUrl}/submittx`, {
|
|
@@ -1269,8 +1463,8 @@ var Koios = class {
|
|
|
1269
1463
|
method: "POST",
|
|
1270
1464
|
body: (0, import_core_utils3.fromHex)(tx)
|
|
1271
1465
|
}).then((res) => res.json());
|
|
1272
|
-
const TxHashSchema =
|
|
1273
|
-
const isTxHash =
|
|
1466
|
+
const TxHashSchema = S4.String;
|
|
1467
|
+
const isTxHash = S4.is(TxHashSchema);
|
|
1274
1468
|
if (!isTxHash(result)) {
|
|
1275
1469
|
throw new Error(JSON.stringify(result));
|
|
1276
1470
|
}
|
|
@@ -1304,8 +1498,10 @@ var toUTxO = (koiosUTxO, address) => ({
|
|
|
1304
1498
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1305
1499
|
0 && (module.exports = {
|
|
1306
1500
|
Blockfrost,
|
|
1501
|
+
FetchProvider,
|
|
1307
1502
|
Koios,
|
|
1308
1503
|
Kupmios,
|
|
1504
|
+
KupmiosError,
|
|
1309
1505
|
Maestro,
|
|
1310
1506
|
datumJsonToCbor
|
|
1311
1507
|
});
|