-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for BumpFootprintExpirationOperation and RestoreFootprint…
…Operation.
- Loading branch information
Showing
9 changed files
with
395 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/org/stellar/sdk/BumpFootprintExpirationOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.stellar.sdk; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
import lombok.experimental.SuperBuilder; | ||
import org.stellar.sdk.xdr.BumpFootprintExpirationOp; | ||
import org.stellar.sdk.xdr.ExtensionPoint; | ||
import org.stellar.sdk.xdr.OperationType; | ||
import org.stellar.sdk.xdr.Uint32; | ||
|
||
/** | ||
* Represents <a | ||
* href="https://developers.stellar.org/docs/fundamentals-and-concepts/list-of-operations#bump-footprint-expiration" | ||
* target="_blank">BumpFootprintExpiration</a> operation. | ||
* | ||
* <p>Bump the expiration of a footprint (read and written ledger keys). | ||
* | ||
* @see <a href="https://developers.stellar.org/docs/fundamentals-and-concepts/list-of-operations" | ||
* target="_blank">List of Operations</a> | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder(toBuilder = true) | ||
@Value | ||
public class BumpFootprintExpirationOperation extends Operation { | ||
|
||
/** | ||
* the number of ledgers past the LCL (last closed ledger) by which to extend the validity of the | ||
* ledger keys in this transaction | ||
*/ | ||
@NonNull Integer ledgersToExpire; | ||
|
||
/** | ||
* Constructs a new BumpFootprintExpirationOperation object from the XDR representation of the | ||
* {@link BumpFootprintExpirationOperation}. | ||
* | ||
* @param op the XDR representation of the {@link BumpFootprintExpirationOperation}. | ||
*/ | ||
public static BumpFootprintExpirationOperation fromXdr(BumpFootprintExpirationOp op) { | ||
return BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(op.getLedgersToExpire().getUint32()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) { | ||
BumpFootprintExpirationOp op = new BumpFootprintExpirationOp(); | ||
op.setExt(new ExtensionPoint.Builder().discriminant(0).build()); | ||
op.setLedgersToExpire(new Uint32(ledgersToExpire)); | ||
|
||
org.stellar.sdk.xdr.Operation.OperationBody body = | ||
new org.stellar.sdk.xdr.Operation.OperationBody(); | ||
body.setDiscriminant(OperationType.BUMP_FOOTPRINT_EXPIRATION); | ||
body.setBumpFootprintExpirationOp(op); | ||
return body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/org/stellar/sdk/RestoreFootprintOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.stellar.sdk; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
import lombok.experimental.SuperBuilder; | ||
import org.stellar.sdk.xdr.ExtensionPoint; | ||
import org.stellar.sdk.xdr.OperationType; | ||
import org.stellar.sdk.xdr.RestoreFootprintOp; | ||
|
||
/** | ||
* Represents <a | ||
* href="https://developers.stellar.org/docs/fundamentals-and-concepts/list-of-operations#restore-footprint" | ||
* target="_blank">RestoreFootprint</a> operation. | ||
* | ||
* @see <a href="https://developers.stellar.org/docs/fundamentals-and-concepts/list-of-operations" | ||
* target="_blank">List of Operations</a> | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@SuperBuilder(toBuilder = true) | ||
@Value | ||
public class RestoreFootprintOperation extends Operation { | ||
|
||
private RestoreFootprintOperation() {} | ||
|
||
/** | ||
* Constructs a new RestoreFootprintOperation object from the XDR representation of the {@link | ||
* RestoreFootprintOperation}. | ||
* | ||
* @param op the XDR representation of the {@link RestoreFootprintOperation}. | ||
*/ | ||
public static RestoreFootprintOperation fromXdr(RestoreFootprintOp op) { | ||
return new RestoreFootprintOperation(); | ||
} | ||
|
||
@Override | ||
org.stellar.sdk.xdr.Operation.OperationBody toOperationBody(AccountConverter accountConverter) { | ||
RestoreFootprintOp op = new RestoreFootprintOp(); | ||
op.setExt(new ExtensionPoint.Builder().discriminant(0).build()); | ||
|
||
org.stellar.sdk.xdr.Operation.OperationBody body = | ||
new org.stellar.sdk.xdr.Operation.OperationBody(); | ||
body.setDiscriminant(OperationType.RESTORE_FOOTPRINT); | ||
body.setRestoreFootprintOp(op); | ||
return body; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...n/java/org/stellar/sdk/responses/operations/BumpFootprintExpirationOperationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.stellar.sdk.responses.operations; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* Represents BumpFootprintExpiration operation response. | ||
* | ||
* @see <a href="https://developers.stellar.org/api/horizon/resources/operations" | ||
* target="_blank">Operation documentation</a> | ||
* @see org.stellar.sdk.requests.OperationsRequestBuilder | ||
* @see org.stellar.sdk.Server#operations() | ||
*/ | ||
public class BumpFootprintExpirationOperationResponse extends OperationResponse { | ||
@SerializedName("ledgers_to_expire") | ||
private final Long ledgers_to_expire; | ||
|
||
public BumpFootprintExpirationOperationResponse(Long ledgersToExpire) { | ||
ledgers_to_expire = ledgersToExpire; | ||
} | ||
|
||
public Long getLedgers_to_expire() { | ||
return ledgers_to_expire; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/stellar/sdk/responses/operations/RestoreFootprintOperationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.stellar.sdk.responses.operations; | ||
|
||
/** | ||
* Represents RestoreFootprint operation response. | ||
* | ||
* @see <a href="https://developers.stellar.org/api/horizon/resources/operations" | ||
* target="_blank">Operation documentation</a> | ||
* @see org.stellar.sdk.requests.OperationsRequestBuilder | ||
* @see org.stellar.sdk.Server#operations() | ||
*/ | ||
public class RestoreFootprintOperationResponse extends OperationResponse {} |
91 changes: 91 additions & 0 deletions
91
src/test/java/org/stellar/sdk/BumpFootprintExpirationOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.stellar.sdk; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
import static junit.framework.TestCase.assertNull; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class BumpFootprintExpirationOperationTest { | ||
@Test | ||
public void testBuilderWithSource() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
BumpFootprintExpirationOperation op = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(123) | ||
.sourceAccount(source) | ||
.build(); | ||
assertEquals(Integer.valueOf(123), op.getLedgersToExpire()); | ||
assertEquals(source, op.getSourceAccount()); | ||
String expectXdr = "AAAAAQAAAAAk4TTtavBWsGnEN3KxHw4Ohwi22ZJHWi8hlamN5pm0TgAAABkAAAAAAAAAew=="; | ||
assertEquals(expectXdr, op.toXdrBase64()); | ||
} | ||
|
||
@Test | ||
public void testBuilderWithoutSource() { | ||
BumpFootprintExpirationOperation op = | ||
BumpFootprintExpirationOperation.builder().ledgersToExpire(123).build(); | ||
assertEquals(Integer.valueOf(123), op.getLedgersToExpire()); | ||
assertNull(op.getSourceAccount()); | ||
String expectXdr = "AAAAAAAAABkAAAAAAAAAew=="; | ||
assertEquals(expectXdr, op.toXdrBase64()); | ||
} | ||
|
||
@Test | ||
public void testFromXdr() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
BumpFootprintExpirationOperation originOp = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(123) | ||
.sourceAccount(source) | ||
.build(); | ||
org.stellar.sdk.xdr.Operation xdrObject = originOp.toXdr(); | ||
Operation restartOp = Operation.fromXdr(xdrObject); | ||
Assert.assertEquals(restartOp, originOp); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
BumpFootprintExpirationOperation operation1 = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(123) | ||
.sourceAccount(source) | ||
.build(); | ||
BumpFootprintExpirationOperation operation2 = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(123) | ||
.sourceAccount(source) | ||
.build(); | ||
assertEquals(operation1, operation2); | ||
} | ||
|
||
@Test | ||
public void testNotEquals() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
BumpFootprintExpirationOperation operation1 = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(123) | ||
.sourceAccount(source) | ||
.build(); | ||
BumpFootprintExpirationOperation operation2 = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(124) | ||
.sourceAccount(source) | ||
.build(); | ||
Assert.assertNotEquals(operation1, operation2); | ||
} | ||
|
||
@Test | ||
public void testNotEqualsSource() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
BumpFootprintExpirationOperation operation1 = | ||
BumpFootprintExpirationOperation.builder() | ||
.ledgersToExpire(123) | ||
.sourceAccount(source) | ||
.build(); | ||
BumpFootprintExpirationOperation operation2 = | ||
BumpFootprintExpirationOperation.builder().ledgersToExpire(123).build(); | ||
Assert.assertNotEquals(operation1, operation2); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/test/java/org/stellar/sdk/RestoreFootprintOperationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.stellar.sdk; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
import static junit.framework.TestCase.assertNull; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class RestoreFootprintOperationTest { | ||
@Test | ||
public void testBuilderWithSource() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
RestoreFootprintOperation op = | ||
RestoreFootprintOperation.builder().sourceAccount(source).build(); | ||
assertEquals(source, op.getSourceAccount()); | ||
String expectXdr = "AAAAAQAAAAAk4TTtavBWsGnEN3KxHw4Ohwi22ZJHWi8hlamN5pm0TgAAABoAAAAA"; | ||
assertEquals(expectXdr, op.toXdrBase64()); | ||
} | ||
|
||
@Test | ||
public void testBuilderWithoutSource() { | ||
RestoreFootprintOperation op = RestoreFootprintOperation.builder().build(); | ||
assertNull(op.getSourceAccount()); | ||
String expectXdr = "AAAAAAAAABoAAAAA"; | ||
assertEquals(expectXdr, op.toXdrBase64()); | ||
} | ||
|
||
@Test | ||
public void testFromXdr() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
RestoreFootprintOperation originOp = | ||
RestoreFootprintOperation.builder().sourceAccount(source).build(); | ||
org.stellar.sdk.xdr.Operation xdrObject = originOp.toXdr(); | ||
Operation restartOp = Operation.fromXdr(xdrObject); | ||
Assert.assertEquals(restartOp, originOp); | ||
} | ||
|
||
@Test | ||
public void testEquals() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
RestoreFootprintOperation operation1 = | ||
RestoreFootprintOperation.builder().sourceAccount(source).build(); | ||
RestoreFootprintOperation operation2 = | ||
RestoreFootprintOperation.builder().sourceAccount(source).build(); | ||
assertEquals(operation1, operation2); | ||
} | ||
|
||
@Test | ||
public void testNotEquals() { | ||
String source = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"; | ||
RestoreFootprintOperation operation1 = | ||
RestoreFootprintOperation.builder().sourceAccount(source).build(); | ||
RestoreFootprintOperation operation2 = RestoreFootprintOperation.builder().build(); | ||
Assert.assertNotEquals(operation1, operation2); | ||
} | ||
} |
Oops, something went wrong.