Skip to content

Commit

Permalink
Wallet restore height configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Dec 23, 2024
1 parent 5a3b850 commit 5aa72ce
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,23 @@ You must provide a valid configuration before running server

```bash
# moneroecwid.conf example
port=8080
db-host=localhost
db-port=3306
db-username=monero_ecwid
db-password=devpassword
required-confirmations=1
client-secret=custom_app_client_secret
client-secret=Pe087Q6jr0CgwI96R2ZTuUMWfUAHQjMq
wallet-address=9xjCAvNQaYYDLc5UsxQPZtP8nNDUJnuhiacmMaE3zzTBetYcLusyCtD5kuQNNGo3TVCEUFKjd7yjeE3rCjPahy3RQGa39aJ
wallet-view-key=9ce15a203d7e31aa930e55e4bf18e65509fb73ba316528182b77b079bb997b0d
wallet-server-uri=http://node2.monerodevs.org:28089
wallet-password=supersecretpassword123
wallet-net-type=testnet
wallet-restore-height=2644330
mail-host=smtp.mailgun.org
mail-port=587
mail-username=
mail-password=
```

```bash
Expand Down
1 change: 1 addition & 0 deletions moneroecwid.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ wallet-view-key=9ce15a203d7e31aa930e55e4bf18e65509fb73ba316528182b77b079bb997b0d
wallet-server-uri=http://node2.monerodevs.org:28089
wallet-password=supersecretpassword123
wallet-net-type=testnet
wallet-restore-height=2644330
mail-host=smtp.mailgun.org
mail-port=587
mail-username=
Expand Down
1 change: 1 addition & 0 deletions src/main/java/monero/ecwid/server/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ServerConfig {
public String walletPassword = "";
public String walletNetType = "testnet";
public String walletServerUri = "";
public Long walletRestoreHeight = Long.valueOf(0);
public String clientSecret = "";

public String mailHost = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public static ServerConfig read(String configFilePath) throws IOException {
String mailUsername = rawConfig.getOrDefault("mail-username", "");
String mailPassword = rawConfig.getOrDefault("mail-password", "");
String serverPort = rawConfig.getOrDefault("port", "8080");
String walletRestoreHeight = rawConfig.getOrDefault("walletRestoreHeight", "0");

Integer port = Integer.valueOf(dbPort);
Long confirmations = Long.valueOf(reqConfirmations);


config.dbHost = dbHost;
config.dbPort = port;
config.dbUsername = dbUsername;
Expand All @@ -62,6 +62,7 @@ public static ServerConfig read(String configFilePath) throws IOException {
config.walletPassword = walletPassword;
config.walletNetType = walletNetType;
config.walletServerUri = walletServerUri;
config.walletRestoreHeight = Long.valueOf(walletRestoreHeight);

config.clientSecret = clientSecret;

Expand Down
20 changes: 13 additions & 7 deletions src/main/java/monero/ecwid/server/utils/WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public abstract class WalletUtils {

private static MoneroWalletFull wallet = null;
private static String walletPath = "monero_ecwid_wallet";
private static final Long restoreHeight = 2644330l;

private static ServerConfig getServerConfig() {
try {
Expand All @@ -34,12 +33,14 @@ private static ServerConfig getServerConfig() {

private static MoneroWalletConfig getWalletConfig() {
ServerConfig serverConfig = getServerConfig();
Long restoreHeight = serverConfig.walletRestoreHeight;
String address = serverConfig.walletAddress;
String viewKey = serverConfig.walletViewKey;
String walletPassword = serverConfig.walletPassword.isEmpty() ? "supersecretpassword123" : serverConfig.walletAddress;
String walletPassword = serverConfig.walletPassword.isEmpty() ? "supersecretpassword123" : serverConfig.walletPassword;
boolean validConfig = !address.isEmpty() && !viewKey.isEmpty() && !walletPassword.isEmpty();
MoneroNetworkType networkType = serverConfig.getNetType();
String serverUri;


if (serverConfig.walletServerUri.isEmpty()) {
serverUri = networkType == MoneroNetworkType.TESTNET ? TESTNET_NODE : networkType == MoneroNetworkType.STAGENET ? STAGENET_NODE : MAINNET_NODE;
Expand All @@ -53,15 +54,16 @@ private static MoneroWalletConfig getWalletConfig() {
.setPassword(walletPassword)
.setNetworkType(networkType)
.setServerUri(serverUri);

if (!MoneroWalletFull.walletExists(walletPath)) {
if (validConfig) {
config.setPrimaryAddress(address);
config.setPrivateViewKey(viewKey);
config
.setPrimaryAddress(address)
.setPrivateViewKey(viewKey)
.setRestoreHeight(restoreHeight);
}
else {
config.setSeed("archer frying slid pruned smuggled elapse touchy assorted cogs sabotage orders directed together aching bikini eels bubble else rigid toenail tweezers alpine energy entrance alpine");
config.setRestoreHeight(restoreHeight);
throw new RuntimeException("Invalid wallet config provided");
}
}

Expand Down Expand Up @@ -103,6 +105,9 @@ public static MoneroWalletFull getWallet(boolean sync) {
if (sync) {
logger.info("Syncing wallet");

ServerConfig serverConfig = getServerConfig();
Long restoreHeight = serverConfig.walletRestoreHeight;

wallet.sync(restoreHeight);

logger.info("Wallet synced");
Expand Down Expand Up @@ -145,4 +150,5 @@ public static Long getTxConfirmations(String txHash, boolean sync) {

return confirmations;
}

}

0 comments on commit 5aa72ce

Please sign in to comment.