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