package com.ripple.core.types.known.tx.signed;

import com.ripple.core.coretypes.Amount;
import com.ripple.core.coretypes.VariableLength;
import com.ripple.core.coretypes.hash.HalfSha512;
import com.ripple.core.coretypes.hash.Hash256;
import com.ripple.core.coretypes.hash.prefixes.HashPrefix;
import com.ripple.core.coretypes.uint.UInt32;
import com.ripple.core.serialized.enums.TransactionType;
import com.ripple.core.serialized.BytesList;
import com.ripple.core.serialized.MultiSink;
import com.ripple.core.types.known.tx.Transaction;
import com.ripple.crypto.ecdsa.IKeyPair;

public class SignedTransaction {
    public Transaction txn;
    public Hash256 hash;
    public Hash256 signingHash;
    public Hash256 previousSigningHash;
    public String tx_blob;

    public void prepare(IKeyPair keyPair, Amount fee, UInt32 Sequence, UInt32 lastLedgerSequence) {
        VariableLength pubKey = new VariableLength(keyPair.pubBytes());

        // This won't always be specified
        if (lastLedgerSequence != null) {
            txn.put(UInt32.LastLedgerSequence, lastLedgerSequence);
        }
        if (Sequence != null) {
            txn.put(UInt32.Sequence, Sequence);
        }
        if (fee != null) {
            txn.put(Amount.Fee, fee);
        }
        txn.put(VariableLength.SigningPubKey, pubKey);

        if (Transaction.CANONICAL_FLAG_DEPLOYED) {
            txn.setCanonicalSignatureFlag();
        }

        signingHash = txn.signingHash();
        if (previousSigningHash != null && signingHash.equals(previousSigningHash)) {
            return;
        }
        try {
            VariableLength signature = new VariableLength(keyPair.sign(signingHash.bytes()));
            txn.put(VariableLength.TxnSignature, signature);

            BytesList blob = new BytesList();
            HalfSha512 id = HalfSha512.prefixed256(HashPrefix.transactionID);

            txn.toBytesSink(new MultiSink(blob, id));
            tx_blob = blob.bytesHex();
            hash = id.finish();
        } catch (Exception e) {
            // electric paranoia
            previousSigningHash = null;
            throw new RuntimeException(e);
        } /*else {*/
        previousSigningHash = signingHash;
        // }
    }

    public TransactionType transactionType() {
        return txn.transactionType();
    }
}

@@ -606,16 +606,146 @@
 ction %7B%0A
+    public SignedTransaction(Transaction txn) %7B%0A        this.txn = txn;%0A    %7D%0A%0A    @Deprecated%0A    public SignedTransaction() %7B%7D%0A%0A
     publ
@@ -934,37 +934,109 @@
 air,
- Amount fee, UInt32 Sequence,
+%0A                        Amount fee,%0A                        UInt32 Sequence,%0A                       
  UIn
@@ -1057,24 +1057,25 @@
 Sequence) %7B%0A
+%0A
         Vari
@@ -1454,32 +1454,33 @@
 fee);%0A        %7D%0A
+%0A
         txn.put(
@@ -2372,16 +2372,20 @@
 lse %7B*/%0A
+    
         

Add constructor to SignedTransaction