Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/min fee ref script #344

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/mesh-common/src/types/transaction-builder/txin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/mesh-core-csl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/mesh-core-csl/test/core/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("Builder", () => {
};
const txHex = serializer.serializeTxBody(body, DEFAULT_PROTOCOL_PARAMETERS);
expect(txHex).toEqual(
"84a300818258201662c4b349907e4d92e0995fd9dcdc9a4489f7dff4f5cce6b4b3901de479308c0e0182825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a0012c97f825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a2e16c3f4021a00029075a0f5f6",
"84a300d90102818258201662c4b349907e4d92e0995fd9dcdc9a4489f7dff4f5cce6b4b3901de479308c0e0182825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a0012c97f825839001e4eb194e3335a0dcc4f5c5d009318167c583bb3b0879d9f718cd9e0d63a93470bd4d8bb986c02ff8a6043796b91cc397ceb29058f5c9ac01a2e16c2ec021a0002917da0f5f6",
);
});
});
34 changes: 31 additions & 3 deletions packages/mesh-transaction/src/mesh-tx-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class MeshTxBuilder extends MeshTxBuilderCore {
txHex: string = "";
protected queriedTxHashes: Set<string> = new Set();
protected queriedUTxOs: { [x: string]: UTxO[] } = {};
protected utxosWithRefScripts: UTxO[] = [];

constructor({
serializer,
Expand Down Expand Up @@ -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);
Expand Down
25 changes: 20 additions & 5 deletions packages/mesh-transaction/src/mesh-tx-builder/tx-builder-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
});
}
});
};

Expand Down