コード例 #1
0
        /// <summary>Publish a signed block.</summary>
        /// <param name="beacon_block">The `BeaconBlock` object, as sent from the beacon node originally, but now with the signature field completed.</param>
        /// <returns>The block was validated successfully and has been broadcast. It has also been integrated into the beacon node's database.</returns>
        public async Task Block2Async(BeaconBlock beacon_block)
        {
            if (_logger.IsInfo())
            {
                Log.BlockPublished(_logger, beacon_block.Slot,
                                   Bytes.ToHexString(beacon_block.Body.Randao_reveal),
                                   beacon_block.Parent_root, beacon_block.State_root,
                                   Bytes.ToHexString(beacon_block.Body.Graffiti),
                                   beacon_block.Signature, null);
            }

            Core2.Containers.BeaconBlock signedBlock = new Core2.Containers.BeaconBlock(
                new Slot((ulong)beacon_block.Slot),
                new Hash32(Bytes.FromHexString(beacon_block.Parent_root)),
                new Hash32(Bytes.FromHexString(beacon_block.State_root)),
                new Core2.Containers.BeaconBlockBody(
                    new BlsSignature(beacon_block.Body.Randao_reveal),
                    new Eth1Data(
                        new Hash32(beacon_block.Body.Eth1_data.Deposit_root),
                        (ulong)beacon_block.Body.Eth1_data.Deposit_count,
                        new Hash32(beacon_block.Body.Eth1_data.Block_hash)
                        ),
                    new Bytes32(beacon_block.Body.Graffiti),
                    beacon_block.Body.Proposer_slashings.Select(x => new ProposerSlashing(
                                                                    new ValidatorIndex((ulong)x.Proposer_index),
                                                                    MapBeaconBlockHeader(x.Header_1),
                                                                    MapBeaconBlockHeader(x.Header_2)
                                                                    )),
                    beacon_block.Body.Attester_slashings.Select(x => new AttesterSlashing(
                                                                    MapIndexedAttestation(x.Attestation_1),
                                                                    MapIndexedAttestation(x.Attestation_2)
                                                                    )),
                    beacon_block.Body.Attestations.Select(x =>
                                                          new Core2.Containers.Attestation(
                                                              new BitArray(x.Aggregation_bits),
                                                              MapAttestationData(x.Data),
                                                              new BlsSignature(x.Signature)
                                                              )
                                                          ),
                    beacon_block.Body.Deposits.Select(x =>
                                                      new Core2.Containers.Deposit(
                                                          x.Proof.Select(y => new Hash32(y)),
                                                          new DepositData(
                                                              new BlsPublicKey(x.Data.Pubkey),
                                                              new Hash32(x.Data.Withdrawal_credentials),
                                                              new Gwei((ulong)x.Data.Amount),
                                                              new BlsSignature(x.Data.Signature)
                                                              )
                                                          )
                                                      ),
                    beacon_block.Body.Voluntary_exits.Select(x =>
                                                             new Core2.Containers.VoluntaryExit(
                                                                 new Epoch((ulong)x.Epoch),
                                                                 new ValidatorIndex((ulong)x.Validator_index),
                                                                 new BlsSignature((x.Signature))
                                                                 )
                                                             )
                    ),
                new BlsSignature(Bytes.FromHexString(beacon_block.Signature))
                );

            bool acceptedLocally = await _beaconNode.PublishBlockAsync(signedBlock, CancellationToken.None);

            // TODO: return 200 or 202 based on whether accepted locally or not
        }
コード例 #2
0
 public Task Block2Async(BeaconBlock body)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
ファイル: BeaconNodeOApi.cs プロジェクト: fosfuan/nethermind
 public System.Threading.Tasks.Task Block2([Microsoft.AspNetCore.Mvc.FromQuery] BeaconBlock beacon_block)
 {
     return(_implementation.Block2Async(beacon_block));
 }