From 625b8895b07dd98ee9ff06d9baaae9b4eabbf5d7 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sun, 1 Jun 2025 17:23:35 -0700 Subject: [PATCH] feat(moveTokensFromCustomWallet()): Using user wallet, not system wallet to stash new Offer UTXOs --- src/adapters/wallet.js | 14 +++++++++++--- test/unit/adapters/wallet.unit.js | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/adapters/wallet.js b/src/adapters/wallet.js index fbb7dd5..572252f 100644 --- a/src/adapters/wallet.js +++ b/src/adapters/wallet.js @@ -161,10 +161,9 @@ class WalletAdapter { } } + // Note: This method uses the system wallet, not the user or admin wallet. // This method returns an object that contains a private key WIF, public address, // and the index of the HD wallet that the key pair was generated from. - // TODO: Allow input integer. If input is used, use that as the index. If no - // input is provided, then call incrementNextAddress(). async getKeyPair (hdIndex = 0) { try { if (!hdIndex) { @@ -173,6 +172,7 @@ class WalletAdapter { } const mnemonic = this.bchWallet.walletInfo.mnemonic + console.log(`getKeyPair() for HD index: ${hdIndex} called on mnemonic: ${mnemonic}`) // root seed buffer const rootSeed = await this.bchWallet.bchjs.Mnemonic.toSeed(mnemonic) @@ -587,6 +587,8 @@ class WalletAdapter { } } + // This function is consumed by the use-cases/order.js/createOrder() function. + // Tokens are moved from the primary address to a holding address to protect the Order UTXO. async moveTokensFromCustomWallet (inObj = {}) { try { const { tokenId, qty, wallet } = inObj @@ -601,7 +603,13 @@ class WalletAdapter { throw new Error('wallet is required!') } - const keyPair = await this.getKeyPair() + // Replace the system wallet with the user wallet. + // this.bchWallet = wallet + + // DEV Note: Storing all token Offers in index 2 of the HD wallet. + // This makes them easy to sweep, and can be uniquely identified by their UTXO. + // Note: use walle.getKeyPair() to use the user wallet. this.getKeyPair uses the system wallet. + const keyPair = await wallet.getKeyPair(2) console.log('keyPair: ', keyPair) const receiver = { diff --git a/test/unit/adapters/wallet.unit.js b/test/unit/adapters/wallet.unit.js index c9e6760..b7d90c5 100644 --- a/test/unit/adapters/wallet.unit.js +++ b/test/unit/adapters/wallet.unit.js @@ -43,6 +43,7 @@ describe('#wallet', () => { }) const customWallet = new MockBchWallet() + customWallet.getKeyPair = () => { return { cashAddress: 'cashAddress', wif: 'wif', hdIndex: 11 } } customWallet.sendTokens = () => { return 'move token tx id result' } customWallet.utxos.utxoStore.slpUtxos.type1.tokens = [ {