Esempio n. 1
0
        /// <summary>
        /// Creates a deep copy of the object.
        /// </summary>
        public static BeaconState Clone(BeaconState other)
        {
            var clone = new BeaconState(
                other.GenesisTime,
                other.Slot,
                other.Fork,
                BeaconBlockHeader.Clone(other.LatestBlockHeader),
                other.BlockRoots.ToArray(),
                other.StateRoots.ToArray(),
                other.HistoricalRoots.ToArray(),
                Eth1Data.Clone(other.Eth1Data),
                other.Eth1DataVotes.Select(x => Eth1Data.Clone(x)).ToList(),
                other.Eth1DepositIndex,
                other.Validators.Select(x => Validator.Clone(x)).ToList(),
                other.Balances.Select(x => x).ToList(),
                other.RandaoMixes.Select(x => x).ToArray(),
                other.Slashings.Select(x => x).ToArray(),
                other.PreviousEpochAttestations.Select(x => PendingAttestation.Clone(x)).ToList(),
                other.CurrentEpochAttestations.Select(x => PendingAttestation.Clone(x)).ToList(),
                new BitArray(other.JustificationBits),
                Checkpoint.Clone(other.PreviousJustifiedCheckpoint),
                Checkpoint.Clone(other.CurrentJustifiedCheckpoint),
                Checkpoint.Clone(other.FinalizedCheckpoint)
                );

            return(clone);
        }
Esempio n. 2
0
 public bool Equals(PendingAttestation other)
 {
     return(Bytes.AreEqual(AggregationBits, other.AggregationBits) &&
            Equals(Data, other.Data) &&
            InclusionDelay == other.InclusionDelay &&
            ProposerIndex == other.ProposerIndex);
 }
Esempio n. 3
0
        public static int SszLength(BeaconState?container)
        {
            if (container is null)
            {
                return(0);
            }

            int result = SszDynamicOffset;

            result += Hash32.SszLength * (container.HistoricalRoots?.Length ?? 0);
            result += Validator.SszLength * (container.Validators?.Length ?? 0);
            result += Gwei.SszLength * (container.Balances?.Length ?? 0);
            result += Eth1Data.SszLength * (container.Eth1DataVotes?.Length ?? 0);

            result += (container.PreviousEpochAttestations?.Length ?? 0) * sizeof(uint);
            if (!(container.PreviousEpochAttestations is null))
            {
                for (int i = 0; i < container.PreviousEpochAttestations.Length; i++)
                {
                    result += PendingAttestation.SszLength(container.PreviousEpochAttestations[i]);
                }
            }

            result += (container.CurrentEpochAttestations?.Length ?? 0) * sizeof(uint);
            if (!(container.CurrentEpochAttestations is null))
            {
                for (int i = 0; i < container.CurrentEpochAttestations.Length; i++)
                {
                    result += PendingAttestation.SszLength(container.CurrentEpochAttestations[i]);
                }
            }

            return(result);
        }
Esempio n. 4
0
        public static int SszLength(PendingAttestation value)
        {
            if (value == null)
            {
                return(0);
            }

            return(SszDynamicOffset + value.AggregationBits.Length);
        }
Esempio n. 5
0
        public static PendingAttestation Clone(PendingAttestation other)
        {
            var clone = new PendingAttestation(
                new BitArray(other.AggregationBits),
                AttestationData.Clone(other.Data),
                other.InclusionDelay,
                other.ProposerIndex);

            return(clone);
        }
Esempio n. 6
0
        public bool Equals(PendingAttestation other)
        {
            if (!Equals(Data, other.Data) ||
                InclusionDelay != other.InclusionDelay ||
                ProposerIndex != other.ProposerIndex ||
                AggregationBits.Length != other.AggregationBits.Length)
            {
                return(false);
            }

            for (int index = 0; index < AggregationBits.Length; index++)
            {
                if (AggregationBits[index] != other.AggregationBits[index])
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 7
0
        public static int SszLength(BeaconState container)
        {
            int result = SszDynamicOffset;

            result += Sha256.SszLength * container.HistoricalRoots.Length;
            result += Validator.SszLength * container.Validators.Length;
            result += Gwei.SszLength * container.Balances.Length;
            result += Eth1Data.SszLength * container.Eth1DataVotes.Length;

            result += container.PreviousEpochAttestations.Length * sizeof(uint);
            for (int i = 0; i < container.PreviousEpochAttestations.Length; i++)
            {
                result += PendingAttestation.SszLength(container.PreviousEpochAttestations[i]);
            }

            result += container.CurrentEpochAttestations.Length * sizeof(uint);
            for (int i = 0; i < container.CurrentEpochAttestations.Length; i++)
            {
                result += PendingAttestation.SszLength(container.CurrentEpochAttestations[i]);
            }

            return(result);
        }
Esempio n. 8
0
 public void AddPreviousAttestation(PendingAttestation attestation) =>
 _previousEpochAttestations.Add(attestation);
Esempio n. 9
0
 public void AddCurrentAttestation(PendingAttestation attestation) => _currentEpochAttestations.Add(attestation);