【问题标题】:How to find senders Bitcoin Address in BitcoinJ after receiving a transaction收到交易后如何在BitcoinJ中找到发件人比特币地址
【发布时间】:2016-12-28 15:58:06
【问题描述】:

所以在我的应用中,我有以下接收比特币的功能

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 框架中的一个 textArea,它为我显示一些文本输出。我现在需要做的是在这一点上找到发件人的地址,我可以用 Transaction 对象 tx 做到这一点吗?任何帮助将不胜感激。

【问题讨论】:

    标签: java bitcoin bitcoinj


    【解决方案1】:

    找到了解决办法!不幸的是,它使用了一种折旧的方法。我只是在适当的位置添加了以下内容。

    String address = "";
    for (TransactionInput txin : tx.getInputs()){
        address = txin.getFromAddress().toString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 2017-03-11
      • 2019-05-16
      • 2017-05-03
      • 2015-03-28
      • 1970-01-01
      • 2016-02-08
      相关资源
      最近更新 更多