本文整理汇总了Java中org.bitcoinj.wallet.Wallet.BalanceType类的典型用法代码示例。如果您正苦于以下问题:Java BalanceType类的具体用法?Java BalanceType怎么用?Java BalanceType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BalanceType类属于org.bitcoinj.wallet.Wallet包,在下文中一共展示了BalanceType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: sideChain
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void sideChain() throws Exception {
// The wallet receives a coin on the main chain, then on a side chain. Balance is equal to both added together
// as we assume the side chain tx is pending and will be included shortly.
Coin v1 = COIN;
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, v1);
assertEquals(v1, wallet.getBalance());
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals(1, wallet.getTransactions(true).size());
Coin v2 = valueOf(0, 50);
sendMoneyToWallet(AbstractBlockChain.NewBlockType.SIDE_CHAIN, v2);
assertEquals(2, wallet.getTransactions(true).size());
assertEquals(v1, wallet.getBalance());
assertEquals(v1.add(v2), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:17,代码来源:WalletTest.java
示例2: generateGenesisTransaction
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
public void generateGenesisTransaction(int lockTime) {
Transaction genesisTx;
try {
//generate genesis transaction if our proof is empty
if(pm.getValidationPath().size() == 0 && wallet.getBalance(BalanceType.AVAILABLE).isGreaterThan(PSNYMVALUE)) {
genesisTx = tg.generateGenesisTransaction(pm, walletFile, lockTime);
//TODO register listener before sending tx out, to avoid missing a confidence change
genesisTx.getConfidence().addEventListener(new Listener() {
@Override
public void onConfidenceChanged(TransactionConfidence arg0,
ChangeReason arg1) {
if (arg0.getConfidenceType() != TransactionConfidence.ConfidenceType.BUILDING) {
return;
}
if(arg0.getDepthInBlocks() == 1) {
//enough confidence, write proof message to the file system
System.out.println("depth of genesis tx is now 1, consider ready for usage");
}
}
});
}
} catch (InsufficientMoneyException e) {
e.printStackTrace();
}
}
开发者ID:kit-tm,项目名称:bitnym,代码行数:27,代码来源:BitNymWallet.java
示例3: updateWidgets
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的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);
}
}
开发者ID:guodroid,项目名称:okwallet,代码行数:17,代码来源:WalletBalanceWidgetProvider.java
示例4: prepareRestoreWalletDialog
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
private void prepareRestoreWalletDialog(final Dialog dialog) {
final AlertDialog alertDialog = (AlertDialog) dialog;
final View replaceWarningView = alertDialog
.findViewById(R.id.restore_wallet_from_content_dialog_replace_warning);
final boolean hasCoins = wallet.getBalance(BalanceType.ESTIMATED).signum() > 0;
replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE);
final EditText passwordView = (EditText) alertDialog
.findViewById(R.id.import_keys_from_content_dialog_password);
passwordView.setText(null);
final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(
passwordView, alertDialog) {
@Override
protected boolean hasFile() {
return true;
}
};
passwordView.addTextChangedListener(dialogButtonEnabler);
final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_content_dialog_show);
showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));
}
开发者ID:guodroid,项目名称:okwallet,代码行数:25,代码来源:RestoreWalletActivity.java
示例5: cleanupCommon
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
private Transaction cleanupCommon(Address destination) throws Exception {
receiveATransaction(wallet, myAddress);
Coin v2 = valueOf(0, 50);
SendRequest req = SendRequest.to(destination, v2);
wallet.completeTx(req);
Transaction t2 = req.tx;
// Broadcast the transaction and commit.
broadcastAndCommit(wallet, t2);
// At this point we have one pending and one spent
Coin v1 = valueOf(0, 10);
Transaction t = sendMoneyToWallet(null, v1, myAddress);
Threading.waitForUserCode();
sendMoneyToWallet(null, t);
assertEquals("Wrong number of PENDING", 2, wallet.getPoolSize(Pool.PENDING));
assertEquals("Wrong number of UNSPENT", 0, wallet.getPoolSize(Pool.UNSPENT));
assertEquals("Wrong number of ALL", 3, wallet.getTransactions(true).size());
assertEquals(valueOf(0, 60), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
// Now we have another incoming pending
return t;
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:27,代码来源:WalletTest.java
示例6: pubkeyOnlyScripts
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void pubkeyOnlyScripts() throws Exception {
// Verify that we support outputs like OP_PUBKEY and the corresponding inputs.
ECKey key1 = wallet.freshReceiveKey();
Coin value = valueOf(5, 0);
Transaction t1 = createFakeTx(PARAMS, value, key1);
if (wallet.isPendingTransactionRelevant(t1))
wallet.receivePending(t1, null);
// TX should have been seen as relevant.
assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
// TX should have been seen as relevant, extracted and processed.
assertEquals(value, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
// Spend it and ensure we can spend the <key> OP_CHECKSIG output correctly.
Transaction t2 = wallet.createSend(OTHER_ADDRESS, value);
assertNotNull(t2);
// TODO: This code is messy, improve the Script class and fixinate!
assertEquals(t2.toString(), 1, t2.getInputs().get(0).getScriptSig().getChunks().size());
assertTrue(t2.getInputs().get(0).getScriptSig().getChunks().get(0).data.length > 50);
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:22,代码来源:WalletTest.java
示例7: outOfOrderPendingTxns
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void outOfOrderPendingTxns() throws Exception {
// Check that if there are two pending transactions which we receive out of order, they are marked as spent
// correctly. For instance, we are watching a wallet, someone pays us (A) and we then pay someone else (B)
// with a change address but the network delivers the transactions to us in order B then A.
Coin value = COIN;
Transaction a = createFakeTx(PARAMS, value, myAddress);
Transaction b = new Transaction(PARAMS);
b.addInput(a.getOutput(0));
b.addOutput(CENT, OTHER_ADDRESS);
Coin v = COIN.subtract(CENT);
b.addOutput(v, wallet.currentChangeAddress());
a = roundTripTransaction(PARAMS, a);
b = roundTripTransaction(PARAMS, b);
wallet.receivePending(b, null);
assertEquals(v, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
wallet.receivePending(a, null);
assertEquals(v, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:20,代码来源:WalletTest.java
示例8: childPaysForParent
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void childPaysForParent() throws Exception {
// Receive confirmed balance to play with.
Transaction toMe = createFakeTxWithoutChangeAddress(PARAMS, COIN, myAddress);
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, toMe);
assertEquals(Coin.COIN, wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE));
assertEquals(Coin.COIN, wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE));
// Receive unconfirmed coin without fee.
Transaction toMeWithoutFee = createFakeTxWithoutChangeAddress(PARAMS, COIN, myAddress);
wallet.receivePending(toMeWithoutFee, null);
assertEquals(Coin.COIN.multiply(2), wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE));
assertEquals(Coin.COIN, wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE));
// Craft a child-pays-for-parent transaction.
final Coin feeRaise = MILLICOIN;
final SendRequest sendRequest = SendRequest.childPaysForParent(wallet, toMeWithoutFee, feeRaise);
wallet.signTransaction(sendRequest);
wallet.commitTx(sendRequest.tx);
assertEquals(Transaction.Purpose.RAISE_FEE, sendRequest.tx.getPurpose());
assertEquals(Coin.COIN.multiply(2).subtract(feeRaise), wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE));
assertEquals(Coin.COIN, wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:22,代码来源:WalletTest.java
示例9: OutputSpec
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
public OutputSpec(String spec) throws IllegalArgumentException {
String[] parts = spec.split(":");
if (parts.length != 2) {
throw new IllegalArgumentException("Malformed output specification, must have two parts separated by :");
}
String destination = parts[0];
if ("ALL".equalsIgnoreCase(parts[1]))
value = wallet.getBalance(BalanceType.ESTIMATED);
else
value = parseCoin(parts[1]);
if (destination.startsWith("0")) {
// Treat as a raw public key.
byte[] pubKey = new BigInteger(destination, 16).toByteArray();
key = ECKey.fromPublicOnly(pubKey);
addr = null;
} else {
// Treat as an address.
addr = Address.fromBase58(params, destination);
key = null;
}
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:22,代码来源:WalletTool.java
示例10: pubkeyOnlyScripts
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void pubkeyOnlyScripts() throws Exception {
// Verify that we support outputs like OP_PUBKEY and the corresponding inputs.
ECKey key1 = wallet.freshReceiveKey();
Coin value = valueOf(5, 0);
Transaction t1 = createFakeTx(PARAMS, value, key1);
if (wallet.isPendingTransactionRelevant(t1))
wallet.receivePending(t1, null);
// TX should have been seen as relevant.
assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
// TX should have been seen as relevant, extracted and processed.
assertEquals(value, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
// Spend it and ensure we can spend the <key> OP_CHECKSIG output correctly.
Transaction t2 = wallet.createSend(OTHER_ADDRESS, value);
assertNotNull(t2);
// TODO: This code is messy, improve the Script class and fixinate!
assertEquals(t2.toString(), 1, t2.getInputs().get(0).getScriptSig().getChunks().size());
assertTrue(t2.getInputs().get(0).getScriptSig().getChunks().get(0).data.length > 50);
log.info(t2.toString(chain));
}
开发者ID:HashEngineering,项目名称:dashj,代码行数:23,代码来源:WalletTest.java
示例11: handleDonate
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
private void handleDonate() {
final Coin balance = wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE);
SendCoinsActivity.startDonate(this, balance, FeeCategory.ECONOMIC,
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
nm.cancel(Constants.NOTIFICATION_ID_INACTIVITY);
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
开发者ID:guodroid,项目名称:okwallet,代码行数:8,代码来源:InactivityNotificationService.java
示例12: onUpdate
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
final WalletApplication application = (WalletApplication) context.getApplicationContext();
final Coin balance = application.getWallet().getBalance(BalanceType.ESTIMATED);
updateWidgets(context, appWidgetManager, appWidgetIds, balance);
}
开发者ID:guodroid,项目名称:okwallet,代码行数:8,代码来源:WalletBalanceWidgetProvider.java
示例13: onAppWidgetOptionsChanged
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Override
public void onAppWidgetOptionsChanged(final Context context, final AppWidgetManager appWidgetManager,
final int appWidgetId, final Bundle newOptions) {
if (newOptions != null)
log.info("app widget {} options changed: minWidth={}", appWidgetId,
newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
final WalletApplication application = (WalletApplication) context.getApplicationContext();
final Coin balance = application.getWallet().getBalance(BalanceType.ESTIMATED);
updateWidget(context, appWidgetManager, appWidgetId, newOptions, balance);
}
开发者ID:guodroid,项目名称:okwallet,代码行数:13,代码来源:WalletBalanceWidgetProvider.java
示例14: handleEmpty
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
private void handleEmpty() {
final Coin available = wallet.getBalance(BalanceType.AVAILABLE);
amountCalculatorLink.setBtcAmount(available);
updateView();
handler.post(dryrunRunnable);
}
开发者ID:guodroid,项目名称:okwallet,代码行数:8,代码来源:SendCoinsFragment.java
示例15: cleanup
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void cleanup() throws Exception {
Transaction t = cleanupCommon(OTHER_ADDRESS);
// Consider the new pending as risky and remove it from the wallet
wallet.setRiskAnalyzer(new TestRiskAnalysis.Analyzer(t));
wallet.cleanup();
assertTrue(wallet.isConsistent());
assertEquals("Wrong number of PENDING", 1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
assertEquals("Wrong number of UNSPENT", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals("Wrong number of ALL", 2, wallet.getTransactions(true).size());
assertEquals(valueOf(0, 50), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:15,代码来源:WalletTest.java
示例16: cleanupFailsDueToSpend
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void cleanupFailsDueToSpend() throws Exception {
Transaction t = cleanupCommon(OTHER_ADDRESS);
// Now we have another incoming pending. Spend everything.
Coin v3 = valueOf(0, 60);
SendRequest req = SendRequest.to(OTHER_ADDRESS, v3);
// Force selection of the incoming coin so that we can spend it
req.coinSelector = new TestCoinSelector();
wallet.completeTx(req);
wallet.commitTx(req.tx);
assertEquals("Wrong number of PENDING", 3, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
assertEquals("Wrong number of UNSPENT", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals("Wrong number of ALL", 4, wallet.getTransactions(true).size());
// Consider the new pending as risky and try to remove it from the wallet
wallet.setRiskAnalyzer(new TestRiskAnalysis.Analyzer(t));
wallet.cleanup();
assertTrue(wallet.isConsistent());
// The removal should have failed
assertEquals("Wrong number of PENDING", 3, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
assertEquals("Wrong number of UNSPENT", 0, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals("Wrong number of ALL", 4, wallet.getTransactions(true).size());
assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:31,代码来源:WalletTest.java
示例17: receiveATransactionAmount
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
private void receiveATransactionAmount(Wallet wallet, Address toAddress, Coin amount) {
final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.AVAILABLE);
final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED);
assertFalse(availFuture.isDone());
assertFalse(estimatedFuture.isDone());
// Send some pending coins to the wallet.
Transaction t1 = sendMoneyToWallet(wallet, null, amount, toAddress);
Threading.waitForUserCode();
final ListenableFuture<TransactionConfidence> depthFuture = t1.getConfidence().getDepthFuture(1);
assertFalse(depthFuture.isDone());
assertEquals(ZERO, wallet.getBalance());
assertEquals(amount, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertFalse(availFuture.isDone());
// Our estimated balance has reached the requested level.
assertTrue(estimatedFuture.isDone());
assertEquals(1, wallet.getPoolSize(Pool.PENDING));
assertEquals(0, wallet.getPoolSize(Pool.UNSPENT));
// Confirm the coins.
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, t1);
assertEquals("Incorrect confirmed tx balance", amount, wallet.getBalance());
assertEquals("Incorrect confirmed tx PENDING pool size", 0, wallet.getPoolSize(Pool.PENDING));
assertEquals("Incorrect confirmed tx UNSPENT pool size", 1, wallet.getPoolSize(Pool.UNSPENT));
assertEquals("Incorrect confirmed tx ALL pool size", 1, wallet.getTransactions(true).size());
Threading.waitForUserCode();
assertTrue(availFuture.isDone());
assertTrue(estimatedFuture.isDone());
assertTrue(depthFuture.isDone());
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:29,代码来源:WalletTest.java
示例18: balance
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void balance() throws Exception {
// Receive 5 coins then half a coin.
Coin v1 = valueOf(5, 0);
Coin v2 = valueOf(0, 50);
Coin expected = valueOf(5, 50);
assertEquals(0, wallet.getTransactions(true).size());
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, v1);
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, v2);
assertEquals(2, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
assertEquals(expected, wallet.getBalance());
// Now spend one coin.
Coin v3 = COIN;
Transaction spend = wallet.createSend(OTHER_ADDRESS, v3);
wallet.commitTx(spend);
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.PENDING));
// Available and estimated balances should not be the same. We don't check the exact available balance here
// because it depends on the coin selection algorithm.
assertEquals(valueOf(4, 50), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertFalse(wallet.getBalance(Wallet.BalanceType.AVAILABLE).equals(
wallet.getBalance(Wallet.BalanceType.ESTIMATED)));
// Now confirm the transaction by including it into a block.
sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, spend);
// Change is confirmed. We started with 5.50 so we should have 4.50 left.
Coin v4 = valueOf(4, 50);
assertEquals(v4, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:33,代码来源:WalletTest.java
示例19: balanceWithIdenticalOutputs
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void balanceWithIdenticalOutputs() {
assertEquals(Coin.ZERO, wallet.getBalance(BalanceType.ESTIMATED));
Transaction tx = new Transaction(PARAMS);
tx.addOutput(Coin.COIN, myAddress);
tx.addOutput(Coin.COIN, myAddress); // identical to the above
wallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
assertEquals(Coin.COIN.plus(Coin.COIN), wallet.getBalance(BalanceType.ESTIMATED));
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:10,代码来源:WalletTest.java
示例20: reset
import org.bitcoinj.wallet.Wallet.BalanceType; //导入依赖的package包/类
@Test
public void reset() {
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN, myAddress);
assertNotEquals(Coin.ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertNotEquals(0, wallet.getTransactions(false).size());
assertNotEquals(0, wallet.getUnspents().size());
wallet.reset();
assertEquals(Coin.ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
assertEquals(0, wallet.getTransactions(false).size());
assertEquals(0, wallet.getUnspents().size());
}
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:12,代码来源:WalletTest.java
注:本文中的org.bitcoinj.wallet.Wallet.BalanceType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论