Exemplo n.º 1
0
        public void Indexed_attestation_there_and_back()
        {
            AttestationData data = new AttestationData();

            data.Slot            = new Slot(1);
            data.CommitteeIndex  = new CommitteeIndex(2);
            data.BeaconBlockRoot = Sha256.OfAnEmptyString;
            data.Source          = new Checkpoint(new Epoch(1), Sha256.OfAnEmptyString);
            data.Target          = new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString);

            IndexedAttestation container = new IndexedAttestation();

            container.AttestingIndices = new ValidatorIndex[3];
            container.Data             = data;
            container.Signature        = BlsSignature.TestSig1;

            Span <byte> encoded = new byte[IndexedAttestation.SszLength(container)];

            Ssz.Encode(encoded, container);
            IndexedAttestation decoded = Ssz.DecodeIndexedAttestation(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Exemplo n.º 2
0
        public static void Encode(Span <byte> span, IndexedAttestation container)
        {
            if (span.Length != IndexedAttestation.SszLength(container))
            {
                ThrowTargetLength <IndexedAttestation>(span.Length, IndexedAttestation.SszLength(container));
            }

            int offset        = 0;
            int dynamicOffset = IndexedAttestation.SszDynamicOffset;

            Encode(span, container.AttestingIndices, ref offset, ref dynamicOffset);
            Encode(span, container.Data, ref offset);
            Encode(span, container.Signature, ref offset);
        }
Exemplo n.º 3
0
        public static void Encode(Span <byte> span, AttesterSlashing?container)
        {
            if (span.Length != AttesterSlashing.SszLength(container))
            {
                ThrowTargetLength <AttesterSlashing>(span.Length, AttesterSlashing.SszLength(container));
            }

            if (container == null)
            {
                return;
            }

            int dynamicOffset = 2 * VarOffsetSize;
            int length1       = IndexedAttestation.SszLength(container.Attestation1);

            Encode(span.Slice(0, VarOffsetSize), dynamicOffset);
            Encode(span.Slice(dynamicOffset, length1), container.Attestation1);

            dynamicOffset += IndexedAttestation.SszLength(container.Attestation1);
            int length2 = IndexedAttestation.SszLength(container.Attestation2);

            Encode(span.Slice(VarOffsetSize, VarOffsetSize), dynamicOffset);
            Encode(span.Slice(dynamicOffset, length2), container.Attestation2);
        }