@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.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
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
|
+
|
|
1
7
|
// src/core.ts
|
|
2
8
|
import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
3
9
|
|
|
@@ -8,7 +14,7 @@ import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
|
|
|
8
14
|
// package.json
|
|
9
15
|
var package_default = {
|
|
10
16
|
name: "@lucid-evolution/provider",
|
|
11
|
-
version: "0.1.
|
|
17
|
+
version: "0.1.31",
|
|
12
18
|
description: "",
|
|
13
19
|
main: "./dist/index.js",
|
|
14
20
|
types: "./dist/index.d.ts",
|
|
@@ -40,17 +46,18 @@ var package_default = {
|
|
|
40
46
|
dependencies: {
|
|
41
47
|
"@anastasia-labs/cardano-multiplatform-lib-browser": "^5.3.1-2",
|
|
42
48
|
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "^5.3.1-2",
|
|
43
|
-
"@effect/
|
|
49
|
+
"@effect/platform": "^0.59.2",
|
|
50
|
+
"@effect/schema": "^0.68.26",
|
|
44
51
|
"@lucid-evolution/core-types": "workspace:*",
|
|
45
52
|
"@lucid-evolution/core-utils": "workspace:*",
|
|
46
53
|
"@lucid-evolution/utils": "workspace:*",
|
|
47
|
-
effect: "^3.
|
|
54
|
+
effect: "^3.5.6"
|
|
48
55
|
},
|
|
49
56
|
devDependencies: {
|
|
50
57
|
"@types/node": "^20.12.8",
|
|
51
58
|
tsup: "^8.0.2",
|
|
52
59
|
typescript: "^5.4.5",
|
|
53
|
-
vitest: "^
|
|
60
|
+
vitest: "^2.0.4"
|
|
54
61
|
}
|
|
55
62
|
};
|
|
56
63
|
|
|
@@ -309,232 +316,402 @@ function datumJsonToCbor(json) {
|
|
|
309
316
|
}
|
|
310
317
|
var lucid = package_default.version;
|
|
311
318
|
|
|
312
|
-
// src/kupmios.ts
|
|
319
|
+
// src/kupmios/kupmios.ts
|
|
313
320
|
import { fromUnit } from "@lucid-evolution/utils";
|
|
321
|
+
import * as S2 from "@effect/schema/Schema";
|
|
322
|
+
import { Effect, pipe, Array as _Array, Schedule, Data } from "effect";
|
|
323
|
+
|
|
324
|
+
// src/kupmios/schema.ts
|
|
325
|
+
import * as S from "@effect/schema/Schema";
|
|
326
|
+
var JSONRPCSchema = (schema) => S.extend(
|
|
327
|
+
S.Struct({
|
|
328
|
+
jsonrpc: S.String,
|
|
329
|
+
method: S.String,
|
|
330
|
+
id: S.NullOr(S.Number)
|
|
331
|
+
}),
|
|
332
|
+
S.Union(S.Struct({ result: schema }), S.Struct({ error: S.Object }))
|
|
333
|
+
);
|
|
334
|
+
var LovelaceAsset = S.Struct({
|
|
335
|
+
lovelace: S.Number
|
|
336
|
+
});
|
|
337
|
+
var TupleNumberFromString = S.compose(
|
|
338
|
+
S.split("/"),
|
|
339
|
+
S.Array(S.NumberFromString)
|
|
340
|
+
);
|
|
341
|
+
var ProtocolParametersSchema = S.Struct({
|
|
342
|
+
minFeeCoefficient: S.Number,
|
|
343
|
+
minFeeConstant: S.Struct({ ada: LovelaceAsset }),
|
|
344
|
+
maxBlockBodySize: S.Struct({ bytes: S.Number }),
|
|
345
|
+
maxBlockHeaderSize: S.Struct({ bytes: S.Number }),
|
|
346
|
+
maxTransactionSize: S.Struct({ bytes: S.Number }),
|
|
347
|
+
stakeCredentialDeposit: S.Struct({ ada: LovelaceAsset }),
|
|
348
|
+
stakePoolDeposit: S.Struct({ ada: LovelaceAsset }),
|
|
349
|
+
stakePoolRetirementEpochBound: S.Number,
|
|
350
|
+
desiredNumberOfStakePools: S.Number,
|
|
351
|
+
stakePoolPledgeInfluence: TupleNumberFromString,
|
|
352
|
+
monetaryExpansion: TupleNumberFromString,
|
|
353
|
+
treasuryExpansion: TupleNumberFromString,
|
|
354
|
+
minStakePoolCost: S.Struct({ ada: LovelaceAsset }),
|
|
355
|
+
minUtxoDepositConstant: S.Struct({ ada: LovelaceAsset }),
|
|
356
|
+
minUtxoDepositCoefficient: S.Number,
|
|
357
|
+
plutusCostModels: S.Struct({
|
|
358
|
+
"plutus:v1": S.Array(S.Number),
|
|
359
|
+
"plutus:v2": S.Array(S.Number)
|
|
360
|
+
}),
|
|
361
|
+
scriptExecutionPrices: S.Struct({
|
|
362
|
+
memory: TupleNumberFromString,
|
|
363
|
+
cpu: TupleNumberFromString
|
|
364
|
+
}),
|
|
365
|
+
maxExecutionUnitsPerTransaction: S.Struct({
|
|
366
|
+
memory: S.Number,
|
|
367
|
+
cpu: S.Number
|
|
368
|
+
}),
|
|
369
|
+
maxExecutionUnitsPerBlock: S.Struct({ memory: S.Number, cpu: S.Number }),
|
|
370
|
+
maxValueSize: S.Struct({ bytes: S.Number }),
|
|
371
|
+
collateralPercentage: S.Number,
|
|
372
|
+
maxCollateralInputs: S.Number,
|
|
373
|
+
version: S.Struct({ major: S.Number, minor: S.Number })
|
|
374
|
+
});
|
|
375
|
+
var KupoValueSchema = S.Struct({
|
|
376
|
+
coins: S.Number,
|
|
377
|
+
assets: S.Record(S.String, S.Number)
|
|
378
|
+
});
|
|
379
|
+
var KupoUTxO = S.Struct({
|
|
380
|
+
transaction_index: S.Number,
|
|
381
|
+
transaction_id: S.String,
|
|
382
|
+
output_index: S.Number,
|
|
383
|
+
address: S.String,
|
|
384
|
+
value: KupoValueSchema,
|
|
385
|
+
datum_hash: S.NullOr(S.String),
|
|
386
|
+
datum_type: S.optional(S.Literal("hash", "inline")),
|
|
387
|
+
script_hash: S.NullOr(S.String),
|
|
388
|
+
created_at: S.Struct({
|
|
389
|
+
slot_no: S.Number,
|
|
390
|
+
header_hash: S.String
|
|
391
|
+
}),
|
|
392
|
+
spent_at: S.NullOr(S.Number)
|
|
393
|
+
});
|
|
394
|
+
var KupoScriptSchema = S.NullOr(
|
|
395
|
+
S.Struct({
|
|
396
|
+
language: S.Literal("native", "plutus:v1", "plutus:v2"),
|
|
397
|
+
script: S.String
|
|
398
|
+
})
|
|
399
|
+
);
|
|
400
|
+
var KupoDatumSchema = S.NullOr(S.Struct({ datum: S.String }));
|
|
401
|
+
var KupoDelegation = S.NullOr(
|
|
402
|
+
S.Record(
|
|
403
|
+
S.String,
|
|
404
|
+
S.Struct({
|
|
405
|
+
delegate: S.Struct({ id: S.String }),
|
|
406
|
+
rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
|
|
407
|
+
deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
|
|
408
|
+
})
|
|
409
|
+
)
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
// src/kupmios/kupmios.ts
|
|
413
|
+
import {
|
|
414
|
+
HttpClient,
|
|
415
|
+
HttpClientRequest,
|
|
416
|
+
HttpClientResponse
|
|
417
|
+
} from "@effect/platform";
|
|
418
|
+
var KupmiosError = class extends Data.TaggedError("KupmiosError") {
|
|
419
|
+
get message() {
|
|
420
|
+
return `${this.cause}`;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var kupmiosError = (cause) => new KupmiosError({
|
|
424
|
+
cause: JSON.stringify(cause)
|
|
425
|
+
});
|
|
314
426
|
var Kupmios = class {
|
|
315
427
|
kupoUrl;
|
|
316
428
|
ogmiosUrl;
|
|
317
429
|
/**
|
|
318
430
|
* @param kupoUrl: http(s)://localhost:1442
|
|
319
|
-
* @param ogmiosUrl:
|
|
431
|
+
* @param ogmiosUrl: http(s)://localhost:1337
|
|
320
432
|
*/
|
|
321
433
|
constructor(kupoUrl, ogmiosUrl) {
|
|
322
434
|
this.kupoUrl = kupoUrl;
|
|
323
435
|
this.ogmiosUrl = ogmiosUrl;
|
|
324
436
|
}
|
|
325
437
|
async getProtocolParameters() {
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
maxTxSize: parseInt(result.maxTransactionSize.bytes),
|
|
345
|
-
maxValSize: parseInt(result.maxValueSize.bytes),
|
|
346
|
-
keyDeposit: BigInt(result.stakeCredentialDeposit.ada.lovelace),
|
|
347
|
-
poolDeposit: BigInt(result.stakePoolDeposit.ada.lovelace),
|
|
348
|
-
priceMem: parseInt(memNum) / parseInt(memDenom),
|
|
349
|
-
priceStep: parseInt(stepsNum) / parseInt(stepsDenom),
|
|
350
|
-
maxTxExMem: BigInt(result.maxExecutionUnitsPerTransaction.memory),
|
|
351
|
-
maxTxExSteps: BigInt(result.maxExecutionUnitsPerTransaction.cpu),
|
|
352
|
-
// NOTE: coinsPerUtxoByte is now called utxoCostPerByte:
|
|
353
|
-
// https://github.com/IntersectMBO/cardano-node/pull/4141
|
|
354
|
-
// Ogmios v6.x calls it minUtxoDepositCoefficient according to the following
|
|
355
|
-
// documentation from its protocol parameters data model:
|
|
356
|
-
// https://github.com/CardanoSolutions/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md#protocol-parameters
|
|
357
|
-
coinsPerUtxoByte: BigInt(result.minUtxoDepositCoefficient),
|
|
358
|
-
collateralPercentage: parseInt(result.collateralPercentage),
|
|
359
|
-
maxCollateralInputs: parseInt(result.maxCollateralInputs),
|
|
360
|
-
costModels
|
|
361
|
-
});
|
|
362
|
-
client.close();
|
|
363
|
-
} catch (e) {
|
|
364
|
-
rej(e);
|
|
365
|
-
}
|
|
366
|
-
},
|
|
367
|
-
{ once: true }
|
|
368
|
-
);
|
|
369
|
-
});
|
|
438
|
+
const data = {
|
|
439
|
+
jsonrpc: "2.0",
|
|
440
|
+
method: "queryLedgerState/protocolParameters",
|
|
441
|
+
params: {},
|
|
442
|
+
id: null
|
|
443
|
+
};
|
|
444
|
+
const schema = JSONRPCSchema(
|
|
445
|
+
ProtocolParametersSchema
|
|
446
|
+
);
|
|
447
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
448
|
+
Effect.flatMap(
|
|
449
|
+
(response) => "error" in response ? kupmiosError(response.error) : Effect.succeed(response.result)
|
|
450
|
+
),
|
|
451
|
+
Effect.timeout(1e4),
|
|
452
|
+
Effect.catchAll(kupmiosError)
|
|
453
|
+
);
|
|
454
|
+
const result = await Effect.runPromise(program);
|
|
455
|
+
return toProtocolParameters(result);
|
|
370
456
|
}
|
|
371
457
|
async getUtxos(addressOrCredential) {
|
|
372
458
|
const isAddress = typeof addressOrCredential === "string";
|
|
373
459
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
460
|
+
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
|
|
461
|
+
const schema = S2.Array(KupoUTxO);
|
|
462
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
463
|
+
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
464
|
+
Effect.timeout(1e4),
|
|
465
|
+
Effect.catchAll(kupmiosError)
|
|
466
|
+
);
|
|
467
|
+
const utxos = await Effect.runPromise(program);
|
|
468
|
+
return utxos;
|
|
378
469
|
}
|
|
379
470
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
380
471
|
const isAddress = typeof addressOrCredential === "string";
|
|
381
472
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
382
473
|
const { policyId, assetName } = fromUnit(unit);
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
474
|
+
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
|
|
475
|
+
const schema = S2.Array(KupoUTxO);
|
|
476
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
477
|
+
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
478
|
+
Effect.timeout(1e4),
|
|
479
|
+
Effect.catchAll(kupmiosError)
|
|
480
|
+
);
|
|
481
|
+
const utxos = await Effect.runPromise(program);
|
|
482
|
+
return utxos;
|
|
387
483
|
}
|
|
388
484
|
async getUtxoByUnit(unit) {
|
|
389
485
|
const { policyId, assetName } = fromUnit(unit);
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
486
|
+
const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
|
|
487
|
+
const schema = S2.Array(KupoUTxO);
|
|
488
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
489
|
+
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
490
|
+
Effect.timeout(1e4),
|
|
491
|
+
Effect.catchAll(kupmiosError)
|
|
492
|
+
);
|
|
493
|
+
const utxos = await Effect.runPromise(program);
|
|
394
494
|
if (utxos.length > 1) {
|
|
395
495
|
throw new Error("Unit needs to be an NFT or only held by one address.");
|
|
396
496
|
}
|
|
397
497
|
return utxos[0];
|
|
398
498
|
}
|
|
399
499
|
async getUtxosByOutRef(outRefs) {
|
|
400
|
-
const queryHashes = [
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
500
|
+
const queryHashes = [
|
|
501
|
+
...new Set(outRefs.map((outRef) => outRef.txHash))
|
|
502
|
+
];
|
|
503
|
+
const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
504
|
+
const schema = S2.Array(KupoUTxO);
|
|
505
|
+
const program = Effect.forEach(
|
|
506
|
+
queryHashes,
|
|
507
|
+
(txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
|
|
508
|
+
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
509
|
+
Effect.timeout(1e4),
|
|
510
|
+
Effect.catchAll(kupmiosError)
|
|
511
|
+
)
|
|
408
512
|
);
|
|
409
|
-
|
|
513
|
+
const utxos = await Effect.runPromise(program);
|
|
514
|
+
return _Array.flatten(utxos).filter(
|
|
410
515
|
(utxo) => outRefs.some(
|
|
411
516
|
(outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
|
|
412
517
|
)
|
|
413
518
|
);
|
|
414
519
|
}
|
|
415
520
|
async getDelegation(rewardAddress) {
|
|
416
|
-
const
|
|
417
|
-
"
|
|
418
|
-
|
|
521
|
+
const data = {
|
|
522
|
+
jsonrpc: "2.0",
|
|
523
|
+
method: "queryLedgerState/rewardAccountSummaries",
|
|
524
|
+
params: { keys: [rewardAddress] },
|
|
525
|
+
id: null
|
|
526
|
+
};
|
|
527
|
+
const schema = JSONRPCSchema(KupoDelegation);
|
|
528
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
529
|
+
Effect.flatMap(
|
|
530
|
+
(response) => "error" in response ? kupmiosError(response.error) : Effect.succeed(response.result)
|
|
531
|
+
),
|
|
532
|
+
Effect.timeout(1e4),
|
|
533
|
+
Effect.catchAll(kupmiosError)
|
|
419
534
|
);
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const delegation = result ? Object.values(result)[0] : {};
|
|
427
|
-
res({
|
|
428
|
-
poolId: delegation?.delegate?.id || null,
|
|
429
|
-
rewards: BigInt(delegation?.rewards?.ada?.lovelace || 0)
|
|
430
|
-
});
|
|
431
|
-
client.close();
|
|
432
|
-
} catch (e) {
|
|
433
|
-
rej(e);
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
{ once: true }
|
|
437
|
-
);
|
|
438
|
-
});
|
|
535
|
+
const result = await Effect.runPromise(program);
|
|
536
|
+
const delegation = result ? Object.values(result)[0] : null;
|
|
537
|
+
return {
|
|
538
|
+
poolId: delegation?.delegate?.id || null,
|
|
539
|
+
rewards: BigInt(delegation?.rewards?.ada?.lovelace || 0)
|
|
540
|
+
};
|
|
439
541
|
}
|
|
440
542
|
async getDatum(datumHash) {
|
|
441
|
-
const
|
|
442
|
-
|
|
543
|
+
const pattern = `${this.kupoUrl}/datums/${datumHash}`;
|
|
544
|
+
const schema = KupoDatumSchema;
|
|
545
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
546
|
+
Effect.timeout(1e4),
|
|
547
|
+
Effect.flatMap(Effect.fromNullable),
|
|
548
|
+
Effect.catchAll(kupmiosError)
|
|
443
549
|
);
|
|
444
|
-
|
|
445
|
-
throw new Error(`No datum found for datum hash: ${datumHash}`);
|
|
446
|
-
}
|
|
550
|
+
const result = await Effect.runPromise(program);
|
|
447
551
|
return result.datum;
|
|
448
552
|
}
|
|
449
|
-
awaitTx(txHash, checkInterval =
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
`${this.kupoUrl}/matches/*@${txHash}?unspent`
|
|
454
|
-
).then((res2) => res2.json());
|
|
455
|
-
if (isConfirmed && isConfirmed.length > 0) {
|
|
456
|
-
clearInterval(confirmation);
|
|
457
|
-
await new Promise((res2) => setTimeout(() => res2(1), 1e3));
|
|
458
|
-
return res(true);
|
|
459
|
-
}
|
|
460
|
-
}, checkInterval);
|
|
553
|
+
async awaitTx(txHash, checkInterval = 2e4) {
|
|
554
|
+
const pattern = `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
555
|
+
const schema = S2.Array(KupoUTxO).annotations({
|
|
556
|
+
identifier: "Array<KupmiosSchema.KupoUTxO>"
|
|
461
557
|
});
|
|
558
|
+
const program = fetchKupoParse(pattern, schema).pipe(
|
|
559
|
+
Effect.repeat({
|
|
560
|
+
schedule: Schedule.exponential(checkInterval),
|
|
561
|
+
until: (result) => result.length > 0
|
|
562
|
+
}),
|
|
563
|
+
Effect.timeout(16e4),
|
|
564
|
+
Effect.catchAll(kupmiosError),
|
|
565
|
+
Effect.as(true)
|
|
566
|
+
);
|
|
567
|
+
return await Effect.runPromise(program);
|
|
462
568
|
}
|
|
463
569
|
async submitTx(cbor) {
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
rej(e);
|
|
478
|
-
}
|
|
479
|
-
},
|
|
480
|
-
{ once: true }
|
|
481
|
-
);
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
kupmiosUtxosToUtxos(utxos) {
|
|
485
|
-
return Promise.all(
|
|
486
|
-
utxos.map(async (utxo) => {
|
|
487
|
-
return {
|
|
488
|
-
txHash: utxo.transaction_id,
|
|
489
|
-
outputIndex: parseInt(utxo.output_index),
|
|
490
|
-
address: utxo.address,
|
|
491
|
-
assets: (() => {
|
|
492
|
-
const a = { lovelace: BigInt(utxo.value.coins) };
|
|
493
|
-
Object.keys(utxo.value.assets).forEach((unit) => {
|
|
494
|
-
a[unit.replace(".", "")] = BigInt(utxo.value.assets[unit]);
|
|
495
|
-
});
|
|
496
|
-
return a;
|
|
497
|
-
})(),
|
|
498
|
-
datumHash: utxo?.datum_type === "hash" ? utxo.datum_hash : null,
|
|
499
|
-
datum: utxo?.datum_type === "inline" ? await this.getDatum(utxo.datum_hash) : null,
|
|
500
|
-
scriptRef: utxo.script_hash && await (async () => {
|
|
501
|
-
const { script, language } = await fetch(
|
|
502
|
-
`${this.kupoUrl}/scripts/${utxo.script_hash}`
|
|
503
|
-
).then((res) => res.json());
|
|
504
|
-
if (language === "native") {
|
|
505
|
-
return { type: "Native", script };
|
|
506
|
-
} else if (language === "plutus:v1") {
|
|
507
|
-
return {
|
|
508
|
-
type: "PlutusV1",
|
|
509
|
-
script: CML.PlutusV1Script.from_cbor_hex(script).to_cbor_hex()
|
|
510
|
-
};
|
|
511
|
-
} else if (language === "plutus:v2") {
|
|
512
|
-
return {
|
|
513
|
-
type: "PlutusV2",
|
|
514
|
-
script: CML.PlutusV2Script.from_cbor_hex(script).to_cbor_hex()
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
})()
|
|
518
|
-
};
|
|
570
|
+
const data = {
|
|
571
|
+
jsonrpc: "2.0",
|
|
572
|
+
method: "submitTransaction",
|
|
573
|
+
params: {
|
|
574
|
+
transaction: { cbor }
|
|
575
|
+
},
|
|
576
|
+
id: null
|
|
577
|
+
};
|
|
578
|
+
const schema = JSONRPCSchema(
|
|
579
|
+
S2.Struct({
|
|
580
|
+
transaction: S2.Struct({
|
|
581
|
+
id: S2.String
|
|
582
|
+
})
|
|
519
583
|
})
|
|
520
584
|
);
|
|
585
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
586
|
+
Effect.flatMap(
|
|
587
|
+
(response) => "error" in response ? Effect.fail(response.error) : Effect.succeed(response)
|
|
588
|
+
),
|
|
589
|
+
Effect.timeout(1e4),
|
|
590
|
+
Effect.catchAll(kupmiosError)
|
|
591
|
+
);
|
|
592
|
+
const { result } = await Effect.runPromise(program);
|
|
593
|
+
return result.transaction.id;
|
|
521
594
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
595
|
+
};
|
|
596
|
+
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* () {
|
|
597
|
+
if (datum_type === "inline" && datum_hash) {
|
|
598
|
+
const pattern = `${kupoUrl}/datums/${datum_hash}`;
|
|
599
|
+
const schema = KupoDatumSchema;
|
|
600
|
+
return yield* fetchKupoParse(pattern, schema).pipe(
|
|
601
|
+
Effect.flatMap(Effect.fromNullable),
|
|
602
|
+
Effect.map((result) => result.datum),
|
|
603
|
+
Effect.timeout(1e4)
|
|
604
|
+
);
|
|
605
|
+
} else return null;
|
|
606
|
+
});
|
|
607
|
+
var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
|
|
608
|
+
if (script_hash) {
|
|
609
|
+
const pattern = `${kupoUrl}/scripts/${script_hash}`;
|
|
610
|
+
const schema = KupoScriptSchema;
|
|
611
|
+
return yield* pipe(
|
|
612
|
+
fetchKupoParse(pattern, schema),
|
|
613
|
+
Effect.flatMap(Effect.fromNullable),
|
|
614
|
+
Effect.timeout(1e4),
|
|
615
|
+
Effect.map(({ language, script }) => {
|
|
616
|
+
switch (language) {
|
|
617
|
+
case "native":
|
|
618
|
+
return { type: "Native", script };
|
|
619
|
+
case "plutus:v1":
|
|
620
|
+
return { type: "PlutusV1", script };
|
|
621
|
+
case "plutus:v2":
|
|
622
|
+
return { type: "PlutusV2", script };
|
|
623
|
+
}
|
|
533
624
|
})
|
|
534
625
|
);
|
|
535
|
-
|
|
626
|
+
} else return null;
|
|
627
|
+
});
|
|
628
|
+
var toAssets = (value) => {
|
|
629
|
+
const assets = { lovelace: BigInt(value.coins) };
|
|
630
|
+
for (const unit of Object.keys(value.assets)) {
|
|
631
|
+
assets[unit.replace(".", "")] = BigInt(value.assets[unit]);
|
|
536
632
|
}
|
|
633
|
+
return assets;
|
|
634
|
+
};
|
|
635
|
+
var toProtocolParameters = (result) => {
|
|
636
|
+
return {
|
|
637
|
+
minFeeA: result.minFeeCoefficient,
|
|
638
|
+
minFeeB: result.minFeeConstant.ada.lovelace,
|
|
639
|
+
maxTxSize: result.maxTransactionSize.bytes,
|
|
640
|
+
maxValSize: result.maxValueSize.bytes,
|
|
641
|
+
keyDeposit: BigInt(result.stakeCredentialDeposit.ada.lovelace),
|
|
642
|
+
poolDeposit: BigInt(result.stakePoolDeposit.ada.lovelace),
|
|
643
|
+
priceMem: result.scriptExecutionPrices.memory[0] / result.scriptExecutionPrices.memory[1],
|
|
644
|
+
priceStep: result.scriptExecutionPrices.cpu[0] / result.scriptExecutionPrices.cpu[1],
|
|
645
|
+
maxTxExMem: BigInt(result.maxExecutionUnitsPerTransaction.memory),
|
|
646
|
+
maxTxExSteps: BigInt(result.maxExecutionUnitsPerTransaction.cpu),
|
|
647
|
+
// NOTE: coinsPerUtxoByte is now called utxoCostPerByte:
|
|
648
|
+
// https://github.com/IntersectMBO/cardano-node/pull/4141
|
|
649
|
+
// Ogmios v6.x calls it minUtxoDepositCoefficient according to the following
|
|
650
|
+
// documentation from its protocol parameters data model:
|
|
651
|
+
// https://github.com/CardanoSolutions/ogmios/blob/master/architectural-decisions/accepted/017-api-version-6-major-rewrite.md#protocol-parameters
|
|
652
|
+
coinsPerUtxoByte: BigInt(result.minUtxoDepositCoefficient),
|
|
653
|
+
collateralPercentage: result.collateralPercentage,
|
|
654
|
+
maxCollateralInputs: result.maxCollateralInputs,
|
|
655
|
+
costModels: {
|
|
656
|
+
PlutusV1: Object.fromEntries(
|
|
657
|
+
result.plutusCostModels["plutus:v1"].map((value, index) => [
|
|
658
|
+
index.toString(),
|
|
659
|
+
value
|
|
660
|
+
])
|
|
661
|
+
),
|
|
662
|
+
PlutusV2: Object.fromEntries(
|
|
663
|
+
result.plutusCostModels["plutus:v2"].map((value, index) => [
|
|
664
|
+
index.toString(),
|
|
665
|
+
value
|
|
666
|
+
])
|
|
667
|
+
)
|
|
668
|
+
}
|
|
669
|
+
};
|
|
537
670
|
};
|
|
671
|
+
var fetchOgmiosParse = (url, data, schema) => pipe(
|
|
672
|
+
HttpClientRequest.post(url),
|
|
673
|
+
HttpClientRequest.jsonBody(data),
|
|
674
|
+
Effect.flatMap(HttpClient.fetch),
|
|
675
|
+
HttpClientResponse.json,
|
|
676
|
+
Effect.flatMap(S2.decodeUnknown(schema))
|
|
677
|
+
// Effect.catchTag("ParseError", (e) =>
|
|
678
|
+
// Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
|
|
679
|
+
// ),
|
|
680
|
+
// Effect.scoped
|
|
681
|
+
);
|
|
682
|
+
var fetchKupoParse = (url, schema) => pipe(
|
|
683
|
+
HttpClientRequest.get(url),
|
|
684
|
+
HttpClient.fetchOk,
|
|
685
|
+
HttpClientResponse.json,
|
|
686
|
+
Effect.flatMap(S2.decodeUnknown(schema))
|
|
687
|
+
// Effect.catchTag("ParseError", (e) =>
|
|
688
|
+
// Effect.fail(ArrayFormatter.formatIssueSync(e.issue)),
|
|
689
|
+
// ),
|
|
690
|
+
// Effect.scoped
|
|
691
|
+
);
|
|
692
|
+
var kupmiosUtxosToUtxos = (kupoURL, utxos) => Effect.forEach(
|
|
693
|
+
utxos,
|
|
694
|
+
(utxo) => {
|
|
695
|
+
return pipe(
|
|
696
|
+
Effect.all([
|
|
697
|
+
getDatumEffect(kupoURL, utxo.datum_type, utxo.datum_hash),
|
|
698
|
+
getScriptEffect(kupoURL, utxo.script_hash)
|
|
699
|
+
]),
|
|
700
|
+
Effect.map(
|
|
701
|
+
([datum, script]) => ({
|
|
702
|
+
txHash: utxo.transaction_id,
|
|
703
|
+
outputIndex: utxo.output_index,
|
|
704
|
+
address: utxo.address,
|
|
705
|
+
assets: toAssets(utxo.value),
|
|
706
|
+
datumHash: utxo.datum_type === "hash" ? utxo.datum_hash : null,
|
|
707
|
+
datum,
|
|
708
|
+
scriptRef: script
|
|
709
|
+
})
|
|
710
|
+
)
|
|
711
|
+
);
|
|
712
|
+
},
|
|
713
|
+
{ concurrency: "unbounded" }
|
|
714
|
+
);
|
|
538
715
|
|
|
539
716
|
// src/maestro.ts
|
|
540
717
|
import { applyDoubleCborEncoding as applyDoubleCborEncoding2 } from "@lucid-evolution/utils";
|
|
@@ -800,194 +977,194 @@ var Maestro = class {
|
|
|
800
977
|
var lucid2 = package_default.version;
|
|
801
978
|
|
|
802
979
|
// src/koios/koios.ts
|
|
803
|
-
import * as
|
|
980
|
+
import * as S4 from "@effect/schema/Schema";
|
|
804
981
|
import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
|
|
805
982
|
import { applyDoubleCborEncoding as applyDoubleCborEncoding3, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
|
|
806
983
|
|
|
807
984
|
// src/koios/schema.ts
|
|
808
|
-
import * as
|
|
809
|
-
var
|
|
810
|
-
epoch_no:
|
|
811
|
-
min_fee_a:
|
|
812
|
-
min_fee_b:
|
|
813
|
-
max_block_size:
|
|
814
|
-
max_tx_size:
|
|
815
|
-
max_bh_size:
|
|
816
|
-
key_deposit:
|
|
817
|
-
pool_deposit:
|
|
818
|
-
max_epoch:
|
|
819
|
-
optimal_pool_count:
|
|
820
|
-
influence:
|
|
821
|
-
monetary_expand_rate:
|
|
822
|
-
treasury_growth_rate:
|
|
823
|
-
decentralisation:
|
|
824
|
-
extra_entropy:
|
|
825
|
-
protocol_major:
|
|
826
|
-
protocol_minor:
|
|
827
|
-
min_utxo_value:
|
|
828
|
-
min_pool_cost:
|
|
829
|
-
nonce:
|
|
830
|
-
block_hash:
|
|
831
|
-
cost_models:
|
|
832
|
-
PlutusV1:
|
|
833
|
-
PlutusV2:
|
|
985
|
+
import * as S3 from "@effect/schema/Schema";
|
|
986
|
+
var ProtocolParametersSchema2 = S3.Struct({
|
|
987
|
+
epoch_no: S3.Number,
|
|
988
|
+
min_fee_a: S3.Number,
|
|
989
|
+
min_fee_b: S3.Number,
|
|
990
|
+
max_block_size: S3.Number,
|
|
991
|
+
max_tx_size: S3.Number,
|
|
992
|
+
max_bh_size: S3.Number,
|
|
993
|
+
key_deposit: S3.BigInt,
|
|
994
|
+
pool_deposit: S3.BigInt,
|
|
995
|
+
max_epoch: S3.Number,
|
|
996
|
+
optimal_pool_count: S3.Number,
|
|
997
|
+
influence: S3.Number,
|
|
998
|
+
monetary_expand_rate: S3.Number,
|
|
999
|
+
treasury_growth_rate: S3.Number,
|
|
1000
|
+
decentralisation: S3.Number,
|
|
1001
|
+
extra_entropy: S3.NullOr(S3.String),
|
|
1002
|
+
protocol_major: S3.Number,
|
|
1003
|
+
protocol_minor: S3.Number,
|
|
1004
|
+
min_utxo_value: S3.String,
|
|
1005
|
+
min_pool_cost: S3.String,
|
|
1006
|
+
nonce: S3.String,
|
|
1007
|
+
block_hash: S3.NullOr(S3.String),
|
|
1008
|
+
cost_models: S3.Struct({
|
|
1009
|
+
PlutusV1: S3.Array(S3.Number),
|
|
1010
|
+
PlutusV2: S3.Array(S3.Number)
|
|
834
1011
|
}),
|
|
835
|
-
price_mem:
|
|
836
|
-
price_step:
|
|
837
|
-
max_tx_ex_mem:
|
|
838
|
-
max_tx_ex_steps:
|
|
839
|
-
max_block_ex_mem:
|
|
840
|
-
max_block_ex_steps:
|
|
841
|
-
max_val_size:
|
|
842
|
-
collateral_percent:
|
|
843
|
-
max_collateral_inputs:
|
|
844
|
-
coins_per_utxo_size:
|
|
1012
|
+
price_mem: S3.Number,
|
|
1013
|
+
price_step: S3.Number,
|
|
1014
|
+
max_tx_ex_mem: S3.BigIntFromNumber,
|
|
1015
|
+
max_tx_ex_steps: S3.BigIntFromNumber,
|
|
1016
|
+
max_block_ex_mem: S3.Number,
|
|
1017
|
+
max_block_ex_steps: S3.Number,
|
|
1018
|
+
max_val_size: S3.Number,
|
|
1019
|
+
collateral_percent: S3.Number,
|
|
1020
|
+
max_collateral_inputs: S3.Number,
|
|
1021
|
+
coins_per_utxo_size: S3.BigInt
|
|
845
1022
|
});
|
|
846
|
-
var KoiosAssetSchema =
|
|
847
|
-
policy_id:
|
|
848
|
-
asset_name:
|
|
849
|
-
fingerprint:
|
|
850
|
-
decimals:
|
|
851
|
-
quantity:
|
|
1023
|
+
var KoiosAssetSchema = S3.Struct({
|
|
1024
|
+
policy_id: S3.String,
|
|
1025
|
+
asset_name: S3.NullOr(S3.String),
|
|
1026
|
+
fingerprint: S3.String,
|
|
1027
|
+
decimals: S3.Number,
|
|
1028
|
+
quantity: S3.String
|
|
852
1029
|
});
|
|
853
|
-
var KoiosUTxOSchema =
|
|
854
|
-
tx_hash:
|
|
855
|
-
tx_index:
|
|
856
|
-
block_height:
|
|
857
|
-
value:
|
|
858
|
-
datum_hash:
|
|
859
|
-
inline_datum:
|
|
860
|
-
|
|
861
|
-
bytes:
|
|
862
|
-
value:
|
|
1030
|
+
var KoiosUTxOSchema = S3.Struct({
|
|
1031
|
+
tx_hash: S3.String,
|
|
1032
|
+
tx_index: S3.Number,
|
|
1033
|
+
block_height: S3.NullOr(S3.Number),
|
|
1034
|
+
value: S3.String,
|
|
1035
|
+
datum_hash: S3.NullOr(S3.String),
|
|
1036
|
+
inline_datum: S3.NullOr(
|
|
1037
|
+
S3.Struct({
|
|
1038
|
+
bytes: S3.String,
|
|
1039
|
+
value: S3.Object
|
|
863
1040
|
})
|
|
864
1041
|
),
|
|
865
|
-
reference_script:
|
|
866
|
-
|
|
867
|
-
hash:
|
|
868
|
-
size:
|
|
869
|
-
type:
|
|
870
|
-
bytes:
|
|
871
|
-
value:
|
|
1042
|
+
reference_script: S3.NullOr(
|
|
1043
|
+
S3.Struct({
|
|
1044
|
+
hash: S3.String,
|
|
1045
|
+
size: S3.Number,
|
|
1046
|
+
type: S3.String,
|
|
1047
|
+
bytes: S3.String,
|
|
1048
|
+
value: S3.NullOr(S3.Object)
|
|
872
1049
|
})
|
|
873
1050
|
),
|
|
874
|
-
asset_list:
|
|
1051
|
+
asset_list: S3.NullOr(S3.Array(KoiosAssetSchema))
|
|
875
1052
|
});
|
|
876
|
-
var KoiosAddressInfoSchema =
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
address:
|
|
880
|
-
balance:
|
|
881
|
-
stake_address:
|
|
882
|
-
script_address:
|
|
883
|
-
utxo_set:
|
|
1053
|
+
var KoiosAddressInfoSchema = S3.Array(
|
|
1054
|
+
S3.NullishOr(
|
|
1055
|
+
S3.Struct({
|
|
1056
|
+
address: S3.String,
|
|
1057
|
+
balance: S3.String,
|
|
1058
|
+
stake_address: S3.NullOr(S3.String),
|
|
1059
|
+
script_address: S3.Boolean,
|
|
1060
|
+
utxo_set: S3.Array(KoiosUTxOSchema)
|
|
884
1061
|
})
|
|
885
1062
|
)
|
|
886
1063
|
);
|
|
887
|
-
var KoiosInputOutputSchema =
|
|
888
|
-
payment_addr:
|
|
889
|
-
bech32:
|
|
890
|
-
cred:
|
|
1064
|
+
var KoiosInputOutputSchema = S3.Struct({
|
|
1065
|
+
payment_addr: S3.Struct({
|
|
1066
|
+
bech32: S3.String,
|
|
1067
|
+
cred: S3.String
|
|
891
1068
|
}),
|
|
892
|
-
stake_addr:
|
|
893
|
-
tx_hash:
|
|
894
|
-
tx_index:
|
|
895
|
-
value:
|
|
896
|
-
datum_hash:
|
|
897
|
-
inline_datum:
|
|
898
|
-
|
|
899
|
-
bytes:
|
|
900
|
-
value:
|
|
1069
|
+
stake_addr: S3.NullOr(S3.String),
|
|
1070
|
+
tx_hash: S3.String,
|
|
1071
|
+
tx_index: S3.Number,
|
|
1072
|
+
value: S3.String,
|
|
1073
|
+
datum_hash: S3.NullOr(S3.String),
|
|
1074
|
+
inline_datum: S3.NullOr(
|
|
1075
|
+
S3.Struct({
|
|
1076
|
+
bytes: S3.String,
|
|
1077
|
+
value: S3.Object
|
|
901
1078
|
})
|
|
902
1079
|
),
|
|
903
|
-
reference_script:
|
|
904
|
-
|
|
905
|
-
hash:
|
|
906
|
-
size:
|
|
907
|
-
type:
|
|
908
|
-
bytes:
|
|
909
|
-
value:
|
|
1080
|
+
reference_script: S3.NullOr(
|
|
1081
|
+
S3.Struct({
|
|
1082
|
+
hash: S3.String,
|
|
1083
|
+
size: S3.Number,
|
|
1084
|
+
type: S3.String,
|
|
1085
|
+
bytes: S3.String,
|
|
1086
|
+
value: S3.NullOr(S3.Object)
|
|
910
1087
|
})
|
|
911
1088
|
),
|
|
912
|
-
asset_list:
|
|
1089
|
+
asset_list: S3.Union(S3.Array(KoiosAssetSchema), S3.String)
|
|
913
1090
|
});
|
|
914
|
-
var KoiosTxInfoSchema =
|
|
915
|
-
tx_hash:
|
|
916
|
-
block_hash:
|
|
917
|
-
block_height:
|
|
918
|
-
epoch_no:
|
|
919
|
-
epoch_slot:
|
|
920
|
-
absolute_slot:
|
|
921
|
-
tx_timestamp:
|
|
922
|
-
tx_block_index:
|
|
923
|
-
tx_size:
|
|
924
|
-
total_output:
|
|
925
|
-
fee:
|
|
926
|
-
deposit:
|
|
927
|
-
invalid_before:
|
|
928
|
-
invalid_after:
|
|
929
|
-
collateral_inputs:
|
|
930
|
-
collateral_output:
|
|
931
|
-
reference_inputs:
|
|
932
|
-
inputs:
|
|
933
|
-
outputs:
|
|
934
|
-
withdrawals:
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
amount:
|
|
938
|
-
stake_addr:
|
|
1091
|
+
var KoiosTxInfoSchema = S3.Struct({
|
|
1092
|
+
tx_hash: S3.String,
|
|
1093
|
+
block_hash: S3.String,
|
|
1094
|
+
block_height: S3.Number,
|
|
1095
|
+
epoch_no: S3.Number,
|
|
1096
|
+
epoch_slot: S3.Number,
|
|
1097
|
+
absolute_slot: S3.Number,
|
|
1098
|
+
tx_timestamp: S3.Number,
|
|
1099
|
+
tx_block_index: S3.Number,
|
|
1100
|
+
tx_size: S3.Number,
|
|
1101
|
+
total_output: S3.String,
|
|
1102
|
+
fee: S3.String,
|
|
1103
|
+
deposit: S3.String,
|
|
1104
|
+
invalid_before: S3.NullOr(S3.String),
|
|
1105
|
+
invalid_after: S3.NullOr(S3.String),
|
|
1106
|
+
collateral_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
|
|
1107
|
+
collateral_output: S3.NullOr(KoiosInputOutputSchema),
|
|
1108
|
+
reference_inputs: S3.NullOr(S3.Array(KoiosInputOutputSchema)),
|
|
1109
|
+
inputs: S3.Array(KoiosInputOutputSchema),
|
|
1110
|
+
outputs: S3.Array(KoiosInputOutputSchema),
|
|
1111
|
+
withdrawals: S3.NullOr(
|
|
1112
|
+
S3.Array(
|
|
1113
|
+
S3.Struct({
|
|
1114
|
+
amount: S3.String,
|
|
1115
|
+
stake_addr: S3.String
|
|
939
1116
|
})
|
|
940
1117
|
)
|
|
941
1118
|
),
|
|
942
|
-
assets_minted:
|
|
943
|
-
metadata:
|
|
944
|
-
certificates:
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
index:
|
|
948
|
-
type:
|
|
949
|
-
info:
|
|
1119
|
+
assets_minted: S3.NullOr(S3.Array(KoiosAssetSchema)),
|
|
1120
|
+
metadata: S3.NullOr(S3.Object),
|
|
1121
|
+
certificates: S3.NullOr(
|
|
1122
|
+
S3.Array(
|
|
1123
|
+
S3.Struct({
|
|
1124
|
+
index: S3.Number,
|
|
1125
|
+
type: S3.String,
|
|
1126
|
+
info: S3.NullOr(S3.Object)
|
|
950
1127
|
})
|
|
951
1128
|
)
|
|
952
1129
|
),
|
|
953
|
-
native_scripts:
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
script_hash:
|
|
957
|
-
script_json:
|
|
1130
|
+
native_scripts: S3.NullOr(
|
|
1131
|
+
S3.Array(
|
|
1132
|
+
S3.Struct({
|
|
1133
|
+
script_hash: S3.String,
|
|
1134
|
+
script_json: S3.Object
|
|
958
1135
|
})
|
|
959
1136
|
)
|
|
960
1137
|
),
|
|
961
|
-
plutus_contracts:
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
address:
|
|
965
|
-
spends_input:
|
|
966
|
-
|
|
967
|
-
tx_hash:
|
|
968
|
-
tx_index:
|
|
1138
|
+
plutus_contracts: S3.NullOr(
|
|
1139
|
+
S3.Array(
|
|
1140
|
+
S3.Struct({
|
|
1141
|
+
address: S3.String,
|
|
1142
|
+
spends_input: S3.NullOr(
|
|
1143
|
+
S3.Struct({
|
|
1144
|
+
tx_hash: S3.String,
|
|
1145
|
+
tx_index: S3.Number
|
|
969
1146
|
})
|
|
970
1147
|
),
|
|
971
|
-
script_hash:
|
|
972
|
-
bytecode:
|
|
973
|
-
size:
|
|
974
|
-
valid_contract:
|
|
975
|
-
input:
|
|
976
|
-
redeemer:
|
|
977
|
-
purpose:
|
|
978
|
-
fee:
|
|
979
|
-
unit:
|
|
980
|
-
steps:
|
|
981
|
-
mem:
|
|
1148
|
+
script_hash: S3.String,
|
|
1149
|
+
bytecode: S3.String,
|
|
1150
|
+
size: S3.Number,
|
|
1151
|
+
valid_contract: S3.Boolean,
|
|
1152
|
+
input: S3.Struct({
|
|
1153
|
+
redeemer: S3.Struct({
|
|
1154
|
+
purpose: S3.Literal("spend", "mint", "cert", "reward"),
|
|
1155
|
+
fee: S3.String,
|
|
1156
|
+
unit: S3.Struct({
|
|
1157
|
+
steps: S3.String,
|
|
1158
|
+
mem: S3.String
|
|
982
1159
|
}),
|
|
983
|
-
datum:
|
|
984
|
-
hash:
|
|
985
|
-
value:
|
|
1160
|
+
datum: S3.Struct({
|
|
1161
|
+
hash: S3.NullOr(S3.String),
|
|
1162
|
+
value: S3.NullOr(S3.Object)
|
|
986
1163
|
})
|
|
987
1164
|
}),
|
|
988
|
-
datum:
|
|
989
|
-
hash:
|
|
990
|
-
value:
|
|
1165
|
+
datum: S3.Struct({
|
|
1166
|
+
hash: S3.NullOr(S3.String),
|
|
1167
|
+
value: S3.NullOr(S3.Object)
|
|
991
1168
|
})
|
|
992
1169
|
})
|
|
993
1170
|
})
|
|
@@ -996,8 +1173,45 @@ var KoiosTxInfoSchema = S.Struct({
|
|
|
996
1173
|
});
|
|
997
1174
|
|
|
998
1175
|
// src/koios/koios.ts
|
|
999
|
-
import { Effect, pipe, Schedule } from "effect";
|
|
1176
|
+
import { Effect as Effect3, pipe as pipe3, Schedule as Schedule2 } from "effect";
|
|
1000
1177
|
import { ArrayFormatter } from "@effect/schema";
|
|
1178
|
+
|
|
1179
|
+
// src/fetch.ts
|
|
1180
|
+
var fetch_exports = {};
|
|
1181
|
+
__export(fetch_exports, {
|
|
1182
|
+
FetchError: () => FetchError,
|
|
1183
|
+
JsonError: () => JsonError,
|
|
1184
|
+
ResponseError: () => ResponseError,
|
|
1185
|
+
fetchEffect: () => fetchEffect
|
|
1186
|
+
});
|
|
1187
|
+
import { Data as Data2, Effect as Effect2, pipe as pipe2 } from "effect";
|
|
1188
|
+
var FetchError = class extends Data2.TaggedError("FetchError") {
|
|
1189
|
+
};
|
|
1190
|
+
var ResponseError = class extends Data2.TaggedError("ResponseError") {
|
|
1191
|
+
};
|
|
1192
|
+
var JsonError = class extends Data2.TaggedError("JsonError") {
|
|
1193
|
+
};
|
|
1194
|
+
var fetchEffect = (input, requestInit) => pipe2(
|
|
1195
|
+
Effect2.tryPromise({
|
|
1196
|
+
try: () => fetch(input, requestInit),
|
|
1197
|
+
catch: (error) => new FetchError({
|
|
1198
|
+
message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
|
|
1199
|
+
})
|
|
1200
|
+
}),
|
|
1201
|
+
Effect2.flatMap(
|
|
1202
|
+
(response) => !response.ok ? new ResponseError({
|
|
1203
|
+
message: `${response.status} ${response.statusText}`
|
|
1204
|
+
}) : Effect2.succeed(response)
|
|
1205
|
+
),
|
|
1206
|
+
Effect2.flatMap(
|
|
1207
|
+
(response) => Effect2.tryPromise({
|
|
1208
|
+
try: () => response.json(),
|
|
1209
|
+
catch: (error) => new JsonError({ message: String(error) })
|
|
1210
|
+
})
|
|
1211
|
+
)
|
|
1212
|
+
);
|
|
1213
|
+
|
|
1214
|
+
// src/koios/koios.ts
|
|
1001
1215
|
var Koios = class {
|
|
1002
1216
|
baseUrl;
|
|
1003
1217
|
constructor(baseUrl) {
|
|
@@ -1007,7 +1221,7 @@ var Koios = class {
|
|
|
1007
1221
|
const result = await fetch(`${this.baseUrl}/epoch_params?limit=1`).then(
|
|
1008
1222
|
(res) => res.json()
|
|
1009
1223
|
);
|
|
1010
|
-
const param =
|
|
1224
|
+
const param = S4.decodeUnknownSync(ProtocolParametersSchema2)(result[0]);
|
|
1011
1225
|
return {
|
|
1012
1226
|
minFeeA: param.min_fee_a,
|
|
1013
1227
|
minFeeB: param.min_fee_b,
|
|
@@ -1051,7 +1265,7 @@ var Koios = class {
|
|
|
1051
1265
|
method: "POST",
|
|
1052
1266
|
body: JSON.stringify(body)
|
|
1053
1267
|
}).then((res) => res.json());
|
|
1054
|
-
const parsedResult =
|
|
1268
|
+
const parsedResult = S4.decodeUnknownSync(KoiosAddressInfoSchema)(
|
|
1055
1269
|
result
|
|
1056
1270
|
)[0];
|
|
1057
1271
|
return parsedResult ? parsedResult.utxo_set.map(
|
|
@@ -1114,7 +1328,7 @@ var Koios = class {
|
|
|
1114
1328
|
method: "POST",
|
|
1115
1329
|
body: JSON.stringify(body)
|
|
1116
1330
|
}).then((res) => res.json());
|
|
1117
|
-
const parsedResult =
|
|
1331
|
+
const parsedResult = S4.decodeUnknownSync(S4.Array(KoiosTxInfoSchema))(
|
|
1118
1332
|
result
|
|
1119
1333
|
)[0];
|
|
1120
1334
|
if (parsedResult) {
|
|
@@ -1177,7 +1391,7 @@ var Koios = class {
|
|
|
1177
1391
|
throw new Error("No Datum Found by Datum Hash");
|
|
1178
1392
|
}
|
|
1179
1393
|
}
|
|
1180
|
-
awaitTx(txHash, checkInterval = 2e4) {
|
|
1394
|
+
async awaitTx(txHash, checkInterval = 2e4) {
|
|
1181
1395
|
const body = {
|
|
1182
1396
|
_tx_hashes: [txHash]
|
|
1183
1397
|
};
|
|
@@ -1189,36 +1403,24 @@ var Koios = class {
|
|
|
1189
1403
|
method: "POST",
|
|
1190
1404
|
body: JSON.stringify(body)
|
|
1191
1405
|
};
|
|
1192
|
-
const program =
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
catch: (error) => new Error(String(error))
|
|
1197
|
-
}),
|
|
1198
|
-
Effect.flatMap(
|
|
1199
|
-
(response) => !response.ok ? Effect.fail(new Error(`${response.status} ${response.statusText}`)) : Effect.succeed(response)
|
|
1406
|
+
const program = pipe3(
|
|
1407
|
+
fetchEffect(`${this.baseUrl}/tx_info`, request),
|
|
1408
|
+
Effect3.flatMap(
|
|
1409
|
+
(json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
|
|
1200
1410
|
),
|
|
1201
|
-
|
|
1202
|
-
(response) => Effect.tryPromise({
|
|
1203
|
-
try: () => response.json(),
|
|
1204
|
-
catch: (error) => new Error(String(error))
|
|
1205
|
-
})
|
|
1206
|
-
),
|
|
1207
|
-
Effect.flatMap(
|
|
1208
|
-
(json) => S2.decodeUnknown(S2.Array(KoiosTxInfoSchema), { errors: "first" })(json)
|
|
1209
|
-
),
|
|
1210
|
-
Effect.catchTag(
|
|
1411
|
+
Effect3.catchTag(
|
|
1211
1412
|
"ParseError",
|
|
1212
|
-
(e) =>
|
|
1413
|
+
(e) => Effect3.fail(ArrayFormatter.formatErrorSync(e))
|
|
1213
1414
|
),
|
|
1214
|
-
|
|
1215
|
-
schedule:
|
|
1415
|
+
Effect3.repeat({
|
|
1416
|
+
schedule: Schedule2.exponential(checkInterval),
|
|
1216
1417
|
until: (result) => result.length > 0
|
|
1217
1418
|
}),
|
|
1218
|
-
|
|
1219
|
-
|
|
1419
|
+
Effect3.timeout(16e4),
|
|
1420
|
+
Effect3.orDie,
|
|
1421
|
+
Effect3.as(true)
|
|
1220
1422
|
);
|
|
1221
|
-
return
|
|
1423
|
+
return Effect3.runPromise(program);
|
|
1222
1424
|
}
|
|
1223
1425
|
async submitTx(tx) {
|
|
1224
1426
|
const result = await fetch(`${this.baseUrl}/submittx`, {
|
|
@@ -1229,8 +1431,8 @@ var Koios = class {
|
|
|
1229
1431
|
method: "POST",
|
|
1230
1432
|
body: fromHex3(tx)
|
|
1231
1433
|
}).then((res) => res.json());
|
|
1232
|
-
const TxHashSchema =
|
|
1233
|
-
const isTxHash =
|
|
1434
|
+
const TxHashSchema = S4.String;
|
|
1435
|
+
const isTxHash = S4.is(TxHashSchema);
|
|
1234
1436
|
if (!isTxHash(result)) {
|
|
1235
1437
|
throw new Error(JSON.stringify(result));
|
|
1236
1438
|
}
|
|
@@ -1263,8 +1465,10 @@ var toUTxO = (koiosUTxO, address) => ({
|
|
|
1263
1465
|
});
|
|
1264
1466
|
export {
|
|
1265
1467
|
Blockfrost,
|
|
1468
|
+
fetch_exports as FetchProvider,
|
|
1266
1469
|
Koios,
|
|
1267
1470
|
Kupmios,
|
|
1471
|
+
KupmiosError,
|
|
1268
1472
|
Maestro,
|
|
1269
1473
|
datumJsonToCbor
|
|
1270
1474
|
};
|