Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/org/stellar/sdk/xdr/Int128Parts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -46,6 +47,12 @@ public static Int128Parts fromXdrBase64(String xdr) throws IOException {
return fromXdrByteArray(bytes);
}

public BigInteger toBigInteger() {
BigInteger hiValue = BigInteger.valueOf(hi.getInt64());
BigInteger loValue = lo.getUint64().getNumber();
return hiValue.shiftLeft(64).add(loValue);
}

public static Int128Parts fromXdrByteArray(byte[] xdr) throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/stellar/sdk/xdr/Int256Parts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -54,6 +55,19 @@ public static Int256Parts fromXdrBase64(String xdr) throws IOException {
return fromXdrByteArray(bytes);
}

public BigInteger toBigInteger() {
BigInteger hi_hiValue = BigInteger.valueOf(hi_hi.getInt64());
BigInteger hi_loValue = hi_lo.getUint64().getNumber();
BigInteger lo_hiValue = lo_hi.getUint64().getNumber();
BigInteger lo_loValue = lo_lo.getUint64().getNumber();

return hi_hiValue
.shiftLeft(192)
.add(hi_loValue.shiftLeft(128))
.add(lo_hiValue.shiftLeft(64))
.add(lo_loValue);
}

public static Int256Parts fromXdrByteArray(byte[] xdr) throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/stellar/sdk/xdr/UInt128Parts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -46,6 +47,12 @@ public static UInt128Parts fromXdrBase64(String xdr) throws IOException {
return fromXdrByteArray(bytes);
}

public BigInteger toBigInteger() {
BigInteger hiValue = hi.getUint64().getNumber();
BigInteger loValue = lo.getUint64().getNumber();
return hiValue.shiftLeft(64).add(loValue);
}

public static UInt128Parts fromXdrByteArray(byte[] xdr) throws IOException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/stellar/sdk/xdr/UInt256Parts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -49,6 +50,18 @@ public static UInt256Parts decode(XdrDataInputStream stream) throws IOException
return decodedUInt256Parts;
}

public BigInteger toBigInteger() {
BigInteger hi_hiValue = hi_hi.getUint64().getNumber();
BigInteger hi_loValue = hi_lo.getUint64().getNumber();
BigInteger lo_hiValue = lo_hi.getUint64().getNumber();
BigInteger lo_loValue = lo_lo.getUint64().getNumber();
return hi_hiValue
.shiftLeft(192)
.add(hi_loValue.shiftLeft(128))
.add(lo_hiValue.shiftLeft(64))
.add(lo_loValue);
}

public static UInt256Parts fromXdrBase64(String xdr) throws IOException {
byte[] bytes = Base64Factory.getInstance().decode(xdr);
return fromXdrByteArray(bytes);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/stellar/sdk/xdr/Uint256.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -36,6 +37,10 @@ public static Uint256 decode(XdrDataInputStream stream) throws IOException {
return decodedUint256;
}

public BigInteger toBigInteger() {
return new BigInteger(1, uint256);
}

public static Uint256 fromXdrBase64(String xdr) throws IOException {
byte[] bytes = Base64Factory.getInstance().decode(xdr);
return fromXdrByteArray(bytes);
Expand Down