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);
}
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();
}
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();
}
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;
}
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()));
}
Aggregations