diff --git a/src/adapters/wallet.js b/src/adapters/wallet.js index 7ed6c64..0e85f6a 100644 --- a/src/adapters/wallet.js +++ b/src/adapters/wallet.js @@ -44,6 +44,9 @@ class WalletAdapter { walletData = walletInstance.walletInfo + // Add the nextAddress property + walletData.nextAddress = 1 + // Write the wallet data to the JSON file. await this.jsonFiles.writeJSON(walletData, this.WALLET_FILE) } @@ -57,6 +60,26 @@ class WalletAdapter { } } + // Increments the 'nextAddress' property in the wallet file. This property + // indicates the HD index that should be used to generate a key pair for + // storing funds for Offers. + // This function opens the wallet file, increments the nextAddress property, + // then saves the change to the wallet file. + async incrementNextAddress () { + try { + const walletData = await this.openWallet() + // console.log('original walletdata: ', walletData) + + walletData.nextAddress++ + + // console.log('walletData finish: ', walletData) + await this.jsonFiles.writeJSON(walletData, this.WALLET_FILE) + } catch (err) { + console.error('Error in incrementNextAddress()') + throw err + } + } + // Create an instance of minimal-slp-wallet. Use data in the wallet.json file, // and pass the bch-js information to the minimal-slp-wallet library. async instanceWallet (walletData, bchjs) { diff --git a/test/unit/adapters/wallet.adapter.unit.js b/test/unit/adapters/wallet.adapter.unit.js index aa869aa..f146366 100644 --- a/test/unit/adapters/wallet.adapter.unit.js +++ b/test/unit/adapters/wallet.adapter.unit.js @@ -196,6 +196,15 @@ describe('#wallet', () => { } }) }) + + describe('#incrementNextAddress', () => { + it('should increment the nextAddress property', async () => { + // Ensure we open the test file, not the production wallet file. + uut.WALLET_FILE = testWalletFile + + await uut.incrementNextAddress() + }) + }) }) const deleteFile = (filepath) => {