本文整理汇总了Java中org.bitcoinj.wallet.SendRequest类的典型用法代码示例。如果您正苦于以下问题:Java SendRequest类的具体用法?Java SendRequest怎么用?Java SendRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SendRequest类属于org.bitcoinj.wallet包,在下文中一共展示了SendRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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"));
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
}
示例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);
}
示例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();
}
}