2015-04-22 55 views
3

我已經創建P2SH地址和發送硬幣我想從2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r地址發送硬幣地址 https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3rbitcoinj P2SH輸入交易連接到輸出交易

下一步。

如何準備P2SH事務並將其連接到輸出腳本?

public static void sendFromP2SH(WalletAppKit kit, Address destAdd, Coin coin) throws AddressFormatException, InsufficientMoneyException, ExecutionException, InterruptedException { 
    Transaction tx = new Transaction(TestNet3Params.get()); 
    tx.addOutput(coin, destAdd); //prepare destination output 


    Wallet.SendRequest req = Wallet.SendRequest.forTx(tx); 

    //TODO prepare P2SH input for output //https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r 
    Script script = P2SHScript(kit); //2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r 
    TransactionOutput t = null;//... HOW TO CONNECT P2SH input transaction to the output ? 
    tx.addInput(t); 

    kit.wallet().completeTx(req); 
    kit.wallet().commitTx(req.tx); 
    kit.peerGroup().broadcastTransaction(req.tx).get(); 
} 

    prepare script for the P2SH address 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r 
     public static Script P2SHScript(WalletAppKit kit) { 
      ECKey pubClientKey = kit.wallet().getImportedKeys().get(0); 
      ECKey pubServerKey = kit.wallet().getImportedKeys().get(1); 
      return ScriptBuilder.createP2SHOutputScript(1, ImmutableList.of(pubClientKey, pubServerKey)); 
     } 

謝謝。

+0

嘿!你解決了這個問題嗎?如果是,請介意分享您找到的解決方案嗎? – hartmut

回答

1

下面的構造函數呢?

public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, Address to) 

在代碼中,它推測'to'地址以檢查它是否是multisig並適當地創建輸出腳本。