예제 #1
0
        public (Event ev, Exception err) ReadWireInfo(WireEvent wev)
        {
            var selfParent  = "";
            var otherParent = "";

            var creator = ReverseParticipants[wev.Body.CreatorId];

            var(creatorBytes, err) = creator.Substring(3).StringToBytesWithErr();

            if (err != null)
            {
                return(null, err);
            }

            if (wev.Body.SelfParentIndex >= 0)
            {
                (selfParent, err) = Store.ParticipantEvent(creator, wev.Body.SelfParentIndex);
                if (err != null)
                {
                    return(null, err);
                }
            }

            if (wev.Body.OtherParentIndex >= 0)
            {
                var otherParentCreator = ReverseParticipants[wev.Body.OtherParentCreatorId];
                (otherParent, err) = Store.ParticipantEvent(otherParentCreator, wev.Body.OtherParentIndex);
                if (err != null)
                {
                    return(null, err);
                }
            }

            var body = new EventBody
            {
                Transactions = wev.Body.Transactions,
                Parents      = new[] { selfParent, otherParent },
                Creator      = creatorBytes,
                Timestamp    = wev.Body.Timestamp,
                Index        = wev.Body.Index,
            };


            body.SetSelfParentIndex(wev.Body.SelfParentIndex);
            body.SetOtherParentCreatorId(wev.Body.OtherParentCreatorId);
            body.SetOtherParentIndex(wev.Body.OtherParentIndex);
            body.SetCreatorId(wev.Body.CreatorId);

            var ev = new Event
            {
                Body = body,
            };

            ev.SetSigniture(wev.Signiture);
            return(ev, null);
        }
예제 #2
0
        public Event(byte[][] transactions, string[] parents, byte[] creator, int index)
        {
            var body = new EventBody
            {
                Transactions = transactions,
                Parents      = parents,
                Creator      = creator,
                Timestamp    = DateTime.UtcNow, //strip monotonic time
                Index        = index
            };

            Body = body;
        }