@bsv/wallet-toolbox 1.2.2 → 1.2.4
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/out/src/services/Services.js +1 -1
- package/out/src/services/Services.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/methods/listOutputs.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputs.js +14 -2
- package/out/src/storage/methods/listOutputs.js.map +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js +1 -1
- package/out/src/storage/sync/StorageMySQLDojoReader.js.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.d.ts.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.js +36 -21
- package/out/test/Wallet/local/localWallet.man.test.js.map +1 -1
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js +14 -13
- package/out/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/services/Services.ts +1 -1
- package/src/storage/StorageProvider.ts +3 -6
- package/src/storage/methods/listOutputs.ts +13 -3
- package/src/storage/sync/StorageMySQLDojoReader.ts +1 -1
- package/test/Wallet/local/localWallet.man.test.ts +32 -18
- package/test/Wallet/sync/Wallet.updateWalletLegacyTestData.man.test.ts +14 -14
package/package.json
CHANGED
package/src/services/Services.ts
CHANGED
|
@@ -39,7 +39,7 @@ export class Services implements sdk.WalletServices {
|
|
|
39
39
|
|
|
40
40
|
//prettier-ignore
|
|
41
41
|
this.getMerklePathServices = new ServiceCollection<sdk.GetMerklePathService>()
|
|
42
|
-
|
|
42
|
+
.add({ name: 'WhatsOnChain', service: this.whatsonchain.getMerklePath.bind(this.whatsonchain) })
|
|
43
43
|
.add({ name: 'Bitails', service: this.bitails.getMerklePath.bind(this.bitails) })
|
|
44
44
|
|
|
45
45
|
//prettier-ignore
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Transaction
|
|
2
|
+
Transaction,
|
|
3
3
|
AbortActionResult,
|
|
4
4
|
Beef,
|
|
5
5
|
InternalizeActionArgs,
|
|
6
6
|
InternalizeActionResult,
|
|
7
|
-
ListActionsArgs,
|
|
8
7
|
ListActionsResult,
|
|
9
|
-
ListOutputsArgs,
|
|
10
8
|
ListOutputsResult,
|
|
11
9
|
PubKeyHex,
|
|
12
10
|
ListCertificatesResult,
|
|
@@ -19,7 +17,6 @@ import {
|
|
|
19
17
|
asArray,
|
|
20
18
|
asString,
|
|
21
19
|
sdk,
|
|
22
|
-
TableCertificate,
|
|
23
20
|
TableCertificateX,
|
|
24
21
|
TableMonitorEvent,
|
|
25
22
|
TableOutput,
|
|
@@ -248,7 +245,7 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
|
|
|
248
245
|
if (!rawTx || !beef) throw new sdk.WERR_INTERNAL(`req rawTx and beef must be valid.`)
|
|
249
246
|
mergeToBeef.mergeRawTx(asArray(rawTx))
|
|
250
247
|
mergeToBeef.mergeBeef(asArray(beef))
|
|
251
|
-
const tx =
|
|
248
|
+
const tx = Transaction.fromBinary(asArray(rawTx))
|
|
252
249
|
for (const input of tx.inputs) {
|
|
253
250
|
if (!input.sourceTXID) throw new sdk.WERR_INTERNAL(`req all transaction inputs must have valid sourceTXID`)
|
|
254
251
|
const txid = input.sourceTXID
|
|
@@ -441,7 +438,7 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
|
|
|
441
438
|
else {
|
|
442
439
|
beef.mergeRawTx(r.rawTx)
|
|
443
440
|
beef.mergeBeef(r.inputBEEF)
|
|
444
|
-
const tx =
|
|
441
|
+
const tx = Transaction.fromBinary(r.rawTx)
|
|
445
442
|
for (const input of tx.inputs) {
|
|
446
443
|
const btx = beef.findTxid(input.sourceTXID!)
|
|
447
444
|
if (!btx) {
|
|
@@ -8,6 +8,7 @@ interface SpecOp {
|
|
|
8
8
|
name: string
|
|
9
9
|
useBasket?: string
|
|
10
10
|
ignoreLimit?: boolean
|
|
11
|
+
includeOutputScripts?: boolean
|
|
11
12
|
resultFromTags?: (
|
|
12
13
|
s: StorageKnex,
|
|
13
14
|
auth: sdk.AuthId,
|
|
@@ -61,6 +62,7 @@ const basketToSpecOp: Record<string, SpecOp> = {
|
|
|
61
62
|
name: 'invalidChangeOutputs',
|
|
62
63
|
useBasket: 'default',
|
|
63
64
|
ignoreLimit: true,
|
|
65
|
+
includeOutputScripts: true,
|
|
64
66
|
tagsToIntercept: ['release'],
|
|
65
67
|
filterOutputs: async (
|
|
66
68
|
s: StorageKnex,
|
|
@@ -71,16 +73,24 @@ const basketToSpecOp: Record<string, SpecOp> = {
|
|
|
71
73
|
): Promise<TableOutput[]> => {
|
|
72
74
|
const filteredOutputs: TableOutput[] = []
|
|
73
75
|
for (const o of outputs) {
|
|
74
|
-
|
|
76
|
+
await s.validateOutputScript(o)
|
|
77
|
+
let ok: boolean | undefined = false
|
|
78
|
+
let r: sdk.GetUtxoStatusResult
|
|
75
79
|
if (o.lockingScript && o.lockingScript.length > 0) {
|
|
76
|
-
|
|
80
|
+
r = await s.getServices().getUtxoStatus(asString(o.lockingScript), 'script')
|
|
77
81
|
if (r.status === 'success' && r.isUtxo && r.details?.length > 0) {
|
|
78
82
|
if (r.details.some(d => d.txid === o.txid && d.satoshis === o.satoshis && d.index === o.vout)) {
|
|
79
83
|
ok = true
|
|
84
|
+
} else {
|
|
85
|
+
ok = undefined
|
|
80
86
|
}
|
|
87
|
+
} else {
|
|
88
|
+
ok = false
|
|
81
89
|
}
|
|
90
|
+
} else {
|
|
91
|
+
ok = undefined
|
|
82
92
|
}
|
|
83
|
-
if (
|
|
93
|
+
if (ok === false) {
|
|
84
94
|
filteredOutputs.push(o)
|
|
85
95
|
}
|
|
86
96
|
}
|
|
@@ -198,7 +198,7 @@ export class StorageMySQLDojoReader extends StorageReader implements sdk.WalletS
|
|
|
198
198
|
reference: forceToBase64(d.referenceNumber),
|
|
199
199
|
isOutgoing: !!d.isOutgoing,
|
|
200
200
|
satoshis: verifyInteger(d.amount),
|
|
201
|
-
description: verifyTruthy(d.note || ''),
|
|
201
|
+
description: verifyTruthy(d.note || '12345'),
|
|
202
202
|
provenTxId: verifyOptionalInteger(d.provenTxId),
|
|
203
203
|
version: verifyOptionalInteger(d.version),
|
|
204
204
|
lockTime: verifyOptionalInteger(d.lockTime),
|
|
@@ -29,51 +29,53 @@ import { _tu, TestWalletNoSetup } from '../../utils/TestUtilsWalletStorage'
|
|
|
29
29
|
import { monitorEventLoopDelay } from 'perf_hooks'
|
|
30
30
|
import { specOpInvalidChange, validateCreateActionArgs, ValidCreateActionArgs } from '../../../src/sdk'
|
|
31
31
|
|
|
32
|
+
const chain: sdk.Chain = 'test'
|
|
32
33
|
const setActiveClient = true
|
|
33
|
-
const useMySQLConnectionForClient =
|
|
34
|
+
const useMySQLConnectionForClient = false
|
|
35
|
+
const useTestIdentityKey = true
|
|
36
|
+
const useIdentityKey2 = false
|
|
34
37
|
|
|
35
38
|
describe('localWallet tests', () => {
|
|
36
39
|
jest.setTimeout(99999999)
|
|
37
40
|
|
|
38
41
|
test('00', () => {})
|
|
39
|
-
if (_tu.noTestEnv(
|
|
40
|
-
if (_tu.noTestEnv('main')) return
|
|
42
|
+
if (_tu.noTestEnv(chain)) return
|
|
41
43
|
|
|
42
44
|
test('0 monitor runOnce', async () => {
|
|
43
|
-
const setup = await createSetup(
|
|
45
|
+
const setup = await createSetup(chain)
|
|
44
46
|
await setup.monitor.runOnce()
|
|
45
47
|
await setup.wallet.destroy()
|
|
46
48
|
})
|
|
47
49
|
|
|
48
50
|
test('1 recover 1 sat outputs', async () => {
|
|
49
|
-
const setup = await createSetup(
|
|
51
|
+
const setup = await createSetup(chain)
|
|
50
52
|
await recoverOneSatTestOutputs(setup)
|
|
51
53
|
await setup.wallet.destroy()
|
|
52
54
|
})
|
|
53
55
|
|
|
54
56
|
test('2 create 1 sat delayed', async () => {
|
|
55
|
-
const setup = await createSetup(
|
|
57
|
+
const setup = await createSetup(chain)
|
|
56
58
|
const car = await createOneSatTestOutput(setup, {}, 1)
|
|
57
59
|
//await trackReqByTxid(setup, car.txid!)
|
|
58
60
|
await setup.wallet.destroy()
|
|
59
61
|
})
|
|
60
62
|
|
|
61
63
|
test('2a create 1 sat immediate', async () => {
|
|
62
|
-
const setup = await createSetup(
|
|
64
|
+
const setup = await createSetup(chain)
|
|
63
65
|
const car = await createOneSatTestOutput(setup, { acceptDelayedBroadcast: false }, 1)
|
|
64
66
|
// await trackReqByTxid(setup, car.txid!)
|
|
65
67
|
await setup.wallet.destroy()
|
|
66
68
|
})
|
|
67
69
|
|
|
68
70
|
test('2b create 2 nosend and sendWith', async () => {
|
|
69
|
-
const setup = await createSetup(
|
|
71
|
+
const setup = await createSetup(chain)
|
|
70
72
|
const car = await createOneSatTestOutput(setup, { noSend: true }, 2)
|
|
71
73
|
//await trackReqByTxid(setup, car.txid!)
|
|
72
74
|
await setup.wallet.destroy()
|
|
73
75
|
})
|
|
74
76
|
|
|
75
77
|
test('3 return active to cloud client', async () => {
|
|
76
|
-
const setup = await createSetup(
|
|
78
|
+
const setup = await createSetup(chain)
|
|
77
79
|
const localBalance = await setup.wallet.balance()
|
|
78
80
|
const log = await setup.storage.setActive(setup.clientStorageIdentityKey!)
|
|
79
81
|
console.log(log)
|
|
@@ -84,10 +86,9 @@ describe('localWallet tests', () => {
|
|
|
84
86
|
})
|
|
85
87
|
|
|
86
88
|
test('4 review change utxos', async () => {
|
|
87
|
-
const setup = await createSetup(
|
|
89
|
+
const setup = await createSetup(chain)
|
|
88
90
|
const lor = await setup.wallet.listOutputs({
|
|
89
|
-
basket: specOpInvalidChange
|
|
90
|
-
limit: 1000
|
|
91
|
+
basket: specOpInvalidChange
|
|
91
92
|
})
|
|
92
93
|
if (lor.totalOutputs > 0) {
|
|
93
94
|
debugger
|
|
@@ -112,7 +113,7 @@ describe('localWallet tests', () => {
|
|
|
112
113
|
})
|
|
113
114
|
|
|
114
115
|
test('5 review synchunk', async () => {
|
|
115
|
-
const setup = await createSetup(
|
|
116
|
+
const setup = await createSetup(chain)
|
|
116
117
|
const identityKey = setup.identityKey
|
|
117
118
|
const reader = setup.activeStorage
|
|
118
119
|
const readerSettings = reader.getSettings()
|
|
@@ -125,7 +126,7 @@ describe('localWallet tests', () => {
|
|
|
125
126
|
})
|
|
126
127
|
|
|
127
128
|
test('6 backup', async () => {
|
|
128
|
-
const setup = await createSetup(
|
|
129
|
+
const setup = await createSetup(chain)
|
|
129
130
|
const log = await setup.storage.updateBackups()
|
|
130
131
|
console.log(log)
|
|
131
132
|
await setup.wallet.destroy()
|
|
@@ -134,13 +135,26 @@ describe('localWallet tests', () => {
|
|
|
134
135
|
|
|
135
136
|
async function createSetup(chain: sdk.Chain): Promise<TestWalletNoSetup> {
|
|
136
137
|
const env = _tu.getEnv(chain)
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
let identityKey: string | undefined
|
|
139
|
+
let filePath: string | undefined
|
|
140
|
+
if (useTestIdentityKey) {
|
|
141
|
+
identityKey = env.testIdentityKey
|
|
142
|
+
filePath = env.testFilePath
|
|
143
|
+
} else {
|
|
144
|
+
if (useIdentityKey2) {
|
|
145
|
+
identityKey = env.identityKey2
|
|
146
|
+
} else {
|
|
147
|
+
identityKey = env.identityKey
|
|
148
|
+
filePath = env.filePath
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!identityKey) throw new sdk.WERR_INVALID_PARAMETER('identityKey', 'valid')
|
|
152
|
+
if (!filePath) filePath = `./backup-${chain}-${identityKey}.sqlite`
|
|
139
153
|
|
|
140
154
|
const setup = await _tu.createTestWallet({
|
|
141
155
|
chain,
|
|
142
|
-
rootKeyHex: env.devKeys[
|
|
143
|
-
filePath
|
|
156
|
+
rootKeyHex: env.devKeys[identityKey],
|
|
157
|
+
filePath,
|
|
144
158
|
setActiveClient,
|
|
145
159
|
addLocalBackup: false,
|
|
146
160
|
useMySQLConnectionForClient
|
|
@@ -8,8 +8,8 @@ import { StorageMySQLDojoReader } from '../../../src/storage/sync'
|
|
|
8
8
|
import { _tu, TestSetup1Wallet } from '../../utils/TestUtilsWalletStorage'
|
|
9
9
|
|
|
10
10
|
import * as dotenv from 'dotenv'
|
|
11
|
-
|
|
12
11
|
dotenv.config()
|
|
12
|
+
const main_satoshi_shop = process.env.MAIN_SATOSHI_SHOP || ''
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* NOTICE: These tests are designed to chain one after the other.
|
|
@@ -64,16 +64,16 @@ describe('Wallet sync tests', () => {
|
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
test.skip('0a sync production dojo to local MySQL', async () => {
|
|
67
|
+
const chain: sdk.Chain = 'main'
|
|
68
|
+
const env = _tu.getEnv(chain)
|
|
67
69
|
console.log('Importing from production dojo to local MySQL productiondojotone')
|
|
68
|
-
|
|
69
|
-
const identityKey = '030b78da8101cd8929ec355c694c275fbaf4f73d4eaa104873463779cac69a2a01' // process.env.MY_MAIN_IDENTITY || ''
|
|
70
|
+
const identityKey = main_satoshi_shop
|
|
70
71
|
const rootKeyHex = env.devKeys[identityKey]
|
|
71
|
-
const chain: sdk.Chain = 'main'
|
|
72
72
|
const connection = JSON.parse(process.env.MAIN_DOJO_CONNECTION || '')
|
|
73
73
|
const readerKnex = _tu.createMySQLFromConnection(connection)
|
|
74
74
|
const reader = new StorageMySQLDojoReader({ chain, knex: readerKnex })
|
|
75
75
|
const writer = await _tu.createMySQLTestWallet({
|
|
76
|
-
databaseName: '
|
|
76
|
+
databaseName: 'main_satoshi_shop',
|
|
77
77
|
chain: 'main',
|
|
78
78
|
rootKeyHex,
|
|
79
79
|
dropAll: true
|
|
@@ -85,23 +85,23 @@ describe('Wallet sync tests', () => {
|
|
|
85
85
|
await writer.activeStorage.destroy()
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
test.skip('0b sweep mysql dojo sync to
|
|
88
|
+
test.skip('0b sweep mysql dojo sync to another wallet', async () => {
|
|
89
89
|
const chain: sdk.Chain = 'main'
|
|
90
|
-
const
|
|
91
|
-
//const
|
|
90
|
+
const env = _tu.getEnv(chain)
|
|
91
|
+
// const prod_faucet = '030b78da8101cd8929ec355c694c275fbaf4f73d4eaa104873463779cac69a2a01' // prod faucet
|
|
92
|
+
// const identityKeyTone = process.env.MY_MAIN_IDENTITY || ''
|
|
93
|
+
const identityKey = main_satoshi_shop
|
|
92
94
|
const rootKeyHex = env.devKeys[identityKey]
|
|
93
95
|
|
|
94
96
|
const sweepFrom = await _tu.createMySQLTestWallet({
|
|
95
|
-
databaseName: '
|
|
97
|
+
databaseName: 'main_satoshi_shop',
|
|
96
98
|
chain,
|
|
97
99
|
rootKeyHex
|
|
98
100
|
})
|
|
99
101
|
|
|
100
|
-
const sweepTo = await _tu.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
chain,
|
|
104
|
-
rootKeyHex
|
|
102
|
+
const sweepTo = await _tu.createTestWalletWithStorageClient({
|
|
103
|
+
rootKeyHex: env.devKeys[env.identityKey],
|
|
104
|
+
chain
|
|
105
105
|
})
|
|
106
106
|
|
|
107
107
|
//await sweepTo.activeStorage.updateProvenTxReq(2, { status: 'invalid' })
|