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

Enums share state, is the implementation fine? #7344

Open
thecockatiel opened this issue Jan 4, 2025 · 2 comments
Open

Enums share state, is the implementation fine? #7344

thecockatiel opened this issue Jan 4, 2025 · 2 comments
Assignees
Labels

Comments

@thecockatiel
Copy link
Contributor

thecockatiel commented Jan 4, 2025

since enums are singletons, setting a value on a member sets it in general. is this really safe?

public enum SignState {
UNSIGNED(Res.get("offerbook.timeSinceSigning.notSigned")),
ARBITRATOR(Res.get("offerbook.timeSinceSigning.info.arbitrator")),
PEER_INITIAL(Res.get("offerbook.timeSinceSigning.info.peer")),
PEER_LIMIT_LIFTED(Res.get("offerbook.timeSinceSigning.info.peerLimitLifted")),
PEER_SIGNER(Res.get("offerbook.timeSinceSigning.info.signer")),
BANNED(Res.get("offerbook.timeSinceSigning.info.banned"));
private String displayString;
private String hash = "";
private long daysUntilLimitLifted = 0;
SignState(String displayString) {
this.displayString = displayString;
}
public SignState addHash(String hash) {
this.hash = hash;
return this;
}
public SignState setDaysUntilLimitLifted(long days) {
this.daysUntilLimitLifted = days;
return this;
}
public String getDisplayString() {
if (!hash.isEmpty()) { // Only showing in DEBUG mode
return displayString + " " + hash;
}
return String.format(displayString, daysUntilLimitLifted);
}
public boolean isLimitLifted() {
return this == PEER_LIMIT_LIFTED || this == PEER_SIGNER || this == ARBITRATOR;
}
}

enum Result implements AssetTxProofRequest.Result {
PENDING, // Tx not visible in network yet, unconfirmed or not enough confirmations
SUCCESS, // Proof succeeded
FAILED, // Proof failed
ERROR; // Error from service, does not mean that proof failed
@Nullable
@Getter
private Detail detail;
Result with(Detail detail) {
this.detail = detail;
return this;
}
@Override
public String toString() {
return "Result{" +
"\n detail=" + detail +
"\n} " + super.toString();
}
}
enum Detail {
// Pending
TX_NOT_FOUND, // Tx not visible in network yet. Could be also other error
PENDING_CONFIRMATIONS,
SUCCESS,
// Error states
CONNECTION_FAILURE,
API_INVALID,
// Failure states
TX_HASH_INVALID,
TX_KEY_INVALID,
ADDRESS_INVALID,
NO_MATCH_FOUND,
AMOUNT_NOT_MATCHING,
TRADE_DATE_NOT_MATCHING,
INVALID_UNLOCK_TIME,
NO_RESULTS_TIMEOUT;
@Getter
private int numConfirmations;
@Nullable
@Getter
private String errorMsg;
public Detail error(String errorMsg) {
this.errorMsg = errorMsg;
return this;
}
public Detail numConfirmations(int numConfirmations) {
this.numConfirmations = numConfirmations;
return this;
}
@Override
public String toString() {
return "Detail{" +
"\n numConfirmations=" + numConfirmations +
",\n errorMsg='" + errorMsg + '\'' +
"\n} " + super.toString();
}
}

enum Result {
VALID(true),
INVALID_PHASE,
INVALID_STATE,
INVALID_PRE_CONDITION,
INVALID_TRADE_ID;
@Getter
private boolean isValid;
@Getter
private String info;
Result() {
}
Result(boolean isValid) {
this.isValid = isValid;
}
public Result info(String info) {
this.info = info;
return this;
}
}

public AssetTxProofResult numSuccessResults(int numSuccessResults) {
this.numSuccessResults = numSuccessResults;
return this;
}
public AssetTxProofResult numRequiredSuccessResults(int numRequiredSuccessResults) {
this.numRequiredSuccessResults = numRequiredSuccessResults;
return this;
}
public AssetTxProofResult numConfirmations(int numConfirmations) {
this.numConfirmations = numConfirmations;
return this;
}
public AssetTxProofResult numRequiredConfirmations(int numRequiredConfirmations) {
this.numRequiredConfirmations = numRequiredConfirmations;
return this;
}
public AssetTxProofResult details(String details) {
this.details = details;
return this;
}

Copy link

boring-cyborg bot commented Jan 4, 2025

Thanks for opening your first issue here!

Be sure to follow the issue template. Your issue will be reviewed by a maintainer and labeled for further action.

@HenrikJannsen
Copy link
Collaborator

Yes, that's wrong.
Fixing it would come with non-trivial dev and testing effort.
As far I saw those properties are used only for display and logging, thus represent low risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants