Skip to content

Commit

Permalink
fix definitions and AmountType.fromParser
Browse files Browse the repository at this point in the history
  • Loading branch information
nkramer44 committed Oct 17, 2024
1 parent 8e83137 commit 21783ff
Show file tree
Hide file tree
Showing 3 changed files with 1,507 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,15 @@ private static void verifyNoDecimal(BigDecimal decimal) {
@Override
public AmountType fromParser(BinaryParser parser) {
UnsignedByte nextByte = parser.peek();
Preconditions.checkArgument(
!(nextByte.isNthBitSet(1) && nextByte.isNthBitSet(3)),
"Invalid STAmount: First and third leading bits are set, which indicates the amount is both an IOU and an MPT."
);
boolean isXrpOrMpt = !nextByte.isNthBitSet(1);
boolean isXrp = !nextByte.isNthBitSet(3);
int numBytes = isXrpOrMpt ? (isXrp ? NATIVE_AMOUNT_BYTE_LENGTH : MPT_AMOUNT_BYTE_LENGTH) : CURRENCY_AMOUNT_BYTE_LENGTH;
int numBytes;
if (nextByte.isNthBitSet(1)) {
numBytes = CURRENCY_AMOUNT_BYTE_LENGTH;
} else {
boolean isMpt = nextByte.isNthBitSet(3);

numBytes = isMpt ? MPT_AMOUNT_BYTE_LENGTH : NATIVE_AMOUNT_BYTE_LENGTH;
}

return new AmountType(parser.read(numBytes));
}

Expand Down
Loading

0 comments on commit 21783ff

Please sign in to comment.