@lucid-evolution/provider 0.1.39 → 0.1.41
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 +256 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +257 -2
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ var import_utils = require("@lucid-evolution/utils");
|
|
|
52
52
|
// package.json
|
|
53
53
|
var package_default = {
|
|
54
54
|
name: "@lucid-evolution/provider",
|
|
55
|
-
version: "0.1.
|
|
55
|
+
version: "0.1.41",
|
|
56
56
|
description: "",
|
|
57
57
|
main: "./dist/index.js",
|
|
58
58
|
types: "./dist/index.d.ts",
|
|
@@ -316,6 +316,56 @@ var Blockfrost = class {
|
|
|
316
316
|
}))
|
|
317
317
|
);
|
|
318
318
|
}
|
|
319
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
320
|
+
const additionalUTxOSet = (additionalUTxOs || []).map((utxo) => [
|
|
321
|
+
{ txId: utxo.txHash, index: utxo.outputIndex },
|
|
322
|
+
{
|
|
323
|
+
address: utxo.address,
|
|
324
|
+
value: { coins: utxo.assets.lovelace, assets: utxo.assets.restAssets },
|
|
325
|
+
datum_hash: utxo.datumHash,
|
|
326
|
+
datum: utxo.datum,
|
|
327
|
+
script: utxo.scriptRef
|
|
328
|
+
}
|
|
329
|
+
]);
|
|
330
|
+
const payload = {
|
|
331
|
+
cbor: tx,
|
|
332
|
+
additionalUTxOSet
|
|
333
|
+
};
|
|
334
|
+
const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
|
|
335
|
+
method: "POST",
|
|
336
|
+
headers: {
|
|
337
|
+
"Content-Type": "application/json",
|
|
338
|
+
project_id: this.projectId,
|
|
339
|
+
lucid
|
|
340
|
+
},
|
|
341
|
+
body: JSON.stringify(
|
|
342
|
+
payload,
|
|
343
|
+
(_, value) => typeof value === "bigint" ? value.toString() : value
|
|
344
|
+
)
|
|
345
|
+
}).then((res2) => res2.json());
|
|
346
|
+
if (!res || res.error) {
|
|
347
|
+
const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}`;
|
|
348
|
+
throw new Error(message);
|
|
349
|
+
}
|
|
350
|
+
const blockfrostRedeemer = res;
|
|
351
|
+
if (!("EvaluationResult" in blockfrostRedeemer.result)) {
|
|
352
|
+
throw new Error(
|
|
353
|
+
`EvaluateTransaction fails: ${JSON.stringify(blockfrostRedeemer.result)}`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
const evalRedeemers = [];
|
|
357
|
+
Object.entries(blockfrostRedeemer.result.EvaluationResult).forEach(
|
|
358
|
+
([redeemerPointer, data]) => {
|
|
359
|
+
const [pTag, pIndex] = redeemerPointer.split(":");
|
|
360
|
+
evalRedeemers.push({
|
|
361
|
+
redeemer_tag: pTag,
|
|
362
|
+
redeemer_index: Number(pIndex),
|
|
363
|
+
ex_units: { mem: Number(data.memory), steps: Number(data.steps) }
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
return evalRedeemers;
|
|
368
|
+
}
|
|
319
369
|
};
|
|
320
370
|
function datumJsonToCbor(json) {
|
|
321
371
|
const convert = (json2) => {
|
|
@@ -627,6 +677,66 @@ var Kupmios = class {
|
|
|
627
677
|
const { result } = await import_effect.Effect.runPromise(program);
|
|
628
678
|
return result.transaction.id;
|
|
629
679
|
}
|
|
680
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
681
|
+
const utxos = (additionalUTxOs || []).map((utxo) => {
|
|
682
|
+
const script = utxo.scriptRef ? {
|
|
683
|
+
language: utxo.scriptRef.type,
|
|
684
|
+
cbor: utxo.scriptRef.script
|
|
685
|
+
} : void 0;
|
|
686
|
+
return [
|
|
687
|
+
{
|
|
688
|
+
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
address: utxo.address,
|
|
692
|
+
value: {
|
|
693
|
+
coins: utxo.assets.lovelace,
|
|
694
|
+
assets: utxo.assets.restAssets
|
|
695
|
+
},
|
|
696
|
+
datumHash: utxo.datumHash,
|
|
697
|
+
datum: utxo.datum,
|
|
698
|
+
script
|
|
699
|
+
}
|
|
700
|
+
];
|
|
701
|
+
});
|
|
702
|
+
const data = {
|
|
703
|
+
jsonrpc: "2.0",
|
|
704
|
+
method: "evaluateTransaction",
|
|
705
|
+
params: { transaction: { cbor: tx }, additionalUTxO: utxos },
|
|
706
|
+
id: null
|
|
707
|
+
};
|
|
708
|
+
const schema = JSONRPCSchema(
|
|
709
|
+
S2.Array(
|
|
710
|
+
S2.Struct({
|
|
711
|
+
validator: S2.Struct({
|
|
712
|
+
purpose: S2.String,
|
|
713
|
+
index: S2.Int
|
|
714
|
+
}),
|
|
715
|
+
budget: S2.Struct({
|
|
716
|
+
memory: S2.Int,
|
|
717
|
+
cpu: S2.Int
|
|
718
|
+
})
|
|
719
|
+
})
|
|
720
|
+
)
|
|
721
|
+
);
|
|
722
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
723
|
+
import_effect.Effect.flatMap(
|
|
724
|
+
(response) => "error" in response ? kupmiosError(response.error) : import_effect.Effect.succeed(response.result)
|
|
725
|
+
),
|
|
726
|
+
import_effect.Effect.timeout(1e4),
|
|
727
|
+
import_effect.Effect.catchAll(kupmiosError)
|
|
728
|
+
);
|
|
729
|
+
const result = await import_effect.Effect.runPromise(program);
|
|
730
|
+
const evalRedeemers = result.map((item) => ({
|
|
731
|
+
ex_units: {
|
|
732
|
+
mem: item.budget.memory,
|
|
733
|
+
steps: item.budget.cpu
|
|
734
|
+
},
|
|
735
|
+
redeemer_index: item.validator.index,
|
|
736
|
+
redeemer_tag: item.validator.purpose
|
|
737
|
+
}));
|
|
738
|
+
return evalRedeemers;
|
|
739
|
+
}
|
|
630
740
|
};
|
|
631
741
|
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => import_effect.Effect.gen(function* () {
|
|
632
742
|
if (datum_type === "inline" && datum_hash) {
|
|
@@ -753,6 +863,7 @@ var import_utils3 = require("@lucid-evolution/utils");
|
|
|
753
863
|
var import_utils4 = require("@lucid-evolution/utils");
|
|
754
864
|
var import_core_utils2 = require("@lucid-evolution/core-utils");
|
|
755
865
|
var import_wallet = require("@lucid-evolution/wallet");
|
|
866
|
+
var import_cardano_multiplatform_lib_nodejs = require("@anastasia-labs/cardano-multiplatform-lib-nodejs");
|
|
756
867
|
function generateEmulatorAccount(assets) {
|
|
757
868
|
const seedPhrase = (0, import_utils3.generateSeedPhrase)();
|
|
758
869
|
return {
|
|
@@ -1340,6 +1451,49 @@ It does not exist or was already spent.`
|
|
|
1340
1451
|
}
|
|
1341
1452
|
return Promise.resolve(txHash);
|
|
1342
1453
|
}
|
|
1454
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
1455
|
+
const desTx = CML.Transaction.from_cbor_hex(tx);
|
|
1456
|
+
const redeemers = desTx.witness_set().redeemers();
|
|
1457
|
+
if (!redeemers) {
|
|
1458
|
+
return [];
|
|
1459
|
+
}
|
|
1460
|
+
let evalRedeemers = [];
|
|
1461
|
+
const arrLegacyRedeemer = redeemers.as_arr_legacy_redeemer();
|
|
1462
|
+
if (arrLegacyRedeemer) {
|
|
1463
|
+
for (let i = 0; i < arrLegacyRedeemer.len(); i++) {
|
|
1464
|
+
const legacyRedeemer = arrLegacyRedeemer.get(i);
|
|
1465
|
+
evalRedeemers.push({
|
|
1466
|
+
ex_units: {
|
|
1467
|
+
mem: Number(legacyRedeemer.ex_units().mem()),
|
|
1468
|
+
steps: Number(legacyRedeemer.ex_units().steps())
|
|
1469
|
+
},
|
|
1470
|
+
redeemer_index: Number(legacyRedeemer.index()),
|
|
1471
|
+
redeemer_tag: redeemerTagToString(legacyRedeemer.tag())
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
return evalRedeemers;
|
|
1475
|
+
}
|
|
1476
|
+
const mapRedeemerKeyToRedeemerVal = redeemers.as_map_redeemer_key_to_redeemer_val();
|
|
1477
|
+
if (mapRedeemerKeyToRedeemerVal) {
|
|
1478
|
+
const keys = mapRedeemerKeyToRedeemerVal.keys();
|
|
1479
|
+
for (let i = 0; i < keys.len(); i++) {
|
|
1480
|
+
const key = keys.get(i);
|
|
1481
|
+
const redeemerVal = mapRedeemerKeyToRedeemerVal.get(key);
|
|
1482
|
+
if (redeemerVal) {
|
|
1483
|
+
evalRedeemers.push({
|
|
1484
|
+
ex_units: {
|
|
1485
|
+
mem: Number(redeemerVal.ex_units().mem()),
|
|
1486
|
+
steps: Number(redeemerVal.ex_units().steps())
|
|
1487
|
+
},
|
|
1488
|
+
redeemer_index: Number(key.index),
|
|
1489
|
+
redeemer_tag: redeemerTagToString(key.tag())
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return evalRedeemers;
|
|
1494
|
+
}
|
|
1495
|
+
return evalRedeemers;
|
|
1496
|
+
}
|
|
1343
1497
|
log() {
|
|
1344
1498
|
function getRandomColor(unit) {
|
|
1345
1499
|
const seed = unit === "lovelace" ? "1" : unit;
|
|
@@ -1406,6 +1560,24 @@ ${"\u2581".repeat(60)}
|
|
|
1406
1560
|
}
|
|
1407
1561
|
}
|
|
1408
1562
|
};
|
|
1563
|
+
function redeemerTagToString(tag) {
|
|
1564
|
+
switch (tag) {
|
|
1565
|
+
case import_cardano_multiplatform_lib_nodejs.RedeemerTag.Spend:
|
|
1566
|
+
return "spend";
|
|
1567
|
+
case import_cardano_multiplatform_lib_nodejs.RedeemerTag.Mint:
|
|
1568
|
+
return "mint";
|
|
1569
|
+
case import_cardano_multiplatform_lib_nodejs.RedeemerTag.Cert:
|
|
1570
|
+
return "cert";
|
|
1571
|
+
case import_cardano_multiplatform_lib_nodejs.RedeemerTag.Reward:
|
|
1572
|
+
return "reward";
|
|
1573
|
+
case import_cardano_multiplatform_lib_nodejs.RedeemerTag.Voting:
|
|
1574
|
+
return "voting";
|
|
1575
|
+
case import_cardano_multiplatform_lib_nodejs.RedeemerTag.Proposing:
|
|
1576
|
+
return "proposing";
|
|
1577
|
+
default:
|
|
1578
|
+
return "unknown";
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1409
1581
|
|
|
1410
1582
|
// src/maestro.ts
|
|
1411
1583
|
var import_utils5 = require("@lucid-evolution/utils");
|
|
@@ -1667,6 +1839,33 @@ var Maestro = class {
|
|
|
1667
1839
|
}
|
|
1668
1840
|
return result;
|
|
1669
1841
|
}
|
|
1842
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
1843
|
+
const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
|
|
1844
|
+
index: utxo.outputIndex,
|
|
1845
|
+
tx_hash: utxo.txHash,
|
|
1846
|
+
tx_cbor: (0, import_utils5.utxoToCore)(utxo).to_cbor_hex
|
|
1847
|
+
}));
|
|
1848
|
+
const payload = {
|
|
1849
|
+
cbor: tx,
|
|
1850
|
+
additionalMaestroUTxOs
|
|
1851
|
+
};
|
|
1852
|
+
const res = await fetch(`${this.url}/transactions/evaluate`, {
|
|
1853
|
+
method: "POST",
|
|
1854
|
+
headers: {
|
|
1855
|
+
"Content-Type": "application/json",
|
|
1856
|
+
Accept: "application/json",
|
|
1857
|
+
"api-key": this.apiKey
|
|
1858
|
+
},
|
|
1859
|
+
body: JSON.stringify(payload)
|
|
1860
|
+
});
|
|
1861
|
+
if (!res.ok) {
|
|
1862
|
+
const body = await res.text();
|
|
1863
|
+
console.error("Response error:", JSON.stringify(res));
|
|
1864
|
+
throw new Error(`Evaluate transaction failed: ${body}`);
|
|
1865
|
+
}
|
|
1866
|
+
const result = await res.json();
|
|
1867
|
+
return result;
|
|
1868
|
+
}
|
|
1670
1869
|
};
|
|
1671
1870
|
var lucid2 = package_default.version;
|
|
1672
1871
|
|
|
@@ -2132,6 +2331,62 @@ var Koios = class {
|
|
|
2132
2331
|
}
|
|
2133
2332
|
return result;
|
|
2134
2333
|
}
|
|
2334
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
2335
|
+
const utxos = (additionalUTxOs || []).map((utxo) => {
|
|
2336
|
+
const script = utxo.scriptRef ? {
|
|
2337
|
+
language: utxo.scriptRef.type,
|
|
2338
|
+
cbor: utxo.scriptRef.script
|
|
2339
|
+
} : void 0;
|
|
2340
|
+
return [
|
|
2341
|
+
{
|
|
2342
|
+
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
2343
|
+
},
|
|
2344
|
+
{
|
|
2345
|
+
address: utxo.address,
|
|
2346
|
+
value: {
|
|
2347
|
+
coins: utxo.assets.lovelace,
|
|
2348
|
+
assets: utxo.assets.restAssets
|
|
2349
|
+
},
|
|
2350
|
+
datumHash: utxo.datumHash,
|
|
2351
|
+
datum: utxo.datum,
|
|
2352
|
+
script
|
|
2353
|
+
}
|
|
2354
|
+
];
|
|
2355
|
+
});
|
|
2356
|
+
const data = {
|
|
2357
|
+
jsonrpc: "2.0",
|
|
2358
|
+
method: "evaluateTransaction",
|
|
2359
|
+
params: { transaction: { cbor: tx }, additionalUTxO: utxos },
|
|
2360
|
+
id: null
|
|
2361
|
+
};
|
|
2362
|
+
const response = await fetch(`${this.baseUrl}/ogmios`, {
|
|
2363
|
+
headers: {
|
|
2364
|
+
Accept: "application/json",
|
|
2365
|
+
"Content-Type": "application/json"
|
|
2366
|
+
},
|
|
2367
|
+
method: "POST",
|
|
2368
|
+
body: JSON.stringify(
|
|
2369
|
+
data,
|
|
2370
|
+
(_, value) => typeof value === "bigint" ? value.toString() : value
|
|
2371
|
+
)
|
|
2372
|
+
});
|
|
2373
|
+
if (!response.ok) {
|
|
2374
|
+
const errorBody = await response.text();
|
|
2375
|
+
throw new Error(
|
|
2376
|
+
`Request failed with status ${response.status}: ${errorBody}`
|
|
2377
|
+
);
|
|
2378
|
+
}
|
|
2379
|
+
const result = await response.json();
|
|
2380
|
+
const evalRedeemers = result.result.map((item) => ({
|
|
2381
|
+
ex_units: {
|
|
2382
|
+
mem: item.budget.memory,
|
|
2383
|
+
steps: item.budget.cpu
|
|
2384
|
+
},
|
|
2385
|
+
redeemer_index: item.validator.index,
|
|
2386
|
+
redeemer_tag: item.validator.purpose
|
|
2387
|
+
}));
|
|
2388
|
+
return evalRedeemers;
|
|
2389
|
+
}
|
|
2135
2390
|
};
|
|
2136
2391
|
var toUTxO = (koiosUTxO, address) => ({
|
|
2137
2392
|
txHash: koiosUTxO.tx_hash,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, Assets, OutputData, UnixTime, Lovelace } from '@lucid-evolution/core-types';
|
|
1
|
+
import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, Assets, OutputData, UnixTime, Lovelace } from '@lucid-evolution/core-types';
|
|
2
2
|
import * as effect_Cause from 'effect/Cause';
|
|
3
3
|
import * as effect_Types from 'effect/Types';
|
|
4
4
|
import { Effect } from 'effect';
|
|
@@ -17,6 +17,7 @@ declare class Blockfrost implements Provider {
|
|
|
17
17
|
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
18
18
|
submitTx(tx: Transaction): Promise<TxHash>;
|
|
19
19
|
private blockfrostUtxosToUtxos;
|
|
20
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* This function is temporarily needed only, until Blockfrost returns the datum natively in Cbor.
|
|
@@ -60,6 +61,7 @@ declare class Kupmios implements Provider {
|
|
|
60
61
|
getDatum(datumHash: DatumHash): Promise<Datum>;
|
|
61
62
|
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
62
63
|
submitTx(cbor: Transaction): Promise<TxHash>;
|
|
64
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
/** Concatentation of txHash + outputIndex */
|
|
@@ -111,6 +113,7 @@ declare class Emulator implements Provider {
|
|
|
111
113
|
*/
|
|
112
114
|
distributeRewards(rewards: Lovelace): void;
|
|
113
115
|
submitTx(tx: Transaction): Promise<TxHash>;
|
|
116
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
114
117
|
log(): void;
|
|
115
118
|
}
|
|
116
119
|
|
|
@@ -139,6 +142,7 @@ declare class Maestro implements Provider {
|
|
|
139
142
|
private requireAmountsAsStrings;
|
|
140
143
|
private maestroUtxoToUtxo;
|
|
141
144
|
private getAllPagesData;
|
|
145
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
/**
|
|
@@ -156,6 +160,7 @@ declare class Koios implements Provider {
|
|
|
156
160
|
getDatum(datumHash: DatumHash): Promise<Datum>;
|
|
157
161
|
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
158
162
|
submitTx(tx: Transaction): Promise<TxHash>;
|
|
163
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
declare const FetchError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, Assets, OutputData, UnixTime, Lovelace } from '@lucid-evolution/core-types';
|
|
1
|
+
import { Provider, ProtocolParameters, Address, Credential, UTxO, Unit, OutRef, RewardAddress, Delegation, DatumHash, Datum, TxHash, Transaction, EvalRedeemer, Assets, OutputData, UnixTime, Lovelace } from '@lucid-evolution/core-types';
|
|
2
2
|
import * as effect_Cause from 'effect/Cause';
|
|
3
3
|
import * as effect_Types from 'effect/Types';
|
|
4
4
|
import { Effect } from 'effect';
|
|
@@ -17,6 +17,7 @@ declare class Blockfrost implements Provider {
|
|
|
17
17
|
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
18
18
|
submitTx(tx: Transaction): Promise<TxHash>;
|
|
19
19
|
private blockfrostUtxosToUtxos;
|
|
20
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* This function is temporarily needed only, until Blockfrost returns the datum natively in Cbor.
|
|
@@ -60,6 +61,7 @@ declare class Kupmios implements Provider {
|
|
|
60
61
|
getDatum(datumHash: DatumHash): Promise<Datum>;
|
|
61
62
|
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
62
63
|
submitTx(cbor: Transaction): Promise<TxHash>;
|
|
64
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
/** Concatentation of txHash + outputIndex */
|
|
@@ -111,6 +113,7 @@ declare class Emulator implements Provider {
|
|
|
111
113
|
*/
|
|
112
114
|
distributeRewards(rewards: Lovelace): void;
|
|
113
115
|
submitTx(tx: Transaction): Promise<TxHash>;
|
|
116
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
114
117
|
log(): void;
|
|
115
118
|
}
|
|
116
119
|
|
|
@@ -139,6 +142,7 @@ declare class Maestro implements Provider {
|
|
|
139
142
|
private requireAmountsAsStrings;
|
|
140
143
|
private maestroUtxoToUtxo;
|
|
141
144
|
private getAllPagesData;
|
|
145
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
/**
|
|
@@ -156,6 +160,7 @@ declare class Koios implements Provider {
|
|
|
156
160
|
getDatum(datumHash: DatumHash): Promise<Datum>;
|
|
157
161
|
awaitTx(txHash: TxHash, checkInterval?: number): Promise<boolean>;
|
|
158
162
|
submitTx(tx: Transaction): Promise<TxHash>;
|
|
163
|
+
evaluateTx(tx: Transaction, additionalUTxOs?: UTxO[]): Promise<EvalRedeemer[]>;
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
declare const FetchError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
|
|
|
14
14
|
// package.json
|
|
15
15
|
var package_default = {
|
|
16
16
|
name: "@lucid-evolution/provider",
|
|
17
|
-
version: "0.1.
|
|
17
|
+
version: "0.1.41",
|
|
18
18
|
description: "",
|
|
19
19
|
main: "./dist/index.js",
|
|
20
20
|
types: "./dist/index.d.ts",
|
|
@@ -278,6 +278,56 @@ var Blockfrost = class {
|
|
|
278
278
|
}))
|
|
279
279
|
);
|
|
280
280
|
}
|
|
281
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
282
|
+
const additionalUTxOSet = (additionalUTxOs || []).map((utxo) => [
|
|
283
|
+
{ txId: utxo.txHash, index: utxo.outputIndex },
|
|
284
|
+
{
|
|
285
|
+
address: utxo.address,
|
|
286
|
+
value: { coins: utxo.assets.lovelace, assets: utxo.assets.restAssets },
|
|
287
|
+
datum_hash: utxo.datumHash,
|
|
288
|
+
datum: utxo.datum,
|
|
289
|
+
script: utxo.scriptRef
|
|
290
|
+
}
|
|
291
|
+
]);
|
|
292
|
+
const payload = {
|
|
293
|
+
cbor: tx,
|
|
294
|
+
additionalUTxOSet
|
|
295
|
+
};
|
|
296
|
+
const res = await fetch(`${this.url}/utils/txs/evaluate/utxos`, {
|
|
297
|
+
method: "POST",
|
|
298
|
+
headers: {
|
|
299
|
+
"Content-Type": "application/json",
|
|
300
|
+
project_id: this.projectId,
|
|
301
|
+
lucid
|
|
302
|
+
},
|
|
303
|
+
body: JSON.stringify(
|
|
304
|
+
payload,
|
|
305
|
+
(_, value) => typeof value === "bigint" ? value.toString() : value
|
|
306
|
+
)
|
|
307
|
+
}).then((res2) => res2.json());
|
|
308
|
+
if (!res || res.error) {
|
|
309
|
+
const message = res?.status_code === 400 ? res.message : `Could not evaluate the transaction: ${JSON.stringify(res)}`;
|
|
310
|
+
throw new Error(message);
|
|
311
|
+
}
|
|
312
|
+
const blockfrostRedeemer = res;
|
|
313
|
+
if (!("EvaluationResult" in blockfrostRedeemer.result)) {
|
|
314
|
+
throw new Error(
|
|
315
|
+
`EvaluateTransaction fails: ${JSON.stringify(blockfrostRedeemer.result)}`
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
const evalRedeemers = [];
|
|
319
|
+
Object.entries(blockfrostRedeemer.result.EvaluationResult).forEach(
|
|
320
|
+
([redeemerPointer, data]) => {
|
|
321
|
+
const [pTag, pIndex] = redeemerPointer.split(":");
|
|
322
|
+
evalRedeemers.push({
|
|
323
|
+
redeemer_tag: pTag,
|
|
324
|
+
redeemer_index: Number(pIndex),
|
|
325
|
+
ex_units: { mem: Number(data.memory), steps: Number(data.steps) }
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
);
|
|
329
|
+
return evalRedeemers;
|
|
330
|
+
}
|
|
281
331
|
};
|
|
282
332
|
function datumJsonToCbor(json) {
|
|
283
333
|
const convert = (json2) => {
|
|
@@ -593,6 +643,66 @@ var Kupmios = class {
|
|
|
593
643
|
const { result } = await Effect.runPromise(program);
|
|
594
644
|
return result.transaction.id;
|
|
595
645
|
}
|
|
646
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
647
|
+
const utxos = (additionalUTxOs || []).map((utxo) => {
|
|
648
|
+
const script = utxo.scriptRef ? {
|
|
649
|
+
language: utxo.scriptRef.type,
|
|
650
|
+
cbor: utxo.scriptRef.script
|
|
651
|
+
} : void 0;
|
|
652
|
+
return [
|
|
653
|
+
{
|
|
654
|
+
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
address: utxo.address,
|
|
658
|
+
value: {
|
|
659
|
+
coins: utxo.assets.lovelace,
|
|
660
|
+
assets: utxo.assets.restAssets
|
|
661
|
+
},
|
|
662
|
+
datumHash: utxo.datumHash,
|
|
663
|
+
datum: utxo.datum,
|
|
664
|
+
script
|
|
665
|
+
}
|
|
666
|
+
];
|
|
667
|
+
});
|
|
668
|
+
const data = {
|
|
669
|
+
jsonrpc: "2.0",
|
|
670
|
+
method: "evaluateTransaction",
|
|
671
|
+
params: { transaction: { cbor: tx }, additionalUTxO: utxos },
|
|
672
|
+
id: null
|
|
673
|
+
};
|
|
674
|
+
const schema = JSONRPCSchema(
|
|
675
|
+
S2.Array(
|
|
676
|
+
S2.Struct({
|
|
677
|
+
validator: S2.Struct({
|
|
678
|
+
purpose: S2.String,
|
|
679
|
+
index: S2.Int
|
|
680
|
+
}),
|
|
681
|
+
budget: S2.Struct({
|
|
682
|
+
memory: S2.Int,
|
|
683
|
+
cpu: S2.Int
|
|
684
|
+
})
|
|
685
|
+
})
|
|
686
|
+
)
|
|
687
|
+
);
|
|
688
|
+
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
689
|
+
Effect.flatMap(
|
|
690
|
+
(response) => "error" in response ? kupmiosError(response.error) : Effect.succeed(response.result)
|
|
691
|
+
),
|
|
692
|
+
Effect.timeout(1e4),
|
|
693
|
+
Effect.catchAll(kupmiosError)
|
|
694
|
+
);
|
|
695
|
+
const result = await Effect.runPromise(program);
|
|
696
|
+
const evalRedeemers = result.map((item) => ({
|
|
697
|
+
ex_units: {
|
|
698
|
+
mem: item.budget.memory,
|
|
699
|
+
steps: item.budget.cpu
|
|
700
|
+
},
|
|
701
|
+
redeemer_index: item.validator.index,
|
|
702
|
+
redeemer_tag: item.validator.purpose
|
|
703
|
+
}));
|
|
704
|
+
return evalRedeemers;
|
|
705
|
+
}
|
|
596
706
|
};
|
|
597
707
|
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* () {
|
|
598
708
|
if (datum_type === "inline" && datum_hash) {
|
|
@@ -722,6 +832,7 @@ import {
|
|
|
722
832
|
import { coreToUtxo, getAddressDetails } from "@lucid-evolution/utils";
|
|
723
833
|
import { fromHex as fromHex2 } from "@lucid-evolution/core-utils";
|
|
724
834
|
import { walletFromSeed } from "@lucid-evolution/wallet";
|
|
835
|
+
import { RedeemerTag } from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
725
836
|
function generateEmulatorAccount(assets) {
|
|
726
837
|
const seedPhrase = generateSeedPhrase();
|
|
727
838
|
return {
|
|
@@ -1309,6 +1420,49 @@ It does not exist or was already spent.`
|
|
|
1309
1420
|
}
|
|
1310
1421
|
return Promise.resolve(txHash);
|
|
1311
1422
|
}
|
|
1423
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
1424
|
+
const desTx = CML.Transaction.from_cbor_hex(tx);
|
|
1425
|
+
const redeemers = desTx.witness_set().redeemers();
|
|
1426
|
+
if (!redeemers) {
|
|
1427
|
+
return [];
|
|
1428
|
+
}
|
|
1429
|
+
let evalRedeemers = [];
|
|
1430
|
+
const arrLegacyRedeemer = redeemers.as_arr_legacy_redeemer();
|
|
1431
|
+
if (arrLegacyRedeemer) {
|
|
1432
|
+
for (let i = 0; i < arrLegacyRedeemer.len(); i++) {
|
|
1433
|
+
const legacyRedeemer = arrLegacyRedeemer.get(i);
|
|
1434
|
+
evalRedeemers.push({
|
|
1435
|
+
ex_units: {
|
|
1436
|
+
mem: Number(legacyRedeemer.ex_units().mem()),
|
|
1437
|
+
steps: Number(legacyRedeemer.ex_units().steps())
|
|
1438
|
+
},
|
|
1439
|
+
redeemer_index: Number(legacyRedeemer.index()),
|
|
1440
|
+
redeemer_tag: redeemerTagToString(legacyRedeemer.tag())
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
return evalRedeemers;
|
|
1444
|
+
}
|
|
1445
|
+
const mapRedeemerKeyToRedeemerVal = redeemers.as_map_redeemer_key_to_redeemer_val();
|
|
1446
|
+
if (mapRedeemerKeyToRedeemerVal) {
|
|
1447
|
+
const keys = mapRedeemerKeyToRedeemerVal.keys();
|
|
1448
|
+
for (let i = 0; i < keys.len(); i++) {
|
|
1449
|
+
const key = keys.get(i);
|
|
1450
|
+
const redeemerVal = mapRedeemerKeyToRedeemerVal.get(key);
|
|
1451
|
+
if (redeemerVal) {
|
|
1452
|
+
evalRedeemers.push({
|
|
1453
|
+
ex_units: {
|
|
1454
|
+
mem: Number(redeemerVal.ex_units().mem()),
|
|
1455
|
+
steps: Number(redeemerVal.ex_units().steps())
|
|
1456
|
+
},
|
|
1457
|
+
redeemer_index: Number(key.index),
|
|
1458
|
+
redeemer_tag: redeemerTagToString(key.tag())
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
return evalRedeemers;
|
|
1463
|
+
}
|
|
1464
|
+
return evalRedeemers;
|
|
1465
|
+
}
|
|
1312
1466
|
log() {
|
|
1313
1467
|
function getRandomColor(unit) {
|
|
1314
1468
|
const seed = unit === "lovelace" ? "1" : unit;
|
|
@@ -1375,9 +1529,27 @@ ${"\u2581".repeat(60)}
|
|
|
1375
1529
|
}
|
|
1376
1530
|
}
|
|
1377
1531
|
};
|
|
1532
|
+
function redeemerTagToString(tag) {
|
|
1533
|
+
switch (tag) {
|
|
1534
|
+
case RedeemerTag.Spend:
|
|
1535
|
+
return "spend";
|
|
1536
|
+
case RedeemerTag.Mint:
|
|
1537
|
+
return "mint";
|
|
1538
|
+
case RedeemerTag.Cert:
|
|
1539
|
+
return "cert";
|
|
1540
|
+
case RedeemerTag.Reward:
|
|
1541
|
+
return "reward";
|
|
1542
|
+
case RedeemerTag.Voting:
|
|
1543
|
+
return "voting";
|
|
1544
|
+
case RedeemerTag.Proposing:
|
|
1545
|
+
return "proposing";
|
|
1546
|
+
default:
|
|
1547
|
+
return "unknown";
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1378
1550
|
|
|
1379
1551
|
// src/maestro.ts
|
|
1380
|
-
import { applyDoubleCborEncoding as applyDoubleCborEncoding2 } from "@lucid-evolution/utils";
|
|
1552
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding2, utxoToCore } from "@lucid-evolution/utils";
|
|
1381
1553
|
import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
|
|
1382
1554
|
var Maestro = class {
|
|
1383
1555
|
url;
|
|
@@ -1636,6 +1808,33 @@ var Maestro = class {
|
|
|
1636
1808
|
}
|
|
1637
1809
|
return result;
|
|
1638
1810
|
}
|
|
1811
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
1812
|
+
const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
|
|
1813
|
+
index: utxo.outputIndex,
|
|
1814
|
+
tx_hash: utxo.txHash,
|
|
1815
|
+
tx_cbor: utxoToCore(utxo).to_cbor_hex
|
|
1816
|
+
}));
|
|
1817
|
+
const payload = {
|
|
1818
|
+
cbor: tx,
|
|
1819
|
+
additionalMaestroUTxOs
|
|
1820
|
+
};
|
|
1821
|
+
const res = await fetch(`${this.url}/transactions/evaluate`, {
|
|
1822
|
+
method: "POST",
|
|
1823
|
+
headers: {
|
|
1824
|
+
"Content-Type": "application/json",
|
|
1825
|
+
Accept: "application/json",
|
|
1826
|
+
"api-key": this.apiKey
|
|
1827
|
+
},
|
|
1828
|
+
body: JSON.stringify(payload)
|
|
1829
|
+
});
|
|
1830
|
+
if (!res.ok) {
|
|
1831
|
+
const body = await res.text();
|
|
1832
|
+
console.error("Response error:", JSON.stringify(res));
|
|
1833
|
+
throw new Error(`Evaluate transaction failed: ${body}`);
|
|
1834
|
+
}
|
|
1835
|
+
const result = await res.json();
|
|
1836
|
+
return result;
|
|
1837
|
+
}
|
|
1639
1838
|
};
|
|
1640
1839
|
var lucid2 = package_default.version;
|
|
1641
1840
|
|
|
@@ -2101,6 +2300,62 @@ var Koios = class {
|
|
|
2101
2300
|
}
|
|
2102
2301
|
return result;
|
|
2103
2302
|
}
|
|
2303
|
+
async evaluateTx(tx, additionalUTxOs) {
|
|
2304
|
+
const utxos = (additionalUTxOs || []).map((utxo) => {
|
|
2305
|
+
const script = utxo.scriptRef ? {
|
|
2306
|
+
language: utxo.scriptRef.type,
|
|
2307
|
+
cbor: utxo.scriptRef.script
|
|
2308
|
+
} : void 0;
|
|
2309
|
+
return [
|
|
2310
|
+
{
|
|
2311
|
+
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
2312
|
+
},
|
|
2313
|
+
{
|
|
2314
|
+
address: utxo.address,
|
|
2315
|
+
value: {
|
|
2316
|
+
coins: utxo.assets.lovelace,
|
|
2317
|
+
assets: utxo.assets.restAssets
|
|
2318
|
+
},
|
|
2319
|
+
datumHash: utxo.datumHash,
|
|
2320
|
+
datum: utxo.datum,
|
|
2321
|
+
script
|
|
2322
|
+
}
|
|
2323
|
+
];
|
|
2324
|
+
});
|
|
2325
|
+
const data = {
|
|
2326
|
+
jsonrpc: "2.0",
|
|
2327
|
+
method: "evaluateTransaction",
|
|
2328
|
+
params: { transaction: { cbor: tx }, additionalUTxO: utxos },
|
|
2329
|
+
id: null
|
|
2330
|
+
};
|
|
2331
|
+
const response = await fetch(`${this.baseUrl}/ogmios`, {
|
|
2332
|
+
headers: {
|
|
2333
|
+
Accept: "application/json",
|
|
2334
|
+
"Content-Type": "application/json"
|
|
2335
|
+
},
|
|
2336
|
+
method: "POST",
|
|
2337
|
+
body: JSON.stringify(
|
|
2338
|
+
data,
|
|
2339
|
+
(_, value) => typeof value === "bigint" ? value.toString() : value
|
|
2340
|
+
)
|
|
2341
|
+
});
|
|
2342
|
+
if (!response.ok) {
|
|
2343
|
+
const errorBody = await response.text();
|
|
2344
|
+
throw new Error(
|
|
2345
|
+
`Request failed with status ${response.status}: ${errorBody}`
|
|
2346
|
+
);
|
|
2347
|
+
}
|
|
2348
|
+
const result = await response.json();
|
|
2349
|
+
const evalRedeemers = result.result.map((item) => ({
|
|
2350
|
+
ex_units: {
|
|
2351
|
+
mem: item.budget.memory,
|
|
2352
|
+
steps: item.budget.cpu
|
|
2353
|
+
},
|
|
2354
|
+
redeemer_index: item.validator.index,
|
|
2355
|
+
redeemer_tag: item.validator.purpose
|
|
2356
|
+
}));
|
|
2357
|
+
return evalRedeemers;
|
|
2358
|
+
}
|
|
2104
2359
|
};
|
|
2105
2360
|
var toUTxO = (koiosUTxO, address) => ({
|
|
2106
2361
|
txHash: koiosUTxO.tx_hash,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"@effect/platform": "^0.59.2",
|
|
31
31
|
"@effect/schema": "^0.68.26",
|
|
32
32
|
"effect": "^3.5.6",
|
|
33
|
-
"@lucid-evolution/core-types": "0.1.
|
|
34
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
35
|
-
"@lucid-evolution/utils": "0.1.
|
|
36
|
-
"@lucid-evolution/wallet": "0.1.
|
|
33
|
+
"@lucid-evolution/core-types": "0.1.13",
|
|
34
|
+
"@lucid-evolution/core-utils": "0.1.12",
|
|
35
|
+
"@lucid-evolution/utils": "0.1.32",
|
|
36
|
+
"@lucid-evolution/wallet": "0.1.36"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^20.12.8",
|