Skip to content

Commit

Permalink
Add support for rpc polling in dev commands
Browse files Browse the repository at this point in the history
  • Loading branch information
niteshbalusu11 authored Nov 1, 2023
1 parent c7f830b commit 2fb8ca8
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
6 changes: 6 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,12 @@
"rpc": {
"title": "Set bitcoind RPC Host"
},
"rpcuser": {
"title": "Set the bitcoind RPC User"
},
"rpcpass": {
"title": "Set the bitcoind RPC Password"
},
"zmqRawBlock": {
"title": "Set bitcoind ZMQ Raw Block Host"
},
Expand Down
2 changes: 1 addition & 1 deletion src/state/Lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import logger from "./../utils/log";

const log = logger("Lightning");

export type LndChainBackend = "neutrino" | "bitcoindWithZmq";
export type LndChainBackend = "neutrino" | "bitcoindWithZmq" | "bitcoindWithRpcPolling";

interface ILightningPeer {
peer: lnrpc.Peer;
Expand Down
24 changes: 24 additions & 0 deletions src/state/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export interface ISettingsModel {
changeNeutrinoPeers: Thunk<ISettingsModel, string[]>;
changeZeroConfPeers: Thunk<ISettingsModel, string[]>;
changeBitcoindRpcHost: Thunk<ISettingsModel, string>;
changeBitcoindRpcUser: Thunk<ISettingsModel, string>;
changeBitcoindRpcPassword: Thunk<ISettingsModel, string>;
changeBitcoindPubRawBlock: Thunk<ISettingsModel, string>;
changeBitcoindPubRawTx: Thunk<ISettingsModel, string>;
changeDunderServer: Thunk<ISettingsModel, string>;
Expand Down Expand Up @@ -110,6 +112,8 @@ export interface ISettingsModel {
setNeutrinoPeers: Action<ISettingsModel, string[]>;
setZeroConfPeers: Action<ISettingsModel, string[]>;
setBitcoindRpcHost: Action<ISettingsModel, string>;
setBitcoindRpcUser: Action<ISettingsModel, string>;
setBitcoindRpcPassword: Action<ISettingsModel, string>;
setBitcoindPubRawBlock: Action<ISettingsModel, string>;
setBitcoindPubRawTx: Action<ISettingsModel, string>;
setDunderServer: Action<ISettingsModel, string>;
Expand Down Expand Up @@ -152,6 +156,8 @@ export interface ISettingsModel {
lndChainBackend: string;
neutrinoPeers: string[];
bitcoindRpcHost: string;
bitcoindRpcUser: string;
bitcoindRpcPassword: string;
bitcoindPubRawBlock: string;
bitcoindPubRawTx: string;
dunderServer: string;
Expand Down Expand Up @@ -384,6 +390,16 @@ export const settings: ISettingsModel = {
actions.setBitcoindRpcHost(payload);
}),

changeBitcoindRpcUser: thunk(async (actions, payload) => {
await setItem(StorageItem.bitcoindRpcUser, payload);
actions.setBitcoindRpcHost(payload);
}),

changeBitcoindRpcPassword: thunk(async (actions, payload) => {
await setItem(StorageItem.bitcoindRpcPass, payload);
actions.setBitcoindRpcHost(payload);
}),

changeBitcoindPubRawBlock: thunk(async (actions, payload) => {
await setItem(StorageItem.bitcoindPubRawBlock, payload);
actions.setBitcoindPubRawBlock(payload);
Expand Down Expand Up @@ -547,6 +563,12 @@ export const settings: ISettingsModel = {
setBitcoindRpcHost: action((state, payload) => {
state.bitcoindRpcHost = payload;
}),
setBitcoindRpcUser: action((state, payload) => {
state.bitcoindRpcUser = payload;
}),
setBitcoindRpcPassword: action((state, payload) => {
state.bitcoindRpcPassword = payload;
}),
setBitcoindPubRawBlock: action((state, payload) => {
state.bitcoindPubRawBlock = payload;
}),
Expand Down Expand Up @@ -626,6 +648,8 @@ export const settings: ISettingsModel = {
neutrinoPeers: [],
zeroConfPeers: [],
bitcoindRpcHost: "",
bitcoindRpcUser: "",
bitcoindRpcPassword: "",
bitcoindPubRawBlock: "",
bitcoindPubRawTx: "",
dunderServer: "",
Expand Down
24 changes: 21 additions & 3 deletions src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { DEFAULT_PATHFINDING_ALGORITHM, PLATFORM } from "../utils/constants";
import { Chain, VersionCode } from "../utils/build";
import { IBlixtLsp, blixtLsp } from "./BlixtLsp";
import { IChannelModel, channel } from "./Channel";
import { IChannelAcceptanceManagerModel, channelAcceptanceManager } from "./ChannelAcceptanceManager";
import {
IChannelAcceptanceManagerModel,
channelAcceptanceManager,
} from "./ChannelAcceptanceManager";
import { IClipboardManagerModel, clipboardManager } from "./ClipboardManager";
import { IContactsModel, contacts } from "./Contacts";
import { ILightningBoxModel, lightningBox } from "./LightningBox";
Expand Down Expand Up @@ -285,8 +288,11 @@ export const model: IStoreModel = {
}
}
}
let persistentServicesEnabled = await getItemObjectAsyncStorage<boolean>(StorageItem.persistentServicesEnabled) ?? false;
let persistentServicesWarningShown = await getItemObjectAsyncStorage<boolean>(StorageItem.persistentServicesWarningShown) ?? false;
let persistentServicesEnabled =
(await getItemObjectAsyncStorage<boolean>(StorageItem.persistentServicesEnabled)) ?? false;
let persistentServicesWarningShown =
(await getItemObjectAsyncStorage<boolean>(StorageItem.persistentServicesWarningShown)) ??
false;
if (persistentServicesEnabled && !persistentServicesWarningShown) {
await setItemObject(StorageItem.persistentServicesWarningShown, true);
await NativeModules.BlixtTor.showMsg();
Expand Down Expand Up @@ -568,6 +574,18 @@ bitcoind.zmqpubrawtx=${bitcoindPubRawTx}
: ""
}
${
lndChainBackend === "bitcoindWithRpcPolling"
? `
[Bitcoind]
bitcoind.rpchost=${bitcoindRpcHost}
bitcoind.rpcuser=${bitcoindRpcUser}
bitcoind.rpcpass=${bitcoindRpcPass}
bitcoind.rpcpolling=true
`
: ""
}
[autopilot]
autopilot.active=0
autopilot.private=1
Expand Down
1 change: 1 addition & 0 deletions src/windows/InitProcess/DEV_Commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ console.log(x);
<Button small onPress={async () => actions.resetDb()}><Text style={styles.buttonText}>actions.resetDb()</Text></Button>
<Button small onPress={async () => await setItem(StorageItem.lndChainBackend, "neutrino")}><Text style={styles.buttonText}>lndChainBackend = neutrino</Text></Button>
<Button small onPress={async () => await setItem(StorageItem.lndChainBackend, "bitcoindWithZmq")}><Text style={styles.buttonText}>lndChainBackend = bitcoindWithZmq</Text></Button>
<Button small onPress={async () => await setItem(StorageItem.lndChainBackend, "bitcoindWithRpcPolling")}><Text style={styles.buttonText}>lndChainBackend = bitcoindWithRpcPolling</Text></Button>
<Button small onPress={async () => await setItemObject(StorageItem.walletCreated, true)}><Text style={styles.buttonText}>walletCreated = true</Text></Button>
<Button small onPress={async () => await setItemObject(StorageItem.loginMethods, ["pincode"])}><Text style={styles.buttonText}>set logginMethods to ["pincode"]</Text></Button>
<Button small onPress={async () => await setItemObject(StorageItem.loginMethods, [])}><Text style={styles.buttonText}>set logginMethods to []</Text></Button>
Expand Down
150 changes: 124 additions & 26 deletions src/windows/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,64 @@ ${t("LN.inbound.dialog.msg3")}`;
);
};

// bitcoind RPC user
const bitcoindRpcUser = useStoreState((store) => store.settings.bitcoindRpcUser);
const changeBitcoindRpcUser = useStoreActions((store) => store.settings.changeBitcoindRpcUser);
const onSetBitcoindRpcUserPress = async () => {
Alert.prompt(
t("bitcoinNetwork.rpcuser.title"),
"",
[
{
text: t("buttons.cancel", { ns: namespaces.common }),
style: "cancel",
onPress: () => {},
},
{
text: t("buttons.save", { ns: namespaces.common }),
onPress: async (text) => {
if (text) {
await changeBitcoindRpcUser(text);
await writeConfig();
}
},
},
],
"plain-text",
bitcoindRpcUser ?? "",
);
};

// bitcoind RPC password
const bitcoindRpcPassword = useStoreState((store) => store.settings.bitcoindRpcPassword);
const changeBitcoindRpcPassword = useStoreActions(
(store) => store.settings.changeBitcoindRpcPassword,
);
const onSetBitcoindRpcPasswordPress = async () => {
Alert.prompt(
t("bitcoinNetwork.rpcpass.title"),
"",
[
{
text: t("buttons.cancel", { ns: namespaces.common }),
style: "cancel",
onPress: () => {},
},
{
text: t("buttons.save", { ns: namespaces.common }),
onPress: async (text) => {
if (text) {
await changeBitcoindRpcPassword(text);
await writeConfig();
}
},
},
],
"plain-text",
bitcoindRpcPassword ?? "",
);
};

// bitcoind zmq block
const bitcoindPubRawBlock = useStoreState((store) => store.settings.bitcoindPubRawBlock);
const changeBitcoindPubRawBlock = useStoreActions(
Expand Down Expand Up @@ -1333,16 +1391,24 @@ ${t("experimental.tor.disabled.msg2")}`;
};

// Persistent services
const persistentServicesEnabled = useStoreState((store) => store.settings.persistentServicesEnabled);
const changePersistentServicesEnabled = useStoreActions((store) => store.settings.changePersistentServicesEnabled);
const persistentServicesEnabled = useStoreState(
(store) => store.settings.persistentServicesEnabled,
);
const changePersistentServicesEnabled = useStoreActions(
(store) => store.settings.changePersistentServicesEnabled,
);
const changePersistentServicesEnabledPress = async () => {
await changePersistentServicesEnabled(!persistentServicesEnabled);
restartNeeded();
};

// Persistent services
const customInvoicePreimageEnabled = useStoreState((store) => store.settings.customInvoicePreimageEnabled);
const changeCustomInvoicePreimageEnabled = useStoreActions((store) => store.settings.changeCustomInvoicePreimageEnabled);
const customInvoicePreimageEnabled = useStoreState(
(store) => store.settings.customInvoicePreimageEnabled,
);
const changeCustomInvoicePreimageEnabled = useStoreActions(
(store) => store.settings.changeCustomInvoicePreimageEnabled,
);
const onToggleCustomInvoicePreimageEnabled = async () => {
await changeCustomInvoicePreimageEnabled(!customInvoicePreimageEnabled);
};
Expand Down Expand Up @@ -1719,6 +1785,35 @@ ${t("experimental.tor.disabled.msg2")}`;
</>
)}

{lndChainBackend === "bitcoindWithRpcPolling" && (
<>
<ListItem style={style.listItem} icon={true} onPress={onSetBitcoindRpcHostPress}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="router-network" />
</Left>
<Body>
<Text>{t("bitcoinNetwork.rpc.title")}</Text>
</Body>
</ListItem>
<ListItem style={style.listItem} icon={true} onPress={onSetBitcoindRpcUserPress}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="router-network" />
</Left>
<Body>
<Text>{t("bitcoinNetwork.rpcuser.title")}</Text>
</Body>
</ListItem>
<ListItem style={style.listItem} icon={true} onPress={onSetBitcoindRpcPasswordPress}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="router-network" />
</Left>
<Body>
<Text>{t("bitcoinNetwork.rpcpass.title")}</Text>
</Body>
</ListItem>
</>
)}

<ListItem style={style.listItem} icon={true} onPress={onToggleReceiveViaP2TR}>
<Left>
<Icon style={style.icon} type="MaterialCommunityIcons" name="carrot" />
Expand Down Expand Up @@ -1904,16 +1999,17 @@ ${t("experimental.tor.disabled.msg2")}`;
</Body>
</ListItem>
)}
{scheduledGossipSyncEnabled && (PLATFORM === "android" || PLATFORM === "ios" || PLATFORM === "macos") && (
<ListItem style={style.listItem} icon={true} onPress={() => copySpeedloaderLog()}>
<Left>
<Icon style={style.icon} type="AntDesign" name="copy1" />
</Left>
<Body>
<Text>{t("miscelaneous.speedloaderLog.title")}</Text>
</Body>
</ListItem>
)}
{scheduledGossipSyncEnabled &&
(PLATFORM === "android" || PLATFORM === "ios" || PLATFORM === "macos") && (
<ListItem style={style.listItem} icon={true} onPress={() => copySpeedloaderLog()}>
<Left>
<Icon style={style.icon} type="AntDesign" name="copy1" />
</Left>
<Body>
<Text>{t("miscelaneous.speedloaderLog.title")}</Text>
</Body>
</ListItem>
)}
<ListItem
style={style.listItem}
button={true}
Expand Down Expand Up @@ -2242,7 +2338,7 @@ ${t("experimental.tor.disabled.msg2")}`;
<Text>{t("debug.lndLog.title")}</Text>
</Body>
</ListItem>
{scheduledGossipSyncEnabled &&
{scheduledGossipSyncEnabled && (
<ListItem
style={style.listItem}
icon={true}
Expand All @@ -2255,7 +2351,7 @@ ${t("experimental.tor.disabled.msg2")}`;
<Text>{t("debug.speedloaderLog.title")}</Text>
</Body>
</ListItem>
}
)}
<ListItem
style={style.listItem}
icon={true}
Expand Down Expand Up @@ -2451,16 +2547,18 @@ ${t("experimental.tor.disabled.msg2")}`;

const json: { pairs: any[] } = await res.json();

const x: routerrpc.IXImportMissionControlRequest["pairs"] = json.pairs.filter((c) => c.history.successAmtSat > 0).map((c) => {
return {
nodeFrom: hexToUint8Array(c.nodeFrom),
nodeTo: hexToUint8Array(c.nodeTo),
history: {
successAmtSat: Long.fromValue(c.history.successAmtSat),
successTime: Long.fromValue(c.history.successTime),
}
}
});
const x: routerrpc.IXImportMissionControlRequest["pairs"] = json.pairs
.filter((c) => c.history.successAmtSat > 0)
.map((c) => {
return {
nodeFrom: hexToUint8Array(c.nodeFrom),
nodeTo: hexToUint8Array(c.nodeTo),
history: {
successAmtSat: Long.fromValue(c.history.successAmtSat),
successTime: Long.fromValue(c.history.successTime),
},
};
});
await xImportMissionControl(x);

toast("Done");
Expand Down

1 comment on commit 2fb8ca8

@vercel
Copy link

@vercel vercel bot commented on 2fb8ca8 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blixt-wallet – ./

blixt-wallet-hsjoberg.vercel.app
blixt-wallet-git-master-hsjoberg.vercel.app

Please sign in to comment.