Empecé a crear mi propia billetera en bitcoinj y tengo un problema grave. Quiero crear una transacción sin formato sin objeto de billetera. Así que escribí este fragmento de código:
//String to a private key
DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params,
privKey);
ECKey key = dumpedPrivateKey.getKey();
//String to an address
Address address2 = Address.fromBase58(params, address);
Transaction tx = new Transaction(params);
//value is a sum of all inputs, fee is 4013
tx.addOutput(Coin.valueOf(amount-4013), address2);
//utxos is an array of inputs from my wallet
for(UTXO utxo : utxos)
{
TransactionOutPoint outPoint = new TransactionOutPoint(params, utxo.getIndex(), utxo.getHash());
tx.addSignedInput(outPoint, utxo.getScript(), key);
}
tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
tx.setPurpose(Transaction.Purpose.USER_PAYMENT);
System.out.println(tx.getHashAsString());
b_peerGroup.GetPeerGroup().broadcastTransaction(tx);
Pero esto termina con:
obligatorio-script-verify-flag-failed (Script evaluado sin error pero terminado con una pila superior falsa/vacía)
¿Qué está mal con mi código?
EDITAR: Encontré una solución. Solo he cambiado esta línea: tx.addSignedInput(outPoint, utxo.getScript(), key, Transaction.SigHash.ALL, true);
Por supuesto :)
Mi solución fue bastante simple:
//String to a private key
DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params,
privKey);
ECKey key = dumpedPrivateKey.getKey();
//String to an address
Address address2 = Address.fromBase58(params, address);
Transaction tx = new Transaction(params);
//value is a sum of all inputs, fee is 4013
tx.addOutput(Coin.valueOf(amount-4013), address2);
//utxos is an array of inputs from my wallet
for(UTXO utxo : utxos)
{
TransactionOutPoint outPoint = new TransactionOutPoint(params, utxo.getIndex(), utxo.getHash());
//YOU HAVE TO CHANGE THIS
tx.addSignedInput(outPoint, utxo.getScript(), key, Transaction.SigHash.ALL, true);
}
tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
tx.setPurpose(Transaction.Purpose.USER_PAYMENT);
System.out.println(tx.getHashAsString());
b_peerGroup.GetPeerGroup().broadcastTransaction(tx);
hartmut
Dragomiro
Nick ODell
Dragomiro
muro