Refine search
private TransactionOutput getOutput(CoinType type, @Nullable Transaction tx, long value, ByteString scriptBytes) { return new TransactionOutput(type, tx, Coin.valueOf(value), scriptBytes.toByteArray()); }
/** * @param plainAmount A String denominated in BTC (e.g. "0.0015") * * @return The satoshi value (e.g. 150 000) */ public static Coin fromPlainAmount(String plainAmount) { Preconditions.checkNotNull(plainAmount, "'plainAmount' must be present"); return Coin.parseCoin(plainAmount); }
/** * Convert an amount expressed in the way humans are used to into satoshis. */ public static Coin valueOf(final int coins, final int cents) { checkArgument(cents < 100); checkArgument(cents >= 0); checkArgument(coins >= 0); final Coin coin = COIN.multiply(coins).add(CENT.multiply(cents)); return coin; }
@SuppressWarnings("FieldAccessNotGuarded") private void checkBalanceFuturesLocked(@Nullable Coin avail) { checkState(lock.isHeldByCurrentThread()); final ListIterator<BalanceFutureRequest> it = balanceFutureRequests.listIterator(); while (it.hasNext()) { final BalanceFutureRequest req = it.next(); Coin val = getBalance(req.type); // This could be slow for lots of futures. if (val.compareTo(req.value) < 0) continue; // Found one that's finished. it.remove(); final Coin v = val; // Don't run any user-provided future listeners with our lock held. Threading.USER_THREAD.execute(new Runnable() { @Override public void run() { req.future.set(v); } }); } }
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) { super(params); // Negative values obviously make no sense, except for -1 which is used as a sentinel value when calculating // SIGHASH_SINGLE signatures, so unfortunately we have to allow that here. checkArgument(value.signum() >= 0 || value.equals(Coin.NEGATIVE_SATOSHI), "Negative values not allowed"); checkArgument(!params.hasMaxMoney() || value.compareTo(params.getMaxMoney()) <= 0, "Values larger than MAX_MONEY not allowed"); this.value = value.value; this.scriptBytes = scriptBytes; setParent(parent); availableForSpending = true; length = 8 + VarInt.sizeOf(scriptBytes.length) + scriptBytes.length; }
/** Returns the outstanding amount of money sent back to us for all channels to this server added together. */ public Coin getBalanceForServer(Sha256Hash id) { Coin balance = Coin.ZERO; lock.lock(); try { Set<StoredClientChannel> setChannels = mapChannels.get(id); for (StoredClientChannel channel : setChannels) { synchronized (channel) { if (channel.close != null) continue; balance = balance.add(channel.valueToMe); } } return balance; } finally { lock.unlock(); } }
@Override public PaymentType getType() { PaymentType type = PaymentType.YOU_REQUESTED; // Work out if it is requested, partly paid or fully paid if (paidAmountCoin != null && amountCoin != null) { if (paidAmountCoin.compareTo(Coin.ZERO) > 0) { // bitcoin has been paid to this payment request if (!amountCoin.isPresent() || paidAmountCoin.compareTo(amountCoin.get()) >= 0) { // fully paid type = PaymentType.PAID; } else { // partly paid type = PaymentType.PART_PAID; } } } return type; }
columns[6] = MBHDPaymentRequestData.getAmountCoin() == null ? "" : MBHDPaymentRequestData.getAmountCoin().toString(); if (MBHDPaymentRequestData.getAmountFiat().getCurrency().isPresent()) { columns[7] = MBHDPaymentRequestData.getAmountFiat().getCurrency().get().getCurrencyCode(); columns[11] = MBHDPaymentRequestData.getPaidAmountCoin() == null ? "" : MBHDPaymentRequestData.getPaidAmountCoin().toString();
private void updateMiningFee(LanguageConfiguration languageConfiguration, BitcoinConfiguration bitcoinConfiguration, Optional<Coin> miningFee, int transactionSize) { if (miningFee.isPresent()) { Coin miningFeeAsCoin = miningFee.get(); String[] minerFeePaidArray = Formats.formatCoinAsSymbolic(miningFeeAsCoin.negate(), languageConfiguration, bitcoinConfiguration, true); miningFeePaidValue.setText(minerFeePaidArray[0] + minerFeePaidArray[1]); // Work out fee rate if (transactionSize > 0) { double feeRate = (double)miningFeeAsCoin.getValue() / transactionSize; miningFeePaidRateValue.setText(feeRateFormat.format(feeRate)); } else { miningFeePaidRateValue.setText(Languages.safeText(MessageKey.NOT_AVAILABLE)); } } else { miningFeePaidValue.setText(Languages.safeText(MessageKey.NOT_AVAILABLE)); miningFeePaidRateValue.setText(Languages.safeText(MessageKey.NOT_AVAILABLE)); } }
/** * @return True if the "next" button should be enabled */ private boolean isNextEnabled() { Optional<Coin> coinAmount = getPanelModel().get() .getEnterAmountModel() .getCoinAmount(); boolean bitcoinAmountOK = coinAmount.isPresent() && !coinAmount.get().equals(Coin.ZERO); boolean recipientOK = getPanelModel().get() .getEnterRecipientModel() .getRecipient() .isPresent(); return bitcoinAmountOK && recipientOK && networkOk; }
/** * Returns the outputs of the payment request. */ public List<PaymentProtocol.Output> getOutputs() { List<PaymentProtocol.Output> outputs = new ArrayList<PaymentProtocol.Output>(paymentDetails.getOutputsCount()); for (Protos.Output output : paymentDetails.getOutputsList()) { Coin amount = output.hasAmount() ? Coin.valueOf(output.getAmount()) : null; outputs.add(new PaymentProtocol.Output(amount, output.getScript().toByteArray())); } return outputs; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MBHDPaymentRequestData that = (MBHDPaymentRequestData) o; if (isGlidera != that.isGlidera) return false; if (address != null ? !address.equals(that.address) : that.address != null) return false; if (amountCoin != null ? !amountCoin.equals(that.amountCoin) : that.amountCoin != null) return false; if (amountFiat != null ? !amountFiat.equals(that.amountFiat) : that.amountFiat != null) return false; if (date != null ? !date.equals(that.date) : that.date != null) return false; if (label != null ? !label.equals(that.label) : that.label != null) return false; if (note != null ? !note.equals(that.note) : that.note != null) return false; if (paidAmountCoin != null ? !paidAmountCoin.equals(that.paidAmountCoin) : that.paidAmountCoin != null) return false; if (!payingTransactionHashes.equals(that.payingTransactionHashes)) { return false; } return true; }
for (TransactionOutput out : tx.getOutputs()) { if (out.isMine(this) == false) { txOutputTotal = txOutputTotal.add(out.getValue()); TransactionOutput prevOut = in.getConnectedOutput(); if (prevOut != null && prevOut.isMine(this)) { txOwnedInputsTotal = txOwnedInputsTotal.add(prevOut.getValue()); BigInteger txOutputTotalNum = new BigInteger(txOutputTotal.toString()); txOutputTotalNum = txOutputTotalNum.multiply(new BigInteger(txOwnedInputsTotal.toString())); txOutputTotalNum = txOutputTotalNum.divide(new BigInteger(txInputsTotal.toString())); txOutputTotal = Coin.valueOf(txOutputTotalNum.longValue()); total = total.add(txOutputTotal);
/** Reduce the value of the first output of a transaction to pay the given feePerKb as appropriate for its size. */ private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin feePerKb, boolean ensureMinRequiredFee) { final int size = tx.unsafeBitcoinSerialize().length + estimateBytesForSigning(coinSelection); Coin fee = feePerKb.multiply(size).divide(1000); if (ensureMinRequiredFee && fee.compareTo(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE) < 0) fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE; TransactionOutput output = tx.getOutput(0); output.setValue(output.getValue().subtract(fee)); return !output.isDust(); }
public TrimmedOutput(NetworkParameters params, long value, Sha256Hash txHash, long index, byte[] scriptBytes) { super(params, null, Coin.valueOf(value), scriptBytes); this.index = index; this.txHash = txHash; }