ecash-lib 4.5.0 → 4.5.2

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.
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { GenesisInfo, TokenType } from '../token/common.js';
6
6
  import { PaymentOutput } from './output.js';
7
+ import { OutPoint } from '../tx.js';
7
8
 
8
9
  /**
9
10
  * Action
@@ -34,10 +35,47 @@ export interface Action {
34
35
  * blank output, i.e. {sats: 0n}, at index 0 of Action.outputs[]
35
36
  */
36
37
  tokenActions?: TokenAction[];
38
+ /**
39
+ * A user may optionally specify any utxos that wish to be included in the action by
40
+ * passing their OutPoint(s)
41
+ *
42
+ * Use cases
43
+ * - Apps that support 0-conf and want to make sure a return tx includes the payment utxo,
44
+ * so that if the payment is doublespent, both txs are invalidated
45
+ * - Users looking to build a chained tx, where the change of 1 tx provides the input for
46
+ * the next tx in the chain
47
+ * - Unknown future use cases where some tx or app actions may require specific utxos
48
+ * for a spec not yet supported by ecash-wallet or ecash-lib
49
+ *
50
+ * If requiredUtxos is specified, the Action will include every ScriptUtxo specified in the
51
+ * first tx of the built action. If it is unable to do so due to fee or size constraints,
52
+ * it will throw an error rather than partially exclude specified inputs
53
+ *
54
+ * We specify these utxos by OutPoint which uniquely identifies them. ecash-wallet still must
55
+ * check that these utxos are actually available in the wallet.
56
+ */
57
+ requiredUtxos?: OutPoint[];
58
+ /**
59
+ * If true, the Action will not include any change outputs in the built txs
60
+ * For power users who want to exactly specify the inputs and outputs of a tx,
61
+ * and to support building deterministic chained txs
62
+ *
63
+ * If unspecified, ecash-wallet will always automatically include change
64
+ *
65
+ * Note that if noChange is specified as true, unless the outputs specify reasonable change or
66
+ * just so happen to about correspond with input + fee, we are likely to get an
67
+ * error on build or broadcast from the fee being too crazy
68
+ *
69
+ * TODO extend this to also block token change when we add support for chained
70
+ * token send txs, as we also want these to be deterministic
71
+ */
72
+ noChange?: boolean;
37
73
  /** Dust sats associated with this tx, defaults to DEFAULT_DUST_SATS */
38
74
  dustSats?: bigint;
39
75
  /** Fee per kb to be used for tx(s) of this action, defaults to DEFAULT_FEE_SATS_PER_KB */
40
76
  feePerKb?: bigint;
77
+ /** Maximum tx sersize to be used for tx(s) of this action, defaults to MAX_TX_SERSIZE */
78
+ maxTxSersize?: number;
41
79
  }
42
80
 
43
81
  /**
@@ -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
  }