-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathClaimClaimableBalanceResult.java
More file actions
152 lines (140 loc) · 5.48 KB
/
ClaimClaimableBalanceResult.java
File metadata and controls
152 lines (140 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Automatically generated by xdrgen
// DO NOT EDIT or your changes may be overwritten
package org.stellar.sdk.xdr;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.stellar.sdk.Base64Factory;
/**
* ClaimClaimableBalanceResult's original definition in the XDR file is:
*
* <pre>
* union ClaimClaimableBalanceResult switch (ClaimClaimableBalanceResultCode code)
* {
* case CLAIM_CLAIMABLE_BALANCE_SUCCESS:
* void;
* case CLAIM_CLAIMABLE_BALANCE_DOES_NOT_EXIST:
* case CLAIM_CLAIMABLE_BALANCE_CANNOT_CLAIM:
* case CLAIM_CLAIMABLE_BALANCE_LINE_FULL:
* case CLAIM_CLAIMABLE_BALANCE_NO_TRUST:
* case CLAIM_CLAIMABLE_BALANCE_NOT_AUTHORIZED:
* case CLAIM_CLAIMABLE_BALANCE_TRUSTLINE_FROZEN:
* void;
* };
* </pre>
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class ClaimClaimableBalanceResult implements XdrElement {
private ClaimClaimableBalanceResultCode discriminant;
public void encode(XdrDataOutputStream stream) throws IOException {
stream.writeInt(discriminant.getValue());
switch (discriminant) {
case CLAIM_CLAIMABLE_BALANCE_SUCCESS:
break;
case CLAIM_CLAIMABLE_BALANCE_DOES_NOT_EXIST:
case CLAIM_CLAIMABLE_BALANCE_CANNOT_CLAIM:
case CLAIM_CLAIMABLE_BALANCE_LINE_FULL:
case CLAIM_CLAIMABLE_BALANCE_NO_TRUST:
case CLAIM_CLAIMABLE_BALANCE_NOT_AUTHORIZED:
case CLAIM_CLAIMABLE_BALANCE_TRUSTLINE_FROZEN:
break;
}
}
public static ClaimClaimableBalanceResult decode(XdrDataInputStream stream, int maxDepth)
throws IOException {
if (maxDepth <= 0) {
throw new IOException("Maximum decoding depth reached");
}
maxDepth -= 1;
ClaimClaimableBalanceResult decodedClaimClaimableBalanceResult =
new ClaimClaimableBalanceResult();
ClaimClaimableBalanceResultCode discriminant =
ClaimClaimableBalanceResultCode.decode(stream, maxDepth);
decodedClaimClaimableBalanceResult.setDiscriminant(discriminant);
switch (decodedClaimClaimableBalanceResult.getDiscriminant()) {
case CLAIM_CLAIMABLE_BALANCE_SUCCESS:
break;
case CLAIM_CLAIMABLE_BALANCE_DOES_NOT_EXIST:
case CLAIM_CLAIMABLE_BALANCE_CANNOT_CLAIM:
case CLAIM_CLAIMABLE_BALANCE_LINE_FULL:
case CLAIM_CLAIMABLE_BALANCE_NO_TRUST:
case CLAIM_CLAIMABLE_BALANCE_NOT_AUTHORIZED:
case CLAIM_CLAIMABLE_BALANCE_TRUSTLINE_FROZEN:
break;
default:
throw new IOException("Unknown discriminant value: " + discriminant);
}
return decodedClaimClaimableBalanceResult;
}
public static ClaimClaimableBalanceResult decode(XdrDataInputStream stream) throws IOException {
return decode(stream, XdrDataInputStream.DEFAULT_MAX_DEPTH);
}
public static ClaimClaimableBalanceResult fromXdrBase64(String xdr) throws IOException {
byte[] bytes = Base64Factory.getInstance().decode(xdr);
return fromXdrByteArray(bytes);
}
public static ClaimClaimableBalanceResult fromXdrByteArray(byte[] xdr) throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
xdrDataInputStream.setMaxInputLen(xdr.length);
return decode(xdrDataInputStream);
}
@Override
public String toJson() {
return XdrElement.gson.toJson(toJsonObject());
}
public static ClaimClaimableBalanceResult fromJson(String json) {
return fromJsonObject(XdrElement.gson.fromJson(json, Object.class));
}
Object toJsonObject() {
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_SUCCESS) {
return "success";
}
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_DOES_NOT_EXIST) {
return "does_not_exist";
}
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_CANNOT_CLAIM) {
return "cannot_claim";
}
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_LINE_FULL) {
return "line_full";
}
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_NO_TRUST) {
return "no_trust";
}
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_NOT_AUTHORIZED) {
return "not_authorized";
}
if (discriminant == ClaimClaimableBalanceResultCode.CLAIM_CLAIMABLE_BALANCE_TRUSTLINE_FROZEN) {
return "trustline_frozen";
}
throw new IllegalArgumentException("Unknown discriminant: " + discriminant);
}
@SuppressWarnings("unchecked")
static ClaimClaimableBalanceResult fromJsonObject(Object json) {
if (json instanceof String) {
String strVal = (String) json;
if (!(strVal.equals("success")
|| strVal.equals("does_not_exist")
|| strVal.equals("cannot_claim")
|| strVal.equals("line_full")
|| strVal.equals("no_trust")
|| strVal.equals("not_authorized")
|| strVal.equals("trustline_frozen"))) {
throw new IllegalArgumentException(
"Unexpected string '" + strVal + "' for ClaimClaimableBalanceResult");
}
ClaimClaimableBalanceResult instance = new ClaimClaimableBalanceResult();
instance.discriminant = ClaimClaimableBalanceResultCode.fromJsonObject(strVal);
return instance;
}
throw new IllegalArgumentException(
"Expected a string for ClaimClaimableBalanceResult, got: " + json);
}
}