所以在我的应用程序中,我有以下接收比特币的功能
kit.wallet().addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
txtLog.append("-----> coins resceived: " + tx.getHashAsString() + "\n");
txtLog.append("received: " + tx.getValue(wallet) + "\n");
Futures.addCallback(tx.getConfidence().getDepthFuture(1), new FutureCallback<TransactionConfidence>() {
@Override
public void onSuccess(TransactionConfidence result) {
txtLog.append("\nSuccess! Recieved: " + tx.getValue(wallet) + "\n");
//Find address of sender here
}
@Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
}
});
}
});
效果很好,OnSuccess 会在确认交易并添加到我的钱包后正确触发。 txtLog 只是我的 java 框架中的一个文本区域,它为我显示一些文本输出。我现在需要做的是在这一点上找到发件人的地址,我可以用交易对象 tx 做到这一点吗?任何帮助将不胜感激。
最佳答案
找到解决方案!不幸的是,它使用了一种贬值的方法。我只是在适当的位置添加了以下内容。
String address = "";
for (TransactionInput txin : tx.getInputs()){
address = txin.getFromAddress().toString();
}
关于java - 收到交易后如何在BitcoinJ中找到发件人比特币地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39073780/