novitski / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 0 forks source link

Wallet does not show any balance inside Tomcat container #508

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have very simple piece of code, which I'm trying to run as a standalone J2SE 
application and also inside Tomcat container within my Spring MVC application. 
When run as a J2SE, everything is OK and wallet.toString() shows also ">>> 
UNSPENT: " part with transactions. But when I run the same piece of code in my 
controller, this part is missing (ie there are no transactions). My blockchain 
is fully synchronized - getChainHead() returns correct value; I also tried add 
allowSpendingUnconfirmedTransactions(), but without results. I'm using 
0.11-SNAPSHOT. You can see my controller code at http://pastebin.com/NALShkXe

Original issue reported on code.google.com by shmo...@gmail.com on 2 Jan 2014 at 9:58

GoogleCodeExporter commented 9 years ago
From Augie:

Hi,

This is regarding the path were your wallet is physically located. I understand 
that you can see the wallet content on your standalone application. However, in 
tomcat(development) the wallet is in tomcat temporary deployed directory. 
Please check how your wallet's been saved and access.

regards,
Augie 

Original comment by hearn@google.com on 5 Jan 2014 at 2:24

GoogleCodeExporter commented 9 years ago
Hi, thanks for reply!
  Sure think I checked wallet in there, it was my bad - I've been adding addresses with no transactions, so nothing displayed (which I'm going to understand why, when whole blockchain was redownloaded). What I'm trying achieve is a watching-only-wallet, where I can put addresses and check ballance etc (maybe more on my question at SO http://stackoverflow.com/questions/20913350/watch-address-with-bitcoinj ). Is this possible with bitcoinj? Is there some example on that? Thanks :)

Original comment by shmo...@gmail.com on 5 Jan 2014 at 4:21

GoogleCodeExporter commented 9 years ago
The balance is zero because you can't spend outputs whose keys you don't know, 
obviously. So that's working as intended.

Could you provide the precise API call you are making, what you expect it to 
produce, what it actually produces, and a dump of the wallet please 
(wallet.toString)

Original comment by mh.in.en...@gmail.com on 5 Jan 2014 at 4:59

GoogleCodeExporter commented 9 years ago
I don't want to spend that balance, I'd just like to see it. I'd like to write 
following methods:

int balance getBalanceAtAddress(String address){}
Collection<Script> getAllTransactionsForAddress(String address){}

which returns expected output - real balance at specified address and all 
transactions for that address since genesis. Take for example this address: 
http://blockexplorer.com/testnet/address/mu695DfbzahgSq8sPPLihNJq6u2ggrHgaH - 
there is some balance and 8 transactions (6 received). When I do simple call 
and printout:

Wallet wallet = kit.wallet(); 
wallet.addWatchedAddress(address);
wallet.clearTransactions(0);
System.out.println(wallet.toString());

it prints 0 transactions and 0 balance ( http://pastebin.com/23X7N980 ). Is 
there a way to achieve this?

Original comment by shmo...@gmail.com on 6 Jan 2014 at 9:37

GoogleCodeExporter commented 9 years ago
After clearing the transactions you need to replay the wallet. See the code in 
WalletAppKit for that. Then you'll have to wait while the node you're 
connecting to (presumably your own node) scans through the block chain looking 
for addresses. 

But what you are really asking for is an arbitrary block explorer. As stated in 
the documentation, BitcoinJ does not support that functionality out of the box. 
There is no way to do fast queries for arbitrary addresses. The P2P network 
does not support that, partly because the databases required for it are rather 
large and expensive to maintain. You should query the blockchain.info or 
biteasy.com API's directly.

Original comment by hearn@google.com on 6 Jan 2014 at 1:06

GoogleCodeExporter commented 9 years ago
Thanks, i looked at WalletAppKit, but saw nothing about replaying wallet. Gonna 
look again. I just wanted to avoid APIs of existing services and create my own, 
so it looks like it'll not be so easy :/.

Original comment by shmo...@gmail.com on 7 Jan 2014 at 9:35

GoogleCodeExporter commented 9 years ago
Look at the code that calls clearTransactions and erases the block store file. 
It has to be done BEFORE the network is brought up and the rest of the system 
initialised, so it starts downloading the chain from scratch.

Original comment by hearn@google.com on 7 Jan 2014 at 10:01

GoogleCodeExporter commented 9 years ago
Either I'm blind, or dumb - can you kindly tell me line number ( 
http://pastebin.com/0UXf0bXd ) with that block store file deletion? (in all 
cases I think it does not matter, because I need to add and remove addresses on 
fly so replaying wallet for each action is impossible)

Original comment by shmo...@gmail.com on 7 Jan 2014 at 12:52

GoogleCodeExporter commented 9 years ago
Ah yes. In that case it's irrelevant. You need to load the blocks into an 
indexed database to do that. Take a look at what drvillo is doing on the 
mailing list - and maybe chip in with some code? Alex Lolis has done this for 
biteasy.com (which is based on bitcoinj though the db code is not open source) 
- he will tell you that the resulting databases are large and slow. But if 
that's what you need, then that's what you need.

Original comment by hearn@google.com on 7 Jan 2014 at 1:08

GoogleCodeExporter commented 9 years ago
thanks for answers, project was dropped by customer, so I'll not need it 
anymore. but I'm thinking about own simple project, so we'll see...

Original comment by shmo...@gmail.com on 12 Jan 2014 at 5:20