Re: Transaction Fee - getInputSum() / getFee()

2017-07-10 Thread Wladimir Filho
So this is a limitation of Bitcoinj, I can solve this by abandoning this 
dependency and using instead the bitcoin core project itself, correct?

On Monday, 10 July 2017 17:30:17 UTC-3, Andreas Schildbach wrote:
>
> It's a limitation of the Bitcoin protocol, inputs do not have value it's 
> their connected output. In bitcoinj, only the Wallet class connects the 
> inputs to their outputs; since you probably don't use the Wallet you 
> likely need to do the connecting yourself. 
>
>
> On 07/06/2017 05:54 PM, Wladimir Filho wrote: 
> > Hi, I'm developing a block explorer in java using BITCOINJ version 
> 0.14.4. 
> > 
> > There is a problem that can not be answered on the internet or in the 
> > forum, I can not access information in the Transaction Input as the fee 
> > or sum of the inputs. I tried to use the *SPVBlockStore* to 
> > *MySQLFullPrunedBlockStore* for a complete copy of the blockchain, even 
> > though the information remains "hidden". 
> > 
> > I need this information to develop services like: 
> > 
> > https://blockchain.info   |   https://live.blockcypher.com   | 
> >   https://blockexplorer.com/ 
> > 
> > Below is part of the application code: 
> > 
> > 
> > | 
> > 
> > 
> > 
> > 
> publicstaticMySQLFullPrunedBlockStorecreateStore(NetworkParametersparams,intblockCount)
>  
>
> > 
> >throwsBlockStoreException{ 
> > 
> >   
> > 
>  
> returnnewMySQLFullPrunedBlockStore(params,blockCount,DB_HOSTNAME,DB_NAME,DB_USERNAME,DB_PASSWORD);
>  
>
> > 
> > } 
> > 
> > 
> > privatestaticNetworkParametersnetworkParameters 
> =TestNet3Params.get(); 
> > 
> > 
> > publicstaticvoidmain(String[]args)throwsException { 
> > 
> > 
> >  MySQLFullPrunedBlockStorechainStore 
> > =createStore(networkParameters,1000); 
> > 
> >  FullPrunedBlockChainchain 
> > =newFullPrunedBlockChain(networkParameters,chainStore); 
> > 
> > 
> >  PeerGrouppeerGroup =newPeerGroup(networkParameters,chain); 
> > 
> >peerGroup.addPeerDiscovery(newDnsDiscovery(networkParameters)); 
> > 
> > 
> > 
> >  BlockDownloadedManagerblockDM =newBlockDownloadedManager(); 
> > 
> > 
> >  peerGroup.startAsync(); 
> > 
> > peerGroup.addBlocksDownloadedEventListener(blockDM); 
> > 
> > peerGroup.downloadBlockChain(); 
> > 
> > blockDEL.wait(); 
> > 
> > 
> > 
> >  peerGroup.stop();   
> > 
> > } 
> > 
> > 
> > 
> > 
> publicclassBlockDownloadedManagerimplementsBlocksDownloadedEventListener{ 
> > 
> >   
> > 
> >@Override 
> > 
> >   
> > 
>  
> publicvoidonBlocksDownloaded(Peerpeer,Blockblock,FilteredBlockfilteredBlock,intblocksLeft){
>  
>
> > 
> >   
> > 
> System.out.println("-");
>  
>
> > 
> >   System.out.println("hash - "+block.getHashAsString()); 
> > 
> >   System.out.println("transactions numer - 
> > "+block.getTransactions().size()); 
> > 
> > 
> > 
> >blockDetail(block); 
> > 
> >} 
> > 
> > 
> >staticvoidblockDetail(Blockblock){ 
> > 
> >  Listtx_list =block.getTransactions(); 
> > 
> > 
> >   for(Transactiont :tx_list){ 
> > 
> > System.out.println("hash - "+t.getHashAsString()); 
> > 
> > System.out.println("input sum -"+t.getInputSum()); 
> > 
> >System.out.println("output sum -"+t.getOutputSum()); 
> > 
> >System.out.println("fee calc - 
> > 
> "+(t.getInputSum().getValue()>0?t.getInputSum().getValue()-t.getOutputSum().getValue():0));
>  
>
> > 
> > System.out.println("fee -"+t.getFee()); 
> > 
> > System.out.println("size - "+t.getMessageSize()); 
> > 
> >  } 
> > 
> >} 
> > 
> > } 
> > 
> > 
> > | 
> > 
> > 
> > 
> > 
> > *LOGS:* 
> > 
> > 
> > 
> -
>  
>
> > 
> > hash - e95fbedad07b7f95fa56e95ba11ed40f6a9f4b74fa2e0ce128ff6a42 
> > 
> > transactions numer - 1 
> > 
> > hash - d2e1049b895946525eb480070bcf678d94f709d6d621d79415dacb5ce73ac9db 
> > 
> > input sum -0 
> > 
> > output sum -50 
> > 
> > fee calc - 0 
> > 
> > fee -null 
> > 
> > size - 96 
> > 
> > 
> -
>  
>
> > 
> > hash - 409087525f6977c2634e636509e20bc61bc1c6e86eb6d17a394d7a7a 
> > 
> > transactions numer - 2 
> > 
> > hash - 1b93146ca6ec328b8f9e976fd49cd8dd4b74f2c1277807c75e941991948701bb 
> > 
> > input sum -0 
> > 
> > output sum -50 
> > 
> > fee calc - 0 
> > 
> > fee -null 
> > 
> > size - 96 
> > 
> > hash - e2e5b1e29596105817b74f50cfde585baeeddb6125f9e03e8a22858def9293f2 
> > 
> > input sum -0 
> > 
> > output sum -49 
> > 
> > fee calc - 0 
> > 
> > fee -null 
> > 
> > size - 192 
> > 
> > 
> -
>  
>
> > 
> > hash - 

Re: Transaction Fee - getInputSum() / getFee()

2017-07-10 Thread Andreas Schildbach
It's a limitation of the Bitcoin protocol, inputs do not have value it's
their connected output. In bitcoinj, only the Wallet class connects the
inputs to their outputs; since you probably don't use the Wallet you
likely need to do the connecting yourself.


On 07/06/2017 05:54 PM, Wladimir Filho wrote:
> Hi, I'm developing a block explorer in java using BITCOINJ version 0.14.4. 
> 
> There is a problem that can not be answered on the internet or in the
> forum, I can not access information in the Transaction Input as the fee
> or sum of the inputs. I tried to use the *SPVBlockStore* to
> *MySQLFullPrunedBlockStore* for a complete copy of the blockchain, even
> though the information remains "hidden".
> 
> I need this information to develop services like:
> 
> https://blockchain.info   |   https://live.blockcypher.com   |
>   https://blockexplorer.com/
> 
> Below is part of the application code:
> 
> 
> |
> 
> 
>
> publicstaticMySQLFullPrunedBlockStorecreateStore(NetworkParametersparams,intblockCount)
> 
>throwsBlockStoreException{
> 
>  
>  
> returnnewMySQLFullPrunedBlockStore(params,blockCount,DB_HOSTNAME,DB_NAME,DB_USERNAME,DB_PASSWORD);
> 
> }
> 
> 
> privatestaticNetworkParametersnetworkParameters =TestNet3Params.get();
> 
> 
> publicstaticvoidmain(String[]args)throwsException {
> 
> 
>  MySQLFullPrunedBlockStorechainStore
> =createStore(networkParameters,1000);
> 
>  FullPrunedBlockChainchain
> =newFullPrunedBlockChain(networkParameters,chainStore);
> 
> 
>  PeerGrouppeerGroup =newPeerGroup(networkParameters,chain);
> 
>peerGroup.addPeerDiscovery(newDnsDiscovery(networkParameters));
> 
> 
> 
>  BlockDownloadedManagerblockDM =newBlockDownloadedManager();
> 
> 
>  peerGroup.startAsync();
> 
> peerGroup.addBlocksDownloadedEventListener(blockDM);
> 
> peerGroup.downloadBlockChain();
> 
> blockDEL.wait();
> 
> 
> 
>  peerGroup.stop();   
> 
> }
> 
> 
> 
> publicclassBlockDownloadedManagerimplementsBlocksDownloadedEventListener{
> 
>  
> 
>@Override
> 
>  
>  
> publicvoidonBlocksDownloaded(Peerpeer,Blockblock,FilteredBlockfilteredBlock,intblocksLeft){
> 
>  
> System.out.println("-");
> 
>   System.out.println("hash - "+block.getHashAsString());
> 
>   System.out.println("transactions numer -
> "+block.getTransactions().size()); 
> 
>
> 
>blockDetail(block);
> 
>}
> 
> 
>staticvoidblockDetail(Blockblock){
> 
>  Listtx_list =block.getTransactions();
> 
> 
>   for(Transactiont :tx_list){
> 
> System.out.println("hash - "+t.getHashAsString());
> 
> System.out.println("input sum -"+t.getInputSum());
> 
>System.out.println("output sum -"+t.getOutputSum());
> 
>System.out.println("fee calc -
> "+(t.getInputSum().getValue()>0?t.getInputSum().getValue()-t.getOutputSum().getValue():0));
> 
> System.out.println("fee -"+t.getFee());
> 
> System.out.println("size - "+t.getMessageSize());
> 
>  }
> 
>}
> 
> }
> 
> 
> |
> 
> 
> 
> 
> *LOGS:*
> 
> 
> -
> 
> hash - e95fbedad07b7f95fa56e95ba11ed40f6a9f4b74fa2e0ce128ff6a42
> 
> transactions numer - 1
> 
> hash - d2e1049b895946525eb480070bcf678d94f709d6d621d79415dacb5ce73ac9db
> 
> input sum -0
> 
> output sum -50
> 
> fee calc - 0
> 
> fee -null
> 
> size - 96
> 
> -
> 
> hash - 409087525f6977c2634e636509e20bc61bc1c6e86eb6d17a394d7a7a
> 
> transactions numer - 2
> 
> hash - 1b93146ca6ec328b8f9e976fd49cd8dd4b74f2c1277807c75e941991948701bb
> 
> input sum -0
> 
> output sum -50
> 
> fee calc - 0
> 
> fee -null
> 
> size - 96
> 
> hash - e2e5b1e29596105817b74f50cfde585baeeddb6125f9e03e8a22858def9293f2
> 
> input sum -0
> 
> output sum -49
> 
> fee calc - 0
> 
> fee -null
> 
> size - 192
> 
> -
> 
> hash - d986f90a094b707e9ef4bf412d9a2a14df872e9409ddca7e0865bde6
> 
> transactions numer - 2
> 
> hash - 5ccf7e3494f5f05398b04f6bb3a72b635b2de6c494572c3e2078c8d89532abb3
> 
> input sum -0
> 
> output sum -55
> 
> fee calc - 0
> 
> fee -null
> 
> size - 96
> 
> hash - 23cc5dadd87f91c1fdce9c0ad090ce8f6e7fd7f79834ad1e579cd5a952c7c6b1
> 
> input sum -0
> 
> output sum -4904431364
> 
> fee calc - 0
> 
> fee -null
> 
> size - 373
> 
> -
> 
> hash - 4480dd8aa5a351cb8d66fb332496f4d54c97fb87584322ab05342144
> 
> transactions numer - 1
> 
> hash - 848771ee8e27418ec8af0c08ecfa61d6af230dfd6ab25809f5792565b4f57b85
> 
> input sum -0
> 
> output sum -50
> 
> fee calc - 0
> 
> fee -null
> 
> 

Re: Filtering out watched txs

2017-07-10 Thread Andreas Schildbach
There is currently no way to have bitcoinj filter the list of
transactions, you'll have to do that yourself ATM.

We always envisioned having a second, more usecase-oriented list of
"payments". This would then represent the list shown to the user.
Lightning payments could be visible there too in future (although LN is
a layer on top, so not sure if it's the right thing). So far, work on
this hasn't started.


On 07/08/2017 09:07 AM, Anton wrote:
> After an LN payment channel is open there is a constant need to monitor
> if it's P2WSH output has been spent, I use `addWatchedScripts` for that
> and it works great. The only UX level problem with this approach is when
> P2WSH output does get spent a user will see a strange spending tx which
> changes nothing in wallet, this may confuse many. 
> 
> So what is needed is a way to filter out purely watched transactions
> before displaying a tx list on a UI. Currently I do this as follows:
> https://github.com/btcontract/bitcoinj/commit/8475c850ef7b5d07ae7b30d605362c2dbea8d0d5,
> the code is based on a fact that a purely watched tx does not change
> wallet's balance so it's `getValue` is 0 when watched outputs and inputs
> are excluded so we can use that when deciding if a given tx should be
> displayed.
> 
> This works but I don't like an approach because it feels hacky
> (`getValue` is essentially duplicated in `getExcludeWatchedValue`),
> perhaps there are much better ways to do that?
> 
> Other simple approaches I was thinking of which won't do:
> 
> - Immediately stop watching a P2WSH output script once it is spent so a
> related watched tx won't be shown anymore (won't do because a peer may
> attempt to spend a P2WSH output multiple times using different commit
> txs which will create a race of double spends and there's no telling
> which of them will win, so we need to continue watching a script even
> after the first spend is seen to react accordingly).
> 
> - Just filter out all txs which contain a watched P2WSH output in their
> inputs (won't do since that will filter out mutual closing tx which does
> spend a P2WSH output but is legitimate since it sends money back to
> user's wallet)
> 
> Thanks!
> 
> -- 
> 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 bitcoinj+unsubscr...@googlegroups.com
> .
> 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 bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: bitcoinj 0.14.4 : Send coin - get callback in receiveCoin too

2017-07-10 Thread Andreas Schildbach
What you probably see is the received change from your transaction. You
could try creating a transaction without change and see if there is an
onCoinsReceived event too.

Also, as always, study the logfile.


On 07/10/2017 04:51 PM, Kunal Ransing wrote:
> Hi
> 
> When I send coins I got callback in broadcastComplete as well
> as onCoinsReceived.
> 
> I added receive listner as below:
> 
>   // We want to know when we receive money.
>   kit.wallet().*addCoinsReceivedEventListener*(new
> *WalletCoinsReceivedEventListener*() {
>   @Override
>   public void *onCoinsReceived*(Wallet w, final Transaction
> tx, Coin prevBalance, Coin newBalance) {
>   Coin value = tx.getValueSentToMe(w);
>  
>   updateTxResult(tx, value, tx.getConfidence());
>   
>  
> Futures.addCallback(tx.getConfidence().getDepthFuture(6), new
> FutureCallback() {
>   @Override
>   public void onSuccess(TransactionConfidence result) 
>   {
> //Updated tx status to confirm when depth become
> 6 block
>   updateTxResult(tx, value,result);
>   }
> 
>   });
>   }
>   });
> 
> 
> I am sending coin using below method :
>   ...
>   Address to = Address.fromBase58("send-address");
>   SendRequest req = SendRequest.to(to, Coin.parseCoin("0.003"));
>   req.aesKey = kit.wallet().getKeyCrypter().deriveKey("--my_key--");
>   req.memo = msg;
>   Wallet.SendResult result = kit.wallet().sendCoins(req);
>   Transaction btcTx = result.tx;
>   Futures.addCallback(result.*broadcastComplete*, new
> FutureCallback() {
>   @Override
>   public void *onSuccess*(org.bitcoinj.core.Transaction resTx) 
>   {
>   //Send message to core that Mark tx as completed
>   }
> 
>   @Override
>   public void onFailure(Throwable t) {
> LOGGER.log(Level.INFO,"PayConfig_sendCoin: Something went
> wrong !!!",t);
>   }
>   });
>   ...
> 
> When I sent coin 0.003 BTC to my mobile wallet from my backend app, I
> receive 0.000812 BTC(i.e got call in *onCoinsReceivedfor all sent of
> different coin i receive this same amount*)...also got call
> in *onSuccess*  where fees for sending coin is 0.000188 BTC.
> 
> Please help me to understand this ?
> 
> Regards,
> Kunal
> 
> 
> 
> -- 
> 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 bitcoinj+unsubscr...@googlegroups.com
> .
> 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 bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


bitcoinj 0.14.4 : Send coin - get callback in receiveCoin too

2017-07-10 Thread Kunal Ransing
Hi

When I send coins I got callback in broadcastComplete as well 
as onCoinsReceived.

I added receive listner as below:

  // We want to know when we receive money.
  kit.wallet().*addCoinsReceivedEventListener*(new 
*WalletCoinsReceivedEventListener*() {
  @Override
  public void *onCoinsReceived*(Wallet w, final Transaction tx, 
Coin prevBalance, Coin newBalance) {
  Coin value = tx.getValueSentToMe(w);
 
  updateTxResult(tx, value, tx.getConfidence());
  
  Futures.addCallback(tx.getConfidence().getDepthFuture(6), 
new FutureCallback() {
  @Override
  public void onSuccess(TransactionConfidence result) 
  {
//Updated tx status to confirm when depth become 6 
block
  updateTxResult(tx, value,result);
  }

  });
  }
  });


I am sending coin using below method :
  ...
  Address to = Address.fromBase58("send-address");
  SendRequest req = SendRequest.to(to, Coin.parseCoin("0.003"));
  req.aesKey = kit.wallet().getKeyCrypter().deriveKey("--my_key--");
  req.memo = msg;
  Wallet.SendResult result = kit.wallet().sendCoins(req);
  Transaction btcTx = result.tx;
  Futures.addCallback(result.*broadcastComplete*, new 
FutureCallback() {
  @Override
  public void *onSuccess*(org.bitcoinj.core.Transaction resTx) 
  {
  //Send message to core that Mark tx as completed
  }

  @Override
  public void onFailure(Throwable t) {
LOGGER.log(Level.INFO,"PayConfig_sendCoin: Something went wrong 
!!!",t);
  }
  });
  ...

When I sent coin 0.003 BTC to my mobile wallet from my backend app, I 
receive 0.000812 BTC(i.e got call in *onCoinsReceivedfor all sent of 
different coin i receive this same amount*)...also got call in *onSuccess*  
where fees for sending coin is 0.000188 BTC.

Please help me to understand this ?

Regards,
Kunal



-- 
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 bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.