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); }
public static void Encode(Span <byte> span, Attestation container) { if (span.Length != Ssz.AttestationLength(container)) { ThrowTargetLength <Attestation>(span.Length, Ssz.AttestationLength(container)); } int offset = 0; int dynamicOffset = Ssz.AttestationDynamicOffset; Encode(span, container.AggregationBits, ref offset, ref dynamicOffset); Encode(span, container.Data, ref offset); Encode(span, container.Signature, ref offset); }
public static void Encode(Span <byte> span, Attestation[] containers) { int offset = 0; int dynamicOffset = containers.Length * VarOffsetSize; for (int i = 0; i < containers.Length; i++) { int currentLength = Ssz.AttestationLength(containers[i]); Encode(span.Slice(offset, VarOffsetSize), dynamicOffset); Encode(span.Slice(dynamicOffset, currentLength), containers[i]); offset += VarOffsetSize; dynamicOffset += currentLength; } }
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); }
private static void Encode(Span <byte> span, Attestation?[]?attestations, ref int offset, ref int dynamicOffset) { int length = (attestations?.Length ?? 0) * VarOffsetSize; if (!(attestations is null)) { for (int i = 0; i < attestations.Length; i++) { length += Ssz.AttestationLength(attestations[i]); } } Encode(span.Slice(offset, VarOffsetSize), dynamicOffset); Encode(span.Slice(dynamicOffset, length), attestations); dynamicOffset += length; offset += VarOffsetSize; }
private static void Encode(Span <byte> span, IReadOnlyList <Attestation> attestations, ref int offset) { // Semantics of Encode = write container into span at offset, then increase offset by the bytes written // Static int staticOffset = offset; int dynamicOffset = attestations.Count * VarOffsetSize; offset += dynamicOffset; foreach (Attestation attestation in attestations) { int length = Ssz.AttestationLength(attestation); Encode(span, dynamicOffset, ref staticOffset); dynamicOffset += length; Encode(span.Slice(offset, length), attestation); offset += length; } }