Search in sources :

Example 56 with Coin

use of org.bitcoinj.core.Coin in project bitcoin-wallet by bitcoin-wallet.

the class BlockListAdapter method bindView.

public void bindView(final View row, final Transaction tx) {
    final boolean isCoinBase = tx.isCoinBase();
    final boolean isInternal = tx.getPurpose() == Purpose.KEY_ROTATION;
    final Coin value = tx.getValue(wallet);
    final boolean sent = value.signum() < 0;
    final boolean self = WalletUtils.isEntirelySelf(tx, wallet);
    final Address address;
    if (sent)
        address = WalletUtils.getToAddressOfSent(tx, wallet);
    else
        address = WalletUtils.getWalletAddressOfReceived(tx, wallet);
    // receiving or sending
    final TextView rowFromTo = (TextView) row.findViewById(R.id.block_row_transaction_fromto);
    if (isInternal || self)
        rowFromTo.setText(R.string.symbol_internal);
    else if (sent)
        rowFromTo.setText(R.string.symbol_to);
    else
        rowFromTo.setText(R.string.symbol_from);
    // address
    final TextView rowAddress = (TextView) row.findViewById(R.id.block_row_transaction_address);
    final String label;
    if (isCoinBase)
        label = textCoinBase;
    else if (isInternal || self)
        label = textInternal;
    else if (address != null)
        label = AddressBookProvider.resolveLabel(context, address.toBase58());
    else
        label = "?";
    rowAddress.setText(label != null ? label : address.toBase58());
    rowAddress.setTypeface(label != null ? Typeface.DEFAULT : Typeface.MONOSPACE);
    // value
    final CurrencyTextView rowValue = (CurrencyTextView) row.findViewById(R.id.block_row_transaction_value);
    rowValue.setAlwaysSigned(true);
    rowValue.setFormat(format);
    rowValue.setAmount(value);
}
Also used : Coin(org.bitcoinj.core.Coin) Address(org.bitcoinj.core.Address) TextView(android.widget.TextView)

Example 57 with Coin

use of org.bitcoinj.core.Coin in project bitcoin-wallet by bitcoin-wallet.

the class RequestCoinsFragment method determineBitcoinRequestStr.

private String determineBitcoinRequestStr(final boolean includeBluetoothMac) {
    final Coin amount = amountCalculatorLink.getAmount();
    final String ownName = config.getOwnName();
    final StringBuilder uri = new StringBuilder(BitcoinURI.convertToBitcoinURI(address, amount, ownName, null));
    if (includeBluetoothMac && bluetoothMac != null) {
        uri.append(amount == null && ownName == null ? '?' : '&');
        uri.append(Bluetooth.MAC_URI_PARAM).append('=').append(bluetoothMac);
    }
    return uri.toString();
}
Also used : Coin(org.bitcoinj.core.Coin) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 58 with Coin

use of org.bitcoinj.core.Coin in project bitcoin-wallet by bitcoin-wallet.

the class RequestCoinsFragment method determinePaymentRequest.

private byte[] determinePaymentRequest(final boolean includeBluetoothMac) {
    final Coin amount = amountCalculatorLink.getAmount();
    final String paymentUrl = includeBluetoothMac && bluetoothMac != null ? "bt:" + bluetoothMac : null;
    return PaymentProtocol.createPaymentRequest(Constants.NETWORK_PARAMETERS, amount, address, config.getOwnName(), paymentUrl, null).build().toByteArray();
}
Also used : Coin(org.bitcoinj.core.Coin)

Example 59 with Coin

use of org.bitcoinj.core.Coin in project bisq-api by mrosseel.

the class BisqProxy method offerTake.

