@lucid-evolution/provider 0.2.2 → 0.2.3
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 +134 -102
- package/dist/index.js +135 -103
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -144,7 +144,7 @@ var import_utils2 = require("@lucid-evolution/utils");
|
|
|
144
144
|
// package.json
|
|
145
145
|
var package_default = {
|
|
146
146
|
name: "@lucid-evolution/provider",
|
|
147
|
-
version: "0.2.
|
|
147
|
+
version: "0.2.3",
|
|
148
148
|
description: "",
|
|
149
149
|
main: "./dist/index.js",
|
|
150
150
|
types: "./dist/index.d.ts",
|
|
@@ -1793,78 +1793,89 @@ var Emulator = class {
|
|
|
1793
1793
|
const datumTable = (() => {
|
|
1794
1794
|
const table = {};
|
|
1795
1795
|
for (let i = 0; i < (datums?.len() || 0); i++) {
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1796
|
+
(0, import_core_utils2.withCMLScope)((own) => {
|
|
1797
|
+
const datum = own(datums.get(i));
|
|
1798
|
+
const datumHash = own(CML.hash_plutus_data(datum)).to_hex();
|
|
1799
|
+
table[datumHash] = datum.to_cbor_hex();
|
|
1800
|
+
});
|
|
1799
1801
|
}
|
|
1800
1802
|
return table;
|
|
1801
1803
|
})();
|
|
1802
1804
|
const consumedHashes = /* @__PURE__ */ new Set();
|
|
1803
|
-
const keyHashes = (() => {
|
|
1805
|
+
const keyHashes = (0, import_core_utils2.withCMLScope)((own) => {
|
|
1804
1806
|
const keyHashes2 = [];
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1807
|
+
const vkeyWitnesses = own(witnesses.vkeywitnesses());
|
|
1808
|
+
for (let i = 0; i < (vkeyWitnesses?.len() || 0); i++) {
|
|
1809
|
+
(0, import_core_utils2.withCMLScope)((own2) => {
|
|
1810
|
+
const witness = own2(vkeyWitnesses.get(i));
|
|
1811
|
+
const publicKey = own2(witness.vkey());
|
|
1812
|
+
const keyHash = own2(publicKey.hash()).to_hex();
|
|
1813
|
+
if (!publicKey.verify((0, import_core_utils2.fromHex)(txHash), own2(witness.ed25519_signature()))) {
|
|
1814
|
+
throw new Error(`Invalid vkey witness. Key hash: ${keyHash}`);
|
|
1815
|
+
}
|
|
1816
|
+
keyHashes2.push(keyHash);
|
|
1817
|
+
});
|
|
1813
1818
|
}
|
|
1814
1819
|
return keyHashes2;
|
|
1815
|
-
})
|
|
1820
|
+
});
|
|
1816
1821
|
const edKeyHashes = CML.Ed25519KeyHashList.new();
|
|
1817
1822
|
keyHashes.forEach(
|
|
1818
|
-
(keyHash) =>
|
|
1823
|
+
(keyHash) => (0, import_core_utils2.withCMLScope)(
|
|
1824
|
+
(own) => edKeyHashes.add(own(CML.Ed25519KeyHash.from_hex(keyHash)))
|
|
1825
|
+
)
|
|
1819
1826
|
);
|
|
1820
|
-
const nativeHashes = (() => {
|
|
1827
|
+
const nativeHashes = (0, import_core_utils2.withCMLScope)((own) => {
|
|
1821
1828
|
const scriptHashes = [];
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1829
|
+
const nativeScripts = own(witnesses.native_scripts());
|
|
1830
|
+
for (let i = 0; i < (nativeScripts?.len() || 0); i++) {
|
|
1831
|
+
(0, import_core_utils2.withCMLScope)((own2) => {
|
|
1832
|
+
const witness = own2(nativeScripts.get(i));
|
|
1833
|
+
const scriptHash = own2(witness.hash()).to_hex();
|
|
1834
|
+
if (!witness.verify(
|
|
1835
|
+
Number.isInteger(lowerBound) ? BigInt(lowerBound) : void 0,
|
|
1836
|
+
Number.isInteger(upperBound) ? BigInt(upperBound) : void 0,
|
|
1837
|
+
edKeyHashes
|
|
1838
|
+
)) {
|
|
1839
|
+
throw new Error(
|
|
1840
|
+
`Invalid native script witness. Script hash: ${scriptHash}`
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
const requiredSigners = own2(witness.get_required_signers());
|
|
1844
|
+
for (let j = 0; j < requiredSigners.len(); j++) {
|
|
1845
|
+
const keyHash = own2(requiredSigners.get(j)).to_hex();
|
|
1846
|
+
consumedHashes.add(keyHash);
|
|
1847
|
+
}
|
|
1848
|
+
scriptHashes.push(scriptHash);
|
|
1849
|
+
});
|
|
1839
1850
|
}
|
|
1840
1851
|
return scriptHashes;
|
|
1841
|
-
})
|
|
1852
|
+
});
|
|
1853
|
+
edKeyHashes.free();
|
|
1842
1854
|
const nativeHashesOptional = {};
|
|
1843
1855
|
const plutusHashesOptional = [];
|
|
1844
|
-
const plutusHashes = (() => {
|
|
1856
|
+
const plutusHashes = (0, import_core_utils2.withCMLScope)((own) => {
|
|
1845
1857
|
const scriptHashes = [];
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
const scriptHash = script.hash().to_hex();
|
|
1859
|
-
scriptHashes.push(scriptHash);
|
|
1860
|
-
}
|
|
1858
|
+
const collectHashes = (scripts) => {
|
|
1859
|
+
own(scripts);
|
|
1860
|
+
for (let i = 0; i < (scripts?.len() || 0); i++) {
|
|
1861
|
+
(0, import_core_utils2.withCMLScope)((own2) => {
|
|
1862
|
+
const script = own2(scripts.get(i));
|
|
1863
|
+
scriptHashes.push(own2(script.hash()).to_hex());
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
collectHashes(witnesses.plutus_v1_scripts());
|
|
1868
|
+
collectHashes(witnesses.plutus_v2_scripts());
|
|
1869
|
+
collectHashes(witnesses.plutus_v3_scripts());
|
|
1861
1870
|
return scriptHashes;
|
|
1862
|
-
})
|
|
1871
|
+
});
|
|
1863
1872
|
const inputs = body.inputs();
|
|
1864
1873
|
const resolvedInputs = [];
|
|
1865
1874
|
for (let i = 0; i < inputs.len(); i++) {
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1875
|
+
const outRef = (0, import_core_utils2.withCMLScope)((own) => {
|
|
1876
|
+
const input = own(inputs.get(i));
|
|
1877
|
+
return own(input.transaction_id()).to_hex() + input.index().toString();
|
|
1878
|
+
});
|
|
1868
1879
|
const entryLedger = this.ledger[outRef];
|
|
1869
1880
|
const { entry, type } = !entryLedger ? { entry: this.mempool[outRef], type: "Mempool" } : { entry: entryLedger, type: "Ledger" };
|
|
1870
1881
|
if (!entry || entry.spent) {
|
|
@@ -1912,9 +1923,13 @@ It does not exist or was already spent.`
|
|
|
1912
1923
|
if (entry.utxo.datumHash) consumedHashes.add(entry.utxo.datumHash);
|
|
1913
1924
|
resolvedInputs.push({ entry, type });
|
|
1914
1925
|
}
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1926
|
+
inputs.free();
|
|
1927
|
+
const referenceInputs = body.reference_inputs();
|
|
1928
|
+
for (let i = 0; i < (referenceInputs?.len() || 0); i++) {
|
|
1929
|
+
const outRef = (0, import_core_utils2.withCMLScope)((own) => {
|
|
1930
|
+
const input = own(referenceInputs.get(i));
|
|
1931
|
+
return own(input.transaction_id()).to_hex() + input.index().toString();
|
|
1932
|
+
});
|
|
1918
1933
|
const entry = this.ledger[outRef] || this.mempool[outRef];
|
|
1919
1934
|
if (!entry || entry.spent) {
|
|
1920
1935
|
throw new Error(
|
|
@@ -1960,6 +1975,7 @@ It does not exist or was already spent.`
|
|
|
1960
1975
|
}
|
|
1961
1976
|
if (entry.utxo.datumHash) consumedHashes.add(entry.utxo.datumHash);
|
|
1962
1977
|
}
|
|
1978
|
+
referenceInputs?.free();
|
|
1963
1979
|
const redeemers = (() => {
|
|
1964
1980
|
const tagMap = {
|
|
1965
1981
|
0: "Spend",
|
|
@@ -2038,9 +2054,12 @@ It does not exist or was already spent.`
|
|
|
2038
2054
|
}
|
|
2039
2055
|
}
|
|
2040
2056
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
const outRef =
|
|
2057
|
+
const collateralInputs = body.collateral_inputs();
|
|
2058
|
+
for (let i = 0; i < (collateralInputs?.len() || 0); i++) {
|
|
2059
|
+
const outRef = (0, import_core_utils2.withCMLScope)((own) => {
|
|
2060
|
+
const input = own(collateralInputs.get(i));
|
|
2061
|
+
return own(input.transaction_id()).to_hex() + input.index().toString();
|
|
2062
|
+
});
|
|
2044
2063
|
const entry = this.ledger[outRef] || this.mempool[outRef];
|
|
2045
2064
|
if (!entry || entry.spent) {
|
|
2046
2065
|
throw new Error(
|
|
@@ -2057,6 +2076,7 @@ It does not exist or was already spent.`
|
|
|
2057
2076
|
}
|
|
2058
2077
|
checkAndConsumeHash(paymentCredential, null, null);
|
|
2059
2078
|
}
|
|
2079
|
+
collateralInputs?.free();
|
|
2060
2080
|
for (let i = 0; i < (body.required_signers()?.len() || 0); i++) {
|
|
2061
2081
|
const signer = body.required_signers().get(i);
|
|
2062
2082
|
checkAndConsumeHash({ type: "Key", hash: signer.to_hex() }, null, null);
|
|
@@ -2322,16 +2342,21 @@ It does not exist or was already spent.`
|
|
|
2322
2342
|
const { paymentCredential } = (0, import_utils6.getAddressDetails)(utxo.address);
|
|
2323
2343
|
checkAndConsumeHash(paymentCredential, "Spend", index);
|
|
2324
2344
|
});
|
|
2325
|
-
const outputs = (() => {
|
|
2345
|
+
const outputs = (0, import_core_utils2.withCMLScope)((own) => {
|
|
2326
2346
|
const collected = [];
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
const
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2347
|
+
const bodyOutputs = own(body.outputs());
|
|
2348
|
+
for (let i = 0; i < bodyOutputs.len(); i++) {
|
|
2349
|
+
const output = own(bodyOutputs.get(i));
|
|
2350
|
+
const unspentOutput = own(
|
|
2351
|
+
CML.TransactionUnspentOutput.new(
|
|
2352
|
+
own(
|
|
2353
|
+
CML.TransactionInput.new(
|
|
2354
|
+
own(CML.TransactionHash.from_hex(txHash)),
|
|
2355
|
+
BigInt(i)
|
|
2356
|
+
)
|
|
2357
|
+
),
|
|
2358
|
+
output
|
|
2359
|
+
)
|
|
2335
2360
|
);
|
|
2336
2361
|
const utxo = (0, import_utils6.coreToUtxo)(unspentOutput);
|
|
2337
2362
|
if (utxo.datumHash) consumedHashes.add(utxo.datumHash);
|
|
@@ -2341,7 +2366,7 @@ It does not exist or was already spent.`
|
|
|
2341
2366
|
});
|
|
2342
2367
|
}
|
|
2343
2368
|
return collected;
|
|
2344
|
-
})
|
|
2369
|
+
});
|
|
2345
2370
|
const [extraKeyHash] = keyHashes.filter(
|
|
2346
2371
|
(keyHash) => !consumedHashes.has(keyHash)
|
|
2347
2372
|
);
|
|
@@ -2415,50 +2440,57 @@ It does not exist or was already spent.`
|
|
|
2415
2440
|
this.datumTable[datumHash] = datum;
|
|
2416
2441
|
}
|
|
2417
2442
|
this.transactionHistory[txHash] = { status: "pending" };
|
|
2443
|
+
(0, import_core_utils2.freeCML)(datums, witnesses, body, desTx);
|
|
2418
2444
|
return Promise.resolve(txHash);
|
|
2419
2445
|
}
|
|
2420
2446
|
async evaluateTx(tx, additionalUTxOs) {
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
let evalRedeemers = [];
|
|
2427
|
-
const arrLegacyRedeemer = redeemers.as_arr_legacy_redeemer();
|
|
2428
|
-
if (arrLegacyRedeemer) {
|
|
2429
|
-
for (let i = 0; i < arrLegacyRedeemer.len(); i++) {
|
|
2430
|
-
const legacyRedeemer = arrLegacyRedeemer.get(i);
|
|
2431
|
-
evalRedeemers.push({
|
|
2432
|
-
ex_units: {
|
|
2433
|
-
mem: Number(legacyRedeemer.ex_units().mem()),
|
|
2434
|
-
steps: Number(legacyRedeemer.ex_units().steps())
|
|
2435
|
-
},
|
|
2436
|
-
redeemer_index: Number(legacyRedeemer.index()),
|
|
2437
|
-
redeemer_tag: (0, import_utils5.fromCMLRedeemerTag)(legacyRedeemer.tag())
|
|
2438
|
-
});
|
|
2447
|
+
return (0, import_core_utils2.withCMLScope)((own) => {
|
|
2448
|
+
const desTx = own(CML.Transaction.from_cbor_hex(tx));
|
|
2449
|
+
const redeemers = own(own(desTx.witness_set()).redeemers());
|
|
2450
|
+
if (!redeemers) {
|
|
2451
|
+
return [];
|
|
2439
2452
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
const key = keys.get(i);
|
|
2447
|
-
const redeemerVal = mapRedeemerKeyToRedeemerVal.get(key);
|
|
2448
|
-
if (redeemerVal) {
|
|
2453
|
+
const evalRedeemers = [];
|
|
2454
|
+
const arrLegacyRedeemer = own(redeemers.as_arr_legacy_redeemer());
|
|
2455
|
+
if (arrLegacyRedeemer) {
|
|
2456
|
+
for (let i = 0; i < arrLegacyRedeemer.len(); i++) {
|
|
2457
|
+
const legacyRedeemer = own(arrLegacyRedeemer.get(i));
|
|
2458
|
+
const exUnits = own(legacyRedeemer.ex_units());
|
|
2449
2459
|
evalRedeemers.push({
|
|
2450
2460
|
ex_units: {
|
|
2451
|
-
mem: Number(
|
|
2452
|
-
steps: Number(
|
|
2461
|
+
mem: Number(exUnits.mem()),
|
|
2462
|
+
steps: Number(exUnits.steps())
|
|
2453
2463
|
},
|
|
2454
|
-
redeemer_index: Number(
|
|
2455
|
-
redeemer_tag: (0, import_utils5.fromCMLRedeemerTag)(
|
|
2464
|
+
redeemer_index: Number(legacyRedeemer.index()),
|
|
2465
|
+
redeemer_tag: (0, import_utils5.fromCMLRedeemerTag)(legacyRedeemer.tag())
|
|
2456
2466
|
});
|
|
2457
2467
|
}
|
|
2468
|
+
return evalRedeemers;
|
|
2469
|
+
}
|
|
2470
|
+
const mapRedeemerKeyToRedeemerVal = own(
|
|
2471
|
+
redeemers.as_map_redeemer_key_to_redeemer_val()
|
|
2472
|
+
);
|
|
2473
|
+
if (mapRedeemerKeyToRedeemerVal) {
|
|
2474
|
+
const keys = own(mapRedeemerKeyToRedeemerVal.keys());
|
|
2475
|
+
for (let i = 0; i < keys.len(); i++) {
|
|
2476
|
+
const key = own(keys.get(i));
|
|
2477
|
+
const redeemerVal = own(mapRedeemerKeyToRedeemerVal.get(key));
|
|
2478
|
+
if (redeemerVal) {
|
|
2479
|
+
const exUnits = own(redeemerVal.ex_units());
|
|
2480
|
+
evalRedeemers.push({
|
|
2481
|
+
ex_units: {
|
|
2482
|
+
mem: Number(exUnits.mem()),
|
|
2483
|
+
steps: Number(exUnits.steps())
|
|
2484
|
+
},
|
|
2485
|
+
redeemer_index: Number(key.index()),
|
|
2486
|
+
redeemer_tag: (0, import_utils5.fromCMLRedeemerTag)(key.tag())
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
return evalRedeemers;
|
|
2458
2491
|
}
|
|
2459
2492
|
return evalRedeemers;
|
|
2460
|
-
}
|
|
2461
|
-
return evalRedeemers;
|
|
2493
|
+
});
|
|
2462
2494
|
}
|
|
2463
2495
|
log() {
|
|
2464
2496
|
function getRandomColor(unit) {
|
package/dist/index.js
CHANGED
|
@@ -101,7 +101,7 @@ import {
|
|
|
101
101
|
// package.json
|
|
102
102
|
var package_default = {
|
|
103
103
|
name: "@lucid-evolution/provider",
|
|
104
|
-
version: "0.2.
|
|
104
|
+
version: "0.2.3",
|
|
105
105
|
description: "",
|
|
106
106
|
main: "./dist/index.js",
|
|
107
107
|
types: "./dist/index.d.ts",
|
|
@@ -1469,7 +1469,7 @@ import {
|
|
|
1469
1469
|
PROTOCOL_PARAMETERS_DEFAULT
|
|
1470
1470
|
} from "@lucid-evolution/utils";
|
|
1471
1471
|
import { coreToUtxo, getAddressDetails } from "@lucid-evolution/utils";
|
|
1472
|
-
import { fromHex as fromHex2 } from "@lucid-evolution/core-utils";
|
|
1472
|
+
import { freeCML, fromHex as fromHex2, withCMLScope } from "@lucid-evolution/core-utils";
|
|
1473
1473
|
import { walletFromSeed } from "@lucid-evolution/wallet";
|
|
1474
1474
|
var EMULATOR_PROVIDER_BRAND = Symbol.for(
|
|
1475
1475
|
"@lucid-evolution/provider/Emulator"
|
|
@@ -1759,78 +1759,89 @@ var Emulator = class {
|
|
|
1759
1759
|
const datumTable = (() => {
|
|
1760
1760
|
const table = {};
|
|
1761
1761
|
for (let i = 0; i < (datums?.len() || 0); i++) {
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1762
|
+
withCMLScope((own) => {
|
|
1763
|
+
const datum = own(datums.get(i));
|
|
1764
|
+
const datumHash = own(CML.hash_plutus_data(datum)).to_hex();
|
|
1765
|
+
table[datumHash] = datum.to_cbor_hex();
|
|
1766
|
+
});
|
|
1765
1767
|
}
|
|
1766
1768
|
return table;
|
|
1767
1769
|
})();
|
|
1768
1770
|
const consumedHashes = /* @__PURE__ */ new Set();
|
|
1769
|
-
const keyHashes = (() => {
|
|
1771
|
+
const keyHashes = withCMLScope((own) => {
|
|
1770
1772
|
const keyHashes2 = [];
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1773
|
+
const vkeyWitnesses = own(witnesses.vkeywitnesses());
|
|
1774
|
+
for (let i = 0; i < (vkeyWitnesses?.len() || 0); i++) {
|
|
1775
|
+
withCMLScope((own2) => {
|
|
1776
|
+
const witness = own2(vkeyWitnesses.get(i));
|
|
1777
|
+
const publicKey = own2(witness.vkey());
|
|
1778
|
+
const keyHash = own2(publicKey.hash()).to_hex();
|
|
1779
|
+
if (!publicKey.verify(fromHex2(txHash), own2(witness.ed25519_signature()))) {
|
|
1780
|
+
throw new Error(`Invalid vkey witness. Key hash: ${keyHash}`);
|
|
1781
|
+
}
|
|
1782
|
+
keyHashes2.push(keyHash);
|
|
1783
|
+
});
|
|
1779
1784
|
}
|
|
1780
1785
|
return keyHashes2;
|
|
1781
|
-
})
|
|
1786
|
+
});
|
|
1782
1787
|
const edKeyHashes = CML.Ed25519KeyHashList.new();
|
|
1783
1788
|
keyHashes.forEach(
|
|
1784
|
-
(keyHash) =>
|
|
1789
|
+
(keyHash) => withCMLScope(
|
|
1790
|
+
(own) => edKeyHashes.add(own(CML.Ed25519KeyHash.from_hex(keyHash)))
|
|
1791
|
+
)
|
|
1785
1792
|
);
|
|
1786
|
-
const nativeHashes = (() => {
|
|
1793
|
+
const nativeHashes = withCMLScope((own) => {
|
|
1787
1794
|
const scriptHashes = [];
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1795
|
+
const nativeScripts = own(witnesses.native_scripts());
|
|
1796
|
+
for (let i = 0; i < (nativeScripts?.len() || 0); i++) {
|
|
1797
|
+
withCMLScope((own2) => {
|
|
1798
|
+
const witness = own2(nativeScripts.get(i));
|
|
1799
|
+
const scriptHash = own2(witness.hash()).to_hex();
|
|
1800
|
+
if (!witness.verify(
|
|
1801
|
+
Number.isInteger(lowerBound) ? BigInt(lowerBound) : void 0,
|
|
1802
|
+
Number.isInteger(upperBound) ? BigInt(upperBound) : void 0,
|
|
1803
|
+
edKeyHashes
|
|
1804
|
+
)) {
|
|
1805
|
+
throw new Error(
|
|
1806
|
+
`Invalid native script witness. Script hash: ${scriptHash}`
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
const requiredSigners = own2(witness.get_required_signers());
|
|
1810
|
+
for (let j = 0; j < requiredSigners.len(); j++) {
|
|
1811
|
+
const keyHash = own2(requiredSigners.get(j)).to_hex();
|
|
1812
|
+
consumedHashes.add(keyHash);
|
|
1813
|
+
}
|
|
1814
|
+
scriptHashes.push(scriptHash);
|
|
1815
|
+
});
|
|
1805
1816
|
}
|
|
1806
1817
|
return scriptHashes;
|
|
1807
|
-
})
|
|
1818
|
+
});
|
|
1819
|
+
edKeyHashes.free();
|
|
1808
1820
|
const nativeHashesOptional = {};
|
|
1809
1821
|
const plutusHashesOptional = [];
|
|
1810
|
-
const plutusHashes = (() => {
|
|
1822
|
+
const plutusHashes = withCMLScope((own) => {
|
|
1811
1823
|
const scriptHashes = [];
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
const scriptHash = script.hash().to_hex();
|
|
1825
|
-
scriptHashes.push(scriptHash);
|
|
1826
|
-
}
|
|
1824
|
+
const collectHashes = (scripts) => {
|
|
1825
|
+
own(scripts);
|
|
1826
|
+
for (let i = 0; i < (scripts?.len() || 0); i++) {
|
|
1827
|
+
withCMLScope((own2) => {
|
|
1828
|
+
const script = own2(scripts.get(i));
|
|
1829
|
+
scriptHashes.push(own2(script.hash()).to_hex());
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
collectHashes(witnesses.plutus_v1_scripts());
|
|
1834
|
+
collectHashes(witnesses.plutus_v2_scripts());
|
|
1835
|
+
collectHashes(witnesses.plutus_v3_scripts());
|
|
1827
1836
|
return scriptHashes;
|
|
1828
|
-
})
|
|
1837
|
+
});
|
|
1829
1838
|
const inputs = body.inputs();
|
|
1830
1839
|
const resolvedInputs = [];
|
|
1831
1840
|
for (let i = 0; i < inputs.len(); i++) {
|
|
1832
|
-
const
|
|
1833
|
-
|
|
1841
|
+
const outRef = withCMLScope((own) => {
|
|
1842
|
+
const input = own(inputs.get(i));
|
|
1843
|
+
return own(input.transaction_id()).to_hex() + input.index().toString();
|
|
1844
|
+
});
|
|
1834
1845
|
const entryLedger = this.ledger[outRef];
|
|
1835
1846
|
const { entry, type } = !entryLedger ? { entry: this.mempool[outRef], type: "Mempool" } : { entry: entryLedger, type: "Ledger" };
|
|
1836
1847
|
if (!entry || entry.spent) {
|
|
@@ -1878,9 +1889,13 @@ It does not exist or was already spent.`
|
|
|
1878
1889
|
if (entry.utxo.datumHash) consumedHashes.add(entry.utxo.datumHash);
|
|
1879
1890
|
resolvedInputs.push({ entry, type });
|
|
1880
1891
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1892
|
+
inputs.free();
|
|
1893
|
+
const referenceInputs = body.reference_inputs();
|
|
1894
|
+
for (let i = 0; i < (referenceInputs?.len() || 0); i++) {
|
|
1895
|
+
const outRef = withCMLScope((own) => {
|
|
1896
|
+
const input = own(referenceInputs.get(i));
|
|
1897
|
+
return own(input.transaction_id()).to_hex() + input.index().toString();
|
|
1898
|
+
});
|
|
1884
1899
|
const entry = this.ledger[outRef] || this.mempool[outRef];
|
|
1885
1900
|
if (!entry || entry.spent) {
|
|
1886
1901
|
throw new Error(
|
|
@@ -1926,6 +1941,7 @@ It does not exist or was already spent.`
|
|
|
1926
1941
|
}
|
|
1927
1942
|
if (entry.utxo.datumHash) consumedHashes.add(entry.utxo.datumHash);
|
|
1928
1943
|
}
|
|
1944
|
+
referenceInputs?.free();
|
|
1929
1945
|
const redeemers = (() => {
|
|
1930
1946
|
const tagMap = {
|
|
1931
1947
|
0: "Spend",
|
|
@@ -2004,9 +2020,12 @@ It does not exist or was already spent.`
|
|
|
2004
2020
|
}
|
|
2005
2021
|
}
|
|
2006
2022
|
}
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
const outRef =
|
|
2023
|
+
const collateralInputs = body.collateral_inputs();
|
|
2024
|
+
for (let i = 0; i < (collateralInputs?.len() || 0); i++) {
|
|
2025
|
+
const outRef = withCMLScope((own) => {
|
|
2026
|
+
const input = own(collateralInputs.get(i));
|
|
2027
|
+
return own(input.transaction_id()).to_hex() + input.index().toString();
|
|
2028
|
+
});
|
|
2010
2029
|
const entry = this.ledger[outRef] || this.mempool[outRef];
|
|
2011
2030
|
if (!entry || entry.spent) {
|
|
2012
2031
|
throw new Error(
|
|
@@ -2023,6 +2042,7 @@ It does not exist or was already spent.`
|
|
|
2023
2042
|
}
|
|
2024
2043
|
checkAndConsumeHash(paymentCredential, null, null);
|
|
2025
2044
|
}
|
|
2045
|
+
collateralInputs?.free();
|
|
2026
2046
|
for (let i = 0; i < (body.required_signers()?.len() || 0); i++) {
|
|
2027
2047
|
const signer = body.required_signers().get(i);
|
|
2028
2048
|
checkAndConsumeHash({ type: "Key", hash: signer.to_hex() }, null, null);
|
|
@@ -2288,16 +2308,21 @@ It does not exist or was already spent.`
|
|
|
2288
2308
|
const { paymentCredential } = getAddressDetails(utxo.address);
|
|
2289
2309
|
checkAndConsumeHash(paymentCredential, "Spend", index);
|
|
2290
2310
|
});
|
|
2291
|
-
const outputs = (() => {
|
|
2311
|
+
const outputs = withCMLScope((own) => {
|
|
2292
2312
|
const collected = [];
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
const
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2313
|
+
const bodyOutputs = own(body.outputs());
|
|
2314
|
+
for (let i = 0; i < bodyOutputs.len(); i++) {
|
|
2315
|
+
const output = own(bodyOutputs.get(i));
|
|
2316
|
+
const unspentOutput = own(
|
|
2317
|
+
CML.TransactionUnspentOutput.new(
|
|
2318
|
+
own(
|
|
2319
|
+
CML.TransactionInput.new(
|
|
2320
|
+
own(CML.TransactionHash.from_hex(txHash)),
|
|
2321
|
+
BigInt(i)
|
|
2322
|
+
)
|
|
2323
|
+
),
|
|
2324
|
+
output
|
|
2325
|
+
)
|
|
2301
2326
|
);
|
|
2302
2327
|
const utxo = coreToUtxo(unspentOutput);
|
|
2303
2328
|
if (utxo.datumHash) consumedHashes.add(utxo.datumHash);
|
|
@@ -2307,7 +2332,7 @@ It does not exist or was already spent.`
|
|
|
2307
2332
|
});
|
|
2308
2333
|
}
|
|
2309
2334
|
return collected;
|
|
2310
|
-
})
|
|
2335
|
+
});
|
|
2311
2336
|
const [extraKeyHash] = keyHashes.filter(
|
|
2312
2337
|
(keyHash) => !consumedHashes.has(keyHash)
|
|
2313
2338
|
);
|
|
@@ -2381,50 +2406,57 @@ It does not exist or was already spent.`
|
|
|
2381
2406
|
this.datumTable[datumHash] = datum;
|
|
2382
2407
|
}
|
|
2383
2408
|
this.transactionHistory[txHash] = { status: "pending" };
|
|
2409
|
+
freeCML(datums, witnesses, body, desTx);
|
|
2384
2410
|
return Promise.resolve(txHash);
|
|
2385
2411
|
}
|
|
2386
2412
|
async evaluateTx(tx, additionalUTxOs) {
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
let evalRedeemers = [];
|
|
2393
|
-
const arrLegacyRedeemer = redeemers.as_arr_legacy_redeemer();
|
|
2394
|
-
if (arrLegacyRedeemer) {
|
|
2395
|
-
for (let i = 0; i < arrLegacyRedeemer.len(); i++) {
|
|
2396
|
-
const legacyRedeemer = arrLegacyRedeemer.get(i);
|
|
2397
|
-
evalRedeemers.push({
|
|
2398
|
-
ex_units: {
|
|
2399
|
-
mem: Number(legacyRedeemer.ex_units().mem()),
|
|
2400
|
-
steps: Number(legacyRedeemer.ex_units().steps())
|
|
2401
|
-
},
|
|
2402
|
-
redeemer_index: Number(legacyRedeemer.index()),
|
|
2403
|
-
redeemer_tag: fromCMLRedeemerTag(legacyRedeemer.tag())
|
|
2404
|
-
});
|
|
2413
|
+
return withCMLScope((own) => {
|
|
2414
|
+
const desTx = own(CML.Transaction.from_cbor_hex(tx));
|
|
2415
|
+
const redeemers = own(own(desTx.witness_set()).redeemers());
|
|
2416
|
+
if (!redeemers) {
|
|
2417
|
+
return [];
|
|
2405
2418
|
}
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
const key = keys.get(i);
|
|
2413
|
-
const redeemerVal = mapRedeemerKeyToRedeemerVal.get(key);
|
|
2414
|
-
if (redeemerVal) {
|
|
2419
|
+
const evalRedeemers = [];
|
|
2420
|
+
const arrLegacyRedeemer = own(redeemers.as_arr_legacy_redeemer());
|
|
2421
|
+
if (arrLegacyRedeemer) {
|
|
2422
|
+
for (let i = 0; i < arrLegacyRedeemer.len(); i++) {
|
|
2423
|
+
const legacyRedeemer = own(arrLegacyRedeemer.get(i));
|
|
2424
|
+
const exUnits = own(legacyRedeemer.ex_units());
|
|
2415
2425
|
evalRedeemers.push({
|
|
2416
2426
|
ex_units: {
|
|
2417
|
-
mem: Number(
|
|
2418
|
-
steps: Number(
|
|
2427
|
+
mem: Number(exUnits.mem()),
|
|
2428
|
+
steps: Number(exUnits.steps())
|
|
2419
2429
|
},
|
|
2420
|
-
redeemer_index: Number(
|
|
2421
|
-
redeemer_tag: fromCMLRedeemerTag(
|
|
2430
|
+
redeemer_index: Number(legacyRedeemer.index()),
|
|
2431
|
+
redeemer_tag: fromCMLRedeemerTag(legacyRedeemer.tag())
|
|
2422
2432
|
});
|
|
2423
2433
|
}
|
|
2434
|
+
return evalRedeemers;
|
|
2435
|
+
}
|
|
2436
|
+
const mapRedeemerKeyToRedeemerVal = own(
|
|
2437
|
+
redeemers.as_map_redeemer_key_to_redeemer_val()
|
|
2438
|
+
);
|
|
2439
|
+
if (mapRedeemerKeyToRedeemerVal) {
|
|
2440
|
+
const keys = own(mapRedeemerKeyToRedeemerVal.keys());
|
|
2441
|
+
for (let i = 0; i < keys.len(); i++) {
|
|
2442
|
+
const key = own(keys.get(i));
|
|
2443
|
+
const redeemerVal = own(mapRedeemerKeyToRedeemerVal.get(key));
|
|
2444
|
+
if (redeemerVal) {
|
|
2445
|
+
const exUnits = own(redeemerVal.ex_units());
|
|
2446
|
+
evalRedeemers.push({
|
|
2447
|
+
ex_units: {
|
|
2448
|
+
mem: Number(exUnits.mem()),
|
|
2449
|
+
steps: Number(exUnits.steps())
|
|
2450
|
+
},
|
|
2451
|
+
redeemer_index: Number(key.index()),
|
|
2452
|
+
redeemer_tag: fromCMLRedeemerTag(key.tag())
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return evalRedeemers;
|
|
2424
2457
|
}
|
|
2425
2458
|
return evalRedeemers;
|
|
2426
|
-
}
|
|
2427
|
-
return evalRedeemers;
|
|
2459
|
+
});
|
|
2428
2460
|
}
|
|
2429
2461
|
log() {
|
|
2430
2462
|
function getRandomColor(unit) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/provider",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"@effect/schema": "^0.68.26",
|
|
32
32
|
"effect": "^3.11.7",
|
|
33
33
|
"@lucid-evolution/core-types": "0.3.0",
|
|
34
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
35
|
-
"@lucid-evolution/utils": "0.1.
|
|
36
|
-
"@lucid-evolution/wallet": "0.2.
|
|
34
|
+
"@lucid-evolution/core-utils": "0.1.17",
|
|
35
|
+
"@lucid-evolution/utils": "0.1.74",
|
|
36
|
+
"@lucid-evolution/wallet": "0.2.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^20.12.8",
|