public boolean hasNativeSource() { for (Alternative alt : this) { if (alt.sourceAmount.isNative()) { return true; } } return false; }
public String toDropsString() { if (!isNative()) { throw new RuntimeException("Amount is not native"); } return bigIntegerDrops().toString(); }
public boolean directXRP() { return !hasPaths() && sourceAmount.isNative(); }
public JSONObject toJSONObject() { if (isNative()) { throw new RuntimeException("Native amounts must be serialized as a string"); } JSONObject out = new JSONObject(); out.put("currency", currencyString()); out.put("value", valueText()); out.put("issuer", issuerString()); return out; }
/** * @return A String representation as used by ripple json format */ public String stringRepr() { if (isNative()) { return toDropsString(); } else { return iouTextFull(); } }
public String toTextFull() { if (isNative()) { return nativeText(); } else { return iouTextFull(); } }
@Override public Object toJSON() { if (isNative()) { return toDropsString(); } else { return toJSONObject(); } }
public String toText() { if (isNative()) { return nativeText(); } else { return iouText(); } }
/** * @return Amount * The real native unit is a drop, one million of which are an XRP. * We want `one` unit at XRP scale (1e6 drops), or if it's an IOU, * just `one`. */ public Amount one() { if (isNative()) { return ONE_XRP; } else { return issue().amount(1); } }
private void initialize() { if (isNative()) { issuer = AccountID.XRP_ISSUER; if (!unbounded) { checkXRPBounds(); } // Offset is unused for native amounts exponent = -6; // compared to drops. } else { issuer = AccountID.NEUTRAL; exponent = calculateExponent(); if (value.precision() > MAXIMUM_IOU_PRECISION && !unbounded) { String err = "value precision of " + value.precision() + " is greater than maximum " + "iou precision of " + MAXIMUM_IOU_PRECISION; throw new PrecisionError(err, this); } } }
/** * @return a positive value for the mantissa */ private UInt64 calculateMantissa() { if (isNative()) { return new UInt64(bigIntegerDrops().abs()); } else { return new UInt64(bigIntegerIOUMantissa()); } }
public boolean equals(Amount amt) { return equalValue(amt) && currency.equals(amt.currency) && (isNative() || issuer.equals(amt.issuer)); }
private Alternatives constructAlternatives(JSONArray alternatives, Alternatives prior) { Alternatives alts; if (alternatives == null) { alts = new Alternatives(); } else { alts = new Alternatives(alternatives, prior); } if (destinationAmount.isNative() && !src.equals(dest) && srcCanSendNative(destinationAmount)) { injectNativeAlternative(alts, prior); } return alts; }
public Vector256 lineIndexes() { Vector256 ret = new Vector256(); Amount takerGets = takerGets(); for (Amount amt : new Amount[]{takerGets, takerPays()}) { // Actually want to compare by reference here :) if (amt == takerGets()) { // selling own funds continue; } if (!amt.isNative()) { ret.add(lineIndex(amt)); } } return ret; }
public Hash256 fundingSource() { Amount takerGets = takerGets(); if (account().equals(takerGets.issuer())) { return null; } else if (takerGets.isNative()) { return Index.accountRoot(account()); } else { return lineIndex(takerGets); } }
Amount amount = tr.txn.get(Amount.Amount); if (amount.isNative()) { successful++; BigDecimal value = amount.value();
@Override public void toBytesSink(BytesSink to) { UInt64 man = mantissa(); if (isNative()) { if (!isNegative()) { man = man.or(BINARY_FLAG_IS_NON_NEGATIVE_NATIVE); } to.add(man.toByteArray()); } else { int exponent = exponent(); UInt64 packed; if (isZero()) { packed = BINARY_FLAG_IS_IOU; } else if (isNegative()) { packed = man.or(new UInt64(512 + 0 + 97 + exponent).shiftLeft(64 - 10)); } else { packed = man.or(new UInt64(512 + 256 + 97 + exponent).shiftLeft(64 - 10)); } to.add(packed.toByteArray()); to.add(currency.bytes()); to.add(issuer.bytes()); } }
if (destinationAmount.isNative()) {