1

I'm getting familiar with BitcoinJ. So now there is a function for user that registers for the first time and there should be created address for him. But it doesn't work. It says there is already some money.

// USER HAS NEVER USED COIN_ATLAS ( IT IS THE FIRST TIME )
public void addUser()
{
    DBObject dbUser;

    WalletAppKit kit = new WalletAppKit(TestNet3Params.get(), new File("."), "forwarding-service-testnet");
    params = TestNet3Params.get();

    Debug.Log("Wait a bit...");

    kit.startAsync();
    kit.awaitRunning();
    BlockChain chain = null;
    my_wallet = kit.wallet(); // Wallet created for that user

    try {
        chain = new BlockChain(params, my_wallet,
                new MemoryBlockStore(params));
    } catch (BlockStoreException e) {
        e.printStackTrace();
    }

    PeerGroup peerGroup = new PeerGroup(params, chain);
    peerGroup.addPeerDiscovery(new DnsDiscovery(params));
    peerGroup.addWallet(my_wallet);
    peerGroup.startAsync();

    Debug.Log("WALLET: " + my_wallet.currentReceiveAddress());
    Debug.Log("WALLET BALANCE: " + my_wallet.getBalance().toFriendlyString());

    my_wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction transaction, Coin coin, Coin coin1) {
            send("NEW TRANSACTION:");
            sendWithMarkdown("FROM: " + wallet.currentReceiveAddress() + " : " + bold(coin1.toFriendlyString()));

            Coin value = transaction.getValueSentToMe(wallet);
            System.out.println("Received tx for " + value.toFriendlyString() + ": " + transaction);

            Futures.addCallback(transaction.getConfidence().getDepthFuture(1), new FutureCallback<TransactionConfidence>() {
                @Override
                public void onSuccess(@Nullable TransactionConfidence transactionConfidence) {
                    send(bold("Transaction confirmed!"));
                    send(bold(value.toFriendlyString() + " is deposited!"));
                }

                @Override
                public void onFailure(Throwable throwable) {

                }
            });
        }
    });

    peerGroup.downloadBlockChain();
    peerGroup.stopAsync();

    dbUser = new BasicDBObject("_id", bot_user.getId())
            .append("firstName", bot_user.getFirstName())
            .append("password", bot_user.getPassword())
            .append("address", my_wallet.currentReceiveAddress().toString())
            .append("BTC", (double)my_wallet.getBalance().getValue());


    collection.insert(dbUser);
}

There is what I get in output:

WALLET: mtrjbnpq5wDzoywrKqod63tpB7ZUFrr7q5
WALLET BALANCE: 1.21503904 BTC

But if I check this address in blockchain, it shows 0. So how to create wallet the right way?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • you probably don't want to give us your wallet ID. delete this question – Philipp Sander May 03 '18 at 11:54
  • 1
    It's painful how you just revealed this information on a public forum. Please for your own sake, delete this question. – Napstablook May 03 '18 at 12:43
  • Bitcoin addresses are designed to be public; google it, and maybe also 'public-key cryptography' for background. Plus this particular address is on testnet (as shown in the code) which does not use real money. But there are probably more people who can help with this Q on bitcoin.stackexchange.com -- I _think_ you can ask a mod to migrate, if not repost with an explanation and link. – dave_thompson_085 May 03 '18 at 13:35

0 Answers0