コード例 #1
0
        public static int BeaconBlockBodyLength(BeaconBlockBody?container)
        {
            if (container is null)
            {
                return(0);
            }

            int result = BeaconBlockBodyDynamicOffset;

            result += Ssz.ProposerSlashingLength * container.ProposerSlashings.Count;
            result += Ssz.DepositLength() * container.Deposits.Count;
            result += Ssz.VoluntaryExitLength * container.VoluntaryExits.Count;

            result += sizeof(uint) * container.AttesterSlashings.Count;
            for (int i = 0; i < container.AttesterSlashings.Count; i++)
            {
                result += Ssz.AttesterSlashingLength(container.AttesterSlashings[i]);
            }

            result += sizeof(uint) * container.Attestations.Count;
            for (int i = 0; i < container.Attestations.Count; i++)
            {
                result += Ssz.AttestationLength(container.Attestations[i]);
            }

            return(result);
        }
コード例 #2
0
        public static void Encode(Span <byte> span, AttesterSlashing[] containers)
        {
            int offset        = 0;
            int dynamicOffset = containers.Length * VarOffsetSize;

            for (int i = 0; i < containers.Length; i++)
            {
                int currentLength = Ssz.AttesterSlashingLength(containers[i]);
                Encode(span.Slice(offset, VarOffsetSize), dynamicOffset);
                Encode(span.Slice(dynamicOffset, currentLength), containers[i]);
                offset        += VarOffsetSize;
                dynamicOffset += currentLength;
            }
        }
コード例 #3
0
        private static void Encode(Span <byte> span, AttesterSlashing[] containers, ref int offset, ref int dynamicOffset)
        {
            int length = containers.Length * VarOffsetSize;

            for (int i = 0; i < containers.Length; i++)
            {
                length += Ssz.AttesterSlashingLength(containers[i]);
            }

            Encode(span.Slice(offset, VarOffsetSize), dynamicOffset);
            Encode(span.Slice(dynamicOffset, length), containers);
            dynamicOffset += length;
            offset        += VarOffsetSize;
        }
コード例 #4
0
        private static void Encode(Span <byte> span, BeaconBlockBody container, ref int offset)
        {
            // Semantics of Encode = write container into span at offset, then increase offset by the bytes written

            // Static
            int dynamicOffset = Ssz.BeaconBlockBodyDynamicOffset;

            Encode(span, container.RandaoReveal, ref offset);
            Encode(span, container.Eth1Data, ref offset);
            Encode(span, container.Graffiti.AsSpan().ToArray(), ref offset);

            Encode(span, dynamicOffset, ref offset);
            int proposerSlashingsLength = container.ProposerSlashings.Count * Ssz.ProposerSlashingLength;

            dynamicOffset += proposerSlashingsLength;

            Encode(span, dynamicOffset, ref offset);
            int attesterSlashingsLength = container.AttesterSlashings.Sum(x => Ssz.AttesterSlashingLength(x) + VarOffsetSize);

            dynamicOffset += attesterSlashingsLength;

            Encode(span, dynamicOffset, ref offset);
            dynamicOffset += container.Attestations.Sum(x => Ssz.AttestationLength(x) + VarOffsetSize);

            Encode(span, dynamicOffset, ref offset);
            int depositsLength = container.Deposits.Count * Ssz.DepositLength();

            dynamicOffset += depositsLength;

            Encode(span, dynamicOffset, ref offset);
            int voluntaryExitsLength = container.VoluntaryExits.Count * Ssz.VoluntaryExitLength;

            dynamicOffset += voluntaryExitsLength;

            // Dynamic
            Encode(span.Slice(offset, proposerSlashingsLength), container.ProposerSlashings.ToArray());
            offset += proposerSlashingsLength;

            Encode(span.Slice(offset, attesterSlashingsLength), container.AttesterSlashings.ToArray());
            offset += attesterSlashingsLength;

            Encode(span, container.Attestations, ref offset);

            Encode(span.Slice(offset, depositsLength), container.Deposits.ToArray());
            offset += depositsLength;

            EncodeList(span, container.VoluntaryExits, ref offset);
        }
コード例 #5
0
        public static void Encode(Span <byte> span, AttesterSlashing?container)
        {
            if (span.Length != Ssz.AttesterSlashingLength(container))
            {
                ThrowTargetLength <AttesterSlashing>(span.Length, Ssz.AttesterSlashingLength(container));
            }

            if (container == null)
            {
                return;
            }

            int dynamicOffset = 2 * VarOffsetSize;
            int length1       = Ssz.IndexedAttestationLength(container.Attestation1);

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

            dynamicOffset += Ssz.IndexedAttestationLength(container.Attestation1);
            int length2 = Ssz.IndexedAttestationLength(container.Attestation2);

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