Skip to content

Commit

Permalink
fix: use utxos that were imported
Browse files Browse the repository at this point in the history
  • Loading branch information
erictaylor committed Nov 27, 2024
1 parent ea9f31e commit cf709de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/vms/pvm/etna-builder/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ describe('./src/vms/pvm/etna-builder/builder.test.ts', () => {
// Ensure that the unsigned tx utxos are the filtered utxos,
// and not the inputUtxos registered in the spend helper.
// This is only relevant for the ImportTx.
expect(unsignedTx.utxos).toHaveLength(2);
expect(unsignedTx.utxos).toHaveLength(1);
expect(unsignedTx.utxos).not.toContain(utxos[0]);
expect(unsignedTx.utxos).not.toContain(utxos[1]);
});

Expand Down
11 changes: 8 additions & 3 deletions src/vms/pvm/etna-builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
utxo.assetId.toString() === context.avaxAssetID,
);

const { importedInputs, importedAmounts } = filteredUtxos.reduce<{
const { importedInputs, importedAmounts, inputUtxos } = filteredUtxos.reduce<{
importedInputs: TransferableInput[];
importedAmounts: Record<string, bigint>;
inputUtxos: Utxo[];
}>(
(acc, utxo) => {
const { sigIndicies: inputSigIndices } =
Expand Down Expand Up @@ -342,9 +343,10 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
[assetId]:
(acc.importedAmounts[assetId] ?? 0n) + utxo.output.amount(),
},
inputUtxos: [...acc.inputUtxos, utxo],
};
},
{ importedInputs: [], importedAmounts: {} },
{ importedInputs: [], importedAmounts: {}, inputUtxos: [] },
);

if (importedInputs.length === 0) {
Expand Down Expand Up @@ -397,6 +399,9 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
context,
);

// Note: We don't use the `inputUTXOs` from `spendResults`
// for the `UnsignedTx` because we want to use the original
// UTXOs that were imported.
const { changeOutputs, inputs } = spendResults;

return new UnsignedTx(
Expand All @@ -411,7 +416,7 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
Id.fromString(sourceChainId),
importedInputs.sort(TransferableInput.compare),
),
filteredUtxos,
inputUtxos,
addressMaps,
);
};
Expand Down

0 comments on commit cf709de

Please sign in to comment.