/** * @param coin The Bitcoin amount * @param exchangeRate The exchange rate in terms of the local currency (e.g. "1000" means 1000 local = 1 bitcoin) * * @return The plain amount in the local currency */ public static BigDecimal toLocalAmount(Coin coin, BigDecimal exchangeRate) { Preconditions.checkNotNull(coin, "'coin' must be present"); Preconditions.checkNotNull(exchangeRate, "'exchangeRate' must be present"); // Convert coins to bitcoins BigDecimal bitcoins = BigDecimal.valueOf(coin.longValue()).divide(BTC_COIN, LOCAL_SCALE, RoundingMode.HALF_EVEN); return exchangeRate.multiply(bitcoins); }
int minimumPosition = (int) FeeService.MINIMUM_FEE_PER_KB.longValue()/RESOLUTION; int defaultPosition = (int)FeeService.DEFAULT_FEE_PER_KB.longValue()/RESOLUTION; int maximumPosition = (int)FeeService.MAXIMUM_FEE_PER_KB.longValue()/RESOLUTION; int currentPosition = (int)FeeService.normaliseRawFeePerKB(initialPosition).longValue()/RESOLUTION; JSlider feePerKBSlider = new JSlider(minimumPosition, maximumPosition, currentPosition);
public ScriptRunner() throws ScriptException { NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); engine = factory.getScriptEngine("-scripting"); BitcoinExtendedClient client = new BitcoinExtendedClient(RegTestParams.get(), RpcURI.getDefaultRegTestURI(), TestServers.getInstance().getRpcTestUser(), TestServers.getInstance().getRpcTestPassword()); RegTestEnvironment env = new RegTestEnvironment(client); RegTestFundingSource funder = new RegTestFundingSource(client); engine.put("client", client); engine.put("env", env); engine.put("funder", funder); engine.put("satoshi", (Function<Number, Coin>) (satoshis) -> Coin.valueOf(satoshis.longValue())); engine.put("btc", (Function<Number, Coin>) (btc) -> Coin.valueOf(btc.longValue() * Coin.COIN.longValue())); engine.put("coin", (BiFunction<Number, Number, Coin>) (btc, cents) -> Coin.valueOf(btc.intValue(), cents.intValue())); engine.put("getBlockCount", (Supplier<Integer>)() -> { try { return client.getBlockCount(); } catch (Exception e) { log.error("Exception: {}", e); throw new RuntimeException(e); } }); }
@Override public void initialiseContent(JPanel contentPanel) { contentPanel.setLayout( new MigLayout( Panels.migXYLayout(), "[]20[]", // Column constraints "[]1[]30[][]" // Row constraints )); WalletConfiguration walletConfiguration = Configurations.currentConfiguration.getWallet().deepCopy(); long feePerKB = walletConfiguration.getFeePerKB(); // Ensure the feePerKB is within the allowable range, updating the local walletConfiguration Coin normalisedFeePerKB = FeeService.normaliseRawFeePerKB(feePerKB); walletConfiguration.setFeePerKB(normalisedFeePerKB.getValue()); feePerKBSlider = Sliders.newAdjustTransactionFeeSlider(this, normalisedFeePerKB.longValue()); transactionFeeDisplayAmountMaV = Components.newDisplayAmountMaV( DisplayAmountStyle.PLAIN, false, "transaction.fee.amount"); JPanel transactionFeeAmountViewPanel = transactionFeeDisplayAmountMaV.getView().newComponentPanel(); transactionFeeDisplayAmountMaV.getView().setVisible(true); transactionFeeDisplayAmountMaV.getModel().setLocalAmountVisible(false); contentPanel.add(Labels.newExplainTransactionFee1(), "span 2, wrap"); contentPanel.add(Labels.newExplainTransactionFee2(), "span 2, wrap"); contentPanel.add(Labels.newAdjustTransactionFee(), "shrink"); contentPanel.add(feePerKBSlider, "growx,shrinky,width min:250:,wrap"); contentPanel.add(Labels.newLabel(MessageKey.TRANSACTION_FEE_CHOSEN), "shrink"); contentPanel.add(transactionFeeAmountViewPanel, "growx,shrinky,push,wrap"); contentPanel.add(Labels.newBlankLabel(), "span 2, push, wrap"); // spacer setChosenFee(Coin.valueOf(walletConfiguration.getFeePerKB())); }
paymentRequestBuilder.setAddress(MBHDPaymentRequestData.getAddress() == null ? "" : MBHDPaymentRequestData.getAddress().toString()); paymentRequestBuilder.setNote(MBHDPaymentRequestData.getNote() == null ? "" : MBHDPaymentRequestData.getNote()); paymentRequestBuilder.setAmountBTC(MBHDPaymentRequestData.getAmountCoin() == null || !MBHDPaymentRequestData.getAmountCoin().isPresent() ? 0 : MBHDPaymentRequestData.getAmountCoin().get().longValue());
@Test public void makeTransaction() throws Exception { /* 8 available Payment. [80200,70000,60000,50000,40000,30000,20000,10000] */ UnspentOutputs unspentOutputs = new UnspentOutputs().fromJson(UnspentTestData.apiResponseString); Payment payment = new Payment(); long spendAmount = 80200L + 70000L + 60000L + 50000L + 40000L + 30000L + 20000L + 10000L - Payment.DUST.longValue(); int inputs = 8;//coins int outputs = 1;//no change long feeManual = calculateFee(outputs, inputs, BigInteger.valueOf(30000L)); SpendableUnspentOutputs paymentBundle = payment .getSpendableCoins(unspentOutputs, BigInteger.valueOf(spendAmount - feeManual), BigInteger.valueOf(30000L)); List<ECKey> keys = new ArrayList<>(); String toAddress = "1GYkgRtJmEp355xUtVFfHSFjFdbqjiwKmb"; String changeAddress = "1GiEQZt9aX2XfDcj14tCC4xAWEJtq9EXW7"; BigInteger bigIntFee = BigInteger.ZERO; BigInteger bigIntAmount = BigInteger.valueOf( Coin.parseCoin("0.0001").longValue()); final HashMap<String, BigInteger> receivers = new HashMap<String, BigInteger>(); receivers.put(toAddress, bigIntAmount); Transaction tx = payment.makeTransaction( paymentBundle.getSpendableOutputs(), receivers, bigIntFee, changeAddress); assertEquals("5ee5cb75b364c13fc3c6457be1fd90f58f0b7b2e4f37fcfbd652b90669686420", tx.getHash().toString()); }
paymentRequestBuilder.setHash(paymentRequestData.getTransactionHash().isPresent() ? paymentRequestData.getTransactionHash().get().toString() : ""); paymentRequestBuilder.setNote(paymentRequestData.getNote() == null ? "" : paymentRequestData.getNote()); paymentRequestBuilder.setAmountBTC(paymentRequestData.getAmountCoin() == null || !paymentRequestData.getAmountCoin().isPresent() ? 0 : paymentRequestData.getAmountCoin().or(Coin.ZERO).longValue()); paymentRequestBuilder.setIdentityDisplayName(paymentRequestData.getIdentityDisplayName() == null ? "" : paymentRequestData.getIdentityDisplayName()); paymentRequestBuilder.setTrustErrorMessage(paymentRequestData.getTrustErrorMessage() == null ? "" : paymentRequestData.getTrustErrorMessage());