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