Exemple #1
0
        public async Task <(Event ev, Exception err)> ReadWireInfo(WireEvent wev)
        {
            var       selfParent  = "";
            var       otherParent = "";
            Exception err;

            var creator      = ReverseParticipants[wev.Body.CreatorId];
            var creatorBytes = creator.FromHex();

            if (wev.Body.SelfParentIndex >= 0)
            {
                (selfParent, err) = await 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) = await Store.ParticipantEvent(otherParentCreator, wev.Body.OtherParentIndex);

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

            var body = new EventBody
            {
                Transactions    = wev.Body.Transactions,
                BlockSignatures = wev.BlockSignatures(creatorBytes),
                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,
                Signiture = wev.Signiture
            };

            return(ev, null);
        }
Exemple #2
0
        public void TestWireEvent()
        {
            var privateKey = CryptoUtils.GenerateEcdsaKey();

            var publicKeyBytes = CryptoUtils.FromEcdsaPub(privateKey);

            var body = CreateDummyEventBody();

            body.Creator = publicKeyBytes;

            var ev = new Event {
                Body = body
            };

            ev.Sign(privateKey);

            ev.SetWireInfo(1, 66, 2, 67);

            var expectedWireEvent = new WireEvent
            {
                Body = new WireBody
                {
                    Transactions         = ev.Body.Transactions,
                    SelfParentIndex      = 1,
                    OtherParentCreatorId = 66,
                    OtherParentIndex     = 2,
                    CreatorId            = 67,
                    Timestamp            = ev.Body.Timestamp,
                    Index           = ev.Body.Index,
                    BlockSignatures = ev.WireBlockSignatures()
                },
                Signiture = ev.Signiture
            };

            var wireEvent = ev.ToWire();

            wireEvent.ShouldCompareTo(expectedWireEvent);
        }