@bsv/wallet-toolbox 1.3.29 → 1.3.30

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/wallet-toolbox",
3
- "version": "1.3.29",
3
+ "version": "1.3.30",
4
4
  "description": "BRC100 conforming wallet, wallet storage and wallet signer components",
5
5
  "main": "./out/src/index.js",
6
6
  "types": "./out/src/index.d.ts",
@@ -40,19 +40,21 @@ export class ServiceCollection<T> {
40
40
  return this.services[this._index].service
41
41
  }
42
42
 
43
- get serviceToCall(): ServiceToCall<T> {
44
- const i = this._index
43
+ getServiceToCall(i: number): ServiceToCall<T> {
45
44
  const name = this.services[i].name
46
45
  const service = this.services[i].service
47
46
  const call = { name, when: new Date(), msecs: 0, success: false, result: undefined, error: undefined }
48
47
  return { serviceName: this.serviceName, providerName: name, service, call }
49
48
  }
50
49
 
50
+ get serviceToCall(): ServiceToCall<T> {
51
+ return this.getServiceToCall(this._index)
52
+ }
53
+
51
54
  get allServicesToCall(): ServiceToCall<T>[] {
52
55
  const all: ServiceToCall<T>[] = []
53
56
  for (let i = 0; i < this.services.length; i++) {
54
- all.push(this.serviceToCall)
55
- this.next()
57
+ all.push(this.getServiceToCall(i))
56
58
  }
57
59
  return all
58
60
  }
@@ -1,6 +1,6 @@
1
1
  import { Transaction as BsvTransaction, Beef, ChainTracker, Utils } from '@bsv/sdk'
2
2
  import { asArray, asString, doubleSha256BE, sdk, sha256Hash, TableOutput, wait } from '../index.client'
3
- import { ServiceCollection } from './ServiceCollection'
3
+ import { ServiceCollection, ServiceToCall } from './ServiceCollection'
4
4
  import { createDefaultWalletServicesOptions } from './createDefaultWalletServicesOptions'
5
5
  import { ChaintracksChainTracker } from './chaintracker'
6
6
  import { WhatsOnChain } from './providers/WhatsOnChain'
@@ -40,7 +40,7 @@ export class Services implements sdk.WalletServices {
40
40
 
41
41
  this.arcTaal = new ARC(this.options.arcUrl, this.options.arcConfig, 'arcTaal')
42
42
  if (this.options.arcGorillaPoolUrl) {
43
- //this.arcGorillaPool = new ARC(this.options.arcGorillaPoolUrl, this.options.arcGorillaPoolConfig, 'arcGorillaPool')
43
+ this.arcGorillaPool = new ARC(this.options.arcGorillaPoolUrl, this.options.arcGorillaPoolConfig, 'arcGorillaPool')
44
44
  }
45
45
 
46
46
  this.bitails = new Bitails(this.chain)
@@ -57,13 +57,13 @@ export class Services implements sdk.WalletServices {
57
57
  this.postBeefServices = new ServiceCollection<sdk.PostBeefService>('postBeef')
58
58
  if (this.arcGorillaPool) {
59
59
  //prettier-ignore
60
- this.postBeefServices.add({ name: 'GorillaPool', service: this.arcGorillaPool.postBeef.bind(this.arcGorillaPool) })
60
+ this.postBeefServices.add({ name: 'GorillaPoolArcBeef', service: this.arcGorillaPool.postBeef.bind(this.arcGorillaPool) })
61
61
  }
62
62
  //prettier-ignore
63
63
  this.postBeefServices
64
64
  .add({ name: 'TaalArcBeef', service: this.arcTaal.postBeef.bind(this.arcTaal) })
65
- .add({ name: 'WhatsOnChain', service: this.whatsonchain.postBeef.bind(this.whatsonchain) })
66
65
  .add({ name: 'Bitails', service: this.bitails.postBeef.bind(this.bitails) })
66
+ .add({ name: 'WhatsOnChain', service: this.whatsonchain.postBeef.bind(this.whatsonchain) })
67
67
  ;
68
68
 
69
69
  //prettier-ignore
@@ -261,6 +261,8 @@ export class Services implements sdk.WalletServices {
261
261
  return r0
262
262
  }
263
263
 
264
+ postBeefMode: 'PromiseAll' | 'UntilSuccess' = 'UntilSuccess'
265
+
264
266
  /**
265
267
  *
266
268
  * @param beef
@@ -268,24 +270,45 @@ export class Services implements sdk.WalletServices {
268
270
  * @returns
269
271
  */
270
272
  async postBeef(beef: Beef, txids: string[]): Promise<sdk.PostBeefResult[]> {
273
+ let rs: sdk.PostBeefResult[] = []
271
274
  const services = this.postBeefServices
272
275
  const stcs = services.allServicesToCall
273
- let rs = await Promise.all(
274
- stcs.map(async stc => {
275
- const r = await stc.service(beef, txids)
276
- if (r.status === 'success') {
277
- services.addServiceCallSuccess(stc)
278
- } else {
279
- if (r.error) {
280
- services.addServiceCallError(stc, r.error)
281
- } else {
282
- services.addServiceCallFailure(stc)
276
+ switch (this.postBeefMode) {
277
+ case 'UntilSuccess':
278
+ {
279
+ for (const stc of stcs) {
280
+ const r = await callService(stc)
281
+ rs.push(r)
282
+ if (r.status === 'success') break
283
283
  }
284
284
  }
285
- return r
286
- })
287
- )
285
+ break
286
+ case 'PromiseAll':
287
+ {
288
+ rs = await Promise.all(
289
+ stcs.map(async stc => {
290
+ const r = await callService(stc)
291
+ return r
292
+ })
293
+ )
294
+ }
295
+ break
296
+ }
288
297
  return rs
298
+
299
+ async function callService(stc: ServiceToCall<sdk.PostBeefService>) {
300
+ const r = await stc.service(beef, txids)
301
+ if (r.status === 'success') {
302
+ services.addServiceCallSuccess(stc)
303
+ } else {
304
+ if (r.error) {
305
+ services.addServiceCallError(stc, r.error)
306
+ } else {
307
+ services.addServiceCallFailure(stc)
308
+ }
309
+ }
310
+ return r
311
+ }
289
312
  }
290
313
 
291
314
  async getRawTx(txid: string, useNext?: boolean): Promise<sdk.GetRawTxResult> {
@@ -104,9 +104,9 @@ export function verifyUnlockScripts(txid: string, beef: Beef): void {
104
104
  })
105
105
 
106
106
  try {
107
- const spendValid = spend.validate()
107
+ const spendValid = spend.validate()
108
108
 
109
- if (!spendValid) throw new WERR_INVALID_PARAMETER(`inputs[${i}].unlockScript`, `valid`)
109
+ if (!spendValid) throw new WERR_INVALID_PARAMETER(`inputs[${i}].unlockScript`, `valid`)
110
110
  } catch (eu: unknown) {
111
111
  const e = WalletError.fromUnknown(eu)
112
112
  throw new WERR_INVALID_PARAMETER(`inputs[${i}].unlockScript`, `valid. ${e.message}`)