fix(wallet): Adding incrementNextAddress() method to wallet adapter

This commit is contained in:
Chris Troutner
2021-09-13 12:05:22 -07:00
parent 34335a13a0
commit 3ef4518db7
2 changed files with 32 additions and 0 deletions
+23
View File
@@ -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) {
@@ -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) => {