ecash-lib 4.4.0 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -193,6 +193,42 @@ export class TestRunner {
193
193
  return (await this.chronik.broadcastTx(setupTx.ser())).txid;
194
194
  }
195
195
 
196
+ /**
197
+ * Fund two addresses with sats
198
+ * Specifically for assigning sats to the maker and taker
199
+ * of an agora offer, it is not generalized for 'n' scripts
200
+ */
201
+ public async sendToTwoScripts(
202
+ maker: { script: Script; sats: bigint },
203
+ taker: { script: Script; sats: bigint },
204
+ ): Promise<string> {
205
+ const coinValue = this.coinValue!;
206
+ const setupTxBuilder = new TxBuilder({
207
+ inputs: [
208
+ {
209
+ input: {
210
+ prevOut: this.getOutpoint(),
211
+ script: ANYONE_SCRIPT_SIG,
212
+ sequence: 0xffffffff,
213
+ signData: {
214
+ sats: coinValue,
215
+ },
216
+ },
217
+ },
218
+ ],
219
+ outputs: [
220
+ { sats: maker.sats, script: maker.script },
221
+ { sats: taker.sats, script: taker.script },
222
+ Script.fromOps([OP_RETURN]), // burn leftover
223
+ ],
224
+ });
225
+ const setupTx = setupTxBuilder.sign({
226
+ feePerKb: 1000n,
227
+ dustSats: 546n,
228
+ });
229
+ return (await this.chronik.broadcastTx(setupTx.ser())).txid;
230
+ }
231
+
196
232
  public generate() {
197
233
  this.runner.send('generate');
198
234
  }
package/src/txBuilder.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright (c) 2024 The Bitcoin developers
1
+ // Copyright (c) 2024-2025 The Bitcoin developers
2
2
  // Distributed under the MIT software license, see the accompanying
3
3
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
4
 
@@ -119,6 +119,19 @@ export class TxBuilder {
119
119
  return { fixedOutputSum, leftoverIdx, outputs };
120
120
  }
121
121
 
122
+ /**
123
+ * Create a TxBuilder from the given tx.
124
+ * This is useful if tx is unsigned/partially signed and needs to be completed.
125
+ **/
126
+ public static fromTx(tx: Tx): TxBuilder {
127
+ return new TxBuilder({
128
+ version: tx.version,
129
+ inputs: tx.inputs.map(input => ({ input: copyTxInput(input) })),
130
+ outputs: tx.outputs.map(output => copyTxOutput(output)),
131
+ locktime: tx.locktime,
132
+ });
133
+ }
134
+
122
135
  /** Sign the tx built by this builder and return a Tx */
123
136
  public sign(params?: {
124
137
  ecc?: Ecc;