Java Code Examples for com.google.common.primitives.UnsignedLong#bigIntegerValue()
The following examples show how to use
com.google.common.primitives.UnsignedLong#bigIntegerValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: unsigned_number_serializer.java From AndroidWallet with GNU General Public License v3.0 | 4 votes |
@Override public JsonElement serialize(UnsignedLong src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.bigIntegerValue()); }
Example 2
Source File: unsigned_number_serializer.java From guarda-android-wallets with GNU General Public License v3.0 | 4 votes |
@Override public JsonElement serialize(UnsignedLong src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.bigIntegerValue()); }
Example 3
Source File: DepositProcessingController.java From teku with Apache License 2.0 | 4 votes |
private synchronized void onNewCanonicalBlockNumber(UnsignedLong newCanonicalBlockNumber) { this.latestCanonicalBlockNumber = newCanonicalBlockNumber.bigIntegerValue(); fetchLatestSubscriptionDeposits(); }
Example 4
Source File: AimdCongestionController.java From quilt with Apache License 2.0 | 4 votes |
/** * <p>Properly handle a rejection containing a {@link InterledgerErrorCode#F08_AMOUNT_TOO_LARGE} error code.</p> * * <p>The goal of this method is to reduce the {@link #maxPacketAmount} (if present) or set a maximum amount if no * value is present for {@link #maxPacketAmount}. This is because an F08 error fundamentally means the ILPv4 packet is * too big (see NOTE below). In order to do this, this function will first look into the data payload returned by the * Connector in {@link InterledgerRejectPacket#getData()}. If values can be computed from here, they will be. * Otherwise, the new `maxPacketAmount` will simply be half of {@code prepAmount}, or {@link UnsignedLong#ONE}, * whichever is greater.</p> * * <p> * NOTE: This condition is not inherently a STREAM error, but is instead an ILPv4 error. From the ILPv4 RFC, an F08 * error means: "The packet amount is higher than the maximum a connector is willing to forward. Senders MAY send * another packet with a lower amount. Connectors that produce this error SHOULD encode the amount they received and * their maximum in the data to help senders determine how much lower the packet amount should be." Thus, we can check * for an AmountTooLargeErrorData in the reject packet's data. If found, we use it. If not found, we just reduce by * the max packet amount by half of the prepared amount (because this value was too high, triggering the F08). * </p> * * @param prepareAmount An {@link UnsignedLong} representing the amount that was originally prepared to the immediate * peer inside of an {@link InterledgerPreparePacket}. * @param rejectPacket The {@link InterledgerRejectPacket} that was returned from the immediate peer. * * @return An {@link UnsignedLong} representing the new value of {@link #maxPacketAmount}. */ @VisibleForTesting protected UnsignedLong handleF08Rejection( final UnsignedLong prepareAmount, final InterledgerRejectPacket rejectPacket ) { Objects.requireNonNull(prepareAmount, "prepareAmount must not be null"); Objects.requireNonNull(rejectPacket, "rejectPacket must not be null"); // Compute the newMaxPacketAmount UnsignedLong newMaxPacketAmount; if (rejectPacket.getData().length > 0) { try { // Assume there's error data, because their should be. final AmountTooLargeErrorData amountTooLargeErrorData = streamCodecContext.read(AmountTooLargeErrorData.class, new ByteArrayInputStream(rejectPacket.getData())); final BigDecimal prepareAmountAsBigDecimal = new BigDecimal(prepareAmount.bigIntegerValue()); final BigDecimal detailsMaxAmount = new BigDecimal(amountTooLargeErrorData.maximumAmount().bigIntegerValue()); final BigDecimal detailsAmountReceived = new BigDecimal( amountTooLargeErrorData.receivedAmount().bigIntegerValue()); if (detailsAmountReceived.equals(BigDecimal.ZERO)) { newMaxPacketAmount = halvePrepareAmount(prepareAmount); } else { // Prepared 10, but only sent 3, max is 2 // receivedAmount: Local amount received by the connector // maxAmount: Maximum amount (inclusive, denominated in same units as the receivedAmount) the connector // will forward // Equation: new_max_packet_amount = prepare_amount * details.max_amount() / details.amount_received(); final BigDecimal newMaxPacketAmountAsBigDecimal = prepareAmountAsBigDecimal.multiply(detailsMaxAmount).divide(detailsAmountReceived, RoundingMode.FLOOR); newMaxPacketAmount = UnsignedLong.valueOf(newMaxPacketAmountAsBigDecimal.toBigIntegerExact()); } } catch (Exception e) { // log a warning, but otherwise eat this exception. We'll continue on using default reduction values. logger.warn("Unable to decode AmountTooLargeErrorData from F08 Reject packet. Setting newMaxPacketAmount to be " + "half the prepare amount. rejectPacket={} error={}", rejectPacket, e ); newMaxPacketAmount = halvePrepareAmount(prepareAmount); } } else { newMaxPacketAmount = halvePrepareAmount(prepareAmount); logger.warn( "F08 Reject packet had no data payload. Setting newMaxPacketAmount to be {} (half the prepare amount)", newMaxPacketAmount ); } final UnsignedLong newMaxPacketAmountFinal = newMaxPacketAmount; return this.maxPacketAmount // If maxPacketAmount is present, take the lower of it or newMaxPacketAmount .map($ -> StreamUtils.min($, newMaxPacketAmountFinal)) // Otherwise, just use newMaxPacketAmount .orElse(newMaxPacketAmount); }
Example 5
Source File: unsigned_number_serializer.java From bitshares_wallet with MIT License | 4 votes |
@Override public JsonElement serialize(UnsignedLong src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src.bigIntegerValue()); }