XRPLF / xrpl4j

A 100% Java implementation to interact with the XRP Ledger.
ISC License
80 stars 45 forks source link

xrpl4j fail to get negative balance value #527

Open hyeongcheolkim opened 3 months ago

hyeongcheolkim commented 3 months ago

xrpl4j fail to get '-2298000050' because type is unsignedlong. but i think it should be signedlong.

XrplClient xrp = new XrplClient(HttpUrl.get("https://xrplcluster.com/"));
try {

    ImmutableLedgerRequestParams params = LedgerRequestParams.builder()
            .ledgerSpecifier(LedgerSpecifier.of(UnsignedInteger.valueOf(354575L)))
            .transactions(true)
            .build();
    ImmutableJsonRpcRequest request = JsonRpcRequest.builder().method("ledger").addParams(params).build();
    JsonNode jsonNode = xrp.getJsonRpcClient().postRpcRequest(request);
    System.out.println("jsonNode = " + jsonNode);

    LedgerResult ledger = xrp.ledger(params);
    System.out.println("ledger = " + ledger);

} catch (Exception e) {
    throw new RuntimeException(e);
}

when i run this code. exception occured.

     org.xrpl.xrpl4j.client.JsonRpcClientErrorException: com.fasterxml.jackson.databind.JsonMappingException: value (-2298000050) is outside the range for an unsigned long value (through reference chain: org.xrpl.xrpl4j.model.transactions.ImmutableTransactionMetadata$Json["AffectedNodes"]->java.util.ArrayList[0]->       org.xrpl.xrpl4j.model.transactions.metadata.ImmutableModifiedNode$Json["PreviousFields"]->       org.xrpl.xrpl4j.model.transactions.metadata.ImmutableMetaAccountRootObject$Json["Balance"]) (through reference chain: org.xrpl.xrpl4j.model.client.ledger.ImmutableLedgerResult$Json["ledger"]->       org.xrpl.xrpl4j.model.ledger.ImmutableLedgerHeader$Json["transactions"]->java.util.ArrayList[0])
hyeongcheolkim commented 3 months ago

i think balance type should be SignedLong. not UnsignedLong. image

nkramer44 commented 2 months ago

Hi @hyeongcheolkim, this is a known issue. There are a few historical (very very old) ledgers that seem to contain negative XRP balances, but the bug that caused that issue in rippled has since been fixed.

The documentation you posted is related to Trustline balances, which can be negative -- these balances are represented as Strings in xrpl4j. I'm not sure of an easy fix to handle historical ledgers with negative XRP balances, as ideally the balance field should remain an UnsignedLong to provide the best developer experience for those querying more recent history. How important is it for you to be able to query these ledgers?