2

I have created P2SH address and send coins to the address https://www.blocktrail.com/tBTC/address/2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r

Next I want to send coins from 2N8Xu6rNAwssXtP2XPjSTuT2ViWQoPeHr3r address.

How to prepare P2SH transaction and connect it to the output script?

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

Thank you.

bodyfarmer
  • 402
  • 1
  • 7
  • 17
mmm mmm
  • 37
  • 2
  • Hey! have you solved this problem? If yes, would you mind sharing the solution you found please? – hartmut Jul 17 '16 at 08:26

1 Answers1

0

What about the following constructor?

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

Inside the code it speculates over the 'to' address to check if it is multisig and creates the output script appropriately.

fcracker79
  • 1,118
  • 13
  • 26