2015-04-22 168 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并适当地创建输出脚本。