diff --git a/package-lock.json b/package-lock.json index 7def41d6..e6ba404d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13203,14 +13203,16 @@ "dev": true }, "node_modules/@sidan-lab/sidan-csl-rs-browser": { - "version": "0.8.7", - "resolved": "https://registry.npmjs.org/@sidan-lab/sidan-csl-rs-browser/-/sidan-csl-rs-browser-0.8.7.tgz", - "integrity": "sha512-8Psoxptlv9tyFRXj5YNR+74zeMoMdoLkGLf6jjzlxlD1MnQhw3qlJ3cPNsicDVfffcNRsPMAhicoH5qVWN8AgQ==" + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/@sidan-lab/sidan-csl-rs-browser/-/sidan-csl-rs-browser-0.9.4.tgz", + "integrity": "sha512-+WUeS0aTkh+j/kSjY/qFcXdJQUfhKvZAAxXrjv+i2/EaIphcv1XDGb05CoPUaX+4nUh2lLssFAnc4tEhei3w/w==", + "license": "Apache-2.0" }, "node_modules/@sidan-lab/sidan-csl-rs-nodejs": { - "version": "0.8.7", - "resolved": "https://registry.npmjs.org/@sidan-lab/sidan-csl-rs-nodejs/-/sidan-csl-rs-nodejs-0.8.7.tgz", - "integrity": "sha512-IAJyqDgKDesebJ/En4haphBO0zUEuz6mar3TDvtkqng/Kf6Pm7qBPp7vi5Yf2/A/S9Ik6gnIL8XflrGxNoqpVQ==" + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/@sidan-lab/sidan-csl-rs-nodejs/-/sidan-csl-rs-nodejs-0.9.4.tgz", + "integrity": "sha512-dmuEkPiDWcdlkOiE72HS3EkY8/XwMxR/ottgrcNcUw6fw09CSL5lynqklQEkTgwV060btvhjZ87ELfEda3w/pA==", + "license": "Apache-2.0" }, "node_modules/@sinclair/typebox": { "version": "0.27.8", @@ -29445,8 +29447,8 @@ "license": "Apache-2.0", "dependencies": { "@meshsdk/common": "1.7.9", - "@sidan-lab/sidan-csl-rs-browser": "0.8.7", - "@sidan-lab/sidan-csl-rs-nodejs": "0.8.7", + "@sidan-lab/sidan-csl-rs-browser": "0.9.4", + "@sidan-lab/sidan-csl-rs-nodejs": "0.9.4", "json-bigint": "^1.0.0" }, "devDependencies": { diff --git a/packages/mesh-common/src/types/transaction-builder/txin.ts b/packages/mesh-common/src/types/transaction-builder/txin.ts index ca0b170e..2e067f6d 100644 --- a/packages/mesh-common/src/types/transaction-builder/txin.ts +++ b/packages/mesh-common/src/types/transaction-builder/txin.ts @@ -2,7 +2,7 @@ import { Asset } from "../asset"; import { DatumSource, Redeemer } from "./data"; import { ScriptSource, SimpleScriptSourceInfo } from "./script"; -export type RefTxIn = { txHash: string; txIndex: number }; +export type RefTxIn = { txHash: string; txIndex: number, scriptSize?: number }; export type TxInParameter = { txHash: string; diff --git a/packages/mesh-core-csl/package.json b/packages/mesh-core-csl/package.json index 50adeeb9..14d85999 100644 --- a/packages/mesh-core-csl/package.json +++ b/packages/mesh-core-csl/package.json @@ -39,8 +39,8 @@ }, "dependencies": { "@meshsdk/common": "1.7.9", - "@sidan-lab/sidan-csl-rs-browser": "0.8.7", - "@sidan-lab/sidan-csl-rs-nodejs": "0.8.7", + "@sidan-lab/sidan-csl-rs-browser": "0.9.4", + "@sidan-lab/sidan-csl-rs-nodejs": "0.9.4", "json-bigint": "^1.0.0" }, "prettier": "@meshsdk/configs/prettier", diff --git a/packages/mesh-core-csl/test/core/builder.test.ts b/packages/mesh-core-csl/test/core/builder.test.ts index 726b23d6..bc690b18 100644 --- a/packages/mesh-core-csl/test/core/builder.test.ts +++ b/packages/mesh-core-csl/test/core/builder.test.ts @@ -95,7 +95,7 @@ describe("Builder", () => { }; const txHex = serializer.serializeTxBody(body, DEFAULT_PROTOCOL_PARAMETERS); expect(txHex).toEqual( - "84a300818258201662c4b349907e4d92e0995fd9dcdc9a4489f7dff4f5cce6b4b3901de479308c0e0182825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a0012c97f825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a2e16c3f4021a00029075a0f5f6", + "84a300d90102818258201662c4b349907e4d92e0995fd9dcdc9a4489f7dff4f5cce6b4b3901de479308c0e0182825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a0012c97f825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a2e16c2ec021a0002917da0f5f6", ); }); }); diff --git a/packages/mesh-transaction/src/mesh-tx-builder/index.ts b/packages/mesh-transaction/src/mesh-tx-builder/index.ts index e02aea58..37affecc 100644 --- a/packages/mesh-transaction/src/mesh-tx-builder/index.ts +++ b/packages/mesh-transaction/src/mesh-tx-builder/index.ts @@ -35,6 +35,7 @@ export class MeshTxBuilder extends MeshTxBuilderCore { txHex: string = ""; protected queriedTxHashes: Set = new Set(); protected queriedUTxOs: { [x: string]: UTxO[] } = {}; + protected utxosWithRefScripts: UTxO[] = []; constructor({ serializer, @@ -83,12 +84,39 @@ export class MeshTxBuilder extends MeshTxBuilderCore { // Checking if all inputs are complete const { inputs, collaterals, mints } = this.meshTxBuilderBody; - const incompleteTxIns = [...inputs, ...collaterals].filter( - (txIn) => !this.isInputComplete(txIn), - ); + // We must check every input for ref scripts + const incompleteTxIns = [...inputs, ...collaterals]; const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint)); // Getting all missing utxo information await this.queryAllTxInfo(incompleteTxIns, incompleteMints); + // Gather all utxos with ref scripts + Object.values(this.queriedUTxOs).forEach((utxos) => { + for (let utxo of utxos) { + if (utxo.output.scriptRef !== undefined) { + this.utxosWithRefScripts.push(utxo); + } + } + }); + const missingRefInput = this.utxosWithRefScripts.filter((utxo) => { + this.meshTxBuilderBody.referenceInputs.forEach((refInput) => { + if ( + refInput.txHash === utxo.input.txHash && + refInput.txIndex === utxo.input.outputIndex + ) { + return false; + } + }); + return true; + }); + // Add any inputs with ref scripts into reference inputs + // serializer will then deduplicate, but keep the script size for fee calc + missingRefInput.forEach((utxo) => { + this.meshTxBuilderBody.referenceInputs.push({ + txHash: utxo.input.txHash, + txIndex: utxo.input.outputIndex, + scriptSize: utxo.output.scriptRef!.length / 2, + }); + }); // Completing all inputs incompleteTxIns.forEach((txIn) => { this.completeTxInformation(txIn); diff --git a/packages/mesh-transaction/src/mesh-tx-builder/tx-builder-core.ts b/packages/mesh-transaction/src/mesh-tx-builder/tx-builder-core.ts index 6cf364a2..a52fbf5f 100644 --- a/packages/mesh-transaction/src/mesh-tx-builder/tx-builder-core.ts +++ b/packages/mesh-transaction/src/mesh-tx-builder/tx-builder-core.ts @@ -544,8 +544,16 @@ export class MeshTxBuilderCore { * @param txIndex The transaction index of the reference UTxO * @returns The MeshTxBuilder instance */ - readOnlyTxInReference = (txHash: string, txIndex: number) => { - this.meshTxBuilderBody.referenceInputs.push({ txHash, txIndex }); + readOnlyTxInReference = ( + txHash: string, + txIndex: number, + scriptSize?: number, + ) => { + this.meshTxBuilderBody.referenceInputs.push({ + txHash, + txIndex, + scriptSize, + }); return this; }; @@ -1037,9 +1045,7 @@ export class MeshTxBuilderCore { ) => { if (!this.voteItem) throw Error("voteTxInReference: Undefined vote"); if (this.voteItem.type === "BasicVote") - throw Error( - "voteTxInReference: Adding script reference to a basic vote", - ); + throw Error("voteTxInReference: Adding script reference to a basic vote"); if (this.voteItem.type === "ScriptVote") { this.voteItem.scriptSource = { type: "Inline", @@ -1755,6 +1761,15 @@ export class MeshTxBuilderCore { }, }; this.meshTxBuilderBody.inputs.push(pubKeyTxIn); + // If an input selected has script ref, then we must + // provide the script size to the tx builder also + if (input.output.scriptRef) { + this.meshTxBuilderBody.referenceInputs.push({ + txHash: input.input.txHash, + txIndex: input.input.outputIndex, + scriptSize: input.output.scriptRef!.length / 2, + }); + } }); };