本文整理汇总了Java中org.bitcoinj.wallet.Wallet类的典型用法代码示例。如果您正苦于以下问题:Java Wallet类的具体用法?Java Wallet怎么用?Java Wallet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Wallet类属于org.bitcoinj.wallet包,在下文中一共展示了Wallet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWalletAddressOfReceived
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
@Nullable
public static Address getWalletAddressOfReceived(final Transaction tx, final Wallet wallet) {
for (final TransactionOutput output : tx.getOutputs()) {
try {
if (output.isMine(wallet)) {
final Script script = output.getScriptPubKey();
return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
}
} catch (final ScriptException x) {
// swallow
}
}
return null;
}
示例2: broadcastTransactions
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
/**
* Broadcasts the list of signed transactions.
* @param transactionsRaw transactions in raw byte[] format
*/
public ArrayList<Transaction> broadcastTransactions(ArrayList<byte[]> transactionsRaw) {
ArrayList<Transaction> transactions = new ArrayList<>();
for (byte[] transactionRaw : transactionsRaw) {
final Wallet.SendResult result = new Wallet.SendResult();
result.tx = new Transaction(params, transactionRaw);
result.broadcast = kit.peerGroup().broadcastTransaction(result.tx);
result.broadcastComplete = result.broadcast.future();
result.broadcastComplete.addListener(new Runnable() {
@Override
public void run() {
System.out.println("Asset spent! txid: " + result.tx.getHashAsString());
}
}, MoreExecutors.directExecutor());
transactions.add(result.tx);
}
return transactions;
}
示例3: calculateSigScript
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
public Script calculateSigScript(Transaction tx, int inOffset, Wallet w) {
assert(inOffset >= 0);
//get key by pubkeyhash from wallet
ECKey key = w.findKeyFromPubHash(this.pubkeyHash);
assert(key != null);
TransactionSignature ts = tx.calculateSignature(inOffset, key, redeemScript, SigHash.ALL, false);
ScriptBuilder sb = new ScriptBuilder();
byte[] sigEncoded = ts.encodeToBitcoin();
sb.data(sigEncoded);
assert(TransactionSignature.isEncodingCanonical(sigEncoded));
sb.data(key.getPubKey());
sb.data(redeemScript.getProgram());
return sb.build();
}
示例4: addWallet
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
/**
* <p>Link the given wallet to this PeerGroup. This is used for three purposes:</p>
*
* <ol>
* <li>So the wallet receives broadcast transactions.</li>
* <li>Announcing pending transactions that didn't get into the chain yet to our peers.</li>
* <li>Set the fast catchup time using {@link PeerGroup#setFastCatchupTimeSecs(long)}, to optimize chain
* download.</li>
* </ol>
*
* <p>Note that this should be done before chain download commences because if you add a wallet with keys earlier
* than the current chain head, the relevant parts of the chain won't be redownloaded for you.</p>
*
* <p>The Wallet will have an event listener registered on it, so to avoid leaks remember to use
* {@link PeerGroup#removeWallet(Wallet)} on it if you wish to keep the Wallet but lose the PeerGroup.</p>
*/
public void addWallet(Wallet wallet) {
lock.lock();
try {
checkNotNull(wallet);
checkState(!wallets.contains(wallet));
wallets.add(wallet);
wallet.setTransactionBroadcaster(this);
wallet.addCoinsReceivedEventListener(Threading.SAME_THREAD, walletCoinsReceivedEventListener);
wallet.addKeyChainEventListener(Threading.SAME_THREAD, walletKeyEventListener);
wallet.addScriptChangeEventListener(Threading.SAME_THREAD, walletScriptEventListener);
addPeerFilterProvider(wallet);
for (Peer peer : peers) {
peer.addWallet(wallet);
}
} finally {
lock.unlock();
}
}
示例5: onCoinsReceived
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
@Override
public void onCoinsReceived(final Wallet wallet, final Transaction tx, final Coin prevBalance,
final Coin newBalance) {
transactionsReceived.incrementAndGet();
final int bestChainHeight = blockChain.getBestChainHeight();
final Address address = WalletUtils.getWalletAddressOfReceived(tx, wallet);
final Coin amount = tx.getValue(wallet);
final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType();
final Sha256Hash hash = tx.getHash();
handler.post(new Runnable() {
@Override
public void run() {
final boolean isReceived = amount.signum() > 0;
final boolean replaying = bestChainHeight < config.getBestChainHeightEver();
final boolean isReplayedTx = confidenceType == ConfidenceType.BUILDING && replaying;
if (isReceived && !isReplayedTx)
notifyCoinsReceived(address, amount, hash);
}
});
}
示例6: handleGetData
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
private List<Message> handleGetData(GetDataMessage m) {
// Scans the wallets and memory pool for transactions in the getdata message and returns them.
// Runs on peer threads.
lock.lock();
try {
LinkedList<Message> transactions = new LinkedList<>();
LinkedList<InventoryItem> items = new LinkedList<>(m.getItems());
Iterator<InventoryItem> it = items.iterator();
while (it.hasNext()) {
InventoryItem item = it.next();
// Check the wallets.
for (Wallet w : wallets) {
Transaction tx = w.getTransaction(item.hash);
if (tx == null) continue;
transactions.add(tx);
it.remove();
break;
}
}
return transactions;
} finally {
lock.unlock();
}
}
示例7: getBalanceFriendlyStr
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
/**
*
*/
@Override
public String getBalanceFriendlyStr() {
//send test coins back to : mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf
Coin balance = _coin.getWalletManager().wallet().getBalance(Wallet.BalanceType.ESTIMATED);
String balanceStatus =
"Friendly balance : " + balance.toFriendlyString()
+ " Estimated : " + _coin.getWalletManager().wallet().getBalance(Wallet.BalanceType.ESTIMATED)
+ " Available : " + _coin.getWalletManager().wallet().getBalance(Wallet.BalanceType.AVAILABLE)
+ " Available Spendable : " + _coin.getWalletManager().wallet().getBalance(Wallet.BalanceType.AVAILABLE_SPENDABLE)
+ " Estimated Spendable : " + _coin.getWalletManager().wallet().getBalance(Wallet.BalanceType.ESTIMATED_SPENDABLE);
return balance.toPlainString();
}
示例8: removeWallet
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
/**
* Unlinks the given wallet so it no longer receives broadcast transactions or has its transactions announced.
*/
public void removeWallet(Wallet wallet) {
wallets.remove(checkNotNull(wallet));
peerFilterProviders.remove(wallet);
wallet.removeCoinsReceivedEventListener(walletCoinsReceivedEventListener);
wallet.removeKeyChainEventListener(walletKeyEventListener);
wallet.removeScriptChangeEventListener(walletScriptEventListener);
wallet.setTransactionBroadcaster(null);
for (Peer peer : peers) {
peer.removeWallet(wallet);
}
}
示例9: onHandleIntent
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
@Override
protected void onHandleIntent(final Intent intent) {
org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
final Wallet wallet = application.getWallet();
if (wallet.isDeterministicUpgradeRequired()) {
log.info("detected non-HD wallet, upgrading");
// upgrade wallet to HD
wallet.upgradeToDeterministic(null);
// let other service pre-generate look-ahead keys
application.startBlockchainService(false);
}
maybeUpgradeToSecureChain(wallet);
}
示例10: updateWidgets
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
public static void updateWidgets(final Context context, final Wallet wallet) {
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
final ComponentName providerName = new ComponentName(context, WalletBalanceWidgetProvider.class);
try {
final int[] appWidgetIds = appWidgetManager.getAppWidgetIds(providerName);
if (appWidgetIds.length > 0) {
final Coin balance = wallet.getBalance(BalanceType.ESTIMATED);
WalletBalanceWidgetProvider.updateWidgets(context, appWidgetManager, appWidgetIds, balance);
}
} catch (final RuntimeException x) // system server dead?
{
log.warn("cannot update app widgets", x);
}
}
示例11: PaymentChannelClient
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
/**
* Constructs a new channel manager which waits for {@link PaymentChannelClient#connectionOpen()} before acting.
*
* @param wallet The wallet which will be paid from, and where completed transactions will be committed.
* Must already have a {@link StoredPaymentChannelClientStates} object in its extensions set.
* @param myKey A freshly generated keypair used for the multisig contract and refund output.
* @param maxValue The maximum value the server is allowed to request that we lock into this channel until the
* refund transaction unlocks. Note that if there is a previously open channel, the refund
* transaction used in this channel may be larger than maxValue. Thus, maxValue is not a method for
* limiting the amount payable through this channel.
* @param serverId An arbitrary hash representing this channel. This must uniquely identify the server. If an
* existing stored channel exists in the wallet's {@link StoredPaymentChannelClientStates}, then an
* attempt will be made to resume that channel.
* @param userKeySetup Key derived from a user password, used to decrypt myKey, if it is encrypted, during setup.
* @param clientChannelProperties Modify the channel's properties. You may extend {@link DefaultClientChannelProperties}
* @param conn A callback listener which represents the connection to the server (forwards messages we generate to
* the server)
*/
public PaymentChannelClient(Wallet wallet, ECKey myKey, Coin maxValue, Sha256Hash serverId,
@Nullable KeyParameter userKeySetup, @Nullable ClientChannelProperties clientChannelProperties,
ClientConnection conn) {
this.wallet = checkNotNull(wallet);
this.myKey = checkNotNull(myKey);
this.maxValue = checkNotNull(maxValue);
this.serverId = checkNotNull(serverId);
this.conn = checkNotNull(conn);
this.userKeySetup = userKeySetup;
if (clientChannelProperties == null) {
this.clientChannelProperties = defaultChannelProperties;
} else {
this.clientChannelProperties = clientChannelProperties;
}
this.timeWindow = clientChannelProperties.timeWindow();
checkState(timeWindow >= 0);
this.versionSelector = clientChannelProperties.versionSelector();
}
示例12: onWalletChanged
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
@Override
public final void onWalletChanged(final Wallet wallet) {
if (relevant.getAndSet(false)) {
handler.removeCallbacksAndMessages(null);
final long now = System.currentTimeMillis();
if (now - lastMessageTime.get() > throttleMs)
handler.post(runnable);
else
handler.postDelayed(runnable, throttleMs);
}
}
示例13: generateNewWallet
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
private Wallet generateNewWallet() {
final Wallet wallet = new Wallet(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
final DeterministicSeed seed = wallet.getKeyChainSeed();
this.masterSeed = seedToString(seed);
return wallet;
}
示例14: initFromMasterSeed
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
private Wallet initFromMasterSeed(final String masterSeed) {
try {
final DeterministicSeed seed = getSeed(masterSeed);
seed.check();
return constructFromSeed(seed);
} catch (final UnreadableWalletException | MnemonicException e) {
throw new RuntimeException("Unable to create wallet. Seed is invalid");
}
}
示例15: getToAddressOfSent
import org.bitcoinj.wallet.Wallet; //导入依赖的package包/类
@Nullable
public static Address getToAddressOfSent(final Transaction tx, final Wallet wallet) {
for (final TransactionOutput output : tx.getOutputs()) {
try {
if (!output.isMine(wallet)) {
final Script script = output.getScriptPubKey();
return script.getToAddress(Constants.NETWORK_PARAMETERS, true);
}
} catch (final ScriptException x) {
// swallow
}
}
return null;
}