Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing segwit BSQ keychain path to wallet info #6604

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@

import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.DeterministicKeyChain;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.common.base.Joiner;

import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;

import java.util.List;

import static bisq.desktop.util.FormBuilder.addButtonAfterGroup;
import static bisq.desktop.util.FormBuilder.addMultilineLabel;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
Expand Down Expand Up @@ -97,18 +102,15 @@ public void initialize() {
bsqTextField = addTopLabelTextField(root, ++gridRow, "BSQ", -Layout.FLOATING_LABEL_DISTANCE).second;

addTitledGroupBg(root, ++gridRow, 4, Res.get("account.menu.walletInfo.xpub.headLine"), Layout.GROUP_DISTANCE);
addXpubKeys(btcWalletService, "BTC", gridRow, Layout.FIRST_ROW_AND_GROUP_DISTANCE);
++gridRow; // update gridRow
addXpubKeys(bsqWalletService, "BSQ", ++gridRow, -Layout.FLOATING_LABEL_DISTANCE);
++gridRow; // update gridRow
addXpubKeys(btcWalletService, "BTC", Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addXpubKeys(bsqWalletService, "BSQ", -Layout.FLOATING_LABEL_DISTANCE);

addTitledGroupBg(root, ++gridRow, 4, Res.get("account.menu.walletInfo.path.headLine"), Layout.GROUP_DISTANCE);
addMultilineLabel(root, gridRow, Res.get("account.menu.walletInfo.path.info"), Layout.FIRST_ROW_AND_GROUP_DISTANCE, Double.MAX_VALUE);
addTopLabelTextField(root, ++gridRow, Res.get("account.menu.walletInfo.walletSelector", "BTC", "legacy"), "44'/0'/0'", -Layout.FLOATING_LABEL_DISTANCE);
addTopLabelTextField(root, ++gridRow, Res.get("account.menu.walletInfo.walletSelector", "BTC", "segwit"), "44'/0'/1'", -Layout.FLOATING_LABEL_DISTANCE);
addTopLabelTextField(root, ++gridRow, Res.get("account.menu.walletInfo.walletSelector", "BSQ", ""), "44'/142'/0'", -Layout.FLOATING_LABEL_DISTANCE);
addTitledGroupBg(root, gridRow, 4, Res.get("account.menu.walletInfo.path.headLine"), Layout.GROUP_DISTANCE);
addMultilineLabel(root, gridRow++, Res.get("account.menu.walletInfo.path.info"), Layout.FIRST_ROW_AND_GROUP_DISTANCE, Double.MAX_VALUE);
addAccountPaths(btcWalletService, "BTC");
addAccountPaths(bsqWalletService, "BSQ");

openDetailsButton = addButtonAfterGroup(root, ++gridRow, Res.get("account.menu.walletInfo.openDetails"));
openDetailsButton = addButtonAfterGroup(root, gridRow, Res.get("account.menu.walletInfo.openDetails"));

btcWalletBalanceListener = new BalanceListener() {
@Override
Expand Down Expand Up @@ -148,28 +150,37 @@ protected void deactivate() {
openDetailsButton.setOnAction(null);
}

private void addXpubKeys(WalletService walletService, String currency, int gridRow, double top) {
int row = gridRow;
private void addXpubKeys(WalletService walletService, String currency, double top) {
double topDist = top;
for (DeterministicKeyChain chain : walletService.getWallet().getActiveKeyChains()) {
Script.ScriptType outputScriptType = chain.getOutputScriptType();
String type = outputScriptType == Script.ScriptType.P2WPKH ? "segwit" : "legacy";
String key = chain.getWatchingKey().serializePubB58(Config.baseCurrencyNetworkParameters(), outputScriptType);
addTopLabelTextField(root, row,
Res.get("account.menu.walletInfo.walletSelector", currency, type),
addTopLabelTextField(root, gridRow++, Res.get("account.menu.walletInfo.walletSelector", currency, type),
key, topDist);
row++;
topDist = -Layout.FLOATING_LABEL_DISTANCE;
}
}

private void addAccountPaths(WalletService walletService, String currency) {
for (DeterministicKeyChain chain : walletService.getWallet().getActiveKeyChains()) {
Script.ScriptType outputScriptType = chain.getOutputScriptType();
String type = outputScriptType == Script.ScriptType.P2WPKH ? "segwit" : "legacy";
String path = formatAccountPath(chain.getAccountPath());
addTopLabelTextField(root, gridRow++, Res.get("account.menu.walletInfo.walletSelector", currency, type),
path, -Layout.FLOATING_LABEL_DISTANCE);
}
}

private String formatAccountPath(List<ChildNumber> path) {
return Joiner.on('/').join(path).replace('H', '\'');
}

private void updateBalances(WalletService walletService) {
if (walletService instanceof BtcWalletService) {
btcTextField.setText(btcFormatter.formatCoinWithCode(walletService.getBalance(ESTIMATED_SPENDABLE)));
} else {
bsqTextField.setText(bsqFormatter.formatCoinWithCode(walletService.getBalance(ESTIMATED_SPENDABLE)));
}
}

}