本文整理汇总了Java中org.bitcoinj.wallet.SendRequest类的典型用法代码示例。如果您正苦于以下问题:Java SendRequest类的具体用法?Java SendRequest怎么用?Java SendRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendRequest类属于org.bitcoinj.wallet包,在下文中一共展示了SendRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testMultiSigOutputToString
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
@Test
public void testMultiSigOutputToString() throws Exception {
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN);
ECKey myKey = new ECKey();
this.wallet.importKey(myKey);
// Simulate another signatory
ECKey otherKey = new ECKey();
// Create multi-sig transaction
Transaction multiSigTransaction = new Transaction(PARAMS);
ImmutableList<ECKey> keys = ImmutableList.of(myKey, otherKey);
Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys);
multiSigTransaction.addOutput(Coin.COIN, scriptPubKey);
SendRequest req = SendRequest.forTx(multiSigTransaction);
this.wallet.completeTx(req);
TransactionOutput multiSigTransactionOutput = multiSigTransaction.getOutput(0);
assertThat(multiSigTransactionOutput.toString(), CoreMatchers.containsString("CHECKMULTISIG"));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:23,代码来源:TransactionOutputTest.java
示例3: testStandardWalletDisconnect
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
@Test
public void testStandardWalletDisconnect() throws Exception {
NetworkParameters params = UnitTestParams.get();
Wallet w = new Wallet(new Context(params));
w.setCoinSelector(new AllowUnconfirmedCoinSelector());
Address a = w.currentReceiveAddress();
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(params, Coin.COIN, a);
w.receivePending(tx1, null);
Transaction tx2 = new Transaction(params);
tx2.addOutput(Coin.valueOf(99000000), new ECKey());
w.completeTx(SendRequest.forTx(tx2));
TransactionInput txInToDisconnect = tx2.getInput(0);
assertEquals(tx1, txInToDisconnect.getOutpoint().fromTx);
assertNull(txInToDisconnect.getOutpoint().connectedOutput);
txInToDisconnect.disconnect();
assertNull(txInToDisconnect.getOutpoint().fromTx);
assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:23,代码来源:TransactionInputTest.java
示例4: _generateCoupons
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
private ArrayList<ECKey> _generateCoupons(int number, Coin value) throws InsufficientMoneyException {
SendRequest sr;
Transaction tx = new Transaction(params);
ArrayList<ECKey> coupons = new ArrayList<>();
for (int i = 0; i < number; i++) {
ECKey ek = couponWallet.freshReceiveKey();
coupons.add(ek);
tx.addOutput(value, ek.toAddress(params));
System.out.printf("Address / Key: %s / %s\n", ek.toAddress(params), ek.getPrivateKeyAsWiF(params));
}
sr = SendRequest.forTx(tx);
sr.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
feedWallet.completeTx(sr);
try {
feedWallet.commitTx(sr.tx);
peerGroup.broadcastTransaction(sr.tx).broadcast().get();
} catch (Exception e) {
e.printStackTrace();
}
return coupons;
}
开发者ID:IUNO-TDM,项目名称:CouponGenerator,代码行数:25,代码来源:CouponWallet.java
示例5: getPreparedSendTx
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
public Transaction getPreparedSendTx(String receiverAddress,
Coin receiverAmount) throws AddressFormatException,
InsufficientMoneyException, WalletException, TransactionVerificationException {
Transaction tx = new Transaction(params);
checkArgument(Restrictions.isAboveDust(receiverAmount),
"The amount is too low (dust limit).");
tx.addOutput(receiverAmount, Address.fromBase58(params, receiverAddress));
SendRequest sendRequest = SendRequest.forTx(tx);
sendRequest.fee = Coin.ZERO;
sendRequest.feePerKb = Coin.ZERO;
sendRequest.ensureMinRequiredFee = false;
sendRequest.aesKey = aesKey;
sendRequest.shuffleOutputs = false;
sendRequest.signInputs = false;
sendRequest.ensureMinRequiredFee = false;
sendRequest.changeAddress = getUnusedAddress();
wallet.completeTx(sendRequest);
checkWalletConsistency(wallet);
verifyTransaction(tx);
// printTx("prepareSendTx", tx);
return tx;
}
开发者ID:bisq-network,项目名称:exchange,代码行数:25,代码来源:BsqWalletService.java
示例6: sendFundsForMultipleAddresses
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
public String sendFundsForMultipleAddresses(Set<String> fromAddresses,
String toAddress,
Coin receiverAmount,
Coin fee,
@Nullable String changeAddress,
@Nullable KeyParameter aesKey,
FutureCallback<Transaction> callback) throws AddressFormatException,
AddressEntryException, InsufficientMoneyException {
SendRequest request = getSendRequestForMultipleAddresses(fromAddresses, toAddress, receiverAmount, fee, changeAddress, aesKey);
Wallet.SendResult sendResult = wallet.sendCoins(request);
Futures.addCallback(sendResult.broadcastComplete, callback);
printTx("sendFunds", sendResult.tx);
return sendResult.tx.getHashAsString();
}
开发者ID:bisq-network,项目名称:exchange,代码行数:17,代码来源:BtcWalletService.java
示例7: 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
示例8: onCoinsReceived
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
logger.info("Received tx with " + tx.getValueSentToMe(wallet).toFriendlyString() + ": " + tx);
// create a hashmap with addresses and the sum of all coins send to each one
HashMap<Address, Coin> addressCoinHashMap = new HashMap<>();
for (TransactionOutput txout : tx.getOutputs()) {
Address addr = txout.getAddressFromP2PKHScript(context.getParams());
if(addr == null) addr = txout.getAddressFromP2SH(context.getParams());
Coin value = txout.getValue();
if (null != addr) {
if (! addressCoinHashMap.containsKey(addr)) {
addressCoinHashMap.put(addr, value);
} else {
addressCoinHashMap.put(addr, addressCoinHashMap.get(addr).add(value));
}
}
}
for (BitcoinInvoice bcInvoice : invoiceHashMap.values()) {
bcInvoice.sortOutputsToAddresses(tx, addressCoinHashMap);
SendRequest sr = bcInvoice.tryFinishInvoice(wallet);
if (null != sr)
syncBroadcastTransaction(sr.tx);
}
logger.info("Balance: " + wallet.getBalance().toFriendlyString());
}
开发者ID:IUNO-TDM,项目名称:PaymentService,代码行数:30,代码来源:Bitcoin.java
示例9: onWalletChanged
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
@Override
public void onWalletChanged(Wallet wallet) {
for (UUID uuid: invoiceHashMap.keySet()) {
SendRequest sr = invoiceHashMap.get(uuid).tryFinishInvoice(wallet);
if (null != sr)
syncBroadcastTransaction(sr.tx);
}
// cleanup expired transactions
if (lastCleanup.plusMinutes(CLEANUPINTERVAL).isBeforeNow()) {
cleanUpInvoices();
}
}
开发者ID:IUNO-TDM,项目名称:PaymentService,代码行数:14,代码来源:Bitcoin.java
示例10: 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
示例11: getSendRequest
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
/**
* Returns a {@link SendRequest} suitable for broadcasting to the network.
*/
public SendRequest getSendRequest() {
Transaction tx = new Transaction(params);
for (Protos.Output output : paymentDetails.getOutputsList())
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(output.getAmount()), output.getScript().toByteArray()));
return SendRequest.forTx(tx).fromPaymentDetails(paymentDetails);
}
开发者ID:guodroid,项目名称:okwallet,代码行数:10,代码来源:PaymentSession.java
示例12: makeUnsignedChannelContract
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
protected synchronized SendRequest makeUnsignedChannelContract(Coin valueToMe) {
Transaction tx = new Transaction(wallet.getParams());
if (!getTotalValue().subtract(valueToMe).equals(Coin.ZERO)) {
tx.addOutput(getTotalValue().subtract(valueToMe), getClientKey().toAddress(wallet.getParams()));
}
tx.addInput(contract.getOutput(0));
return SendRequest.forTx(tx);
}
开发者ID:guodroid,项目名称:okwallet,代码行数:9,代码来源:PaymentChannelServerState.java
示例13: doRaiseFee
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
private void doRaiseFee(final KeyParameter encryptionKey) {
// construct child-pays-for-parent
final TransactionOutput outputToSpend = checkNotNull(findSpendableOutput(wallet, transaction, feeRaise));
final Transaction transactionToSend = new Transaction(Constants.NETWORK_PARAMETERS);
transactionToSend.addInput(outputToSpend);
transactionToSend.addOutput(outputToSpend.getValue().subtract(feeRaise),
wallet.freshAddress(KeyPurpose.CHANGE));
transactionToSend.setPurpose(Transaction.Purpose.RAISE_FEE);
final SendRequest sendRequest = SendRequest.forTx(transactionToSend);
sendRequest.aesKey = encryptionKey;
try {
wallet.signTransaction(sendRequest);
log.info("raise fee: cpfp {}", transactionToSend);
wallet.commitTx(transactionToSend);
application.broadcastTransaction(transactionToSend);
state = State.DONE;
updateView();
dismiss();
} catch (final KeyCrypterException x) {
badPasswordView.setVisibility(View.VISIBLE);
state = State.INPUT;
updateView();
passwordView.requestFocus();
log.info("raise fee: bad spending password");
}
}
开发者ID:guodroid,项目名称:okwallet,代码行数:36,代码来源:RaiseFeeDialogFragment.java
示例14: testUTXOWalletDisconnect
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
@Test
public void testUTXOWalletDisconnect() throws Exception {
final NetworkParameters params = UnitTestParams.get();
Wallet w = new Wallet(new Context(params));
Address a = w.currentReceiveAddress();
final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
ScriptBuilder.createOutputScript(a));
w.setUTXOProvider(new UTXOProvider() {
@Override
public NetworkParameters getParams() {
return params;
}
@Override
public List<UTXO> getOpenTransactionOutputs(List<Address> addresses) throws UTXOProviderException {
return Lists.newArrayList(utxo);
}
@Override
public int getChainHeadHeight() throws UTXOProviderException {
return Integer.MAX_VALUE;
}
});
Transaction tx2 = new Transaction(params);
tx2.addOutput(Coin.valueOf(99000000), new ECKey());
w.completeTx(SendRequest.forTx(tx2));
TransactionInput txInToDisconnect = tx2.getInput(0);
assertNull(txInToDisconnect.getOutpoint().fromTx);
assertEquals(utxo.getHash(), txInToDisconnect.getOutpoint().connectedOutput.getParentTransactionHash());
txInToDisconnect.disconnect();
assertNull(txInToDisconnect.getOutpoint().fromTx);
assertNull(txInToDisconnect.getOutpoint().connectedOutput);
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:39,代码来源:TransactionInputTest.java
示例15: sweepCoupons
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
public void sweepCoupons() throws InsufficientMoneyException {
downloadBlockChain(); // essential here since coupons can be spent anytime
SendRequest sr = SendRequest.emptyWallet(feedWallet.currentChangeAddress());
sr.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
couponWallet.completeTx(sr);
try {
couponWallet.commitTx(sr.tx);
peerGroup.broadcastTransaction(sr.tx).broadcast().get();
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:IUNO-TDM,项目名称:CouponGenerator,代码行数:13,代码来源:CouponWallet.java
示例16: sweepUtxo
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
private String sweepUtxo(Map<Sha256Hash, Transaction> transactions) {
final KeyChainGroup group = new KeyChainGroup(param);
String ret = "";
group.importKeys(ecKey);
Wallet walletToSweep = new Wallet(param, group);
walletToSweep.clearTransactions(0);
for (final Transaction tx : transactions.values())
walletToSweep.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.UNSPENT, tx));
Coin dust = Transaction.MIN_NONDUST_OUTPUT;
Coin balance = walletToSweep.getBalance();
if (dust.isLessThan(balance.multiply(2))) {
SendRequest sr = SendRequest.emptyWallet(Address.fromBase58(param, "mzM2i82Y9e4ZDwQVWqY4HcJbuAHYQdXd7A"));
sr.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE;
try {
final Transaction transaction;
transaction = walletToSweep.sendCoinsOffline(sr);
ret = BaseEncoding.base16().lowerCase().encode(transaction.bitcoinSerialize());
} catch (InsufficientMoneyException e) {
e.printStackTrace();
}
} else {
System.out.println("Too few coins in wallet: " + walletToSweep.getBalance().toFriendlyString());
}
return ret;
}
开发者ID:IUNO-TDM,项目名称:CouponGenerator,代码行数:29,代码来源:CouponRedemption.java
示例17: getSendRequest
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
/**
* Returns a {@link Wallet.SendRequest} suitable for broadcasting to the network.
*/
public SendRequest getSendRequest() {
Transaction tx = new Transaction(params);
for (Protos.Output output : paymentDetails.getOutputsList())
tx.addOutput(new TransactionOutput(params, tx, Coin.valueOf(output.getAmount()), output.getScript().toByteArray()));
return SendRequest.forTx(tx).fromPaymentDetails(paymentDetails);
}
开发者ID:dogecoin,项目名称:libdohj,代码行数:10,代码来源:PaymentSession.java
示例18: sendFunds
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
public String sendFunds(String fromAddress,
String toAddress,
Coin receiverAmount,
Coin fee,
@Nullable KeyParameter aesKey,
@SuppressWarnings("SameParameterValue") AddressEntry.Context context,
FutureCallback<Transaction> callback) throws AddressFormatException,
AddressEntryException, InsufficientMoneyException {
SendRequest sendRequest = getSendRequest(fromAddress, toAddress, receiverAmount, fee, aesKey, context);
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
printTx("sendFunds", sendResult.tx);
return sendResult.tx.getHashAsString();
}
开发者ID:bisq-network,项目名称:exchange,代码行数:16,代码来源:BtcWalletService.java
示例19: getSendRequest
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
private SendRequest getSendRequest(String fromAddress,
String toAddress,
Coin amount,
Coin fee,
@Nullable KeyParameter aesKey,
AddressEntry.Context context) throws AddressFormatException,
AddressEntryException {
Transaction tx = new Transaction(params);
Preconditions.checkArgument(Restrictions.isAboveDust(amount, fee),
"The amount is too low (dust limit).");
tx.addOutput(amount.subtract(fee), Address.fromBase58(params, toAddress));
SendRequest sendRequest = SendRequest.forTx(tx);
sendRequest.fee = fee;
sendRequest.feePerKb = Coin.ZERO;
sendRequest.ensureMinRequiredFee = false;
sendRequest.aesKey = aesKey;
sendRequest.shuffleOutputs = false;
Optional<AddressEntry> addressEntry = findAddressEntry(fromAddress, context);
if (!addressEntry.isPresent())
throw new AddressEntryException("WithdrawFromAddress is not found in our wallet.");
checkNotNull(addressEntry.get(), "addressEntry.get() must not be null");
checkNotNull(addressEntry.get().getAddress(), "addressEntry.get().getAddress() must not be null");
sendRequest.coinSelector = new BtcCoinSelector(addressEntry.get().getAddress());
sendRequest.changeAddress = addressEntry.get().getAddress();
return sendRequest;
}
开发者ID:bisq-network,项目名称:exchange,代码行数:29,代码来源:BtcWalletService.java
示例20: estimateBtcTradingFeeTxSize
import org.bitcoinj.wallet.SendRequest; //导入依赖的package包/类
public Transaction estimateBtcTradingFeeTxSize(Address fundingAddress,
Address reservedForTradeAddress,
Address changeAddress,
Coin reservedFundsForOffer,
boolean useSavingsWallet,
Coin tradingFee,
Coin txFee,
String feeReceiverAddresses)
throws InsufficientMoneyException, AddressFormatException {
Transaction tradingFeeTx = new Transaction(params);
tradingFeeTx.addOutput(tradingFee, Address.fromBase58(params, feeReceiverAddresses));
tradingFeeTx.addOutput(reservedFundsForOffer, reservedForTradeAddress);
SendRequest sendRequest = SendRequest.forTx(tradingFeeTx);
sendRequest.shuffleOutputs = false;
sendRequest.aesKey = aesKey;
if (useSavingsWallet)
sendRequest.coinSelector = new BtcCoinSelector(walletsSetup.getAddressesByContext(AddressEntry.Context.AVAILABLE));
else
sendRequest.coinSelector = new BtcCoinSelector(fundingAddress);
sendRequest.fee = txFee;
sendRequest.feePerKb = Coin.ZERO;
sendRequest.ensureMinRequiredFee = false;
sendRequest.changeAddress = changeAddress;
checkNotNull(wallet, "Wallet must not be null");
log.info("estimateBtcTradingFeeTxSize");
wallet.completeTx(sendRequest);
return tradingFeeTx;
}
开发者ID:bisq-network,项目名称:exchange,代码行数:31,代码来源:TradeWalletService.java
注:本文中的org.bitcoinj.wallet.SendRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论