Skip to content

Commit c62cce6

Browse files
authored
Add support for deep freeze (#620)
* Add support for the Deep Freeze amendment (https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0077-deep-freeze)
1 parent c3e3259 commit c62cce6

File tree

8 files changed

+464
-32
lines changed

8 files changed

+464
-32
lines changed

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/client/accounts/TrustLine.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -170,4 +170,26 @@ default boolean freezePeer() {
170170
return false;
171171
}
172172

173+
/**
174+
* Whether or not this account has deep-frozen this trust line.
175+
*
176+
* @return {@code true} if this account has deep-frozen this trust line, otherwise {@code false}.
177+
*/
178+
@JsonProperty("deep_freeze")
179+
@Value.Default
180+
default boolean deepFreeze() {
181+
return false;
182+
}
183+
184+
/**
185+
* Whether or not the peer account has deep-frozen this trust line.
186+
*
187+
* @return {@code true} if the peer account has deep-frozen this trust line, otherwise {@code false}.
188+
*/
189+
@JsonProperty("deep_freeze_peer")
190+
@Value.Default
191+
default boolean deepFreezePeer() {
192+
return false;
193+
}
194+
173195
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/RippleStateFlags.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -67,6 +67,16 @@ public class RippleStateFlags extends Flags {
6767
*/
6868
public static final RippleStateFlags HIGH_FREEZE = new RippleStateFlags(0x00800000);
6969

70+
/**
71+
* Constant {@link RippleStateFlags} for the {@code lsfLowDeepFreeze} flag.
72+
*/
73+
public static final RippleStateFlags LOW_DEEP_FREEZE = new RippleStateFlags(0x02000000);
74+
75+
/**
76+
* Constant {@link RippleStateFlags} for the {@code lsfHighDeepFreeze} flag.
77+
*/
78+
public static final RippleStateFlags HIGH_DEEP_FREEZE = new RippleStateFlags(0x04000000);
79+
7080
private RippleStateFlags(long value) {
7181
super(value);
7282
}
@@ -157,4 +167,22 @@ public boolean lsfLowFreeze() {
157167
public boolean lsfHighFreeze() {
158168
return this.isSet(HIGH_FREEZE);
159169
}
170+
171+
/**
172+
* The low account has deep-frozen the trust line, preventing the high account from sending and receiving the asset.
173+
*
174+
* @return {@code true} if {@code lsfLowDeepFreeze} is set, otherwise {@code false}.
175+
*/
176+
public boolean lsfLowDeepFreeze() {
177+
return this.isSet(LOW_DEEP_FREEZE);
178+
}
179+
180+
/**
181+
* The high account has deep-frozen the trust line, preventing the low account from sending and receiving the asset.
182+
*
183+
* @return {@code true} if {@code lsfHighDeepFreeze} is set, otherwise {@code false}.
184+
*/
185+
public boolean lsfHighDeepFreeze() {
186+
return this.isSet(HIGH_DEEP_FREEZE);
187+
}
160188
}

xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/flags/TrustSetFlags.java

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -59,6 +59,16 @@ public class TrustSetFlags extends TransactionFlags {
5959
*/
6060
protected static final TrustSetFlags CLEAR_FREEZE = new TrustSetFlags(0x00200000);
6161

62+
/**
63+
* Constant {@link TrustSetFlags} for the {@code tfSetDeepFreeze} flag.
64+
*/
65+
protected static final TrustSetFlags SET_DEEP_FREEZE = new TrustSetFlags(0x00400000);
66+
67+
/**
68+
* Constant {@link TrustSetFlags} for the {@code tfClearDeepFreeze} flag.
69+
*/
70+
protected static final TrustSetFlags CLEAR_DEEP_FREEZE = new TrustSetFlags(0x00800000);
71+
6272
private TrustSetFlags(long value) {
6373
super(value);
6474
}
@@ -81,7 +91,9 @@ private static TrustSetFlags of(
8191
boolean tfSetNoRipple,
8292
boolean tfClearNoRipple,
8393
boolean tfSetFreeze,
84-
boolean tfClearFreeze
94+
boolean tfClearFreeze,
95+
boolean tfSetDeepFreeze,
96+
boolean tfClearDeepFreeze
8597
) {
8698
return new TrustSetFlags(
8799
Flags.of(
@@ -90,7 +102,9 @@ private static TrustSetFlags of(
90102
tfSetNoRipple ? SET_NO_RIPPLE : UNSET,
91103
tfClearNoRipple ? CLEAR_NO_RIPPLE : UNSET,
92104
tfSetFreeze ? SET_FREEZE : UNSET,
93-
tfClearFreeze ? CLEAR_FREEZE : UNSET).getValue()
105+
tfClearFreeze ? CLEAR_FREEZE : UNSET,
106+
tfSetDeepFreeze ? SET_DEEP_FREEZE : UNSET,
107+
tfClearDeepFreeze ? CLEAR_DEEP_FREEZE : UNSET).getValue()
94108
);
95109
}
96110

@@ -171,6 +185,24 @@ public boolean tfClearFreeze() {
171185
return this.isSet(CLEAR_FREEZE);
172186
}
173187

188+
/**
189+
* <a href="https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0077-deep-freeze">Deep freeze</a> the trust line.
190+
*
191+
* @return {@code true} if {@code tfSetDeepFreeze} is set, otherwise {@code false}.
192+
*/
193+
public boolean tfSetDeepFreeze() {
194+
return this.isSet(SET_DEEP_FREEZE);
195+
}
196+
197+
/**
198+
* <a href="https://github.com/XRPLF/XRPL-Standards/tree/master/XLS-0077-deep-freeze">Clear deep freeze</a> on the trust line.
199+
*
200+
* @return {@code true} if {@code tfClearDeepFreeze} is set, otherwise {@code false}.
201+
*/
202+
public boolean tfClearDeepFreeze() {
203+
return this.isSet(CLEAR_DEEP_FREEZE);
204+
}
205+
174206
/**
175207
* A builder class for {@link TrustSetFlags}.
176208
*/
@@ -180,6 +212,8 @@ public static class Builder {
180212
private boolean tfClearNoRipple = false;
181213
private boolean tfSetFreeze = false;
182214
private boolean tfClearFreeze = false;
215+
private boolean tfSetDeepFreeze = false;
216+
private boolean tfClearDeepFreeze = false;
183217

184218
/**
185219
* Set {@code tfSetfAuth} to the given value.
@@ -233,6 +267,26 @@ public Builder tfClearFreeze() {
233267
return this;
234268
}
235269

270+
/**
271+
* Set {@code tfSetDeepFreeze} to {@code true}.
272+
*
273+
* @return The same {@link Builder}.
274+
*/
275+
public Builder tfSetDeepFreeze() {
276+
this.tfSetDeepFreeze = true;
277+
return this;
278+
}
279+
280+
/**
281+
* Set {@code tfClearDeepFreeze} to {@code true}.
282+
*
283+
* @return The same {@link Builder}.
284+
*/
285+
public Builder tfClearDeepFreeze() {
286+
this.tfClearDeepFreeze = true;
287+
return this;
288+
}
289+
236290
/**
237291
* Build a new {@link TrustSetFlags} from the current boolean values.
238292
*
@@ -245,7 +299,9 @@ public TrustSetFlags build() {
245299
tfSetNoRipple,
246300
tfClearNoRipple,
247301
tfSetFreeze,
248-
tfClearFreeze
302+
tfClearFreeze,
303+
tfSetDeepFreeze,
304+
tfClearDeepFreeze
249305
);
250306
}
251307
}

xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/client/accounts/AccountLinesResultJsonTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -75,6 +75,8 @@ public void testJson() throws JsonProcessingException, JSONException {
7575
" \"peer_authorized\": false,\n" +
7676
" \"freeze\": false,\n" +
7777
" \"freeze_peer\": false,\n" +
78+
" \"deep_freeze\": false,\n" +
79+
" \"deep_freeze_peer\": false,\n" +
7880
" \"quality_in\": 0,\n" +
7981
" \"quality_out\": 0\n" +
8082
" },\n" +
@@ -90,6 +92,8 @@ public void testJson() throws JsonProcessingException, JSONException {
9092
" \"peer_authorized\": false,\n" +
9193
" \"freeze\": false,\n" +
9294
" \"freeze_peer\": false,\n" +
95+
" \"deep_freeze\": false,\n" +
96+
" \"deep_freeze_peer\": false,\n" +
9397
" \"quality_in\": 0,\n" +
9498
" \"quality_out\": 0\n" +
9599
" }\n" +

xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/flags/RippleStateFlagsTests.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@
3333
public class RippleStateFlagsTests extends AbstractFlagsTest {
3434

3535
public static Stream<Arguments> data() {
36-
return getBooleanCombinations(8);
36+
return getBooleanCombinations(10);
3737
}
3838

3939
@ParameterizedTest
@@ -46,7 +46,9 @@ public void testDeriveIndividualFlagsFromFlags(
4646
boolean lsfLowNoRipple,
4747
boolean lsfHighNoRipple,
4848
boolean lsfLowFreeze,
49-
boolean lsfHighFreeze
49+
boolean lsfHighFreeze,
50+
boolean lsfLowDeepFreeze,
51+
boolean lsfHighDeepFreeze
5052
) {
5153
long expectedFlags = getExpectedFlags(
5254
lsfLowReserve,
@@ -56,7 +58,9 @@ public void testDeriveIndividualFlagsFromFlags(
5658
lsfLowNoRipple,
5759
lsfHighNoRipple,
5860
lsfLowFreeze,
59-
lsfHighFreeze
61+
lsfHighFreeze,
62+
lsfLowDeepFreeze,
63+
lsfHighDeepFreeze
6064
);
6165
RippleStateFlags flags = RippleStateFlags.of(expectedFlags);
6266

@@ -69,6 +73,8 @@ public void testDeriveIndividualFlagsFromFlags(
6973
assertThat(flags.lsfHighNoRipple()).isEqualTo(lsfHighNoRipple);
7074
assertThat(flags.lsfLowFreeze()).isEqualTo(lsfLowFreeze);
7175
assertThat(flags.lsfHighFreeze()).isEqualTo(lsfHighFreeze);
76+
assertThat(flags.lsfLowDeepFreeze()).isEqualTo(lsfLowDeepFreeze);
77+
assertThat(flags.lsfHighDeepFreeze()).isEqualTo(lsfHighDeepFreeze);
7278
}
7379

7480
@ParameterizedTest
@@ -81,7 +87,9 @@ void testJson(
8187
boolean lsfLowNoRipple,
8288
boolean lsfHighNoRipple,
8389
boolean lsfLowFreeze,
84-
boolean lsfHighFreeze
90+
boolean lsfHighFreeze,
91+
boolean lsfLowDeepFreeze,
92+
boolean lsfHighDeepFreeze
8593
) throws JSONException, JsonProcessingException {
8694
long expectedFlags = getExpectedFlags(
8795
lsfLowReserve,
@@ -91,7 +99,9 @@ void testJson(
9199
lsfLowNoRipple,
92100
lsfHighNoRipple,
93101
lsfLowFreeze,
94-
lsfHighFreeze
102+
lsfHighFreeze,
103+
lsfLowDeepFreeze,
104+
lsfHighDeepFreeze
95105
);
96106

97107
RippleStateFlags flags = RippleStateFlags.of(expectedFlags);
@@ -113,7 +123,9 @@ protected long getExpectedFlags(
113123
boolean lsfLowNoRipple,
114124
boolean lsfHighNoRipple,
115125
boolean lsfLowFreeze,
116-
boolean lsfHighFreeze
126+
boolean lsfHighFreeze,
127+
boolean lsfLowDeepFreeze,
128+
boolean lsfHighDeepFreeze
117129
) {
118130
return (lsfLowReserve ? RippleStateFlags.LOW_RESERVE.getValue() : 0L) |
119131
(lsfHighReserve ? RippleStateFlags.HIGH_RESERVE.getValue() : 0L) |
@@ -122,6 +134,8 @@ protected long getExpectedFlags(
122134
(lsfLowNoRipple ? RippleStateFlags.LOW_NO_RIPPLE.getValue() : 0L) |
123135
(lsfHighNoRipple ? RippleStateFlags.HIGH_NO_RIPPLE.getValue() : 0L) |
124136
(lsfLowFreeze ? RippleStateFlags.LOW_FREEZE.getValue() : 0L) |
125-
(lsfHighFreeze ? RippleStateFlags.HIGH_FREEZE.getValue() : 0L);
137+
(lsfHighFreeze ? RippleStateFlags.HIGH_FREEZE.getValue() : 0L) |
138+
(lsfLowDeepFreeze ? RippleStateFlags.LOW_DEEP_FREEZE.getValue() : 0L) |
139+
(lsfHighDeepFreeze ? RippleStateFlags.HIGH_DEEP_FREEZE.getValue() : 0L);
126140
}
127141
}

0 commit comments

Comments
 (0)