So erstellen Sie eine Rohtransaktion

Ich habe angefangen, meine eigene Brieftasche in Bitcoinj zu erstellen, und ich habe ein ernsthaftes Problem. Ich möchte eine Rohtransaktion ohne Wallet-Objekt erstellen. Also habe ich diesen Code geschrieben:

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

Aber das endet mit:

Mandatory-Script-Verify-Flag-Failed (Skript wurde ohne Fehler ausgewertet, aber mit einem falschen/leeren obersten Stack beendet, z

Was ist falsch an meinem Code?

EDIT: Ich habe eine Lösung gefunden. Ich habe nur diese Zeile geändert: tx.addSignedInput(outPoint, utxo.getScript(), key, Transaction.SigHash.ALL, true);

Leider habe ich diesen Code bereits verwendet :(
Ich glaube, das bedeutet, dass Sie den richtigen öffentlichen Schlüssel angegeben haben, aber die Signatur nicht mit der Transaktion übereinstimmt. Wird die Transaktion zwischen der Unterzeichnung und der Übertragung geändert?
Habe die Lösung bereits gefunden :) Alles wird bearbeitet
Könnten Sie Ihre Lösung bitte in einem Antwortbeitrag beschreiben, anstatt sie in die Frage zu stellen? Vielen Dank.

Antworten (1)

Sicher :)

Meine Lösung war ziemlich einfach:

//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);
Wie entsteht UTXO?
Pawan, du musst es vorher per Listunspent-API-Anfrage abrufen