@bsv/wallet-toolbox 1.3.22 → 1.3.24
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/docs/client.md +99 -59
- package/docs/storage.md +55 -75
- package/docs/wallet.md +99 -59
- package/mobile/out/src/Wallet.d.ts +1 -1
- package/mobile/out/src/Wallet.d.ts.map +1 -1
- package/mobile/out/src/Wallet.js +16 -6
- package/mobile/out/src/Wallet.js.map +1 -1
- package/mobile/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/mobile/out/src/WalletPermissionsManager.js.map +1 -1
- package/mobile/out/src/index.mobile.d.ts +0 -2
- package/mobile/out/src/index.mobile.d.ts.map +1 -1
- package/mobile/out/src/index.mobile.js +0 -2
- package/mobile/out/src/index.mobile.js.map +1 -1
- package/mobile/out/src/monitor/Monitor.d.ts.map +1 -1
- package/mobile/out/src/monitor/Monitor.js +2 -4
- package/mobile/out/src/monitor/Monitor.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskNewHeader.d.ts +1 -1
- package/mobile/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
- package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts +14 -1
- package/mobile/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.js.map +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/index.d.ts +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/index.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/index.js +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/index.js.map +1 -1
- package/mobile/out/src/signer/methods/internalizeAction.d.ts +2 -2
- package/mobile/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
- package/mobile/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/mobile/out/src/storage/StorageIdb.d.ts +2 -1
- package/mobile/out/src/storage/StorageIdb.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageIdb.js +63 -29
- package/mobile/out/src/storage/StorageIdb.js.map +1 -1
- package/mobile/out/src/storage/StorageProvider.d.ts +4 -4
- package/mobile/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageProvider.js +35 -26
- package/mobile/out/src/storage/StorageProvider.js.map +1 -1
- package/mobile/out/src/storage/StorageReader.d.ts +2 -1
- package/mobile/out/src/storage/StorageReader.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageReader.js +45 -11
- package/mobile/out/src/storage/StorageReader.js.map +1 -1
- package/mobile/out/src/storage/StorageReaderWriter.d.ts +2 -1
- package/mobile/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageReaderWriter.js +29 -29
- package/mobile/out/src/storage/StorageReaderWriter.js.map +1 -1
- package/mobile/out/src/storage/StorageSyncReader.d.ts +2 -1
- package/mobile/out/src/storage/StorageSyncReader.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageSyncReader.js +36 -3
- package/mobile/out/src/storage/StorageSyncReader.js.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.d.ts +2 -2
- package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/mobile/out/src/storage/index.mobile.d.ts +1 -1
- package/mobile/out/src/storage/index.mobile.js +1 -1
- package/mobile/out/src/storage/methods/generateChange.d.ts +0 -24
- package/mobile/out/src/storage/methods/generateChange.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/generateChange.js +2 -50
- package/mobile/out/src/storage/methods/generateChange.js.map +1 -1
- package/mobile/out/src/storage/methods/getBeefForTransaction.js +3 -2
- package/mobile/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
- package/mobile/out/src/storage/methods/internalizeAction.d.ts +2 -10
- package/mobile/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/internalizeAction.js +16 -1
- package/mobile/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/mobile/out/src/storage/methods/processAction.d.ts +16 -1
- package/mobile/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/processAction.js +4 -1
- package/mobile/out/src/storage/methods/processAction.js.map +1 -1
- package/mobile/out/src/storage/methods/utils.d.ts +25 -0
- package/mobile/out/src/storage/methods/utils.d.ts.map +1 -0
- package/mobile/out/src/storage/methods/utils.js +53 -0
- package/mobile/out/src/storage/methods/utils.js.map +1 -0
- package/mobile/out/src/storage/remoting/StorageClient.d.ts +2 -2
- package/mobile/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/mobile/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/mobile/out/src/storage/remoting/StorageMobile.d.ts +283 -0
- package/mobile/out/src/storage/remoting/StorageMobile.d.ts.map +1 -0
- package/mobile/out/src/storage/remoting/StorageMobile.js +477 -0
- package/mobile/out/src/storage/remoting/StorageMobile.js.map +1 -0
- package/mobile/out/src/utility/utilityHelpers.d.ts +1 -1
- package/mobile/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/mobile/out/src/utility/utilityHelpers.js +3 -3
- package/mobile/out/src/utility/utilityHelpers.js.map +1 -1
- package/mobile/package-lock.json +5 -6
- package/mobile/package.json +1 -1
- package/out/src/Wallet.d.ts +1 -1
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +16 -6
- package/out/src/Wallet.js.map +1 -1
- package/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/out/src/WalletPermissionsManager.js.map +1 -1
- package/out/src/index.mobile.d.ts +0 -2
- package/out/src/index.mobile.d.ts.map +1 -1
- package/out/src/index.mobile.js +0 -2
- package/out/src/index.mobile.js.map +1 -1
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +2 -4
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.d.ts +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts +14 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/Api/BlockHeaderApi.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts +1 -1
- package/out/src/services/chaintracker/chaintracks/ChaintracksServiceClient.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.d.ts +1 -1
- package/out/src/services/chaintracker/chaintracks/index.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/index.js +1 -1
- package/out/src/services/chaintracker/chaintracks/index.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts +144 -0
- package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js +463 -0
- package/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.js.map +1 -0
- package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts +20 -0
- package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.d.ts.map +1 -0
- package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js +31 -0
- package/out/src/services/chaintracker/chaintracks/util/dirtyHashes.js.map +1 -0
- package/out/src/signer/methods/internalizeAction.d.ts +2 -2
- package/out/src/signer/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/StorageIdb.d.ts +2 -1
- package/out/src/storage/StorageIdb.d.ts.map +1 -1
- package/out/src/storage/StorageIdb.js +63 -29
- package/out/src/storage/StorageIdb.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts +1 -1
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/StorageKnex.js +10 -6
- package/out/src/storage/StorageKnex.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts +4 -4
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +35 -26
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/StorageReader.d.ts +2 -1
- package/out/src/storage/StorageReader.d.ts.map +1 -1
- package/out/src/storage/StorageReader.js +45 -11
- package/out/src/storage/StorageReader.js.map +1 -1
- package/out/src/storage/StorageReaderWriter.d.ts +2 -1
- package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
- package/out/src/storage/StorageReaderWriter.js +29 -29
- package/out/src/storage/StorageReaderWriter.js.map +1 -1
- package/out/src/storage/StorageSyncReader.d.ts +2 -1
- package/out/src/storage/StorageSyncReader.d.ts.map +1 -1
- package/out/src/storage/StorageSyncReader.js +36 -3
- package/out/src/storage/StorageSyncReader.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts +2 -2
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/__test/StorageIdb.test.js +1 -0
- package/out/src/storage/__test/StorageIdb.test.js.map +1 -1
- package/out/src/storage/__test/adminStats.man.test.js +2 -0
- package/out/src/storage/__test/adminStats.man.test.js.map +1 -1
- package/out/src/storage/index.mobile.d.ts +1 -1
- package/out/src/storage/index.mobile.js +1 -1
- package/out/src/storage/methods/generateChange.d.ts +0 -24
- package/out/src/storage/methods/generateChange.d.ts.map +1 -1
- package/out/src/storage/methods/generateChange.js +2 -50
- package/out/src/storage/methods/generateChange.js.map +1 -1
- package/out/src/storage/methods/getBeefForTransaction.js +3 -2
- package/out/src/storage/methods/getBeefForTransaction.js.map +1 -1
- package/out/src/storage/methods/internalizeAction.d.ts +2 -10
- package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/storage/methods/internalizeAction.js +16 -1
- package/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts +16 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +4 -1
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/methods/utils.Buffer.d.ts +21 -0
- package/out/src/storage/methods/utils.Buffer.d.ts.map +1 -0
- package/out/src/storage/methods/utils.Buffer.js +37 -0
- package/out/src/storage/methods/utils.Buffer.js.map +1 -0
- package/out/src/storage/methods/utils.d.ts +25 -0
- package/out/src/storage/methods/utils.d.ts.map +1 -0
- package/out/src/storage/methods/utils.js +53 -0
- package/out/src/storage/methods/utils.js.map +1 -0
- package/out/src/storage/remoting/StorageClient.d.ts +2 -2
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/out/src/storage/remoting/StorageMobile.d.ts +283 -0
- package/out/src/storage/remoting/StorageMobile.d.ts.map +1 -0
- package/out/src/storage/remoting/StorageMobile.js +477 -0
- package/out/src/storage/remoting/StorageMobile.js.map +1 -0
- package/out/src/utility/Format.d.ts +14 -0
- package/out/src/utility/Format.d.ts.map +1 -0
- package/out/src/utility/Format.js +167 -0
- package/out/src/utility/Format.js.map +1 -0
- package/out/src/utility/utilityHelpers.d.ts +1 -1
- package/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.js +3 -3
- package/out/src/utility/utilityHelpers.js.map +1 -1
- package/out/test/Wallet/support/operations.man.test.js +18 -138
- package/out/test/Wallet/support/operations.man.test.js.map +1 -1
- package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.d.ts +2 -0
- package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.d.ts.map +1 -0
- package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.js +385 -0
- package/out/test/Wallet/support/reqErrorReview.2025.05.06.man.test.js.map +1 -0
- package/out/test/utils/TestUtilsWalletStorage.d.ts +5 -0
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.js +20 -0
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Wallet.ts +25 -10
- package/src/WalletPermissionsManager.ts +19 -8
- package/src/index.mobile.ts +0 -2
- package/src/monitor/Monitor.ts +2 -4
- package/src/monitor/tasks/TaskNewHeader.ts +1 -1
- package/src/sdk/WalletStorage.interfaces.ts +16 -1
- package/src/services/chaintracker/chaintracks/ChaintracksServiceClient.ts +1 -1
- package/src/services/chaintracker/chaintracks/index.ts +1 -1
- package/src/services/chaintracker/chaintracks/util/blockHeaderUtilities.ts +490 -0
- package/src/services/chaintracker/chaintracks/util/dirtyHashes.ts +29 -0
- package/src/signer/methods/internalizeAction.ts +2 -2
- package/src/storage/StorageIdb.ts +4 -5
- package/src/storage/StorageKnex.ts +7 -6
- package/src/storage/StorageProvider.ts +34 -26
- package/src/storage/StorageReader.ts +4 -7
- package/src/storage/StorageReaderWriter.ts +4 -8
- package/src/storage/StorageSyncReader.ts +2 -19
- package/src/storage/WalletStorageManager.ts +1 -1
- package/src/storage/__test/StorageIdb.test.ts +1 -0
- package/src/storage/__test/adminStats.man.test.ts +2 -0
- package/src/storage/index.mobile.ts +1 -1
- package/src/storage/methods/generateChange.ts +1 -54
- package/src/storage/methods/getBeefForTransaction.ts +10 -2
- package/src/storage/methods/internalizeAction.ts +22 -14
- package/src/storage/methods/processAction.ts +5 -2
- package/src/storage/methods/utils.Buffer.ts +33 -0
- package/src/storage/methods/utils.ts +56 -0
- package/src/storage/remoting/StorageClient.ts +2 -3
- package/src/storage/remoting/StorageMobile.ts +527 -0
- package/src/utility/Format.ts +133 -0
- package/src/utility/utilityHelpers.ts +2 -2
- package/test/Wallet/support/operations.man.test.ts +20 -125
- package/test/Wallet/support/reqErrorReview.2025.05.06.man.test.ts +359 -0
- package/test/utils/TestUtilsWalletStorage.ts +23 -0
- package/tsconfig.all.json +2 -1
- package/tsconfig.client.json +6 -0
- package/tsconfig.mobile.json +6 -0
- package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +0 -1
- package/mobile/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +0 -1
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.d.ts.map +0 -1
- package/out/src/services/chaintracker/chaintracks/BlockHeaderApi.js.map +0 -1
- /package/mobile/out/src/services/chaintracker/chaintracks/{BlockHeaderApi.d.ts → Api/BlockHeaderApi.d.ts} +0 -0
- /package/mobile/out/src/services/chaintracker/chaintracks/{BlockHeaderApi.js → Api/BlockHeaderApi.js} +0 -0
- /package/out/src/services/chaintracker/chaintracks/{BlockHeaderApi.d.ts → Api/BlockHeaderApi.d.ts} +0 -0
- /package/out/src/services/chaintracker/chaintracks/{BlockHeaderApi.js → Api/BlockHeaderApi.js} +0 -0
- /package/src/services/chaintracker/chaintracks/{BlockHeaderApi.ts → Api/BlockHeaderApi.ts} +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* These hashes are for blocks that are to known to have violated the Bitcoin
|
|
3
|
+
* protocol. Regardless of the amount of proof-of-work that chains built on top
|
|
4
|
+
* of them may have accumulated, they cannot be considered valid Bitcoin blocks.
|
|
5
|
+
*
|
|
6
|
+
* In the first instance, segregating witness data from transactions is not
|
|
7
|
+
* part of the design of Bitcoin.
|
|
8
|
+
*
|
|
9
|
+
* In the second instance, adding new opcodes to be used when evaluating
|
|
10
|
+
* scripts is also not allowed.
|
|
11
|
+
*/
|
|
12
|
+
export const dirtyHashes = {
|
|
13
|
+
// Block 478,558 with hash of 0000000000000000011865af4122fe3b144e2cbeea86142e8ff2fb4107352d43 was the last block shared by BSV, BCH and BTC
|
|
14
|
+
// Block 478,559 with hash of 00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148 was the first block of the BTC Segwit chain.
|
|
15
|
+
// Block 478,559 with hash of 000000000000000000651ef99cb9fcbe0dadde1d424bd9f15ff20136191a5eec was the valid Bitcoin block shared by BSV and BCH.
|
|
16
|
+
'00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148':
|
|
17
|
+
'This is the first header of the invalid SegWit chain.',
|
|
18
|
+
'0000000000000000004626ff6e3b936941d341c5932ece4357eeccac44e6d56c':
|
|
19
|
+
'This is the first header of the invalid ABC chain.'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Throws Error if blockHash is in the dirtyHashes list.
|
|
24
|
+
*/
|
|
25
|
+
export function validateAgainstDirtyHashes(blockHash: string): void {
|
|
26
|
+
if (dirtyHashes[blockHash]) {
|
|
27
|
+
throw new Error(`Not adding a header with a dirty hash: ${dirtyHashes[blockHash]}`)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -39,7 +39,7 @@ export async function internalizeAction(
|
|
|
39
39
|
wallet: Wallet,
|
|
40
40
|
auth: sdk.AuthId,
|
|
41
41
|
args: InternalizeActionArgs
|
|
42
|
-
): Promise<
|
|
42
|
+
): Promise<sdk.StorageInternalizeActionResult> {
|
|
43
43
|
const vargs = sdk.validateInternalizeActionArgs(args)
|
|
44
44
|
|
|
45
45
|
const { ab, tx, txid } = await validateAtomicBeef()
|
|
@@ -60,7 +60,7 @@ export async function internalizeAction(
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const r:
|
|
63
|
+
const r: sdk.StorageInternalizeActionResult = await wallet.storage.internalizeAction(args)
|
|
64
64
|
|
|
65
65
|
return r
|
|
66
66
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deleteDB, IDBPCursorWithValue, IDBPDatabase, IDBPTransaction, openDB } from 'idb'
|
|
2
2
|
import { ListActionsResult, ListOutputsResult } from '@bsv/sdk'
|
|
3
3
|
import {
|
|
4
|
-
sdk,
|
|
5
4
|
TableCertificate,
|
|
6
5
|
TableCertificateField,
|
|
7
6
|
TableCertificateX,
|
|
@@ -18,10 +17,10 @@ import {
|
|
|
18
17
|
TableTransaction,
|
|
19
18
|
TableTxLabel,
|
|
20
19
|
TableTxLabelMap,
|
|
21
|
-
TableUser
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} from '../
|
|
20
|
+
TableUser
|
|
21
|
+
} from './schema/tables'
|
|
22
|
+
import * as sdk from '../sdk/index'
|
|
23
|
+
import { verifyOne, verifyOneOrNone } from '../utility/utilityHelpers'
|
|
25
24
|
import { StorageAdminStats, StorageProvider, StorageProviderOptions } from './StorageProvider'
|
|
26
25
|
import { StorageIdbSchema } from './schema/StorageIdbSchema'
|
|
27
26
|
import { DBType } from './StorageReader'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ListActionsResult, ListOutputsResult
|
|
1
|
+
import { ListActionsResult, ListOutputsResult } from '@bsv/sdk'
|
|
2
2
|
import { sdk, verifyOne, verifyOneOrNone, verifyTruthy } from '../index.all'
|
|
3
3
|
import {
|
|
4
|
-
KnexMigrations,
|
|
5
4
|
outputColumnsWithoutLockingScript,
|
|
6
5
|
TableCertificate,
|
|
7
6
|
TableCertificateField,
|
|
@@ -12,7 +11,6 @@ import {
|
|
|
12
11
|
TableOutputBasket,
|
|
13
12
|
TableOutputTag,
|
|
14
13
|
TableOutputTagMap,
|
|
15
|
-
TableOutputX,
|
|
16
14
|
TableProvenTx,
|
|
17
15
|
TableProvenTxReq,
|
|
18
16
|
TableSettings,
|
|
@@ -22,8 +20,8 @@ import {
|
|
|
22
20
|
TableTxLabelMap,
|
|
23
21
|
TableUser,
|
|
24
22
|
transactionColumnsWithoutRawTx
|
|
25
|
-
} from './
|
|
26
|
-
|
|
23
|
+
} from './schema/tables'
|
|
24
|
+
import { KnexMigrations } from './schema/KnexMigrations'
|
|
27
25
|
import { Knex } from 'knex'
|
|
28
26
|
import { StorageAdminStats, StorageProvider, StorageProviderOptions } from './StorageProvider'
|
|
29
27
|
import { purgeData } from './methods/purgeData'
|
|
@@ -797,7 +795,10 @@ export class StorageKnex extends StorageProvider implements sdk.WalletStoragePro
|
|
|
797
795
|
for (let i = 0; i < count; i++) {
|
|
798
796
|
try {
|
|
799
797
|
const r = await this.knex.migrate.down(config)
|
|
800
|
-
|
|
798
|
+
if (!r) {
|
|
799
|
+
console.error(`Migration returned falsy result await this.knex.migrate.down(config)`)
|
|
800
|
+
break
|
|
801
|
+
}
|
|
801
802
|
} catch (eu: unknown) {
|
|
802
803
|
break
|
|
803
804
|
}
|
|
@@ -170,7 +170,7 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
|
|
|
170
170
|
return r
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
async internalizeAction(auth: sdk.AuthId, args: InternalizeActionArgs): Promise<
|
|
173
|
+
async internalizeAction(auth: sdk.AuthId, args: InternalizeActionArgs): Promise<sdk.StorageInternalizeActionResult> {
|
|
174
174
|
return await internalizeAction(this, auth, args)
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -413,9 +413,10 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
|
|
|
413
413
|
mergeToBeef?: Beef,
|
|
414
414
|
trustSelf?: TrustSelf,
|
|
415
415
|
knownTxids?: string[],
|
|
416
|
-
trx?: sdk.TrxToken
|
|
416
|
+
trx?: sdk.TrxToken,
|
|
417
|
+
requiredLevels?: number
|
|
417
418
|
): Promise<Beef> {
|
|
418
|
-
const beef = await this.getValidBeefForTxid(txid, mergeToBeef, trustSelf, knownTxids, trx)
|
|
419
|
+
const beef = await this.getValidBeefForTxid(txid, mergeToBeef, trustSelf, knownTxids, trx, requiredLevels)
|
|
419
420
|
if (!beef) throw new sdk.WERR_INVALID_PARAMETER('txid', `${txid} is not known to storage.`)
|
|
420
421
|
return beef
|
|
421
422
|
}
|
|
@@ -425,43 +426,50 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
|
|
|
425
426
|
mergeToBeef?: Beef,
|
|
426
427
|
trustSelf?: TrustSelf,
|
|
427
428
|
knownTxids?: string[],
|
|
428
|
-
trx?: sdk.TrxToken
|
|
429
|
+
trx?: sdk.TrxToken,
|
|
430
|
+
requiredLevels?: number
|
|
429
431
|
): Promise<Beef | undefined> {
|
|
430
432
|
const beef = mergeToBeef || new Beef()
|
|
431
433
|
|
|
432
434
|
const r = await this.getProvenOrRawTx(txid, trx)
|
|
433
435
|
if (r.proven) {
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
if (requiredLevels) {
|
|
437
|
+
r.rawTx = r.proven.rawTx
|
|
438
|
+
} else {
|
|
439
|
+
if (trustSelf === 'known') beef.mergeTxidOnly(txid)
|
|
440
|
+
else {
|
|
441
|
+
beef.mergeRawTx(r.proven.rawTx)
|
|
442
|
+
const mp = new EntityProvenTx(r.proven).getMerklePath()
|
|
443
|
+
beef.mergeBump(mp)
|
|
444
|
+
return beef
|
|
445
|
+
}
|
|
440
446
|
}
|
|
441
447
|
}
|
|
442
448
|
|
|
443
|
-
if (r.rawTx
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
449
|
+
if (!r.rawTx) return undefined
|
|
450
|
+
|
|
451
|
+
if (trustSelf === 'known') {
|
|
452
|
+
beef.mergeTxidOnly(txid)
|
|
453
|
+
} else {
|
|
454
|
+
beef.mergeRawTx(r.rawTx)
|
|
455
|
+
if (r.inputBEEF) beef.mergeBeef(r.inputBEEF)
|
|
456
|
+
const tx = Transaction.fromBinary(r.rawTx)
|
|
457
|
+
if (requiredLevels) requiredLevels--
|
|
458
|
+
for (const input of tx.inputs) {
|
|
459
|
+
const btx = beef.findTxid(input.sourceTXID!)
|
|
460
|
+
if (!btx) {
|
|
461
|
+
if (!requiredLevels && knownTxids && knownTxids.indexOf(input.sourceTXID!) > -1)
|
|
462
|
+
beef.mergeTxidOnly(input.sourceTXID!)
|
|
463
|
+
else await this.getValidBeefForKnownTxid(input.sourceTXID!, beef, trustSelf, knownTxids, trx, requiredLevels)
|
|
455
464
|
}
|
|
456
|
-
return beef
|
|
457
465
|
}
|
|
458
466
|
}
|
|
459
|
-
|
|
460
|
-
return undefined
|
|
467
|
+
return beef
|
|
461
468
|
}
|
|
462
469
|
|
|
463
470
|
async getBeefForTransaction(txid: string, options: sdk.StorageGetBeefOptions): Promise<Beef> {
|
|
464
|
-
|
|
471
|
+
const beef = await getBeefForTransaction(this, txid, options)
|
|
472
|
+
return beef
|
|
465
473
|
}
|
|
466
474
|
|
|
467
475
|
async findMonitorEventById(id: number, trx?: sdk.TrxToken): Promise<TableMonitorEvent | undefined> {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
sdk,
|
|
3
|
-
TableCertificate,
|
|
4
2
|
TableCertificateField,
|
|
5
3
|
TableCertificateX,
|
|
6
4
|
TableCommission,
|
|
@@ -16,11 +14,10 @@ import {
|
|
|
16
14
|
TableTransaction,
|
|
17
15
|
TableTxLabel,
|
|
18
16
|
TableTxLabelMap,
|
|
19
|
-
TableUser
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from '../index.client'
|
|
17
|
+
TableUser
|
|
18
|
+
} from './schema/tables'
|
|
19
|
+
import * as sdk from '../sdk/index'
|
|
20
|
+
import { validateSecondsSinceEpoch, verifyOneOrNone, verifyTruthy } from '../utility/utilityHelpers'
|
|
24
21
|
import { getSyncChunk } from './methods/getSyncChunk'
|
|
25
22
|
|
|
26
23
|
/**
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
randomBytesBase64,
|
|
3
|
-
sdk,
|
|
4
2
|
TableCertificate,
|
|
5
3
|
TableCertificateField,
|
|
6
4
|
TableCommission,
|
|
@@ -15,12 +13,10 @@ import {
|
|
|
15
13
|
TableTransaction,
|
|
16
14
|
TableTxLabel,
|
|
17
15
|
TableTxLabelMap,
|
|
18
|
-
TableUser
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
verifyTruthy
|
|
23
|
-
} from '../index.client'
|
|
16
|
+
TableUser
|
|
17
|
+
} from './schema/tables'
|
|
18
|
+
import { randomBytesBase64, verifyOneOrNone, verifyId, verifyOne } from '../utility/utilityHelpers'
|
|
19
|
+
import * as sdk from '../sdk/index'
|
|
24
20
|
import { createSyncMap } from './schema/entities'
|
|
25
21
|
import { StorageReader, StorageReaderOptions } from './StorageReader'
|
|
26
22
|
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
TableCertificate,
|
|
4
|
-
TableCertificateField,
|
|
5
|
-
TableCertificateX,
|
|
6
|
-
TableCommission,
|
|
7
|
-
TableOutput,
|
|
8
|
-
TableOutputBasket,
|
|
9
|
-
TableOutputTag,
|
|
10
|
-
TableOutputTagMap,
|
|
11
|
-
TableProvenTx,
|
|
12
|
-
TableProvenTxReq,
|
|
13
|
-
TableSettings,
|
|
14
|
-
TableSyncState,
|
|
15
|
-
TableTransaction,
|
|
16
|
-
TableTxLabel,
|
|
17
|
-
TableTxLabelMap,
|
|
18
|
-
TableUser
|
|
19
|
-
} from '../index.client'
|
|
1
|
+
import * as sdk from '../sdk/index'
|
|
2
|
+
import { TableSettings } from '../storage/schema/tables/TableSettings'
|
|
20
3
|
import { StorageReader } from './StorageReader'
|
|
21
4
|
|
|
22
5
|
/**
|
|
@@ -438,7 +438,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
438
438
|
return await writer.createAction(auth, vargs)
|
|
439
439
|
})
|
|
440
440
|
}
|
|
441
|
-
async internalizeAction(args: InternalizeActionArgs): Promise<
|
|
441
|
+
async internalizeAction(args: InternalizeActionArgs): Promise<sdk.StorageInternalizeActionResult> {
|
|
442
442
|
sdk.validateInternalizeActionArgs(args)
|
|
443
443
|
return await this.runAsWriter(async writer => {
|
|
444
444
|
const auth = await this.getAuth(true)
|
|
@@ -17,6 +17,7 @@ describe('StorageIdb tests', () => {
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
test('1', async () => {
|
|
20
|
+
// TODO: THIS TEST PASSES WHEN Describe is run alone, but fails to exit cleanly when run with `npm run test`
|
|
20
21
|
if (Setup.noEnv('test')) return
|
|
21
22
|
const env = Setup.getEnv('test')
|
|
22
23
|
const wallet = await SetupClient.createWalletClientNoEnv({
|
|
@@ -4,6 +4,7 @@ import { Setup } from '../../Setup'
|
|
|
4
4
|
import { StorageKnex } from '../StorageKnex'
|
|
5
5
|
import { AuthFetch, WalletInterface } from '@bsv/sdk'
|
|
6
6
|
import { StorageAdminStats, StorageClient } from '../index.client'
|
|
7
|
+
import { Format } from '../../utility/Format'
|
|
7
8
|
|
|
8
9
|
describe('storage adminStats tests', () => {
|
|
9
10
|
jest.setTimeout(99999999)
|
|
@@ -36,6 +37,7 @@ describe('storage adminStats tests', () => {
|
|
|
36
37
|
|
|
37
38
|
test('0 adminStats StorageKnex', async () => {
|
|
38
39
|
const r = await storage.adminStats(env.identityKey)
|
|
40
|
+
console.log(Format.toLogStringAdminStats(r))
|
|
39
41
|
expect(r.requestedBy).toBe(env.identityKey)
|
|
40
42
|
expect(r.usersTotal).toBeGreaterThan(0)
|
|
41
43
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sdk, validateStorageFeeModel } from '../../index.client'
|
|
2
|
+
import { transactionSize } from './utils'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* An output of this satoshis amount will be adjusted to the largest fundable amount.
|
|
@@ -545,57 +546,3 @@ export function generateChangeSdkMakeStorage(availableChange: GenerateChangeSdkC
|
|
|
545
546
|
|
|
546
547
|
return { allocateChangeInput, releaseChangeInput, getLog }
|
|
547
548
|
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Returns the byte size required to encode number as Bitcoin VarUint
|
|
551
|
-
* @publicbody
|
|
552
|
-
*/
|
|
553
|
-
export function varUintSize(val: number): 1 | 3 | 5 | 9 {
|
|
554
|
-
if (val < 0) throw new sdk.WERR_INVALID_PARAMETER('varUint', 'non-negative')
|
|
555
|
-
return val <= 0xfc ? 1 : val <= 0xffff ? 3 : val <= 0xffffffff ? 5 : 9
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* @param scriptSize byte length of input script
|
|
560
|
-
* @returns serialized byte length a transaction input
|
|
561
|
-
*/
|
|
562
|
-
export function transactionInputSize(scriptSize: number): number {
|
|
563
|
-
return (
|
|
564
|
-
32 + // txid
|
|
565
|
-
4 + // vout
|
|
566
|
-
varUintSize(scriptSize) + // script length, this is already in bytes
|
|
567
|
-
scriptSize + // script
|
|
568
|
-
4
|
|
569
|
-
) // sequence number
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* @param scriptSize byte length of output script
|
|
574
|
-
* @returns serialized byte length a transaction output
|
|
575
|
-
*/
|
|
576
|
-
export function transactionOutputSize(scriptSize: number): number {
|
|
577
|
-
return (
|
|
578
|
-
varUintSize(scriptSize) + // output script length, from script encoded as hex string
|
|
579
|
-
scriptSize + // output script
|
|
580
|
-
8
|
|
581
|
-
) // output amount (satoshis)
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* Compute the serialized binary transaction size in bytes
|
|
586
|
-
* given the number of inputs and outputs,
|
|
587
|
-
* and the size of each script.
|
|
588
|
-
* @param inputs array of input script lengths, in bytes
|
|
589
|
-
* @param outputs array of output script lengths, in bytes
|
|
590
|
-
* @returns total transaction size in bytes
|
|
591
|
-
*/
|
|
592
|
-
export function transactionSize(inputs: number[], outputs: number[]): number {
|
|
593
|
-
return (
|
|
594
|
-
4 + // Version
|
|
595
|
-
varUintSize(inputs.length) + // Number of inputs
|
|
596
|
-
inputs.reduce((a, e) => a + transactionInputSize(e), 0) + // all inputs
|
|
597
|
-
varUintSize(outputs.length) + // Number of outputs
|
|
598
|
-
outputs.reduce((a, e) => a + transactionOutputSize(e), 0) + // all outputs
|
|
599
|
-
4
|
|
600
|
-
) // lock time
|
|
601
|
-
}
|
|
@@ -71,7 +71,15 @@ async function mergeBeefForTransactionRecurse(
|
|
|
71
71
|
|
|
72
72
|
if (!options.ignoreStorage) {
|
|
73
73
|
// if we can use storage, ask storage if it has the txid
|
|
74
|
-
const
|
|
74
|
+
const requiredLevels = options.minProofLevel === undefined ? undefined : options.minProofLevel + recursionDepth
|
|
75
|
+
const knownBeef = await storage.getValidBeefForTxid(
|
|
76
|
+
txid,
|
|
77
|
+
beef,
|
|
78
|
+
options.trustSelf,
|
|
79
|
+
options.knownTxids,
|
|
80
|
+
undefined,
|
|
81
|
+
requiredLevels
|
|
82
|
+
)
|
|
75
83
|
if (knownBeef) return knownBeef
|
|
76
84
|
}
|
|
77
85
|
|
|
@@ -82,7 +90,7 @@ async function mergeBeefForTransactionRecurse(
|
|
|
82
90
|
// to find it and if it has a proof, remember it.
|
|
83
91
|
const r = await getProvenOrRawTxFromServices(storage, txid, options)
|
|
84
92
|
|
|
85
|
-
if (r.proven && options.minProofLevel && options.minProofLevel > recursionDepth) {
|
|
93
|
+
if (r.proven && options.minProofLevel !== undefined && options.minProofLevel > recursionDepth) {
|
|
86
94
|
// ignore proof at this recursion depth
|
|
87
95
|
r.proven = undefined
|
|
88
96
|
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
WalletPayment,
|
|
6
6
|
BasketInsertion,
|
|
7
7
|
InternalizeActionArgs,
|
|
8
|
-
InternalizeActionResult,
|
|
9
8
|
TransactionOutput,
|
|
10
9
|
Beef
|
|
11
10
|
} from '@bsv/sdk'
|
|
@@ -13,7 +12,6 @@ import {
|
|
|
13
12
|
EntityProvenTxReq,
|
|
14
13
|
randomBytesBase64,
|
|
15
14
|
sdk,
|
|
16
|
-
stampLog,
|
|
17
15
|
StorageProvider,
|
|
18
16
|
TableOutput,
|
|
19
17
|
TableOutputBasket,
|
|
@@ -22,15 +20,7 @@ import {
|
|
|
22
20
|
verifyOne,
|
|
23
21
|
verifyOneOrNone
|
|
24
22
|
} from '../../index.client'
|
|
25
|
-
|
|
26
|
-
export interface StorageInternalizeActionResult extends InternalizeActionResult {
|
|
27
|
-
/** true if internalizing outputs on an existing storage transaction */
|
|
28
|
-
isMerge: boolean
|
|
29
|
-
/** txid of transaction being internalized */
|
|
30
|
-
txid: string
|
|
31
|
-
/** net change in change balance for user due to this internalization */
|
|
32
|
-
satoshis: number
|
|
33
|
-
}
|
|
23
|
+
import { shareReqsWithWorld } from './processAction'
|
|
34
24
|
|
|
35
25
|
/**
|
|
36
26
|
* Internalize Action allows a wallet to take ownership of outputs in a pre-existing transaction.
|
|
@@ -62,7 +52,7 @@ export async function internalizeAction(
|
|
|
62
52
|
storage: StorageProvider,
|
|
63
53
|
auth: sdk.AuthId,
|
|
64
54
|
args: InternalizeActionArgs
|
|
65
|
-
): Promise<
|
|
55
|
+
): Promise<sdk.StorageInternalizeActionResult> {
|
|
66
56
|
const ctx = new InternalizeActionContext(storage, auth, args)
|
|
67
57
|
await ctx.asyncSetup()
|
|
68
58
|
|
|
@@ -94,7 +84,7 @@ interface WalletPaymentX extends WalletPayment {
|
|
|
94
84
|
|
|
95
85
|
class InternalizeActionContext {
|
|
96
86
|
/** result to be returned */
|
|
97
|
-
r: StorageInternalizeActionResult
|
|
87
|
+
r: sdk.StorageInternalizeActionResult
|
|
98
88
|
/** the parsed input AtomicBEEF */
|
|
99
89
|
ab: Beef
|
|
100
90
|
/** the incoming transaction extracted from AtomicBEEF */
|
|
@@ -356,11 +346,29 @@ class InternalizeActionContext {
|
|
|
356
346
|
// transaction record for user is new, but the txid may not be new to storage
|
|
357
347
|
// make sure storage pursues getting a proof for it.
|
|
358
348
|
const newReq = EntityProvenTxReq.fromTxid(this.txid, this.tx.toBinary(), this.args.tx)
|
|
359
|
-
|
|
349
|
+
// this status is only relevant if the transaction is new to storage.
|
|
350
|
+
newReq.status = 'unprocessed'
|
|
351
|
+
// this history and notify will be merged into an existing req if it exists.
|
|
360
352
|
newReq.addHistoryNote({ what: 'internalizeAction', userId: this.userId })
|
|
361
353
|
newReq.addNotifyTransactionId(transactionId)
|
|
362
354
|
const pr = await this.storage.getProvenOrReq(this.txid, newReq.toApi())
|
|
363
355
|
|
|
356
|
+
if (pr.isNew) {
|
|
357
|
+
// This storage doesn't know about this txid yet.
|
|
358
|
+
|
|
359
|
+
// TODO Can we immediately prove this txid?
|
|
360
|
+
|
|
361
|
+
// Attempt to broadcast it to the network, throwing an error if it fails.
|
|
362
|
+
|
|
363
|
+
const { swr, ndr } = await shareReqsWithWorld(this.storage, this.userId, [this.txid], false)
|
|
364
|
+
if (ndr![0].status !== 'success') {
|
|
365
|
+
this.r.sendWithResults = swr
|
|
366
|
+
this.r.notDelayedResults = ndr
|
|
367
|
+
// abort the internalize action, WERR_REVIEW_ACTIONS exception will be thrown
|
|
368
|
+
return
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
364
372
|
await this.addLabels(transactionId)
|
|
365
373
|
|
|
366
374
|
for (const payment of this.walletPayments) {
|
|
@@ -108,7 +108,7 @@ export interface PostBeefResultForTxidApi {
|
|
|
108
108
|
* @param txids
|
|
109
109
|
* @param isDelayed
|
|
110
110
|
*/
|
|
111
|
-
async function shareReqsWithWorld(
|
|
111
|
+
export async function shareReqsWithWorld(
|
|
112
112
|
storage: StorageProvider,
|
|
113
113
|
userId: number,
|
|
114
114
|
txids: string[],
|
|
@@ -154,7 +154,10 @@ async function shareReqsWithWorld(
|
|
|
154
154
|
// If isDelayed, this (or a different beef) will have to be rebuilt at the time of sending.
|
|
155
155
|
if (readyToSendReqs.length > 0) {
|
|
156
156
|
const beefIsValid = await r.beef.verify(await storage.getServices().getChainTracker())
|
|
157
|
-
if (!beefIsValid)
|
|
157
|
+
if (!beefIsValid) {
|
|
158
|
+
console.log(`VERIFY FALSE BEEF: ${r.beef.toLogString()}`)
|
|
159
|
+
throw new sdk.WERR_INTERNAL(`merged Beef failed validation.`)
|
|
160
|
+
}
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
// Set req batch property for the reqs being sent
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a copy of a Buffer with byte order reversed.
|
|
3
|
+
* @returns new buffer with byte order reversed.
|
|
4
|
+
* @publicbody
|
|
5
|
+
*/
|
|
6
|
+
export function swapByteOrder(buffer: Buffer): Buffer {
|
|
7
|
+
return Buffer.from(buffer).reverse()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param num a number value in the Uint32 value range
|
|
12
|
+
* @param littleEndian true for little-endian byte order in Buffer
|
|
13
|
+
* @returns four byte buffer with Uint32 number encoded
|
|
14
|
+
* @publicbody
|
|
15
|
+
*/
|
|
16
|
+
export function convertUint32ToBuffer(num: number, littleEndian = true): Buffer {
|
|
17
|
+
const arr = new ArrayBuffer(4)
|
|
18
|
+
const view = new DataView(arr)
|
|
19
|
+
view.setUint32(0, num, littleEndian) // byteOffset = 0
|
|
20
|
+
return Buffer.from(arr)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param buffer four byte buffer with Uint32 number encoded
|
|
25
|
+
* @param littleEndian true for little-endian byte order in Buffer
|
|
26
|
+
* @returns a number value in the Uint32 value range
|
|
27
|
+
* @publicbody
|
|
28
|
+
*/
|
|
29
|
+
export function convertBufferToUint32(buffer: Buffer, littleEndian = true): number {
|
|
30
|
+
const arr = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)
|
|
31
|
+
const view = new DataView(arr)
|
|
32
|
+
return view.getUint32(0, littleEndian)
|
|
33
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { sdk } from '../../index.client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the byte size required to encode number as Bitcoin VarUint
|
|
5
|
+
* @publicbody
|
|
6
|
+
*/
|
|
7
|
+
export function varUintSize(val: number): 1 | 3 | 5 | 9 {
|
|
8
|
+
if (val < 0) throw new sdk.WERR_INVALID_PARAMETER('varUint', 'non-negative')
|
|
9
|
+
return val <= 0xfc ? 1 : val <= 0xffff ? 3 : val <= 0xffffffff ? 5 : 9
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param scriptSize byte length of input script
|
|
14
|
+
* @returns serialized byte length a transaction input
|
|
15
|
+
*/
|
|
16
|
+
export function transactionInputSize(scriptSize: number): number {
|
|
17
|
+
return (
|
|
18
|
+
32 + // txid
|
|
19
|
+
4 + // vout
|
|
20
|
+
varUintSize(scriptSize) + // script length, this is already in bytes
|
|
21
|
+
scriptSize + // script
|
|
22
|
+
4
|
|
23
|
+
) // sequence number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param scriptSize byte length of output script
|
|
28
|
+
* @returns serialized byte length a transaction output
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export function transactionOutputSize(scriptSize: number): number {
|
|
32
|
+
return (
|
|
33
|
+
varUintSize(scriptSize) + // output script length, from script encoded as hex string
|
|
34
|
+
scriptSize + // output script
|
|
35
|
+
8
|
|
36
|
+
) // output amount (satoshis)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Compute the serialized binary transaction size in bytes
|
|
41
|
+
* given the number of inputs and outputs,
|
|
42
|
+
* and the size of each script.
|
|
43
|
+
* @param inputs array of input script lengths, in bytes
|
|
44
|
+
* @param outputs array of output script lengths, in bytes
|
|
45
|
+
* @returns total transaction size in bytes
|
|
46
|
+
*/
|
|
47
|
+
export function transactionSize(inputs: number[], outputs: number[]): number {
|
|
48
|
+
return (
|
|
49
|
+
4 + // Version
|
|
50
|
+
varUintSize(inputs.length) + // Number of inputs
|
|
51
|
+
inputs.reduce((a, e) => a + transactionInputSize(e), 0) + // all inputs
|
|
52
|
+
varUintSize(outputs.length) + // Number of outputs
|
|
53
|
+
outputs.reduce((a, e) => a + transactionOutputSize(e), 0) + // all outputs
|
|
54
|
+
4
|
|
55
|
+
) // lock time
|
|
56
|
+
}
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
} from '@bsv/sdk'
|
|
14
14
|
import {
|
|
15
15
|
sdk,
|
|
16
|
-
TableCertificate,
|
|
17
16
|
TableCertificateX,
|
|
18
17
|
TableOutput,
|
|
19
18
|
TableOutputBasket,
|
|
@@ -196,8 +195,8 @@ export class StorageClient implements sdk.WalletStorageProvider {
|
|
|
196
195
|
* @param args Original wallet `internalizeAction` arguments.
|
|
197
196
|
* @returns `internalizeAction` results
|
|
198
197
|
*/
|
|
199
|
-
async internalizeAction(auth: sdk.AuthId, args: InternalizeActionArgs): Promise<
|
|
200
|
-
return this.rpcCall<
|
|
198
|
+
async internalizeAction(auth: sdk.AuthId, args: InternalizeActionArgs): Promise<sdk.StorageInternalizeActionResult> {
|
|
199
|
+
return this.rpcCall<sdk.StorageInternalizeActionResult>('internalizeAction', [auth, args])
|
|
201
200
|
}
|
|
202
201
|
|
|
203
202
|
/**
|