MCPcopy Create free account
hub / github.com/NoteProtocol/NoteWallet / createP2TRNotePsbt

Function createP2TRNotePsbt

src/btc/btc-p2tr-note.ts:70–134  ·  view source on GitHub ↗
(
  privateKey: ECPairInterface,
  notePayload: NotePayload,
  noteUtxos: IUtxo[],
  payUtxos: IUtxo[],
  toAddresses: ISendToAddress[],
  change: string,
  network: bitcoin.Network,
  fee: number = 1000,
  locktime?: number
)

Source from the content-addressed store, hash-verified

68 * in Partially Signed Bitcoin Transaction (PSBT) format.
69 */
70export function createP2TRNotePsbt(
71 privateKey: ECPairInterface,
72 notePayload: NotePayload,
73 noteUtxos: IUtxo[],
74 payUtxos: IUtxo[],
75 toAddresses: ISendToAddress[],
76 change: string,
77 network: bitcoin.Network,
78 fee: number = 1000,
79 locktime?: number
80) {
81 const psbt = new bitcoin.Psbt({network});
82 psbt.setVersion(2);
83 psbt.setLocktime(locktime ?? 0);
84
85 const p2note = generateP2TRNoteInfo(privateKey.publicKey, network);
86 const tapLeafNoteScript = createTapLeafScript(
87 p2note.noteRedeem,
88 p2note.noteP2TR
89 );
90 const tapLeafP2PKScript = createTapLeafScript(
91 p2note.p2pkRedeem,
92 p2note.p2pkP2TR
93 );
94
95 let totalInput = 0;
96
97 // Add NOTE input
98 totalInput += addNoteInput(
99 psbt,
100 noteUtxos[0]!,
101 p2note.noteP2TR,
102 tapLeafNoteScript
103 );
104
105 // Add other note inputs
106 for (let i = 1; i < noteUtxos.length; i++) {
107 totalInput += addNoteInput(
108 psbt,
109 noteUtxos[i]!,
110 p2note.p2pkP2TR,
111 tapLeafP2PKScript
112 );
113 }
114
115 // Add pay inputs
116 totalInput += addPsbtPayUtxos(privateKey, psbt, payUtxos, network);
117
118 // Add outputs
119 const totalOutput = addOutputs(psbt, toAddresses);
120
121 // Add change output
122 addChangeOutput(psbt, totalInput, totalOutput, fee, change);
123
124 // Sign inputs
125 signInputs(psbt, noteUtxos, payUtxos, privateKey, network);
126
127 // Finalize inputs

Callers 1

mintP2TRNoteMethod · 0.90

Calls 8

generateP2TRNoteInfoFunction · 0.90
addPsbtPayUtxosFunction · 0.90
createTapLeafScriptFunction · 0.85
addNoteInputFunction · 0.85
addOutputsFunction · 0.85
addChangeOutputFunction · 0.85
signInputsFunction · 0.85
finalizeP2TRNoteInputFunction · 0.85

Tested by

no test coverage detected