It's very likely the reason is in your custom code. Coin selection
obviously has a lot of effect on the various balances. If you haven't
already, I suggest writing a proper unit test with all your expectations
about balance behaviour.
On 05/23/2017 08:55 PM, Ajit Soman wrote:
> Hi,
>
> @Oscar and @Andreas thank for suggestion . Based on your suggestions i
> have put some logs in my transaction API . I am have put some logs to
> get balance after transaction using
> *AVAILABLE,AVAILABLE_SPENDABLE,ESTIMATED,ESTIMATED_SPENDABLE *. You will
> find these balances in logs.
>
> Here are the logs:
>
> _*CASE 1: Logs in which AVAILABLE_and ESTIMATED Balance are equal:*_
>
> |
>
>
> 2017-05-2311:57:07.872 INFO 2575---[inj user
> thread]c.o.c.listner.PeerEventListner :onTransaction
> 2017-05-2311:57:09.934 INFO
> 2575---[nio-8080-exec-9]c.o.c.controllers.WalletController
> :fetching address
> Addressn3qsp4GjoeXPc8vkjdH4kw7EpaHAugZiQH
> change address:mkKrFQC5DBop3vxEmfpnnG4tHJPoTfpVNy
> 2017-05-2311:57:12.297 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet
> :Completingsend tx with1outputs totalling 0.01B
> TC (notincluding fees)
> 2017-05-2311:57:12.297 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet :
> with0.08934456BTC change
> 2017-05-2311:57:12.298 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet : witha
> fee of 0.00044444BTC/kB,0.0001BTC for
> 225bytes
> 2017-05-2311:57:12.298 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet :
> completed: a451150d9405648d30a570dbfa376990504
> b6e9828e4f683ac5241296d393a55
> in
> PUSHDATA(71)[3044022074b302e1df7abd9d3dd59b4f3d4ce71aba800754c77e4a9361c0b1cffec39e0c02205780ea878d6fe13a923035440ddec3315b029d4731b1e7fbe35
> 0009cd0fffcef01]PUSHDATA(33)[03529f41ae977dd703bcf8a84c46404c9f32642c75c26c408a870cc0a4435df404]0.09944456BTC
>
> outpoint:5c4c6f5a3d8b24dc6b6dad31114b76279249b0eaf0ddeb7a13e22a6284780017:1hash160:94c7087f5ed390cb5f6ce0cc098a45363713c199
> out DUP HASH160
> PUSHDATA(20)[f4e6edb51ab4a70cd430a3b2f465eff196a635b2]EQUALVERIFY
> CHECKSIG 0.01BTC
> out DUP HASH160
> PUSHDATA(20)[34bf01b0c04287b086a99d326f6b4a3dcbe12d2e]EQUALVERIFY
> CHECKSIG 0.08934456BTC
> fee 0.00044444BTC/kB,0.0001BTC for225bytes
> prps USER_PAYMENT
>
>
> 2017-05-2311:57:12.298 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet
> :commitTx of a451150d9405648d30a570dbfa376990504b6e
> 9828e4f683ac5241296d393a55
> 2017-05-2311:57:12.298DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125438
> 2017-05-2311:57:12.298DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125457
> 2017-05-2311:57:12.298 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet :
> marked 5c4c6f5a3d8b24dc6b6dad31114b76279249b0eaf
> 0ddeb7a13e22a6284780017:1asspent
> bya451150d9405648d30a570dbfa376990504b6e9828e4f683ac5241296d393a55
> 2017-05-2311:57:12.298 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet :
> 5c4c6f5a3d8b24dc6b6dad31114b76279249b0eaf0ddeb7a
> 13e22a6284780017prevtx <-unspent ->spent
> 2017-05-2311:57:12.298 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet
> :->pending:a451150d9405648d30a570dbfa376990504b6e9
> 828e4f683ac5241296d393a55
> 2017-05-2311:57:12.299 INFO
> 2575---[nio-8080-exec-7]org.bitcoinj.core.Wallet
> :Estimatedbalance isnow:0.09992657BTC
> 2017-05-2311:57:12.299 INFO 2575---[inj user
> thread]c.o.c.listner.CoinReceiveListner
> :onCoinsReceivedcom.oodles.coreservice.services.Wal
> letStoreService@17f0b0cb
> 2017-05-2311:57:12.299DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125438
> 2017-05-2311:57:12.299DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125457
> wallet.getBalance()------->9992657
> 2017-05-2311:57:12.303DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125438
> 2017-05-2311:57:12.303DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125457
> wallet.getBalance(BalanceType.AVAILABLE)------->9992657
> 2017-05-2311:57:12.303DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125438
> 2017-05-2311:57:12.303DEBUG
> 2575---[nio-8080-exec-7]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125457
> wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE)------->9992657
> wallet.getBalance(BalanceType.ESTIMATED------->9992657
> wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE)------->9992657
> 2017-05-2311:57:12.321 WARN
> 2575---[nio-8080-exec-7]bitronix.tm.twopc.Preparer
> :executing transaction with0enlisted resource
> 2017-05-2311:57:15.771 INFO 2575---[inj user
> thread]c.o.c.listner.PeerEventListner :onTransaction
> 2017-05-2311:57:17.955 INFO 2575---[inj user
> thread]c.o.c.listner.PeerEventListner :onTransaction
> |
>
>
> _*CASE 2: Logs in which AVAILABLE and ESTIMATED Balance differs: *_
>
>
> |
>
> 2017-05-2312:17:26.316DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.316DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> 2017-05-2312:17:26.316DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125438
> 2017-05-2312:17:26.316DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> 2017-05-2312:17:26.316 INFO
> 2575---[nio-8080-exec-8]org.bitcoinj.core.Wallet :
> marked a8d6ccaafe53f72a9313d9d487d36e441470d8aff
> a5b09051f68d501bdbbc1f0:0asspent
> by3b171e81b8e7637b0421653e15307515faa8f47f3be75b046a7b490ec0df247d
> 2017-05-2312:17:26.316 INFO
> 2575---[nio-8080-exec-8]org.bitcoinj.core.Wallet :
> a8d6ccaafe53f72a9313d9d487d36e441470d8affa5b0905
> 1f68d501bdbbc1f0prevtx <-unspent ->spent
> 2017-05-2312:17:26.317 INFO
> 2575---[nio-8080-exec-8]org.bitcoinj.core.Wallet
> :->pending:3b171e81b8e7637b0421653e15307515faa8f47
> f3be75b046a7b490ec0df247d
> 2017-05-2312:17:26.317 INFO
> 2575---[nio-8080-exec-8]org.bitcoinj.core.Wallet
> :Estimatedbalance isnow:0.74982657BTC
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> wallet.getBalance()------->9882657
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> wallet.getBalance(BalanceType.AVAILABLE)------->9882657
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
> 2017-05-2312:17:26.317DEBUG
> 2575---[nio-8080-exec-8]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :Chainheight inConfirmedCoinSelector-->1125458
> wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE)------->9882657
> wallet.getBalance(BalanceType.ESTIMATED------->74982657
>
> wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE)------->74982657
> 2017-05-2312:17:26.318 INFO 2575---[inj user
> thread]c.o.c.listner.CoinReceiveListner
> :onCoinsReceivedcom.oodles.coreservice.services.WalletStoreService@17f0b0cb
> 2017-05-2312:17:26.331 WARN
> 2575---[nio-8080-exec-8]bitronix.tm.twopc.Preparer
> :executing transaction with0enlisted resource
> 2017-05-2312:17:27.076DEBUG
> 2575---[nio-8080-exec-2]c.o.c.controllers.WalletController
> :{"walletId":"1495448349","transactionDescription":null,"transactionTradeAmount":null,"receiverAddress":null}
> 2017-05-2312:17:27.080DEBUG
> 2575---[nio-8080-exec-2]c.o.c.s.bitcoinj.ConfirmedCoinSelector
> :TransactionHeight1125458
>
> |
>
>
> *_CASE 3: L__ogs in which AVAILABLE_Balance__ become 0 BTC:_*
> *_
> _*
> |
>
>
>
> 017-05-2312:38:29.070 INFO 2575---[inj user
> thread]c.o.c.listner.PeerEventListner :onTransaction
> 2017-05-2312:38:35.046 INFO 2575---[inj user
> thread]c.o.c.listner.PeerEventListner :onTransaction
> 2017-05-2312:38:35.300 INFO
> 2575---[io-8080-exec-10]c.o.c.controllers.WalletController
> :fetching address
> AddressmhcWftaGpExZKWSY77vdausBnz1jBbCC1t
> change address:mw4GtcjeJa45dMGWASks6bLitTnbXChQDs
> 2017-05-2312:38:35.659 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet
> :Completingsend tx with1outputs totalling 0.01B
> TC (notincluding fees)
> 2017-05-2312:38:35.659 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet :
> with0.0009BTC change
> 2017-05-2312:38:35.660 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet : witha
> fee of 0.00026737BTC/kB,0.0001BTC for
> 374bytes
> 2017-05-2312:38:35.660 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet :
> completed: dd5e1586ca367f06cec7a6259e7fe7a0853
> facf652cd8fe73b205d10778d7e8f
> in
> PUSHDATA(72)[3045022100862d559937d476ab412a0756ff448d4acd53908d9e11361b89b9913f00847e6902207135ed61bc5c6e6760a1b6c1c93a9d54abcc9dcff146c4190
> 40d5c8f7a7e446801]PUSHDATA(33)[0293f1deb1fc85c2c6c291d20d9875f795e6efd0c59b7cc5a235df39b734b9aa37]0.01BTC
>
> outpoint:a451150d9405648d30a570dbfa376990504b6e9828e4f683ac5241296d393a55:0hash160:f4e6edb51ab4a70cd430a3b2f465eff196a635b2
> in
> PUSHDATA(72)[30450221009b5c5d044fdf64df0766035b3712abbb17d29a9b7a09e0482c0902936c6164cc02201bf5a0e33fb8e936803d101c819a167c4f69a6516519bb734
> f463edbfc73893901]PUSHDATA(33)[0293f1deb1fc85c2c6c291d20d9875f795e6efd0c59b7cc5a235df39b734b9aa37]0.001BTC
>
> outpoint:65009f6a688c04fa33c260b3af697bc95f028b6f879810d9f2737c7ff1eac2a9:1hash160:f4e6edb51ab4a70cd430a3b2f465eff196a635b2
> out DUP HASH160
> PUSHDATA(20)[16fd5b9f8b8efaff80398cc1e91b49272e6c609b]EQUALVERIFY
> CHECKSIG 0.01BTC
> out DUP HASH160
> PUSHDATA(20)[aa764dfe126dcd304c2570e3f1c95be2d8138c78]EQUALVERIFY
> CHECKSIG 0.0009BTC
> fee 0.00026737BTC/kB,0.0001BTC for374bytes
> prps USER_PAYMENT
>
>
> 2017-05-2312:38:35.660 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet
> :commitTx of
> dd5e1586ca367f06cec7a6259e7fe7a0853facf652cd8fe73b205d10778d7e8f
> 2017-05-2312:38:35.660 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet :
> marked
> a451150d9405648d30a570dbfa376990504b6e9828e4f683ac5241296d393a55:0asspent
> bydd5e1586ca367f06cec7a6259e7fe7a0853facf652cd8fe73b205d10778d7e8f
> 2017-05-2312:38:35.660 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet :
> a451150d9405648d30a570dbfa376990504b6e9828e4f683ac5241296d393a55 prevtx
> <-unspent ->spent
> 2017-05-2312:38:35.661 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet :
> marked
> 65009f6a688c04fa33c260b3af697bc95f028b6f879810d9f2737c7ff1eac2a9:1asspent
> bydd5e1586ca367f06cec7a6259e7fe7a0853facf652cd8fe73b205d10778d7e8f
> 2017-05-2312:38:35.661 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet :
> 65009f6a688c04fa33c260b3af697bc95f028b6f879810d9f2737c7ff1eac2a9prevtx
> <-unspent ->spent
> 2017-05-2312:38:35.661 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet
> :->pending:dd5e1586ca367f06cec7a6259e7fe7a0853facf652cd8fe73b205d10778d7e8f
> 2017-05-2312:38:35.661 INFO
> 2575---[nio-8080-exec-6]org.bitcoinj.core.Wallet
> :Estimatedbalance isnow:0.0009BTC
> wallet.getBalance()------->0
> wallet.getBalance(BalanceType.AVAILABLE)------->0
> wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE)------->0
> wallet.getBalance(BalanceType.ESTIMATED------->90000
> wallet.getBalance(BalanceType.ESTIMATED_SPENDABLE)------->90000
> 2017-05-2312:38:35.678 WARN
> 2575---[nio-8080-exec-6]bitronix.tm.twopc.Preparer
> :executing transaction with0enlisted resource
> 2017-05-2312:38:36.355DEBUG
> 2575---[nio-8080-exec-5]c.o.c.controllers.WalletController
> :{"walletId":"1495519777","transactionDescription":null,"transactionTradeAmount":null,"receiverAddress":null}
> 2017-05-2312:38:47.133DEBUG 2575---[
> Thread-12]c.o.c.s.w.TransactionBroadcastService :count:3069
> 2017-05-2312:38:47.133DEBUG 2575---[
> Thread-12]c.o.c.s.w.TransactionBroadcastService
> :BroadcastThreadisstarted
> fora00b27e30de8b9402572bfec4a874379247adb76679b582b62fa5283d9c23a1c
> which has getDepthInBlocks 0andtype status DEAD
> 2017-05-2312:38:47.133 INFO
> 2575---[broadcastThread]org.bitcoinj.core.TransactionBroadcast
> :Waitingfor1peers required forbroadcast,we have 1...
> 2017-05-2312:38:47.133DEBUG 2575---[
> Thread-12]c.o.c.s.w.TransactionBroadcastService :Broadc
>
> |
>
>
> *So My Questions is : What is the reason Balances in case 1 are same ,
> in case 2 are different and case 3 AVAILABLE become 0 BTC.*
>
> We have customerized coinSelector here is the code:
>
>
> |
> importjava.math.BigInteger;
> importjava.util.ArrayList;
> importjava.util.Collections;
> importjava.util.Comparator;
> importjava.util.HashSet;
> importjava.util.List;
>
>
> importorg.bitcoinj.core.Coin;
> importorg.bitcoinj.core.NetworkParameters;
> importorg.bitcoinj.core.Transaction;
> importorg.bitcoinj.core.TransactionConfidence;
> importorg.bitcoinj.core.TransactionOutput;
> importorg.bitcoinj.wallet.CoinSelection;
> importorg.bitcoinj.wallet.CoinSelector;
> importorg.slf4j.Logger;
> importorg.slf4j.LoggerFactory;
>
>
> importcom.google.common.annotations.VisibleForTesting;
>
>
> publicclassConfirmedCoinSelectorimplementsCoinSelector{
> publicstaticLoggerlog =LoggerFactory
> .getLogger(ConfirmedCoinSelector.class);
> publicstaticintminConfidenceLevel =0;
> // chainHeight is current block in block chain
> privatestaticintchainHeight =0;
>
>
> privatestaticConfirmedCoinSelectorconfirmedCoinSelector;
>
>
> privateConfirmedCoinSelector(){
>
>
> }
>
>
> publicstaticConfirmedCoinSelectorget(){
> if(confirmedCoinSelector ==null){
> confirmedCoinSelector =newConfirmedCoinSelector();
> }
> returnconfirmedCoinSelector;
> }
>
>
> publicstaticbooleanisConfirmed(Transactiontx){
> if(calculateConfirmations(tx)>=minConfidenceLevel){
> returntrue;
> }
> returnfalse;
> }
>
>
> publicstaticintcalculateConfirmations(Transactiontx){
>
>
> try{
> // chainHeight is the block number at this transaction exist in
> // block chain
> intchainHeight =tx.getConfidence().getAppearedAtChainHeight();
> log.debug("Transaction Height "+chainHeight);
> if(ConfirmedCoinSelector.chainHeight !=0&&chainHeight !=0
> &&ConfirmedCoinSelector.chainHeight >=chainHeight){
> log.debug("Chain height in Confirmed Coin Selector
> -->"+ConfirmedCoinSelector.chainHeight);
> return(ConfirmedCoinSelector.chainHeight -chainHeight +1);
> }else{
> // we can't calculate confirmations because peerGroup does not
> // have information about
> // current block in block ledger
> return0;
> }
> }catch(Exceptione){
> // exception indicate transaction is not confirmed yet.
> return0;
> }
> }
>
>
> publicstaticintgetChainHeight(){
>
>
> returnchainHeight;
> }
>
>
> publicstaticvoidsetChainHeight(intchainHeight){
> if(chainHeight >ConfirmedCoinSelector.chainHeight){
> ConfirmedCoinSelector.chainHeight =chainHeight;
> if(ConfirmedCoinSelector.chainHeight >=809032)
> log.debug("block height is updated by "+ConfirmedCoinSelector.chainHeight);
> }
> }
>
>
> publicstaticvoidsetMinConfidenceLevel(intminConfidenceLevel){
> ConfirmedCoinSelector.minConfidenceLevel =minConfidenceLevel;
> }
>
>
> publicstaticintgetMinConfidenceLevel(){
> returnminConfidenceLevel;
> }
>
>
> @Override
> publicCoinSelectionselect(CoinbiTarget,
> List<TransactionOutput>candidates){
> // TODO Auto-generated method stub
> longtarget =biTarget.value;
> HashSet<TransactionOutput>selected =newHashSet<TransactionOutput>();
> // Sort the inputs by age*value so we get the highest "coindays" spent.
> // TODO: Consider changing the wallets internal format to track just
> // outputs and keep them ordered.
> ArrayList<TransactionOutput>sortedOutputs =newArrayList<TransactionOutput>(
> candidates);
> // When calculating the wallet balance, we may be asked to select all
> // possible coins, if so, avoid sorting
> // them in order to improve performance.
> if(!biTarget.equals(NetworkParameters.MAX_MONEY)){
> sortOutputs(sortedOutputs);
> }
> // Now iterate over the sorted outputs until we have got as close to the
> // target as possible or a little
> // bit over (excessive value will be change).
> longtotal =0;
> for(TransactionOutputoutput :sortedOutputs){
> if(total >=target)
> break;
> // Only pick chain-included transactions, or transactions that are
> // ours and pending.
> if(!shouldSelect(output.getParentTransaction()))
> continue;
> selected.add(output);
> total +=output.getValue().value;
> }
> // Total may be lower than target here, if the given candidates were
> // insufficient to create to requested
> // transaction.
> returnnewCoinSelection(Coin.valueOf(total),selected);
> }
>
>
> @VisibleForTesting
> staticvoidsortOutputs(ArrayList<TransactionOutput>outputs){
>
>
> Collections.sort(outputs,newComparator<TransactionOutput>(){
> @Override
> publicintcompare(TransactionOutputa,TransactionOutputb){
> intdepth1 =0;
> intdepth2 =0;
> TransactionConfidenceconf1 =a.getParentTransaction()
> .getConfidence();
> TransactionConfidenceconf2 =b.getParentTransaction()
> .getConfidence();
> if(conf1.getConfidenceType()==TransactionConfidence.ConfidenceType.BUILDING)
> depth1 =conf1.getDepthInBlocks();
> if(conf2.getConfidenceType()==TransactionConfidence.ConfidenceType.BUILDING)
> depth2 =conf2.getDepthInBlocks();
> CoinaValue =a.getValue();
> CoinbValue =b.getValue();
> BigIntegeraCoinDepth =BigInteger.valueOf(aValue.value)
> .multiply(BigInteger.valueOf(depth1));
> BigIntegerbCoinDepth =BigInteger.valueOf(bValue.value)
> .multiply(BigInteger.valueOf(depth2));
> intc1 =bCoinDepth.compareTo(aCoinDepth);
> if(c1 !=0)
> returnc1;
> // The "coin*days" destroyed are equal, sort by value alone to
> // get the lowest transaction size.
> intc2 =bValue.compareTo(aValue);
> if(c2 !=0)
> returnc2;
> // They are entirely equivalent (possibly pending) so sort by
> // hash to ensure a total ordering.
> BigIntegeraHash =a.getParentTransaction().getHash()
> .toBigInteger();
> BigIntegerbHash =b.getParentTransaction().getHash()
> .toBigInteger();
> returnaHash.compareTo(bHash);
> }
> });
> }
>
>
> /**
> * Sub-classes can override this to just customize whether transactions are
> * usable, but keep age sorting.
> */
> protectedbooleanshouldSelect(Transactiontx){
>
>
> returnisSelectable(tx);
> }
>
>
> publicstaticbooleanisSelectable(Transactiontx){
>
>
> // Only pick chain-included transactions, or transactions that are ours
> // and pending.
> TransactionConfidenceconfidence =tx.getConfidence();
> TransactionConfidence.ConfidenceTypetype =confidence
> .getConfidenceType();
>
>
> // first check weather transaction is created by us and status is
> // pending in such case we will
> // allow user to use this balance.
> booleanresult =(type
> .equals(TransactionConfidence.ConfidenceType.BUILDING)||type
> .equals(TransactionConfidence.ConfidenceType.PENDING))
> &&confidence.getSource().equals(
> TransactionConfidence.Source.SELF);
>
>
> if((result ||isConfirmed(tx))){
> returntrue;
> }
> returnfalse;
> }
>
>
> }
> |
>
>
>
>
>
> On Tuesday, May 23, 2017 at 5:15:24 PM UTC+5:30,
> [email protected] wrote:
>
> I am also facing this issue. Can you tell how to fix this issue ?
>
> On Saturday, May 13, 2017 at 8:15:16 PM UTC+5:30, Andreas Schildbach
> wrote:
>
> Yes, using ESTIMATED_SPENDABLE your balance should behave more
> like you
> expect. Just beware that you can only spend confirmed coins (as
> long as
> you're using the default CoinSelector).
>
>
> On 05/12/2017 06:53 PM, Ajit Soman wrote:
> > Hi Oscar,
> >
> > I am using this:
> wallet.getBalance(BalanceType.AVAILABLE_SPENDABLE) to
> > get balance.
> >
> > I am facing this issue in 1 out of 10 transactions . i did a
> transaction
> > right now it works fine. i am unable to figure out what is the
> issue.
> >
> > On Friday, May 12, 2017 at 6:32:50 PM UTC+5:30, Oscar
> Guindzberg wrote:
> >
> > Hi,
> >
> > wallet.getBalance() returns the confirmed balance
> > You can use
> > wallet.getBalance(Wallet.BalanceType.ESTIMATED)
> > to get the unconfirmed balance.
> >
> > Oscar
> >
> > On Thu, May 11, 2017 at 2:04 PM, Ajit Soman
> <[email protected]> wrote:
> > > Hi ,
> > >
> > > Initially my wallet has 2 BTC . I did a transaction of 1
> BTC to a
> > wallet
> > > address . Transaction was successful i got a transaction
> hash now
> > when i
> > > check my wallet balance it shows 0 BTC . After getting
> more than 1
> > > confirmation i got my actual wallet balance i.e 1 BTC.
> Here is my
> > > bitcoinTransaction code:
> > >
> > > public String createTransaction(TransactionParams
> > transactionparams) throws
> > > Exception { // TransactionParams is a entity
> > > String transactionHash = null;
> > > Wallet wallet = null;
> > >
> > > Address receiverAddress;
> > > Context.propagate(new
> Context(netparams.getNetworkParameters())); //
> > > netparams is a util through which we are getting
> testnet3 or mainnet
> > > depending upon environment
> > > receiverAddress = new
> Address(netparams.getNetworkParameters(),
> > > transactionparams.getReceiverAddress());
> > > String amount =
> > >
> String.valueOf(transactionparams.getTransactionTradeAmount());
> > > System.out.println("Address " +
> > transactionparams.getReceiverAddress());
> > >
> > > final File walletFile = new
> File(configuration.getWalletLocation()
> > + "/" +
> > > transactionparams.getWalletId() + ".dat");
> > > wallet = (Wallet)
> > >
> >
>
> walletStoreService.getWalletMap().get(transactionparams.getWalletId());
>
> > //
> > > walletStoreService that has information about wallet object
> > >
> > > if (walletFile.exists()) {
> > > Coin btcCoin = Coin.parseCoin(amount);
> > > Wallet.SendRequest.DEFAULT_FEE_PER_KB = Coin.ZERO;
> > >
> > > SendRequest request = SendRequest.to(receiverAddress,
> btcCoin);
> > > request.ensureMinRequiredFee = false;
> > > request.fee = Coin.valueOf(10000);
> > > request.feePerKb = Coin.ZERO;
> > > request.changeAddress = wallet.currentReceiveAddress();
> // one of
> > my friend
> > > think this line is making this issue
> > >
> > > Transaction transaction = wallet.sendCoinsOffline(request);
> > > TransactionPoolManager.addTransaction(transaction); //
> > addTransaction is a
> > > method in TransactioPoolManager service
> > > walletStoreService.saveWallet(wallet); // saves the
> wallet object
> > > transactionHash = request.tx.getHashAsString();
> > > return transactionHash;
> > > } else {
> > > throw new FileNotFoundException("Wallet not found");
> > > }
> > > }
> > >
> > >
> > > addTransaction method in TransactioPoolManager service:
> > >
> > > private static Vector<Entry> transactionPool;
> > >
> > > public static void addTransaction(Transaction tx) {
> > > if (find(tx) != null) {
> > > return;
> > > }
> > > for (Map.Entry<String, Wallet> entry :
> > > walletStoreService.getWalletMap().entrySet()) {
> > > if (entry.getValue().isPendingTransactionRelevant(tx)) {
> > > transactionPool.add(new Entry(entry.getKey(), tx));
> > > break;
> > > }
> > > }
> > > }
> > >
> > > Thanks in advance
> > >
> > > --
> > > You received this message because you are subscribed to
> the Google
> > Groups
> > > "bitcoinj" group.
> > > To unsubscribe from this group and stop receiving emails
> from it,
> > send an
> > > email to [email protected].
> > > For more options, visit
> https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> >
> >
> > --
> > Oscar Guindzberg
> >
> > --
> > You received this message because you are subscribed to the
> Google
> > Groups "bitcoinj" group.
> > To unsubscribe from this group and stop receiving emails from
> it, send
> > an email to [email protected]
> > <mailto:[email protected]>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.