BitcoinJ钱包显示错误的平衡

时间:2018-05-03 11:52:55

标签: java bitcoin bitcoinj

我熟悉BitcoinJ。所以现在有一个用户首次注册的功能,应该为他创建地址。但它不起作用。它说已经有了一些钱。

// 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);
}

我在输出中得到了什么:

WALLET: mtrjbnpq5wDzoywrKqod63tpB7ZUFrr7q5
WALLET BALANCE: 1.21503904 BTC

但如果我在区块链中检查此地址,则显示0。 那么如何以正确的方式创建钱包呢?

0 个答案:

没有答案