diff --git a/backends/EmbeddedLND.ts b/backends/EmbeddedLND.ts index 2c27dd3f8c..9a3b0b4232 100644 --- a/backends/EmbeddedLND.ts +++ b/backends/EmbeddedLND.ts @@ -51,8 +51,13 @@ const { importAccount, rescan } = lndMobile.wallet; -const { walletBalance, newAddress, getTransactions, sendCoins } = - lndMobile.onchain; +const { + walletBalance, + newAddress, + newChangeAddress, + getTransactions, + sendCoins +} = lndMobile.onchain; export default class EmbeddedLND extends LND { openChannelListener: any; @@ -93,6 +98,8 @@ export default class EmbeddedLND extends LND { getPayments = async () => await listPayments(); getNewAddress = async (data: any) => await newAddress(data.type, data.account); + getNewChangeAddress = async (data: any) => + await newChangeAddress(data.type, data.account); openChannelSync = async (data: OpenChannelRequest) => await openChannelSync( data.node_pubkey_string, diff --git a/ios/LndMobile/Lnd.swift b/ios/LndMobile/Lnd.swift index be156e4320..39457c0295 100644 --- a/ios/LndMobile/Lnd.swift +++ b/ios/LndMobile/Lnd.swift @@ -128,6 +128,7 @@ open class Lnd { "WalletKitListUnspent": { bytes, cb in LndmobileWalletKitListUnspent(bytes, cb) }, "WalletKitDeriveKey": { bytes, cb in LndmobileWalletKitDeriveKey(bytes, cb) }, "WalletKitRescan": { bytes, cb in LndmobileWalletKitRescan(bytes, cb) }, + "WalletKitNextAddr": { bytes, cb in LndmobileWalletKitNextAddr(bytes, cb) }, // derivePrivateKey "VerifyMessage": { bytes, cb in LndmobileVerifyMessage(bytes, cb) }, diff --git a/lndmobile/LndMobileInjection.ts b/lndmobile/LndMobileInjection.ts index 7dd82779b7..8958a880d7 100644 --- a/lndmobile/LndMobileInjection.ts +++ b/lndmobile/LndMobileInjection.ts @@ -66,6 +66,7 @@ import { import { getTransactions, newAddress, + newChangeAddress, sendCoins, sendCoinsAll, walletBalance, @@ -325,6 +326,10 @@ export interface ILndMobileInjections { type: lnrpc.AddressType, account?: string ) => Promise; + newChangeAddress: ( + type: walletrpc.AddressType, + account?: string + ) => Promise; sendCoins: ( address: string, sat: number, @@ -516,6 +521,7 @@ export default { onchain: { getTransactions, newAddress, + newChangeAddress, sendCoins, sendCoinsAll, walletBalance, diff --git a/lndmobile/onchain.ts b/lndmobile/onchain.ts index d0e31116e2..208101050a 100644 --- a/lndmobile/onchain.ts +++ b/lndmobile/onchain.ts @@ -1,5 +1,5 @@ import { sendCommand, sendStreamCommand, decodeStreamResult } from './utils'; -import { lnrpc } from './../proto/lightning'; +import { lnrpc, walletrpc } from './../proto/lightning'; import Long from 'long'; /** @@ -42,6 +42,30 @@ export const newAddress = async ( return response; }; +/** + * @throws + */ +export const newChangeAddress = async ( + type: walletrpc.AddressType = walletrpc.AddressType.WITNESS_PUBKEY_HASH, + account: string = 'default' +): Promise => { + const response = await sendCommand< + walletrpc.IAddrRequest, + walletrpc.AddrRequest, + walletrpc.AddrResponse + >({ + request: walletrpc.AddrRequest, + response: walletrpc.AddrResponse, + method: 'WalletKitNextAddr', + options: { + type, + account, + change: true + } + }); + return response; +}; + /** * @throws */ diff --git a/stores/UTXOsStore.ts b/stores/UTXOsStore.ts index 7393166341..dcbdb69979 100644 --- a/stores/UTXOsStore.ts +++ b/stores/UTXOsStore.ts @@ -199,6 +199,8 @@ export default class UTXOsStore { data.birthday_height = this.start_height; } + console.log('importAccount req', data); + return BackendUtils.importAccount(data) .then(async (response: any) => { this.importingAccount = false; @@ -219,6 +221,18 @@ export default class UTXOsStore { response.address ); }); + await BackendUtils.getNewChangeAddress({ + account: this.accountToImport.account.name, + type: walletrpc.AddressType[ + this.accountToImport.account.address_type + ], + change: true + }).then((response: any) => { + console.log( + 'generated change address', + response.addr + ); + }); } console.log( diff --git a/utils/BackendUtils.ts b/utils/BackendUtils.ts index 5d4fa9816a..af9f1363e6 100644 --- a/utils/BackendUtils.ts +++ b/utils/BackendUtils.ts @@ -85,6 +85,8 @@ class BackendUtils { createInvoice = (...args: any[]) => this.call('createInvoice', args); getPayments = (...args: any[]) => this.call('getPayments', args); getNewAddress = (...args: any[]) => this.call('getNewAddress', args); + getNewChangeAddress = (...args: any[]) => + this.call('getNewChangeAddress', args); openChannelSync = (...args: any[]) => this.call('openChannelSync', args); openChannelStream = (...args: any[]) => this.call('openChannelStream', args);