package org.bitcoinj.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;

/**
 * Created by Hash Engineering on 2/20/2015.
 */
public class MasternodeSignature extends ChildMessage {
    private static final Logger log = LoggerFactory.getLogger(MasternodeSignature.class);

    byte [] bytes;

    MasternodeSignature(NetworkParameters params)
    {
        super(params);
    }

    public MasternodeSignature(NetworkParameters params, byte[] payload, int offset) throws ProtocolException {
        super(params, payload, offset);
    }

    /*public MasternodeSignature(NetworkParameters params, byte[] payloadBytes, int cursor, Message parent, boolean parseLazy, boolean parseRetain)
    {
        super(params, payloadBytes, cursor, parent, parseLazy, parseRetain, payloadBytes.length);
    }*/

    public MasternodeSignature(byte [] signature)
    {
        super(Context.get().getParams());
        bytes = new byte[signature.length];
        System.arraycopy(signature, 0, bytes, 0, signature.length);
    }

    protected static int calcLength(byte[] buf, int offset) {
        VarInt varint;

        int cursor = offset;// + 4;
        varint = new VarInt(buf, cursor);
        long len = varint.value;
        len += varint.getOriginalSizeInBytes();
        cursor += len;

        return cursor - offset;
    }

    public int calculateMessageSizeInBytes()
    {
        return VarInt.sizeOf(bytes.length) + bytes.length;
    }
    @Override
    protected void parse() throws ProtocolException {

        cursor = offset;

        bytes = readByteArray();

        length = cursor - offset;
    }
    @Override
    protected void bitcoinSerializeToStream(OutputStream stream) throws IOException {

        stream.write(new VarInt(bytes.length).encode());
        stream.write(bytes);
    }

    public String toString()
    {
        return "sig: " + Utils.HEX.encode(bytes);

    }

    public byte [] getBytes() { return bytes; }

    public boolean equals(Object o)
    {
       MasternodeSignature key = (MasternodeSignature)o;
        if(key.bytes.length == this.bytes.length)
        {
            if(Arrays.equals(key.bytes, this.bytes) == true)
                return true;
        }
        return false;
    }

    MasternodeSignature duplicate()
    {
        MasternodeSignature copy = new MasternodeSignature(params, getBytes(), 0);

        return copy;
    }

}

@@ -1101,24 +1101,243 @@
 th);%0A    %7D%0A%0A
+    public MasternodeSignature(MasternodeSignature other) %7B%0A        super(other.getParams());%0A        bytes = new byte%5Bother.bytes.length%5D;%0A        System.arraycopy(other.bytes, 0, bytes, 0, other.bytes.length);%0A    %7D%0A%0A
     protecte
@@ -2188,22 +2188,42 @@
 .encode(
+Utils.reverseBytes(
 bytes)
+)
 ;%0A%0A    %7D
@@ -2715,10 +2715,82 @@
 %0A    %7D%0A%0A
+    public boolean isEmpty() %7B%0A        return bytes.length == 0;%0A    %7D%0A%0A
 %7D%0A

Add contructor, modify toString, add isEmpty