Example #1
0
        public static ConsensusMessage DeserializeFrom(byte[] data)
        {
            ConsensusMessage message = ReflectionCache.CreateInstance <ConsensusMessage>(data[0]);

            if (message == null)
            {
                throw new FormatException();
            }

            using (MemoryStream ms = new MemoryStream(data, false))
                using (BinaryReader r = new BinaryReader(ms))
                {
                    message.Deserialize(r);
                }
            return(message);
        }
            public static PreparationPayloadCompact FromPayload(ConsensusPayload payload)
            {
                byte[]           StateRootSignature = Array.Empty <byte>();
                ConsensusMessage message            = payload.ConsensusMessage;

                if (message is PrepareRequest req)
                {
                    StateRootSignature = req.StateRootSignature;
                }
                else if (message is PrepareResponse resp)
                {
                    StateRootSignature = resp.StateRootSignature;
                }
                return(new PreparationPayloadCompact
                {
                    ValidatorIndex = payload.ValidatorIndex,
                    InvocationScript = payload.Witness.InvocationScript,
                    StateRootSignature = StateRootSignature
                });
            }