java - 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。那么如何正确创建钱包呢?
解决方案
推荐阅读
- django - PyTest-fixtures:让数据持久化(Django)
- node.js - 运行 expo start 后 package.json 路径不存在
- python - Python函数:遍历列表并将列表中出现的每个内容添加到字典中
- python - Python+Graphql:KeyError:执行时收到“数据”
- swift - 如何使用 SwiftUI 修复“调用中位置 #1、#2 的额外参数”
- youtube - 从 Discord python API 获取用户的流信息
- php - 从控制器获取数据到控制器ın laravel
- node.js - Electron 的 setTimeout 与 window.setTimeout
- amazon-web-services - 使用 domtoimage 时,AWS 上的特定文件被 CORS 阻止
- python - 从包含字典项的键和嵌套列表的字典创建 Pandas DataFrame