Skip to content

Commit

Permalink
Create bitcoind specific RpcConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Sep 20, 2024
1 parent 257653f commit 21e2b57
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,14 @@

package bisq.wallets.json_rpc;

import bisq.common.proto.PersistableProto;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public final class RpcConfig implements PersistableProto {
public final class RpcConfig {
private String hostname;
private int port;
private String user;
private String password;

@Override
public bisq.wallets.protobuf.RpcConfig toProto(boolean serializeForHash) {
return resolveProto(serializeForHash);
}

@Override
public bisq.wallets.protobuf.RpcConfig.Builder getBuilder(boolean serializeForHash) {
return bisq.wallets.protobuf.RpcConfig.newBuilder()
.setHostname(hostname)
.setPort(port)
.setUser(user)
.setPassword(password);
}

public static RpcConfig fromProto(bisq.wallets.protobuf.RpcConfig proto) {
return RpcConfig.builder()
.hostname(proto.getHostname())
.port(proto.getPort())
.user(proto.getUser())
.password(proto.getPassword())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import bisq.persistence.Persistence;
import bisq.persistence.PersistenceService;
import bisq.wallets.bitcoind.AbstractBitcoindWalletService;
import bisq.wallets.json_rpc.RpcConfig;
import bisq.wallets.bitcoind.RpcConfig;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -47,19 +47,25 @@ public LiquidWalletService(PersistenceService persistenceService,
}

@Override
protected LiquidWallet createWallet(RpcConfig rpcConfig) {
return WalletFactory.createLiquidWallet(rpcConfig, walletName, persistableStore);
protected LiquidWallet createWallet(bisq.wallets.bitcoind.RpcConfig rpcConfig) {
return WalletFactory.createLiquidWallet(rpcConfig.toJsonRpcConfig(), walletName, persistableStore);
}

@Override
protected void persistRpcConfig(RpcConfig rpcConfig) {
persistableStore.setRpcConfig(Optional.of(rpcConfig));
protected void persistRpcConfig(bisq.wallets.bitcoind.RpcConfig rpcConfig) {
persistableStore.setRpcConfig(Optional.of(rpcConfig.toJsonRpcConfig()));
persist();
}

@Override
protected Optional<RpcConfig> getRpcConfigFromPersistableStore() {
return persistableStore.getRpcConfig();
protected Optional<bisq.wallets.bitcoind.RpcConfig> getRpcConfigFromPersistableStore() {
return persistableStore.getRpcConfig().map(jsonRpcConfig ->
RpcConfig.builder()
.hostname(jsonRpcConfig.getHostname())
.port(jsonRpcConfig.getPort())
.user(jsonRpcConfig.getUser())
.password(jsonRpcConfig.getPassword())
.build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public bisq.wallets.protobuf.LiquidWalletStore.Builder getBuilder(boolean serial
bisq.wallets.protobuf.LiquidWalletStore.newBuilder()
.addAllWalletAddresses(walletAddresses);

rpcConfig.ifPresent(config -> builder.setRpcConfig(config.toProto(serializeForHash)));
return builder;
throw new UnsupportedOperationException("Not implemented.");
/* rpcConfig.ifPresent(config -> builder.setRpcConfig(config.toProto(serializeForHash)));
return builder; */
}

@Override
Expand All @@ -61,9 +62,10 @@ public bisq.wallets.protobuf.LiquidWalletStore toProto(boolean serializeForHash)
}

public static LiquidWalletStore fromProto(bisq.wallets.protobuf.LiquidWalletStore proto) {
Optional<RpcConfig> rpcConfig = proto.hasRpcConfig() ? Optional.of(RpcConfig.fromProto(proto.getRpcConfig()))
throw new UnsupportedOperationException("Not implemented.");
/* Optional<RpcConfig> rpcConfig = proto.hasRpcConfig() ? Optional.of(RpcConfig.fromProto(proto.getRpcConfig()))
: Optional.empty();
return new LiquidWalletStore(rpcConfig, new ArrayList<>(proto.getWalletAddressesList()));
return new LiquidWalletStore(rpcConfig, new ArrayList<>(proto.getWalletAddressesList())); */
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import bisq.wallets.core.model.Transaction;
import bisq.wallets.core.model.TransactionInfo;
import bisq.wallets.core.model.Utxo;
import bisq.wallets.json_rpc.RpcConfig;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -115,8 +114,17 @@ public CompletableFuture<Boolean> shutdown() {
// WalletService
///////////////////////////////////////////////////////////////////////////////////////////////////


@Override
public CompletableFuture<Boolean> initializeWallet(RpcConfig rpcConfig, Optional<String> walletPassphrase) {
public CompletableFuture<Boolean> initializeWallet(bisq.wallets.json_rpc.RpcConfig jsonRpcConfig,
Optional<String> walletPassphrase) {
RpcConfig rpcConfig = RpcConfig.builder()
.hostname(jsonRpcConfig.getHostname())
.port(jsonRpcConfig.getPort())
.user(jsonRpcConfig.getUser())
.password(jsonRpcConfig.getPassword())
.build();

if (wallet.isEmpty()) {
boolean isSuccess = verifyRpcConfigAndCreateWallet(Optional.of(rpcConfig));

Expand Down Expand Up @@ -242,7 +250,7 @@ private boolean verifyRpcConfigAndCreateWallet(Optional<RpcConfig> optionalRpcCo
if (optionalRpcConfig.isEmpty()) return false;

RpcConfig rpcConfig = optionalRpcConfig.get();
boolean isValidRpcConfig = BitcoindDaemon.verifyRpcConfig(rpcConfig);
boolean isValidRpcConfig = BitcoindDaemon.verifyRpcConfig(rpcConfig.toJsonRpcConfig());
if (isValidRpcConfig) {
T walletImpl = createWallet(rpcConfig);
wallet = Optional.of(walletImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import bisq.persistence.DbSubDirectory;
import bisq.persistence.Persistence;
import bisq.persistence.PersistenceService;
import bisq.wallets.json_rpc.RpcConfig;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -63,7 +62,7 @@ public BitcoinWalletService(Config config,

@Override
protected BitcoinWallet createWallet(RpcConfig rpcConfig) {
return WalletFactory.createBitcoinWallet(rpcConfig, walletName, persistableStore);
return WalletFactory.createBitcoinWallet(rpcConfig.toJsonRpcConfig(), walletName, persistableStore);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import bisq.common.proto.ProtoResolver;
import bisq.common.proto.UnresolvableProtobufMessageException;
import bisq.persistence.PersistableStore;
import bisq.wallets.json_rpc.RpcConfig;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.Getter;
import lombok.Setter;
Expand Down
64 changes: 64 additions & 0 deletions wallets/wallet/src/main/java/bisq/wallets/bitcoind/RpcConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.wallets.bitcoind;

import bisq.common.proto.PersistableProto;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public final class RpcConfig implements PersistableProto {
private String hostname;
private int port;
private String user;
private String password;

@Override
public bisq.wallets.protobuf.RpcConfig toProto(boolean serializeForHash) {
return resolveProto(serializeForHash);
}

@Override
public bisq.wallets.protobuf.RpcConfig.Builder getBuilder(boolean serializeForHash) {
return bisq.wallets.protobuf.RpcConfig.newBuilder()
.setHostname(hostname)
.setPort(port)
.setUser(user)
.setPassword(password);
}

public static RpcConfig fromProto(bisq.wallets.protobuf.RpcConfig proto) {
return RpcConfig.builder()
.hostname(proto.getHostname())
.port(proto.getPort())
.user(proto.getUser())
.password(proto.getPassword())
.build();
}

public bisq.wallets.json_rpc.RpcConfig toJsonRpcConfig() {
return bisq.wallets.json_rpc.RpcConfig.builder()
.hostname(hostname)
.port(port)
.user(user)
.password(password)
.build();
}
}

0 comments on commit 21e2b57

Please sign in to comment.