@meshsdk/transaction 1.6.9 → 1.6.11
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 +93 -40
- package/dist/index.d.cts +19 -12
- package/dist/index.d.ts +19 -12
- package/dist/index.js +93 -40
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1286,7 +1286,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1286
1286
|
submitter,
|
|
1287
1287
|
evaluator,
|
|
1288
1288
|
params,
|
|
1289
|
-
isHydra = false
|
|
1289
|
+
isHydra = false,
|
|
1290
|
+
verbose = false
|
|
1290
1291
|
} = {}) {
|
|
1291
1292
|
super();
|
|
1292
1293
|
if (serializer) {
|
|
@@ -1294,6 +1295,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1294
1295
|
} else {
|
|
1295
1296
|
this.serializer = new import_core_csl.CSLSerializer();
|
|
1296
1297
|
}
|
|
1298
|
+
this.serializer.verbose = verbose;
|
|
1297
1299
|
if (fetcher) this.fetcher = fetcher;
|
|
1298
1300
|
if (submitter) this.submitter = submitter;
|
|
1299
1301
|
if (evaluator) this.evaluator = evaluator;
|
|
@@ -1320,14 +1322,25 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1320
1322
|
this.queueAllLastItem();
|
|
1321
1323
|
}
|
|
1322
1324
|
this.removeDuplicateInputs();
|
|
1323
|
-
const { inputs, collaterals } = this.meshTxBuilderBody;
|
|
1325
|
+
const { inputs, collaterals, mints } = this.meshTxBuilderBody;
|
|
1324
1326
|
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1325
1327
|
(txIn) => !this.isInputComplete(txIn)
|
|
1326
1328
|
);
|
|
1327
|
-
|
|
1329
|
+
const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
|
|
1330
|
+
await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
|
|
1328
1331
|
incompleteTxIns.forEach((txIn) => {
|
|
1329
1332
|
this.completeTxInformation(txIn);
|
|
1330
1333
|
});
|
|
1334
|
+
incompleteMints.forEach((mint) => {
|
|
1335
|
+
if (mint.type === "Plutus") {
|
|
1336
|
+
const scriptSource = mint.scriptSource;
|
|
1337
|
+
this.completeScriptInfo(scriptSource);
|
|
1338
|
+
}
|
|
1339
|
+
if (mint.type === "Native") {
|
|
1340
|
+
const scriptSource = mint.scriptSource;
|
|
1341
|
+
this.completeSimpleScriptInfo(scriptSource);
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1331
1344
|
this.addUtxosFromSelection();
|
|
1332
1345
|
let txHex = this.serializer.serializeTxBody(
|
|
1333
1346
|
this.meshTxBuilderBody,
|
|
@@ -1387,7 +1400,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1387
1400
|
};
|
|
1388
1401
|
/**
|
|
1389
1402
|
* Get the UTxO information from the blockchain
|
|
1390
|
-
* @param
|
|
1403
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
1391
1404
|
*/
|
|
1392
1405
|
getUTxOInfo = async (txHash) => {
|
|
1393
1406
|
let utxos = [];
|
|
@@ -1397,9 +1410,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1397
1410
|
this.queriedUTxOs[txHash] = utxos;
|
|
1398
1411
|
}
|
|
1399
1412
|
};
|
|
1400
|
-
queryAllTxInfo = (incompleteTxIns) => {
|
|
1413
|
+
queryAllTxInfo = (incompleteTxIns, incompleteMints) => {
|
|
1401
1414
|
const queryUTxOPromises = [];
|
|
1402
|
-
if (incompleteTxIns.length > 0 && !this.fetcher)
|
|
1415
|
+
if ((incompleteTxIns.length > 0 || incompleteMints.length > 0) && !this.fetcher)
|
|
1403
1416
|
throw Error(
|
|
1404
1417
|
"Transaction information is incomplete while no fetcher instance is provided"
|
|
1405
1418
|
);
|
|
@@ -1408,68 +1421,108 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1408
1421
|
if (!this.isInputInfoComplete(currentTxIn)) {
|
|
1409
1422
|
queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
|
|
1410
1423
|
}
|
|
1411
|
-
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn)) {
|
|
1424
|
+
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn.scriptTxIn.scriptSource)) {
|
|
1412
1425
|
queryUTxOPromises.push(
|
|
1413
1426
|
this.getUTxOInfo(currentTxIn.scriptTxIn.scriptSource.txHash)
|
|
1414
1427
|
);
|
|
1415
1428
|
}
|
|
1416
1429
|
}
|
|
1430
|
+
for (let i = 0; i < incompleteMints.length; i++) {
|
|
1431
|
+
const currentMint = incompleteMints[i];
|
|
1432
|
+
if (currentMint.type === "Plutus") {
|
|
1433
|
+
const scriptSource = currentMint.scriptSource;
|
|
1434
|
+
if (scriptSource.type === "Inline") {
|
|
1435
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
1436
|
+
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1417
1441
|
return Promise.all(queryUTxOPromises);
|
|
1418
1442
|
};
|
|
1419
1443
|
completeTxInformation = (input) => {
|
|
1420
1444
|
if (!this.isInputInfoComplete(input)) {
|
|
1421
|
-
|
|
1422
|
-
const utxo = utxos?.find(
|
|
1423
|
-
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1424
|
-
);
|
|
1425
|
-
const amount = utxo?.output.amount;
|
|
1426
|
-
const address = utxo?.output.address;
|
|
1427
|
-
if (!amount || amount.length === 0)
|
|
1428
|
-
throw Error(
|
|
1429
|
-
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1430
|
-
);
|
|
1431
|
-
input.txIn.amount = amount;
|
|
1432
|
-
if (input.type === "PubKey") {
|
|
1433
|
-
if (!address || address === "")
|
|
1434
|
-
throw Error(
|
|
1435
|
-
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1436
|
-
);
|
|
1437
|
-
input.txIn.address = address;
|
|
1438
|
-
}
|
|
1445
|
+
this.completeInputInfo(input);
|
|
1439
1446
|
}
|
|
1440
|
-
if (input.type === "Script" &&
|
|
1447
|
+
if (input.type === "Script" && !this.isRefScriptInfoComplete(input.scriptTxIn.scriptSource)) {
|
|
1441
1448
|
const scriptSource = input.scriptTxIn.scriptSource;
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1449
|
+
this.completeScriptInfo(scriptSource);
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
completeInputInfo = (input) => {
|
|
1453
|
+
const utxos = this.queriedUTxOs[input.txIn.txHash];
|
|
1454
|
+
const utxo = utxos?.find(
|
|
1455
|
+
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1456
|
+
);
|
|
1457
|
+
const amount = utxo?.output.amount;
|
|
1458
|
+
const address = utxo?.output.address;
|
|
1459
|
+
if (!amount || amount.length === 0)
|
|
1460
|
+
throw Error(
|
|
1461
|
+
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1445
1462
|
);
|
|
1446
|
-
|
|
1463
|
+
input.txIn.amount = amount;
|
|
1464
|
+
if (input.type === "PubKey") {
|
|
1465
|
+
if (!address || address === "")
|
|
1447
1466
|
throw Error(
|
|
1448
|
-
`Couldn't find
|
|
1467
|
+
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1449
1468
|
);
|
|
1450
|
-
|
|
1451
|
-
scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
|
|
1469
|
+
input.txIn.address = address;
|
|
1452
1470
|
}
|
|
1453
1471
|
};
|
|
1472
|
+
completeScriptInfo = (scriptSource) => {
|
|
1473
|
+
if (scriptSource?.type != "Inline") return;
|
|
1474
|
+
const refUtxos = this.queriedUTxOs[scriptSource.txHash];
|
|
1475
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1476
|
+
(utxo) => utxo.input.outputIndex === scriptSource.txIndex
|
|
1477
|
+
);
|
|
1478
|
+
if (!scriptRefUtxo)
|
|
1479
|
+
throw Error(
|
|
1480
|
+
`Couldn't find script reference utxo for ${scriptSource.txHash}#${scriptSource.txIndex}`
|
|
1481
|
+
);
|
|
1482
|
+
scriptSource.scriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1483
|
+
scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
|
|
1484
|
+
};
|
|
1485
|
+
completeSimpleScriptInfo = (simpleScript) => {
|
|
1486
|
+
if (simpleScript.type !== "Inline") return;
|
|
1487
|
+
const refUtxos = this.queriedUTxOs[simpleScript.txHash];
|
|
1488
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1489
|
+
(utxo) => utxo.input.outputIndex === simpleScript.txIndex
|
|
1490
|
+
);
|
|
1491
|
+
if (!scriptRefUtxo)
|
|
1492
|
+
throw Error(
|
|
1493
|
+
`Couldn't find script reference utxo for ${simpleScript.txHash}#${simpleScript.txIndex}`
|
|
1494
|
+
);
|
|
1495
|
+
simpleScript.simpleScriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1496
|
+
};
|
|
1454
1497
|
isInputComplete = (txIn) => {
|
|
1455
1498
|
if (txIn.type === "PubKey") return this.isInputInfoComplete(txIn);
|
|
1456
1499
|
if (txIn.type === "Script") {
|
|
1457
|
-
|
|
1500
|
+
const { scriptSource } = txIn.scriptTxIn;
|
|
1501
|
+
return this.isInputInfoComplete(txIn) && this.isRefScriptInfoComplete(scriptSource);
|
|
1458
1502
|
}
|
|
1459
1503
|
return true;
|
|
1460
1504
|
};
|
|
1461
1505
|
isInputInfoComplete = (txIn) => {
|
|
1462
1506
|
const { amount, address } = txIn.txIn;
|
|
1463
|
-
if (
|
|
1464
|
-
|
|
1465
|
-
|
|
1507
|
+
if (!amount || !address) return false;
|
|
1508
|
+
return true;
|
|
1509
|
+
};
|
|
1510
|
+
isMintComplete = (mint) => {
|
|
1511
|
+
if (mint.type === "Plutus") {
|
|
1512
|
+
const scriptSource = mint.scriptSource;
|
|
1513
|
+
return this.isRefScriptInfoComplete(scriptSource);
|
|
1514
|
+
}
|
|
1515
|
+
if (mint.type === "Native") {
|
|
1516
|
+
const scriptSource = mint.scriptSource;
|
|
1517
|
+
if (scriptSource.type === "Inline") {
|
|
1518
|
+
if (!scriptSource?.simpleScriptHash) return false;
|
|
1519
|
+
}
|
|
1466
1520
|
}
|
|
1467
1521
|
return true;
|
|
1468
1522
|
};
|
|
1469
|
-
isRefScriptInfoComplete = (
|
|
1470
|
-
const { scriptSource } = scriptTxIn.scriptTxIn;
|
|
1523
|
+
isRefScriptInfoComplete = (scriptSource) => {
|
|
1471
1524
|
if (scriptSource?.type === "Inline") {
|
|
1472
|
-
if (scriptSource?.scriptHash || scriptSource?.scriptSize) return false;
|
|
1525
|
+
if (!scriptSource?.scriptHash || !scriptSource?.scriptSize) return false;
|
|
1473
1526
|
}
|
|
1474
1527
|
return true;
|
|
1475
1528
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Network, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
1
|
+
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Network, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, ScriptSource, SimpleScriptSourceInfo, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
2
2
|
|
|
3
3
|
declare class MeshTxBuilderCore {
|
|
4
4
|
txEvaluationMultiplier: number;
|
|
@@ -387,6 +387,7 @@ interface MeshTxBuilderOptions {
|
|
|
387
387
|
serializer?: IMeshTxSerializer;
|
|
388
388
|
isHydra?: boolean;
|
|
389
389
|
params?: Partial<Protocol>;
|
|
390
|
+
verbose?: boolean;
|
|
390
391
|
}
|
|
391
392
|
declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
392
393
|
serializer: IMeshTxSerializer;
|
|
@@ -394,9 +395,11 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
394
395
|
submitter?: ISubmitter;
|
|
395
396
|
evaluator?: IEvaluator;
|
|
396
397
|
txHex: string;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
protected queriedTxHashes: Set<string>;
|
|
399
|
+
protected queriedUTxOs: {
|
|
400
|
+
[x: string]: UTxO[];
|
|
401
|
+
};
|
|
402
|
+
constructor({ serializer, fetcher, submitter, evaluator, params, isHydra, verbose, }?: MeshTxBuilderOptions);
|
|
400
403
|
/**
|
|
401
404
|
* It builds the transaction and query the blockchain for missing information
|
|
402
405
|
* @param customizedTx The optional customized transaction body
|
|
@@ -422,14 +425,18 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
422
425
|
submitTx: (txHex: string) => Promise<string | undefined>;
|
|
423
426
|
/**
|
|
424
427
|
* Get the UTxO information from the blockchain
|
|
425
|
-
* @param
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
428
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
429
|
+
*/
|
|
430
|
+
protected getUTxOInfo: (txHash: string) => Promise<void>;
|
|
431
|
+
protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteMints: MintItem[]) => Promise<void[]>;
|
|
432
|
+
protected completeTxInformation: (input: TxIn) => void;
|
|
433
|
+
protected completeInputInfo: (input: TxIn) => void;
|
|
434
|
+
protected completeScriptInfo: (scriptSource: ScriptSource) => void;
|
|
435
|
+
protected completeSimpleScriptInfo: (simpleScript: SimpleScriptSourceInfo) => void;
|
|
436
|
+
protected isInputComplete: (txIn: TxIn) => boolean;
|
|
437
|
+
protected isInputInfoComplete: (txIn: TxIn) => boolean;
|
|
438
|
+
protected isMintComplete: (mint: MintItem) => boolean;
|
|
439
|
+
protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
|
|
433
440
|
}
|
|
434
441
|
|
|
435
442
|
declare class ForgeScript {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Network, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
1
|
+
import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Network, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, ScriptSource, SimpleScriptSourceInfo, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
2
2
|
|
|
3
3
|
declare class MeshTxBuilderCore {
|
|
4
4
|
txEvaluationMultiplier: number;
|
|
@@ -387,6 +387,7 @@ interface MeshTxBuilderOptions {
|
|
|
387
387
|
serializer?: IMeshTxSerializer;
|
|
388
388
|
isHydra?: boolean;
|
|
389
389
|
params?: Partial<Protocol>;
|
|
390
|
+
verbose?: boolean;
|
|
390
391
|
}
|
|
391
392
|
declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
392
393
|
serializer: IMeshTxSerializer;
|
|
@@ -394,9 +395,11 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
394
395
|
submitter?: ISubmitter;
|
|
395
396
|
evaluator?: IEvaluator;
|
|
396
397
|
txHex: string;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
protected queriedTxHashes: Set<string>;
|
|
399
|
+
protected queriedUTxOs: {
|
|
400
|
+
[x: string]: UTxO[];
|
|
401
|
+
};
|
|
402
|
+
constructor({ serializer, fetcher, submitter, evaluator, params, isHydra, verbose, }?: MeshTxBuilderOptions);
|
|
400
403
|
/**
|
|
401
404
|
* It builds the transaction and query the blockchain for missing information
|
|
402
405
|
* @param customizedTx The optional customized transaction body
|
|
@@ -422,14 +425,18 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
422
425
|
submitTx: (txHex: string) => Promise<string | undefined>;
|
|
423
426
|
/**
|
|
424
427
|
* Get the UTxO information from the blockchain
|
|
425
|
-
* @param
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
428
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
429
|
+
*/
|
|
430
|
+
protected getUTxOInfo: (txHash: string) => Promise<void>;
|
|
431
|
+
protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteMints: MintItem[]) => Promise<void[]>;
|
|
432
|
+
protected completeTxInformation: (input: TxIn) => void;
|
|
433
|
+
protected completeInputInfo: (input: TxIn) => void;
|
|
434
|
+
protected completeScriptInfo: (scriptSource: ScriptSource) => void;
|
|
435
|
+
protected completeSimpleScriptInfo: (simpleScript: SimpleScriptSourceInfo) => void;
|
|
436
|
+
protected isInputComplete: (txIn: TxIn) => boolean;
|
|
437
|
+
protected isInputInfoComplete: (txIn: TxIn) => boolean;
|
|
438
|
+
protected isMintComplete: (mint: MintItem) => boolean;
|
|
439
|
+
protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
|
|
433
440
|
}
|
|
434
441
|
|
|
435
442
|
declare class ForgeScript {
|
package/dist/index.js
CHANGED
|
@@ -1252,7 +1252,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1252
1252
|
submitter,
|
|
1253
1253
|
evaluator,
|
|
1254
1254
|
params,
|
|
1255
|
-
isHydra = false
|
|
1255
|
+
isHydra = false,
|
|
1256
|
+
verbose = false
|
|
1256
1257
|
} = {}) {
|
|
1257
1258
|
super();
|
|
1258
1259
|
if (serializer) {
|
|
@@ -1260,6 +1261,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1260
1261
|
} else {
|
|
1261
1262
|
this.serializer = new CSLSerializer();
|
|
1262
1263
|
}
|
|
1264
|
+
this.serializer.verbose = verbose;
|
|
1263
1265
|
if (fetcher) this.fetcher = fetcher;
|
|
1264
1266
|
if (submitter) this.submitter = submitter;
|
|
1265
1267
|
if (evaluator) this.evaluator = evaluator;
|
|
@@ -1286,14 +1288,25 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1286
1288
|
this.queueAllLastItem();
|
|
1287
1289
|
}
|
|
1288
1290
|
this.removeDuplicateInputs();
|
|
1289
|
-
const { inputs, collaterals } = this.meshTxBuilderBody;
|
|
1291
|
+
const { inputs, collaterals, mints } = this.meshTxBuilderBody;
|
|
1290
1292
|
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1291
1293
|
(txIn) => !this.isInputComplete(txIn)
|
|
1292
1294
|
);
|
|
1293
|
-
|
|
1295
|
+
const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
|
|
1296
|
+
await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
|
|
1294
1297
|
incompleteTxIns.forEach((txIn) => {
|
|
1295
1298
|
this.completeTxInformation(txIn);
|
|
1296
1299
|
});
|
|
1300
|
+
incompleteMints.forEach((mint) => {
|
|
1301
|
+
if (mint.type === "Plutus") {
|
|
1302
|
+
const scriptSource = mint.scriptSource;
|
|
1303
|
+
this.completeScriptInfo(scriptSource);
|
|
1304
|
+
}
|
|
1305
|
+
if (mint.type === "Native") {
|
|
1306
|
+
const scriptSource = mint.scriptSource;
|
|
1307
|
+
this.completeSimpleScriptInfo(scriptSource);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1297
1310
|
this.addUtxosFromSelection();
|
|
1298
1311
|
let txHex = this.serializer.serializeTxBody(
|
|
1299
1312
|
this.meshTxBuilderBody,
|
|
@@ -1353,7 +1366,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1353
1366
|
};
|
|
1354
1367
|
/**
|
|
1355
1368
|
* Get the UTxO information from the blockchain
|
|
1356
|
-
* @param
|
|
1369
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
1357
1370
|
*/
|
|
1358
1371
|
getUTxOInfo = async (txHash) => {
|
|
1359
1372
|
let utxos = [];
|
|
@@ -1363,9 +1376,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1363
1376
|
this.queriedUTxOs[txHash] = utxos;
|
|
1364
1377
|
}
|
|
1365
1378
|
};
|
|
1366
|
-
queryAllTxInfo = (incompleteTxIns) => {
|
|
1379
|
+
queryAllTxInfo = (incompleteTxIns, incompleteMints) => {
|
|
1367
1380
|
const queryUTxOPromises = [];
|
|
1368
|
-
if (incompleteTxIns.length > 0 && !this.fetcher)
|
|
1381
|
+
if ((incompleteTxIns.length > 0 || incompleteMints.length > 0) && !this.fetcher)
|
|
1369
1382
|
throw Error(
|
|
1370
1383
|
"Transaction information is incomplete while no fetcher instance is provided"
|
|
1371
1384
|
);
|
|
@@ -1374,68 +1387,108 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1374
1387
|
if (!this.isInputInfoComplete(currentTxIn)) {
|
|
1375
1388
|
queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
|
|
1376
1389
|
}
|
|
1377
|
-
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn)) {
|
|
1390
|
+
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn.scriptTxIn.scriptSource)) {
|
|
1378
1391
|
queryUTxOPromises.push(
|
|
1379
1392
|
this.getUTxOInfo(currentTxIn.scriptTxIn.scriptSource.txHash)
|
|
1380
1393
|
);
|
|
1381
1394
|
}
|
|
1382
1395
|
}
|
|
1396
|
+
for (let i = 0; i < incompleteMints.length; i++) {
|
|
1397
|
+
const currentMint = incompleteMints[i];
|
|
1398
|
+
if (currentMint.type === "Plutus") {
|
|
1399
|
+
const scriptSource = currentMint.scriptSource;
|
|
1400
|
+
if (scriptSource.type === "Inline") {
|
|
1401
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
1402
|
+
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1383
1407
|
return Promise.all(queryUTxOPromises);
|
|
1384
1408
|
};
|
|
1385
1409
|
completeTxInformation = (input) => {
|
|
1386
1410
|
if (!this.isInputInfoComplete(input)) {
|
|
1387
|
-
|
|
1388
|
-
const utxo = utxos?.find(
|
|
1389
|
-
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1390
|
-
);
|
|
1391
|
-
const amount = utxo?.output.amount;
|
|
1392
|
-
const address = utxo?.output.address;
|
|
1393
|
-
if (!amount || amount.length === 0)
|
|
1394
|
-
throw Error(
|
|
1395
|
-
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1396
|
-
);
|
|
1397
|
-
input.txIn.amount = amount;
|
|
1398
|
-
if (input.type === "PubKey") {
|
|
1399
|
-
if (!address || address === "")
|
|
1400
|
-
throw Error(
|
|
1401
|
-
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1402
|
-
);
|
|
1403
|
-
input.txIn.address = address;
|
|
1404
|
-
}
|
|
1411
|
+
this.completeInputInfo(input);
|
|
1405
1412
|
}
|
|
1406
|
-
if (input.type === "Script" &&
|
|
1413
|
+
if (input.type === "Script" && !this.isRefScriptInfoComplete(input.scriptTxIn.scriptSource)) {
|
|
1407
1414
|
const scriptSource = input.scriptTxIn.scriptSource;
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1415
|
+
this.completeScriptInfo(scriptSource);
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
completeInputInfo = (input) => {
|
|
1419
|
+
const utxos = this.queriedUTxOs[input.txIn.txHash];
|
|
1420
|
+
const utxo = utxos?.find(
|
|
1421
|
+
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1422
|
+
);
|
|
1423
|
+
const amount = utxo?.output.amount;
|
|
1424
|
+
const address = utxo?.output.address;
|
|
1425
|
+
if (!amount || amount.length === 0)
|
|
1426
|
+
throw Error(
|
|
1427
|
+
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1411
1428
|
);
|
|
1412
|
-
|
|
1429
|
+
input.txIn.amount = amount;
|
|
1430
|
+
if (input.type === "PubKey") {
|
|
1431
|
+
if (!address || address === "")
|
|
1413
1432
|
throw Error(
|
|
1414
|
-
`Couldn't find
|
|
1433
|
+
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1415
1434
|
);
|
|
1416
|
-
|
|
1417
|
-
scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
|
|
1435
|
+
input.txIn.address = address;
|
|
1418
1436
|
}
|
|
1419
1437
|
};
|
|
1438
|
+
completeScriptInfo = (scriptSource) => {
|
|
1439
|
+
if (scriptSource?.type != "Inline") return;
|
|
1440
|
+
const refUtxos = this.queriedUTxOs[scriptSource.txHash];
|
|
1441
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1442
|
+
(utxo) => utxo.input.outputIndex === scriptSource.txIndex
|
|
1443
|
+
);
|
|
1444
|
+
if (!scriptRefUtxo)
|
|
1445
|
+
throw Error(
|
|
1446
|
+
`Couldn't find script reference utxo for ${scriptSource.txHash}#${scriptSource.txIndex}`
|
|
1447
|
+
);
|
|
1448
|
+
scriptSource.scriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1449
|
+
scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
|
|
1450
|
+
};
|
|
1451
|
+
completeSimpleScriptInfo = (simpleScript) => {
|
|
1452
|
+
if (simpleScript.type !== "Inline") return;
|
|
1453
|
+
const refUtxos = this.queriedUTxOs[simpleScript.txHash];
|
|
1454
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1455
|
+
(utxo) => utxo.input.outputIndex === simpleScript.txIndex
|
|
1456
|
+
);
|
|
1457
|
+
if (!scriptRefUtxo)
|
|
1458
|
+
throw Error(
|
|
1459
|
+
`Couldn't find script reference utxo for ${simpleScript.txHash}#${simpleScript.txIndex}`
|
|
1460
|
+
);
|
|
1461
|
+
simpleScript.simpleScriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1462
|
+
};
|
|
1420
1463
|
isInputComplete = (txIn) => {
|
|
1421
1464
|
if (txIn.type === "PubKey") return this.isInputInfoComplete(txIn);
|
|
1422
1465
|
if (txIn.type === "Script") {
|
|
1423
|
-
|
|
1466
|
+
const { scriptSource } = txIn.scriptTxIn;
|
|
1467
|
+
return this.isInputInfoComplete(txIn) && this.isRefScriptInfoComplete(scriptSource);
|
|
1424
1468
|
}
|
|
1425
1469
|
return true;
|
|
1426
1470
|
};
|
|
1427
1471
|
isInputInfoComplete = (txIn) => {
|
|
1428
1472
|
const { amount, address } = txIn.txIn;
|
|
1429
|
-
if (
|
|
1430
|
-
|
|
1431
|
-
|
|
1473
|
+
if (!amount || !address) return false;
|
|
1474
|
+
return true;
|
|
1475
|
+
};
|
|
1476
|
+
isMintComplete = (mint) => {
|
|
1477
|
+
if (mint.type === "Plutus") {
|
|
1478
|
+
const scriptSource = mint.scriptSource;
|
|
1479
|
+
return this.isRefScriptInfoComplete(scriptSource);
|
|
1480
|
+
}
|
|
1481
|
+
if (mint.type === "Native") {
|
|
1482
|
+
const scriptSource = mint.scriptSource;
|
|
1483
|
+
if (scriptSource.type === "Inline") {
|
|
1484
|
+
if (!scriptSource?.simpleScriptHash) return false;
|
|
1485
|
+
}
|
|
1432
1486
|
}
|
|
1433
1487
|
return true;
|
|
1434
1488
|
};
|
|
1435
|
-
isRefScriptInfoComplete = (
|
|
1436
|
-
const { scriptSource } = scriptTxIn.scriptTxIn;
|
|
1489
|
+
isRefScriptInfoComplete = (scriptSource) => {
|
|
1437
1490
|
if (scriptSource?.type === "Inline") {
|
|
1438
|
-
if (scriptSource?.scriptHash || scriptSource?.scriptSize) return false;
|
|
1491
|
+
if (!scriptSource?.scriptHash || !scriptSource?.scriptSize) return false;
|
|
1439
1492
|
}
|
|
1440
1493
|
return true;
|
|
1441
1494
|
};
|