Skip to content

Commit

Permalink
NewChangeAddress endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Sep 23, 2024
1 parent be601bc commit 12bed87
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
11 changes: 9 additions & 2 deletions backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions ios/LndMobile/Lnd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
6 changes: 6 additions & 0 deletions lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
import {
getTransactions,
newAddress,
newChangeAddress,
sendCoins,
sendCoinsAll,
walletBalance,
Expand Down Expand Up @@ -325,6 +326,10 @@ export interface ILndMobileInjections {
type: lnrpc.AddressType,
account?: string
) => Promise<lnrpc.NewAddressResponse>;
newChangeAddress: (
type: walletrpc.AddressType,
account?: string
) => Promise<walletrpc.AddrResponse>;
sendCoins: (
address: string,
sat: number,
Expand Down Expand Up @@ -516,6 +521,7 @@ export default {
onchain: {
getTransactions,
newAddress,
newChangeAddress,
sendCoins,
sendCoinsAll,
walletBalance,
Expand Down
26 changes: 25 additions & 1 deletion lndmobile/onchain.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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<walletrpc.AddrResponse> => {
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
*/
Expand Down
14 changes: 14 additions & 0 deletions stores/UTXOsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions utils/BackendUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 12bed87

Please sign in to comment.