Skip to content

Commit

Permalink
Merge pull request #2242 from myxmaster/on-chain-addresses
Browse files Browse the repository at this point in the history
New screen: On-chain addresses
  • Loading branch information
kaloudis authored Sep 27, 2024
2 parents d1a8502 + 97305d5 commit 10f3f4d
Show file tree
Hide file tree
Showing 27 changed files with 773 additions and 59 deletions.
7 changes: 7 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Payment from './views/Payment';
import PaymentPaths from './views/PaymentPaths';
import Invoice from './views/Invoice';
import Sweep from './views/Sweep';
import OnChainAddresses from './views/OnChainAddresses';

import SparkQRScanner from './views/SparkQRScanner';
import NodeInfo from './views/NodeInfo';
Expand Down Expand Up @@ -876,6 +877,12 @@ export default class App extends React.PureComponent {
name="PendingHTLCs"
component={PendingHTLCs}
/>
<Stack.Screen
name="OnChainAddresses"
component={
OnChainAddresses
}
/>
</Stack.Navigator>
</NavigationContainer>
</>
Expand Down
1 change: 1 addition & 0 deletions backends/CLNRest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ export default class CLNRest {
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
supportsOffers = async () => {
const { configs } = await this.postRequest('/v1/listconfigs');

Expand Down
1 change: 1 addition & 0 deletions backends/CLightningREST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export default class CLightningREST extends LND {
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
supportsOffers = async () => {
const res = await this.getRequest('/v1/utility/listConfigs');
const supportsOffers: boolean = res['experimental-offers'] || false;
Expand Down
1 change: 1 addition & 0 deletions backends/Eclair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ export default class Eclair {
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
supportsOffers = () => false;
isLNDBased = () => false;
supportInboundFees = () => false;
Expand Down
3 changes: 3 additions & 0 deletions backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const {
finalizePsbt,
publishTransaction,
listAccounts,
listAddresses,
importAccount,
rescan
} = lndMobile.wallet;
Expand Down Expand Up @@ -272,6 +273,7 @@ export default class EmbeddedLND extends LND {
lookupInvoice = async (data: any) => await lookupInvoice(data.r_hash);

listAccounts = async () => await listAccounts();
listAddresses = async () => await listAddresses();
importAccount = async (data: any) => await importAccount(data);
rescan = async (data: any) => await rescan(data);

Expand Down Expand Up @@ -314,6 +316,7 @@ export default class EmbeddedLND extends LND {
supportsLSPS1rest = () => false;
supportsOffers = () => false;
supportsBolt11BlindedRoutes = () => this.supports('v0.18.3');
supportsAddressesWithDerivationPaths = () => this.supports('v0.18.0');
isLNDBased = () => true;
supportInboundFees = () => this.supports('v0.18.0');
}
4 changes: 4 additions & 0 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ export default class LND {
});
getPayments = () => this.getRequest('/v1/payments?include_incomplete=true');
getNewAddress = (data: any) => this.getRequest('/v1/newaddress', data);
getNewChangeAddress = (data: any) =>
this.postRequest('/v2/wallet/address/next', data);
openChannelSync = (data: OpenChannelRequest) => {
let request: any = {
private: data.privateChannel,
Expand Down Expand Up @@ -571,6 +573,7 @@ export default class LND {
getUTXOs = (data: any) => this.postRequest('/v2/wallet/utxos', data);
bumpFee = (data: any) => this.postRequest('/v2/wallet/bumpfee', data);
listAccounts = () => this.getRequest('/v2/wallet/accounts');
listAddresses = () => this.getRequest('/v2/wallet/addresses');
importAccount = (data: any) =>
this.postRequest('/v2/wallet/accounts/import', data);
signMessage = (message: string) =>
Expand Down Expand Up @@ -690,6 +693,7 @@ export default class LND {
supportsLSPS1rest = () => false;
supportsOffers = (): Promise<boolean> | boolean => false;
supportsBolt11BlindedRoutes = () => this.supports('v0.18.3');
supportsAddressesWithDerivationPaths = () => this.supports('v0.18.0');
isLNDBased = () => true;
supportInboundFees = () => this.supports('v0.18.0');
}
27 changes: 24 additions & 3 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ const ADDRESS_TYPES = [
'UNUSED_TAPROOT_PUBKEY'
];

const NEXT_ADDR_MAP: any = {
WITNESS_PUBKEY_HASH: 0,
NESTED_PUBKEY_HASH: 1,
UNUSED_WITNESS_PUBKEY_HASH: 2,
UNUSED_NESTED_PUBKEY_HASH: 3,
TAPROOT_PUBKEY: 4,
UNUSED_TAPROOT_PUBKEY: 5
};

export default class LightningNodeConnect {
lnc: any;
listener: any;
Expand Down Expand Up @@ -170,11 +179,18 @@ export default class LightningNodeConnect {
getNewAddress = async (data: any) =>
await this.lnc.lnd.lightning
.newAddress({
type: ADDRESS_TYPES[data.type],
type: ADDRESS_TYPES[data.type] || data.type,
account: data.account || 'default'
})
.then((data: lnrpc.NewAddressResponse) => snakeize(data));

.then((data: walletrpc.AddrRequest) => snakeize(data));
getNewChangeAddress = async (data: any) =>
await this.lnc.lnd.walletKit
.nextAddr({
type: NEXT_ADDR_MAP[data.type],
account: data.account || 'default',
change: true
})
.then((data: walletrpc.AddrResponse) => snakeize(data));
openChannelSync = async (data: OpenChannelRequest) => {
let request: lnrpc.OpenChannelRequest = {
private: data.privateChannel,
Expand Down Expand Up @@ -435,6 +451,10 @@ export default class LightningNodeConnect {
await this.lnc.lnd.walletKit
.listAccounts({})
.then((data: walletrpc.ListAccountsResponse) => snakeize(data));
listAddresses = async () =>
await this.lnc.lnd.walletKit
.listAddresses({})
.then((data: walletrpc.ListAddressesResponse) => snakeize(data));
importAccount = async (req: walletrpc.ImportAccountRequest) =>
await this.lnc.lnd.walletKit
.importAccount(req)
Expand Down Expand Up @@ -511,6 +531,7 @@ export default class LightningNodeConnect {
supportsLSPS1rest = () => false;
supportsOffers = () => false;
supportsBolt11BlindedRoutes = () => this.supports('v0.18.3');
supportsAddressesWithDerivationPaths = () => this.supports('v0.18.0');
isLNDBased = () => true;
supportInboundFees = () => this.supports('v0.18.0');
}
1 change: 1 addition & 0 deletions backends/LndHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export default class LndHub extends LND {
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => false;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
supportsOffers = () => false;
isLNDBased = () => false;
supportInboundFees = () => false;
Expand Down
1 change: 1 addition & 0 deletions backends/Spark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export default class Spark {
supportsLSPS1customMessage = () => false;
supportsLSPS1rest = () => true;
supportsBolt11BlindedRoutes = () => false;
supportsAddressesWithDerivationPaths = () => false;
supportsOffers = () => false;
isLNDBased = () => false;
supportInboundFees = () => false;
Expand Down
4 changes: 2 additions & 2 deletions components/DropdownSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export default class DropdownSetting extends React.Component<
}
);

const displayItem = values.filter(
const displayItem = values.find(
(value: any) => value.value === selectedValue
)[0];
);

const display = displayItem ? displayItem.key : null;

Expand Down
1 change: 1 addition & 0 deletions ios/LndMobile/Lnd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ open class Lnd {
"WalletKitSignPsbt": { bytes, cb in LndmobileWalletKitSignPsbt(bytes, cb) },
"WalletKitFinalizePsbt": { bytes, cb in LndmobileWalletKitFinalizePsbt(bytes, cb) },
"WalletKitPublishTransaction": { bytes, cb in LndmobileWalletKitPublishTransaction(bytes, cb) },
"WalletKitListAddresses": { bytes, cb in LndmobileWalletKitListAddresses(bytes, cb) },
"WalletKitListAccounts": { bytes, cb in LndmobileWalletKitListAccounts(bytes, cb) },
"WalletKitImportAccount": { bytes, cb in LndmobileWalletKitImportAccount(bytes, cb) },
"WalletKitBumpFee": { bytes, cb in LndmobileWalletKitBumpFee(bytes, cb) },
Expand Down
3 changes: 3 additions & 0 deletions lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
finalizePsbt,
publishTransaction,
listAccounts,
listAddresses,
importAccount,
rescan
} from './wallet';
Expand Down Expand Up @@ -426,6 +427,7 @@ export interface ILndMobileInjections {
tx_hex: Uint8Array;
}) => Promise<walletrpc.PublishResponse>;
listAccounts: () => Promise<walletrpc.ListAccountsResponse>;
listAddresses: () => Promise<walletrpc.ListAddressesResponse>;
importAccount: ({
name,
extended_public_key,
Expand Down Expand Up @@ -548,6 +550,7 @@ export default {
finalizePsbt,
publishTransaction,
listAccounts,
listAddresses,
importAccount,
rescan
},
Expand Down
18 changes: 18 additions & 0 deletions lndmobile/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ export const listAccounts =
return response;
};

/**
* @throws
*/
export const listAddresses =
async (): Promise<walletrpc.ListAddressesResponse> => {
const response = await sendCommand<
walletrpc.IListAddressesRequest,
walletrpc.ListAddressesRequest,
walletrpc.ListAddressesResponse
>({
request: walletrpc.ListAddressesRequest,
response: walletrpc.ListAddressesResponse,
method: 'WalletKitListAddresses',
options: {}
});
return response;
};

/**
* @throws
*/
Expand Down
17 changes: 15 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"general.used": "Used",
"general.unused": "Unused",
"general.discountCode": "Discount code",
"general.accountName": "Account name",
"general.addressType": "Address type",
"general.sorting": "Sorting",
"general.count": "Count",
"restart.title": "Restart required",
"restart.msg": "ZEUS has to be restarted before the new configuration is applied.",
"restart.msg1": "Would you like to restart now?",
Expand Down Expand Up @@ -277,7 +281,6 @@
"views.SparkQRScanner.text": "Scan a Spark QR code",
"views.SparkQRScanner.error": "Error fetching Spark config",
"views.ImportAccount.title": "Import account",
"views.ImportAccount.name": "Account name",
"views.ImportAccount.extendedPubKey": "Extended Public Key (xpub, zpub, tpub, etc.)",
"views.ImportAccount.masterKeyFingerprint": "Master Key Fingerprint",
"views.ImportAccount.addressType": "Address type",
Expand Down Expand Up @@ -1247,5 +1250,15 @@
"views.PendingHTLCs.outgoing": "Outgoing",
"views.PendingHTLCs.expirationHeight": "Expiration height",
"views.PendingHTLCs.recommendationIOS": "It's recommended to leave ZEUS running while there are pending HTLCs to prevent force closes.",
"views.PendingHTLCs.recommendationAndroid": "It's recommended to enable Persistent LND or leave ZEUS running while there are pending HTLCs to prevent force closes."
"views.PendingHTLCs.recommendationAndroid": "It's recommended to enable Persistent LND or leave ZEUS running while there are pending HTLCs to prevent force closes.",
"views.OnChainAddresses.title": "On-chain addresses",
"views.OnChainAddresses.noAddressesAvailable": "No addresses available",
"views.OnChainAddresses.hideZeroBalanance": "Hide 0-balance",
"views.OnChainAddresses.hideChangeAddresses": "Hide change addresses",
"views.OnChainAddresses.sortBy.creationTimeAscending": "Creation time (ascending)",
"views.OnChainAddresses.sortBy.creationTimeDescending": "Creation time (descending)",
"views.OnChainAddresses.sortBy.balanceAscending": "Balance (ascending)",
"views.OnChainAddresses.sortBy.balanceDescending": "Balance (descending)",
"views.OnChainAddresses.createAddress": "Create address",
"views.OnChainAddresses.changeAddresses": "Change addresses"
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@
"@types/lodash": "4.14.198",
"@types/object-hash": "1.3.4",
"@types/pako": "2.0.3",
"@types/react": "18.0.38",
"@types/react-native": "0.70.6",
"@types/react": "18.2.21",
"@types/react-native": "0.73.0",
"@types/react-native-vector-icons": "6.4.14",
"@types/react-test-renderer": "18.0.2",
"@types/sha.js": "2.4.1",
Expand All @@ -198,6 +198,9 @@
"rn-nodeify": "10.3.0",
"typescript": "4.8.4"
},
"resolutions": {
"@types/react": "18.2.21"
},
"react-native": {
"zlib": "browserify-zlib",
"console": "console-browserify",
Expand Down
26 changes: 26 additions & 0 deletions stores/InvoicesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,32 @@ export default class InvoicesStore {
});
};

@action
public getNewChangeAddress = (params: any) => {
if (!params.unified) {
this.creatingInvoice = true;
this.error_msg = null;
}

params.change = true;

this.onChainAddress = null;
return BackendUtils.getNewChangeAddress(params)
.then((data: any) => {
const address = data.addr;
if (!params.unified) this.onChainAddress = address;
if (!params.unified) this.creatingInvoice = false;
return address;
})
.catch((error: any) => {
// handle error
this.error_msg =
error.toString() ||
localeString('stores.InvoicesStore.errorGeneratingAddress');
this.creatingInvoice = false;
});
};

@action
public clearAddress = () => (this.onChainAddress = null);

Expand Down
30 changes: 30 additions & 0 deletions stores/UTXOsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default class UTXOsStore {
// rescan
@observable public attemptingRescan = false;
@observable public rescanErrorMsg: string;
// addresses
@observable public loadingAddresses: boolean = false;
@observable public accountsWithAddresses = [];
@observable public loadingAddressesError: string = '';
//
settingsStore: SettingsStore;

Expand All @@ -45,6 +49,10 @@ export default class UTXOsStore {
this.accounts = [];
this.accountToImport = null;
this.utxos = [];
// addresses
this.loadingAddresses = false;
this.accountsWithAddresses = [];
this.loadingAddressesError = '';
};

getUtxosError = () => {
Expand Down Expand Up @@ -293,4 +301,26 @@ export default class UTXOsStore {
return;
});
};

@action
public listAddresses = async () => {
this.loadingAddresses = true;
this.accountsWithAddresses = [];
this.loadingAddressesError = '';

return await new Promise((resolve, reject) => {
BackendUtils.listAddresses()
.then((response: any) => {
this.accountsWithAddresses =
response.account_with_addresses;
this.loadingAddresses = false;
resolve(this.accountsWithAddresses);
})
.catch((err: Error) => {
this.loadingAddressesError = err.toString();
this.loadingAddresses = false;
reject();
});
});
};
}
Loading

0 comments on commit 10f3f4d

Please sign in to comment.