私はJavaウォレットの生成コードを書きました。私は暗号化ウォレットを生成するためにこれを使用します。コードが提供されたエンティティがまだ発生している間に、POSTリクエスト後にNULLが返される
public synchronized WalletInfo generateAddress(GenerateWallet generateWallet) {
final WalletInfo walletInfo = new WalletInfo();
String walletName = generateWallet.getWalletName();
String currencyName = generateWallet.getCurrencyName();
WalletInfo walletInfoDb = iWalletInfoDao.getWalletInfoWithWalletNameAndCurrency(walletName, currencyName);
if (walletInfoDb == null && genWalletMap.get(walletName) == null) {
String currency = currencyName.toUpperCase();
if (currency.equals("BITCOIN")) {
final WalletManager walletManager = WalletManager.setupWallet(walletName);
walletManager.addWalletSetupCompletedListener((wallet) -> {
Address address = wallet.currentReceiveAddress();
WalletInfo newWallet = createWalletInfo(walletName, currencyName, address.toString());
// set the properties of the walletInfo
// the instance is final and can work inside the lambda expression
walletInfo.setId(newWallet.getId());
walletInfo.setName(newWallet.getName());
walletInfo.setAddress(newWallet.getAddress());
walletInfo.setCurrency(newWallet.getCurrency());
walletMangersMap.put(newWallet.getId(), walletManager);
genWalletMap.remove(walletName);
});
genWalletMap.put(walletName, walletManager);
return walletInfo;
} else if (currency.equals("ETHEREUM")) {
return walletInfo;
} else {
return walletInfo;
}
}
return walletInfo;
}
私はcURL
、
curl -H "Content-Type: application/json" -X POST -d '{"walletName": "Florence8","currencyName":"Bitcoin"}' http://localhost:8080/rest/wallet/generateAddress
を使用してPOST
要求を行うと、私はnull
を取得するには、
{
"id" : null,
"name" : null,
"address" : null,
"currency" : null
}
リターンですMySQLで永続化されました。
私はデバッグを続けており、これは配線されています。デバッグはコードのtop-to-bottom
のシーケンスに従いません。デバッグのシーケンスは、コードはそれが必要この行walletManager.addWalletSetupCompletedListener((wallet)
に来る場合、私は意味
、同様です内部で操作を実行しますか?
任意のsugesstionデータベースに正しく保持された後、どのようにエンティティを元に戻すことができますか?
コードを[mcve]に切り落としてください。 –
'walletInfo'を' final'にするのはどうですか? –
'walletInfo'は最終的なものではないという上記の理由はありません。 '= new WalletInfo()'を削除して、次の行に上書きします。これを1行にまとめます。 'final WalletInfo walletInfo = iWalletInfoDao/* ...* /; 'また、' if(walletInfo == null) 'ブランチで' walletInfo'のメソッドを呼び出すことには意味がありません。これはNPEを投げることになります。 –