当前位置: 首页>>代码示例>>Java>>正文


Java SendRequest.to方法代码示例

本文整理汇总了Java中org.bitcoinj.wallet.SendRequest.to方法的典型用法代码示例。如果您正苦于以下问题:Java SendRequest.to方法的具体用法?Java SendRequest.to怎么用?Java SendRequest.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bitcoinj.wallet.SendRequest的用法示例。


在下文中一共展示了SendRequest.to方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.bitcoinj.wallet.SendRequest; //导入方法依赖的package包/类
/**
 *
 * @param callbacks
 */
@Override
public void execute(final CoinActionCallback<CurrencyCoin>... callbacks) {
    this._callbacks = callbacks;
    this._bitcoin.getWalletManager().wallet().addCoinsSentEventListener(this);

    Coin balance = _bitcoin.getWalletManager().wallet().getBalance();
    Coin amountCoin = Coin.parseCoin(_amount);

    Address addr = Address.fromBase58(_bitcoin.getWalletManager().wallet().getParams(), _address);
    SendRequest sendRequest = SendRequest.to(addr, amountCoin);

    Coin feeCoin = BitcoinManager.CalculateFeeTxSizeBytes(sendRequest.tx, sendRequest.feePerKb.getValue());

    long balValue = balance.getValue();
    long amountValue = amountCoin.getValue();
    long txFeeValue = feeCoin.getValue();

    if (amountValue + txFeeValue > balValue) {
        amountCoin = Coin.valueOf(balValue - txFeeValue);
        sendRequest = SendRequest.to(addr, amountCoin);
    }

    try {
        _bitcoin.getWalletManager().wallet().sendCoins(sendRequest);
    } catch (InsufficientMoneyException e) {

        for (CoinActionCallback<CurrencyCoin> callback : _callbacks) {
            callback.onError(_bitcoin);
        }
        e.printStackTrace();
    }
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:37,代码来源:BitcoinSendAction.java

示例2: sendBitcoin

import org.bitcoinj.wallet.SendRequest; //导入方法依赖的package包/类
/** Sends Bitcoin to the specified bitcoin address.
 * @author Francis Fasola
 * @param address String representation of the public address.
 * @param amount The amount of Bitcoin to send.
 * @throws InsufficientMoneyException Not enough money.
 * @throws ExecutionException Error during execution.
 * @throws InterruptedException Error during execution. */
@SuppressWarnings("deprecation")
public void sendBitcoin(String address, String amount) 
			throws InsufficientMoneyException, ExecutionException, InterruptedException {
	Address destinationAddress = Address.fromBase58(params, address);
	SendRequest request = SendRequest.to(destinationAddress, Coin.parseCoin(amount));
	SendResult result = wallet.sendCoins(request);
	result.broadcastComplete.addListener(() -> {
		System.out.println("Coins were sent. Transaction hash: " + result.tx.getHashAsString());
	}, MoreExecutors.sameThreadExecutor());
}
 
开发者ID:FrankieF,项目名称:FJSTSeniorProjectSpring2017,代码行数:18,代码来源:WalletController.java

示例3: applyTxFee

import org.bitcoinj.wallet.SendRequest; //导入方法依赖的package包/类
/**
 *
 * @param valueMessage
 * @return
 */
@Override
public SpentValueMessage applyTxFee(SpentValueMessage valueMessage) {
    Coin amountCoin = Coin.parseCoin(valueMessage.getAmount());
    Address addr = Address.fromBase58(_coin.getWalletManager().wallet().getParams(), valueMessage.getAddress());
    SendRequest sendRequest = SendRequest.to(addr, amountCoin);

    Coin txValue = CalculateFeeTxSizeBytes(sendRequest.tx, sendRequest.feePerKb.getValue());
    valueMessage.setTxFee(txValue.toPlainString());

    String amountStr = amountCoin.toPlainString();
    valueMessage.setAmount(amountStr);

    return valueMessage;
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:20,代码来源:BitcoinManager.java

示例4: payOutVirtualBalance

import org.bitcoinj.wallet.SendRequest; //导入方法依赖的package包/类
@Transactional(isolation = Isolation.SERIALIZABLE)
public PayoutResponse payOutVirtualBalance(ECKey accountOwner, String addressAsString) throws UserNotFoundException,
	InsufficientMoneyException, IOException, BusinessException, InsufficientFunds {
	final Address toAddress = Address.fromBase58(appConfig.getNetworkParameters(), addressAsString);

	final Account account = accountService.getByClientPublicKey(accountOwner.getPubKey());
	if (account == null)
		throw new UserNotFoundException(accountOwner.getPublicKeyAsHex());

	final Coin virtualBalance = Coin.valueOf(account.virtualBalance());
	if (!virtualBalance.isPositive())
		throw new InsufficientFunds();

	final Coin potValue = getMicroPaymentPotValue();
	LOG.info("Micropot value is {}", potValue);
	if (potValue.isLessThan(virtualBalance)) {
		eventService.warn(MICRO_PAYMENT_POT_EXHAUSTED, "Not enough coin in pot. " + virtualBalance + " needed " +
		"but only " + potValue + " available.");
		return new PayoutResponse();
	}

	Address changeAddress = appConfig.getMicroPaymentPotPrivKey().toAddress(appConfig.getNetworkParameters());

	// Estimate fee by creating a send request
	final Coin feePer1000Bytes = Coin.valueOf(feeService.fee() * 1000);
	SendRequest estimateRequest = SendRequest.to(toAddress, virtualBalance);
	estimateRequest.feePerKb = feePer1000Bytes;
	estimateRequest.changeAddress = changeAddress;
	walletService.getWallet().completeTx(estimateRequest);
	final Coin requiredFee = estimateRequest.tx.getFee();

	// Make actual request which subtracts fee from virtual balance
	final Coin coinSendToUser = virtualBalance.minus(requiredFee);
	SendRequest actualRequest = SendRequest.to(toAddress, coinSendToUser);
	actualRequest.feePerKb = feePer1000Bytes;
	actualRequest.changeAddress = changeAddress;
	Wallet.SendResult sendResult =  walletService.getWallet().sendCoins(actualRequest);

	// At this point we must consider the coins to be gone, even in case of failure as it has been transmitted
	// to the broadcaster.
	account.virtualBalance(0L);
	accountRepository.save(account);

	// Wait for actual broadcast to succeed
	Transaction broadcastedTx;
	try {
		broadcastedTx = sendResult.broadcastComplete.get();
	} catch (InterruptedException | ExecutionException e) {
		eventService.error(EventType.MICRO_PAYMENT_PAYOUT_ERROR, "Could not broadcast payout request "
			+ "for account " + accountOwner.getPublicKeyAsHex() + ". Transaction: "
			+ DTOUtils.toHex(sendResult.tx.bitcoinSerialize()) + " Reason:" + e.toString());
		e.printStackTrace();
		return new PayoutResponse();
	}

	PayoutResponse response = new PayoutResponse();
	response.transaction = DTOUtils.toHex(broadcastedTx.bitcoinSerialize());
	response.valuePaidOut = coinSendToUser.getValue();
	return response;
}
 
开发者ID:coinblesk,项目名称:coinblesk-server,代码行数:61,代码来源:MicropaymentService.java


注:本文中的org.bitcoinj.wallet.SendRequest.to方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。