diff --git a/CHANGELOG.md b/CHANGELOG.md index 313effca..3320df96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/common/utxobased/engine/UtxoEngine.ts b/src/common/utxobased/engine/UtxoEngine.ts index b68f8400..cc4ff6bd 100644 --- a/src/common/utxobased/engine/UtxoEngine.ts +++ b/src/common/utxobased/engine/UtxoEngine.ts @@ -541,6 +541,7 @@ export async function makeUtxoEngine( ) const txOptions = spendInfoOtherParams.txOptions ?? {} const { + memoIndex, outputSort, utxoSourceAddress, forceChangeAddress @@ -669,6 +670,7 @@ export async function makeUtxoEngine( freshChangeAddress, subtractFee, log, + memoIndex, outputSort }) if (tx.changeUsed) { diff --git a/src/common/utxobased/engine/types.ts b/src/common/utxobased/engine/types.ts index cac93725..f5c179dd 100644 --- a/src/common/utxobased/engine/types.ts +++ b/src/common/utxobased/engine/types.ts @@ -2,6 +2,7 @@ import { asArray, asBoolean, asMaybe, + asNumber, asObject, asOptional, asString, @@ -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) diff --git a/src/common/utxobased/keymanager/keymanager.ts b/src/common/utxobased/keymanager/keymanager.ts index 7e760510..17a84718 100644 --- a/src/common/utxobased/keymanager/keymanager.ts +++ b/src/common/utxobased/keymanager/keymanager.ts @@ -235,6 +235,7 @@ export interface MakeTxArgs { subtractFee?: boolean log?: EdgeLog outputSort: 'bip69' | 'targets' + memoIndex?: number } export interface MakeTxTarget { @@ -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 @@ -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]) + } + } + const psbt = new Psbt() try { psbt.addInputs(sortedInputs)