persist wallet creation date when created

This commit is contained in:
woodser 2024-01-19 10:43:29 -05:00
parent 036f40e861
commit a6b8723ebe
4 changed files with 36 additions and 2 deletions

View File

@ -374,6 +374,11 @@ public class User implements PersistedDataHost {
requestPersistence();
}
public void setWalletCreationDate(long walletCreationDate) {
userPayload.setWalletCreationDate(walletCreationDate);
requestPersistence();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
@ -521,4 +526,8 @@ public class User implements PersistedDataHost {
public Cookie getCookie() {
return userPayload.getCookie();
}
public long getWalletCreationDate() {
return userPayload.getWalletCreationDate();
}
}

View File

@ -82,6 +82,7 @@ public class UserPayload implements PersistableEnvelope {
// Generic map for persisting various UI states. We keep values un-typed as string to
// provide sufficient flexibility.
private Cookie cookie = new Cookie();
private long walletCreationDate;
public UserPayload() {
}
@ -122,6 +123,7 @@ public class UserPayload implements PersistableEnvelope {
.ifPresent(e -> builder.addAllAcceptedRefundAgents(ProtoUtil.collectionToProto(acceptedRefundAgents,
message -> ((protobuf.StoragePayload) message).getRefundAgent())));
Optional.ofNullable(cookie).ifPresent(e -> builder.putAllCookie(cookie.toProtoMessage()));
builder.setWalletCreationDate(walletCreationDate);
return protobuf.PersistableEnvelope.newBuilder().setUserPayload(builder).build();
}
@ -153,7 +155,8 @@ public class UserPayload implements PersistableEnvelope {
proto.getAcceptedRefundAgentsList().isEmpty() ? new ArrayList<>() : new ArrayList<>(proto.getAcceptedRefundAgentsList().stream()
.map(RefundAgent::fromProto)
.collect(Collectors.toList())),
Cookie.fromProto(proto.getCookieMap())
Cookie.fromProto(proto.getCookieMap()),
proto.getWalletCreationDate()
);
}
}

View File

@ -20,6 +20,7 @@ import haveno.core.trade.MakerTrade;
import haveno.core.trade.Trade;
import haveno.core.trade.TradeManager;
import haveno.core.user.Preferences;
import haveno.core.user.User;
import haveno.core.xmr.listeners.XmrBalanceListener;
import haveno.core.xmr.model.XmrAddressEntry;
import haveno.core.xmr.model.XmrAddressEntryList;
@ -60,6 +61,9 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.io.File;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -109,6 +113,7 @@ public class XmrWalletService {
private static final boolean PRINT_STACK_TRACE = false;
private static final String THREAD_ID = XmrWalletService.class.getSimpleName();
private final User user;
private final Preferences preferences;
private final CoreAccountService accountService;
private final XmrConnectionService xmrConnectionService;
@ -135,13 +140,15 @@ public class XmrWalletService {
private TaskLooper syncLooper = null;
@Inject
XmrWalletService(Preferences preferences,
XmrWalletService(User user,
Preferences preferences,
CoreAccountService accountService,
XmrConnectionService xmrConnectionService,
WalletsSetup walletsSetup,
XmrAddressEntryList xmrAddressEntryList,
@Named(Config.WALLET_DIR) File walletDir,
@Named(Config.WALLET_RPC_BIND_PORT) int rpcBindPort) {
this.user = user;
this.preferences = preferences;
this.accountService = accountService;
this.xmrConnectionService = xmrConnectionService;
@ -203,6 +210,15 @@ public class XmrWalletService {
return wallet;
}
/**
* Get the wallet creation date in seconds since epoch.
*
* @return the wallet creation date in seconds since epoch
*/
public long getWalletCreationDate() {
return user.getWalletCreationDate();
}
public void saveMainWallet() {
saveMainWallet(true);
}
@ -787,6 +803,11 @@ public class XmrWalletService {
wallet = openWalletRpc(walletConfig, rpcBindPort, isProxyApplied(wasWalletSynced));
} else if (xmrConnectionService.getConnection() != null && Boolean.TRUE.equals(xmrConnectionService.getConnection().isConnected())) {
wallet = createWalletRpc(walletConfig, rpcBindPort);
// set wallet creation date to yesterday to guarantee complete restore
LocalDateTime localDateTime = LocalDate.now().atStartOfDay().minusDays(1);
long date = localDateTime.toEpochSecond(ZoneOffset.UTC);
user.setWalletCreationDate(date);
}
}

View File

@ -1756,6 +1756,7 @@ message UserPayload {
repeated RefundAgent accepted_refund_agents = 14;
RefundAgent registered_refund_agent = 15;
map<string, string> cookie = 16;
int64 wallet_creation_date = 17;
}
message BlockChainExplorer {