estoy tratando de gastar las monedas en un p2sh
primero, genero p2sh y envío monedas a ese p2sh
ECKey clientKey = new ECKey();
ECKey serverKey = new ECKey();
ECKey thirdPartyKey = new ECKey();
List<ECKey> keys = ImmutableList.of(clientKey, serverKey,thirdPartyKey);
Script multisigScript = ScriptBuilder.createP2SHOutputScript(2, keys);
String address = multisigScript.getToAddress(params).toString();
luego envío monedas a la "dirección" en testnet3
segundo, uso la billetera en bitcoinj para ver la "dirección" y obtener el tx
WalletAppKit walletAppKit = new WalletAppKit(params, new File("./btcWallet"), "test");
walletAppKit.startAsync();
walletAppKit.awaitRunning();
Wallet walletTemp = walletAppKit.wallet();
Address watchAddress = Address.fromString(params, "2NGY4n3Wc2iftWufhUg2MzZtccbkQWgdUiz");
walletTemp.addWatchedAddress(watchAddress,1576573079);
Set<Transaction> transSet = walletTemp.getTransactions(false);
tercero, después de obtener el tx y la salida, quiero gastarlo
TransactionOutput out = ...//output that the second step i get from the tx
Script scriptOut = out.getScriptPubKey()
Coin outValue = Coin.valueOf(10000);
Script redeemScript = ScriptBuilder.createRedeemScript(2, keys);
Address sendAddress = LegacyAddress.fromBase58(params, "2N6846hvswyZEdJ5DuEcjQZPaT5Xwb6PdGT");
Transaction spendTx = new Transaction(params);
spendTx.addOutput(outValue, sendAddress);
TransactionInput input = spendTx.addInput(out);
Sha256Hash sighash = spendTx.hashForSignature(0, redeemScript, Transaction.SigHash.ALL,
false);
ECKey.ECDSASignature cSignature = clientKey.sign(sighash);
ECKey.ECDSASignature sSignature = serverKey.sign(sighash);
TransactionSignature cTransactionSignature = new TransactionSignature(cSignature, Transaction.SigHash.ALL,
false);
TransactionSignature sTransactionSignature = new TransactionSignature(sSignature, Transaction.SigHash.ALL,
false);
Script inputScript = ScriptBuilder.createP2SHMultiSigInputScript(ImmutableList.of(cTransactionSignature, sTransactionSignature), scriptOut);
input.setScriptSig(inputScript);
input.verify(out);
tiene un error en "input.verify(out);",Script resulted in a non-true stack: [] [3044022043d0cdddb087c4db2937a3b656c37bf240fd95e16714125c0672875bb18b4c1902200f96e1ec0adc2258e324cbacba598cb72d502a4e3185212dea40c50b365d3fb901] []
No sé dónde está mal mi código y cómo resolverlo.
encuentre un problema similar, pero no el mismo [1]: Errores al construir/enviar transacciones multisig
Según su ejemplo, parece que está firmando el mismo sighash dos veces, por lo que solo parece una clave firmada.
Este ejemplo podría ayudar: https://github.com/magmahindenburg/MultisigExamples/blob/master/src/se/moar/bitcoin/multisig/MultisigPresentation.java
// Sign the first part of the transaction using private key #1
Sha256Hash sighash = spendTx.hashForSignature(0, redeemScript, Transaction.SigHash.ALL, false);
ECKey.ECDSASignature ecdsaSignature = key1.sign(sighash);
TransactionSignature transactionSignarture = new TransactionSignature(ecdsaSignature, Transaction.SigHash.ALL, false);
// Create the sighash2 using the redeem script
Sha256Hash sighash2 = spendTx.hashForSignature(0, redeemScript, Transaction.sighash2.ALL, false);
ECKey.ECDSASignature secondSignature;
// Take out the key and sign the signhash
ECKey key2 = createKeyFromSha256Passphrase("Super secret key 2");
secondSignature = key2.sign(sighash2);
// Add the second signature to the signature list
TransactionSignature transactionSignarture = new TransactionSignature(secondSignature, Transaction.sighash2.ALL, false);
signatureList.add(transactionSignarture);
// Rebuild p2sh multisig input script
inputScript = ScriptBuilder.createP2SHMultiSigInputScript(signatureList, redeemScript);
spendTx.getInput(0).setScriptSig(inputScript);
System.out.println(byteArrayToHex(spendTx.bitcoinSerialize()));
m1xolyd1an
sighash
dos veces, por lo que solo parece una clave firmada.pez pequeño