-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/maven/jackson.version-2.15.2
- Loading branch information
Showing
97 changed files
with
9,858 additions
and
1,403 deletions.
There are no files selected for viewing
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
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
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
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
63 changes: 63 additions & 0 deletions
63
xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/binary/types/XChainBridge.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,63 @@ | ||
package org.xrpl.xrpl4j.codec.binary.types; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.google.common.annotations.Beta; | ||
import org.immutables.value.Value.Immutable; | ||
|
||
/** | ||
* JSON mapping object for the XChainBridge serialized type. | ||
*/ | ||
@Beta | ||
@Immutable | ||
@JsonSerialize(as = ImmutableXChainBridge.class) | ||
@JsonDeserialize(as = ImmutableXChainBridge.class) | ||
public interface XChainBridge { | ||
|
||
/** | ||
* Construct a {@code XChainBridge} builder. | ||
* | ||
* @return An {@link ImmutableXChainBridge.Builder}. | ||
*/ | ||
static ImmutableXChainBridge.Builder builder() { | ||
return ImmutableXChainBridge.builder(); | ||
} | ||
|
||
/** | ||
* The door account on the issuing chain. For an XRP-XRP bridge, this must be the genesis account (the account that is | ||
* created when the network is first started, which contains all of the XRP). | ||
* | ||
* @return The address of the door account as a {@link JsonNode}. | ||
*/ | ||
@JsonProperty("IssuingChainDoor") | ||
JsonNode issuingChainDoor(); | ||
|
||
/** | ||
* The asset that is minted and burned on the issuing chain. For an IOU-IOU bridge, the issuer of the asset must be | ||
* the door account on the issuing chain, to avoid supply issues. | ||
* | ||
* @return An {@link Issue}. | ||
*/ | ||
@JsonProperty("IssuingChainIssue") | ||
JsonNode issuingChainIssue(); | ||
|
||
/** | ||
* The door account on the locking chain. | ||
* | ||
* @return The address of the door account as a {@link JsonNode}. | ||
*/ | ||
@JsonProperty("LockingChainDoor") | ||
JsonNode lockingChainDoor(); | ||
|
||
/** | ||
* The asset that is locked and unlocked on the locking chain. | ||
* | ||
* @return An {@link Issue}. | ||
*/ | ||
@JsonProperty("LockingChainIssue") | ||
JsonNode lockingChainIssue(); | ||
|
||
|
||
} |
104 changes: 104 additions & 0 deletions
104
xrpl4j-core/src/main/java/org/xrpl/xrpl4j/codec/binary/types/XChainBridgeType.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,104 @@ | ||
package org.xrpl.xrpl4j.codec.binary.types; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.xrpl.xrpl4j.codec.addresses.UnsignedByte; | ||
import org.xrpl.xrpl4j.codec.addresses.UnsignedByteArray; | ||
import org.xrpl.xrpl4j.codec.binary.BinaryCodecObjectMapperFactory; | ||
import org.xrpl.xrpl4j.codec.binary.serdes.BinaryParser; | ||
|
||
public class XChainBridgeType extends SerializedType<XChainBridgeType> { | ||
|
||
private static final ObjectMapper objectMapper = BinaryCodecObjectMapperFactory.getObjectMapper(); | ||
|
||
/** | ||
* XChainBridge typed fields are serialized by serializing the LockingChainDoor, LockingChainIssue, IssuingChainDoor | ||
* IssuingChainIssue fields in order without type or field codes. LockingChainDoor and IssuingChainDoor are an | ||
* {@link AccountIdType}, and LockingChainIssue and IssuingChainIssue are {@link IssueType}s. | ||
* | ||
* <p>The "empty" or "zero" | ||
* XChainBridge type has LockingChainDoor and IssuingChainDoor = ACCOUNT_ZERO, and LockingChainIssue and | ||
* IssuingChainIssue = XRP. AccountIDs are serialized with a length prefix, which is always {@code 0x14}. The XRP | ||
* issue is serialized as 160 zero bits. Therefore, the "zero" XChainBridge is {@code 0x14} followed by 20 zero bytes | ||
* for the LockingChainDoor, followed by 20 zero bytes for LockingChainIssue, followed by {@code 0x14} and 20 zero | ||
* bytes for the IssuingChainDoor and 20 zero bytes for IssuingChainIssue.</p> | ||
*/ | ||
private static final byte[] ZERO_XCHAIN_BRIDGE = new byte[82]; | ||
|
||
static { | ||
ZERO_XCHAIN_BRIDGE[0] = 0x14; | ||
ZERO_XCHAIN_BRIDGE[41] = 0x14; | ||
} | ||
|
||
public XChainBridgeType() { | ||
this(UnsignedByteArray.of(ZERO_XCHAIN_BRIDGE)); | ||
} | ||
|
||
public XChainBridgeType(UnsignedByteArray bytes) { | ||
super(bytes); | ||
} | ||
|
||
|
||
@Override | ||
public XChainBridgeType fromJson(JsonNode node) throws JsonProcessingException { | ||
if (!node.isObject()) { | ||
throw new IllegalArgumentException("node is not an object"); | ||
} | ||
XChainBridge bridge = objectMapper.treeToValue(node, XChainBridge.class); | ||
|
||
// AccountIDs have a VL prefix that is always 20 (except for ACCOUNT_ZERO). Usually this length prefix is | ||
// added in BinarySerializer.writeFieldAndValue because STAccounts are VL encoded according to definitions.json. | ||
// However, because STXChainBridges are not VL encoded, we need to manually add the length prefix to the two | ||
// STAccount types here. | ||
UnsignedByteArray byteArray = UnsignedByteArray.of(UnsignedByte.of(20)); | ||
byteArray.append(new AccountIdType().fromJson(bridge.lockingChainDoor()).value()); | ||
byteArray.append(new IssueType().fromJson(bridge.lockingChainIssue()).value()); | ||
|
||
// Need to add length prefix for issuing chain door account. | ||
byteArray.append(UnsignedByte.of(20)); | ||
byteArray.append(new AccountIdType().fromJson(bridge.issuingChainDoor()).value()); | ||
byteArray.append(new IssueType().fromJson(bridge.issuingChainIssue()).value()); | ||
|
||
return new XChainBridgeType(byteArray); | ||
} | ||
|
||
@Override | ||
public XChainBridgeType fromParser(BinaryParser parser) { | ||
parser.skip(1); | ||
AccountIdType lockingChainDoor = new AccountIdType().fromParser(parser); | ||
IssueType lockingChainIssue = new IssueType().fromParser(parser); | ||
parser.skip(1); | ||
AccountIdType issuingChainDoor = new AccountIdType().fromParser(parser); | ||
IssueType issuingChainIssue = new IssueType().fromParser(parser); | ||
|
||
return new XChainBridgeType( | ||
UnsignedByteArray.of(UnsignedByte.of(20)) | ||
.append(lockingChainDoor.value()) | ||
.append(lockingChainIssue.value()) | ||
.append(UnsignedByte.of(20)) | ||
.append(issuingChainDoor.value()) | ||
.append(issuingChainIssue.value()) | ||
); | ||
} | ||
|
||
@Override | ||
public JsonNode toJson() { | ||
BinaryParser parser = new BinaryParser(this.toHex()); | ||
parser.skip(1); | ||
AccountIdType lockingChainDoor = new AccountIdType().fromParser(parser); | ||
IssueType lockingChainIssue = new IssueType().fromParser(parser); | ||
parser.skip(1); | ||
AccountIdType issuingChainDoor = new AccountIdType().fromParser(parser); | ||
IssueType issuingChainIssue = new IssueType().fromParser(parser); | ||
|
||
XChainBridge bridge = XChainBridge.builder() | ||
.lockingChainDoor(lockingChainDoor.toJson()) | ||
.lockingChainIssue(lockingChainIssue.toJson()) | ||
.issuingChainDoor(issuingChainDoor.toJson()) | ||
.issuingChainIssue(issuingChainIssue.toJson()) | ||
.build(); | ||
|
||
return objectMapper.valueToTree(bridge); | ||
} | ||
} |
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
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
Oops, something went wrong.