2016-08-22 28 views
2

所以接收交易接受比特币如何在我的应用程序

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

这个伟大的工程,我有以下功能后发现比特币在BitcoinJ地址发件人的onSuccess正确触发,一旦交易被确认并添加到我的钱包。 txtLog只是我的java框架中的textArea,它为我显示了一些文本输出。我现在需要做的是找到发件人的地址,我可以用Transaction对象tx来做这件事吗?任何帮助,将不胜感激。

回答

1

找到解决方案!不幸的是,它使用了折旧方法。我在适当的地方添加了以下内容。

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