Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: Add optional `memoIndex` to otherParams to force output index of OP_RETURN

## 3.8.4 (2025-08-20)

- changed: Update blockbook servers
Expand Down
2 changes: 2 additions & 0 deletions src/common/utxobased/engine/UtxoEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ export async function makeUtxoEngine(
)
const txOptions = spendInfoOtherParams.txOptions ?? {}
const {
memoIndex,
outputSort,
utxoSourceAddress,
forceChangeAddress
Expand Down Expand Up @@ -669,6 +670,7 @@ export async function makeUtxoEngine(
freshChangeAddress,
subtractFee,
log,
memoIndex,
outputSort
})
if (tx.changeUsed) {
Expand Down
2 changes: 2 additions & 0 deletions src/common/utxobased/engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
asArray,
asBoolean,
asMaybe,
asNumber,
asObject,
asOptional,
asString,
Expand Down Expand Up @@ -53,6 +54,7 @@ export const asUtxoSpendInfoOtherParams = asObject({
/** @deprecated use `EdgeSpendInfo['enableRbf']` */
enableRbf: asOptional(asBoolean),
forceChangeAddress: asOptional(asString),
memoIndex: asOptional(asNumber),
outputSort: asOptional(asOutputSort, 'bip69'),
txOptions: asOptional(asTxOptions),
utxoSourceAddress: asOptional(asString)
Expand Down
13 changes: 12 additions & 1 deletion src/common/utxobased/keymanager/keymanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface MakeTxArgs {
subtractFee?: boolean
log?: EdgeLog
outputSort: 'bip69' | 'targets'
memoIndex?: number
}

export interface MakeTxTarget {
Expand Down Expand Up @@ -949,7 +950,7 @@ export function signMessageBase64(message: string, privateKey: string): string {
}

export function makeTx(args: MakeTxArgs): MakeTxReturn {
const { log, outputSort, memos } = args
const { log, outputSort, memos, memoIndex } = args
let sequence = 0xffffffff
if (args.enableRbf) {
sequence -= 2
Expand Down Expand Up @@ -1102,6 +1103,16 @@ export function makeTx(args: MakeTxArgs): MakeTxReturn {
}
})()

if (memoIndex != null) {
const currentMemoIndex = sortedOutputs.findIndex(
output => output.value === 0
)
if (currentMemoIndex !== -1) {
const memoOutput = sortedOutputs.splice(currentMemoIndex, 1)
sortedOutputs.splice(memoIndex, 0, memoOutput[0])
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Memo Placement Error in Transactions

The memoIndex parameter in makeTx lacks bounds validation. If memoIndex is negative or exceeds the output array's length, the splice operation places the memo output at an unintended position. This could cause issues if precise memo placement is critical for transaction validity or downstream processing.

Fix in Cursor Fix in Web


const psbt = new Psbt()
try {
psbt.addInputs(sortedInputs)
Expand Down
Loading