// / START TODO REFACTOR OFFER TAKE DEPENDENCIES //////////////////////////
public CompletableFuture<Trade> offerTake(String offerId, String paymentAccountId, String amount, boolean useSavingsWallet) {
    final CompletableFuture<Trade> futureResult = new CompletableFuture<>();
    final Offer offer;
    try {
        offer = getOffer(offerId);
    } catch (NotFoundException e) {
        return failFuture(futureResult, e);
    }
    // check the paymentAccountId is valid
    final PaymentAccount paymentAccount = getPaymentAccount(paymentAccountId);
    if (paymentAccount == null) {
        return failFuture(futureResult, new PaymentAccountNotFoundException("Could not find payment account with id: " + paymentAccountId));
    }
    // check the paymentAccountId is compatible with the offer
    if (!isPaymentAccountValidForOffer(offer, paymentAccount)) {
        final String errorMessage = "PaymentAccount is not valid for offer, needs " + offer.getCurrencyCode();
        return failFuture(futureResult, new IncompatiblePaymentAccountException(errorMessage));
    }
    // check the amount is within the range
    Coin coinAmount = Coin.valueOf(Long.valueOf(amount));
    // workaround because TradeTask does not have an error handler to notify us that something went wrong
    if (btcWalletService.getAvailableBalance().isLessThan(coinAmount)) {
        final String errorMessage = "Available balance " + btcWalletService.getAvailableBalance() + " is less than needed amount: " + coinAmount;
        return failFuture(futureResult, new InsufficientMoneyException(errorMessage));
    }
    // check that the price is correct ??
    // check taker fee
    // check security deposit for BTC buyer
    // check security deposit for BTC seller
    Coin securityDeposit = offer.getDirection() == OfferPayload.Direction.SELL ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit();
    Coin txFeeFromFeeService = feeService.getTxFee(600);
    Coin fundsNeededForTradeTemp = securityDeposit.add(txFeeFromFeeService).add(txFeeFromFeeService);
    final Coin fundsNeededForTrade;
    if (offer.isBuyOffer())
        fundsNeededForTrade = fundsNeededForTradeTemp.add(coinAmount);
    else
        fundsNeededForTrade = fundsNeededForTradeTemp;
    Coin takerFee = getTakerFee(coinAmount);
    checkNotNull(txFeeFromFeeService, "txFeeFromFeeService must not be null");
    checkNotNull(takerFee, "takerFee must not be null");
    tradeManager.onTakeOffer(coinAmount, txFeeFromFeeService, takerFee, isCurrencyForTakerFeeBtc(coinAmount), offer.getPrice().getValue(), fundsNeededForTrade, offer, paymentAccount.getId(), useSavingsWallet, futureResult::complete, error -> futureResult.completeExceptionally(new RuntimeException(error)));
    return futureResult;
}
Also used : PaymentAccount(io.bisq.core.payment.PaymentAccount) SellerAsMakerTrade(io.bisq.core.trade.SellerAsMakerTrade) Trade(io.bisq.core.trade.Trade) BuyerAsMakerTrade(io.bisq.core.trade.BuyerAsMakerTrade) Coin(org.bitcoinj.core.Coin) CompletableFuture(java.util.concurrent.CompletableFuture) PaymentAccountUtil.isPaymentAccountValidForOffer(io.bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer)

Example 60 with Coin

use of org.bitcoinj.core.Coin in project bisq-api by mrosseel.

the class BisqProxy method getWalletDetails.

public BisqProxyResult<WalletDetails> getWalletDetails() {
    if (!btcWalletService.isWalletReady()) {
        return BisqProxyResult.createSimpleError("Wallet is not ready");
    }
    Coin availableBalance = btcWalletService.getAvailableBalance();
    Coin reservedBalance = updateReservedBalance();
    Coin lockedBalance = updateLockedBalance();
    return new BisqProxyResult<>(new WalletDetails(availableBalance.toPlainString(), reservedBalance.toPlainString(), lockedBalance.toPlainString()));
}
Also used : Coin(org.bitcoinj.core.Coin)

Aggregations

Coin (org.bitcoinj.core.Coin)64 Transaction (org.bitcoinj.core.Transaction)16 AddressEntry (io.bitsquare.btc.AddressEntry)13 WalletService (io.bitsquare.btc.WalletService)13 Address (org.bitcoinj.core.Address)10 Popup (io.bitsquare.gui.main.overlays.popups.Popup)8 Inject (com.google.inject.Inject)7 Nullable (javax.annotation.Nullable)7 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)6 Collectors (java.util.stream.Collectors)6 FXCollections (javafx.collections.FXCollections)6 ListChangeListener (javafx.collections.ListChangeListener)6 ObservableList (javafx.collections.ObservableList)6 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 Offer (io.bitsquare.trade.offer.Offer)5 AddressEntry (io.bisq.core.btc.AddressEntry)4 Trade (io.bisq.core.trade.Trade)4 UserThread (io.bitsquare.common.UserThread)4 PaymentAccountUtil.isPaymentAccountValidForOffer (io.bisq.core.payment.PaymentAccountUtil.isPaymentAccountValidForOffer)3 DevFlags (io.bitsquare.app.DevFlags)3