本文整理汇总了Java中org.bitcoinj.wallet.WalletTransaction类的典型用法代码示例。如果您正苦于以下问题:Java WalletTransaction类的具体用法?Java WalletTransaction怎么用?Java WalletTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WalletTransaction类属于org.bitcoinj.wallet包,在下文中一共展示了WalletTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: broadcastTransaction
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Override
public boolean broadcastTransaction (Transaction tx) {
broadcastedTransaction.add(tx.getHash());
//TODO not perfect yet - later we can connect multiple MockBlockchainHelper that will propagate tx across each other
for (OnTxCommand onTxCommand : txListener) {
if (onTxCommand.compare(tx)) {
onTxCommand.execute(tx);
}
}
if (wallet != null) {
wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.PENDING, tx));
}
return true;
}
示例2: getMines
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
private List<TransactionOutput> getMines(Address address) {
Map<Sha256Hash, Transaction> unspent = wallet.getTransactionPool(WalletTransaction.Pool.UNSPENT);
List<TransactionOutput> transactionOutputList= new ArrayList<>();
for (Map.Entry<Sha256Hash, Transaction> entry : unspent.entrySet()) {
Transaction current = entry.getValue();
List<TransactionOutput> outputs = current.getOutputs();
for (TransactionOutput o : outputs) {
if(o.isAvailableForSpending()) {
Address a = o.getAddressFromP2PKHScript(PARAMS);
if(address.equals(a)) {
transactionOutputList.add(o);
}
}
}
}
return transactionOutputList;
}
示例3: addWalletTransaction
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Override
public void addWalletTransaction (WalletTransaction wtx) {
wtx.getTransaction().getInputs().stream().forEach(new Consumer<TransactionInput>() {
@Override
public void accept (TransactionInput transactionInput) {
outputs = outputs.stream().filter(new Predicate<TransactionOutput>() {
@Override
public boolean test (TransactionOutput transactionOutput) {
return !transactionInput.getOutpoint().equals(transactionOutput.getOutPointFor());
}
}).collect(Collectors.toList());
}
});
wtx.getTransaction().getOutputs().forEach(transactionOutput ->
{
Address address = transactionOutput.getAddressFromP2PKHScript(Constants.getNetwork());
if (address != null) {
if (keyList.stream().anyMatch(
ecKey -> ecKey.toAddress(Constants.getNetwork()).equals(address))) {
outputs.add(transactionOutput);
}
} else {
}
});
}
示例4: broadcastTransaction
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Override
public boolean broadcastTransaction (Transaction tx) {
System.out.println("Broadcast transaction: ");
System.out.println(tx);
try {
TransactionBroadcast broadcast = peerGroup.broadcastTransaction(tx);
broadcast.future().get(10, TimeUnit.SECONDS);
System.out.println(tx.getHash() + " broadcasted successfully!");
wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.PENDING, tx));
return true;
} catch (Exception e) {
System.out.println("e.getMessage() = " + e.getMessage());
}
return false;
}
示例5: evaluateConfirmedLookAhead
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
private int evaluateConfirmedLookAhead() {
Collection<Transaction> pendingTransactions= couponWallet.getTransactionPool(WalletTransaction.Pool.PENDING).values();
int pendingOutputs = 0;
for (Transaction tx : pendingTransactions) {
System.out.println("pending: " + tx.toString());
pendingOutputs += tx.getOutputs().size(); // likely off by one due to change output
}
int lookAhead = couponWallet.getActiveKeyChain().getLookaheadSize();
System.out.printf("pending outputs / lookAhead: %d / %d\n", pendingOutputs, lookAhead);
return lookAhead - pendingOutputs;
}
示例6: sweepUtxo
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的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;
}
示例7: getExtendedTransactionPool
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Nullable
@Override
public Map<Sha256Hash, Transaction> getExtendedTransactionPool(WalletTransaction.Pool pool) {
checkState(CoreHelper.getWalletLock(wallet).isHeldByCurrentThread());
if (pool == INSTANTX_PENDING) {
return instantXPending;
} else if (pool == INSTANTX_LOCKED) {
return instantXLocked;
} else {
return null;
}
}
示例8: putTransactionIntoPool
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Nullable
@Override
public Transaction putTransactionIntoPool(WalletTransaction.Pool pool, Sha256Hash key, Transaction value) throws IllegalArgumentException {
checkState(CoreHelper.getWalletLock(wallet).isHeldByCurrentThread());
final DashTransactionExtension txExtension = CommonUtils.extractTransactionExtension(value);
final DashTransactionWireStrategy wireStrategy = txExtension.getWireStrategy();
if (wireStrategy == DashTransactionWireStrategy.INSTANT_X_LOCKED || wireStrategy == DashTransactionWireStrategy.INSTANT_X) {
if (InstantXManager.isTransactionExpired(txExtension)) {
logger.warn("Wallet coin specifics transaction pool put with wire strategy {}, but wire lock expired;");
logger.warn("that can happen if we load a wallet from file;");
logger.warn("we'll put it in a wallet as PENDING for now and will wait for discovery of a block which contains it.");
wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.PENDING, value));
return null;
}
if (pool == INSTANTX_PENDING) {
return instantXPending.put(key, value);
} else if (pool == INSTANTX_LOCKED) {
if (instantXPending.remove(key) != null) {
logger.info("<-instantx locked: {}", value.getHashAsString());
}
return instantXLocked.put(key, value);
} else {
throw new IllegalArgumentException("Pool " + pool + " unsupported");
}
} else {
logger.warn("Wallet coin specifics transaction pool put, but transactions wire strategy is " + wireStrategy);
wallet.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.PENDING, value));
return null;
}
}
示例9: addPoolsToSetIfContainKey
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Override
public void addPoolsToSetIfContainKey(Set<WalletTransaction.Pool> set, Sha256Hash key) {
checkState(CoreHelper.getWalletLock(wallet).isHeldByCurrentThread());
if (instantXPending.containsKey(key))
set.add(INSTANTX_PENDING);
if (instantXLocked.containsKey(key))
set.add(INSTANTX_LOCKED);
}
示例10: getPoolSize
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Nullable
@Override
public Integer getPoolSize(WalletTransaction.Pool pool) {
checkState(CoreHelper.getWalletLock(wallet).isHeldByCurrentThread());
if (pool == INSTANTX_PENDING) {
return instantXPending.size();
} else if (pool == INSTANTX_LOCKED) {
return instantXLocked.size();
} else {
return null;
}
}
示例11: commitTxExtendedPool
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Override
@Nullable
public WalletTransaction.Pool commitTxExtendedPool(Transaction tx) {
final TransactionWireStrategy wireStrategy = tx.getTransactionExtension().getWireStrategy();
return wireStrategy == DashTransactionWireStrategy.INSTANT_X
? INSTANTX_PENDING
: wireStrategy == DashTransactionWireStrategy.INSTANT_X_LOCKED ? INSTANTX_LOCKED : null;
}
示例12: getPoolName
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Override
public String getPoolName(WalletTransaction.Pool pool) {
if (pool == INSTANTX_LOCKED)
return "instantx locked";
else if (pool == INSTANTX_PENDING)
return "instantx pending";
return null;
}
示例13: getProtoExtendedPool
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Nullable
@Override
public Protos.Transaction.Pool getProtoExtendedPool(WalletTransaction.Pool pool) {
if (pool == DashWalletCoinSpecifics.INSTANTX_PENDING) {
return Protos.Transaction.Pool.INSTANTX_PENDING;
} else if (pool == DashWalletCoinSpecifics.INSTANTX_LOCKED) {
return Protos.Transaction.Pool.INSTANTX_LOCKED;
} else {
return null;
}
}
示例14: getTxsExtendedPool
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
@Nullable
@Override
public WalletTransaction.Pool getTxsExtendedPool(Protos.Transaction.Pool pool) {
switch (pool) {
case INSTANTX_LOCKED:
return DashWalletCoinSpecifics.INSTANTX_LOCKED;
case INSTANTX_PENDING:
return DashWalletCoinSpecifics.INSTANTX_PENDING;
default:
return null;
}
}
示例15: getProtoPool
import org.bitcoinj.wallet.WalletTransaction; //导入依赖的package包/类
private static Protos.Transaction.Pool getProtoPool(WalletTransaction wtx) {
switch (wtx.getPool()) {
case UNSPENT: return Protos.Transaction.Pool.UNSPENT;
case SPENT: return Protos.Transaction.Pool.SPENT;
case DEAD: return Protos.Transaction.Pool.DEAD;
case PENDING: return Protos.Transaction.Pool.PENDING;
default:
throw new RuntimeException("Unreachable");
}
}