public Bencodex.Types.Dictionary ToBencodex() { var preEvalHeaderDict = BlockMarshaler.MarshalPreEvaluationBlockHeader( BlockMarshaler.MarshalBlockMetadata(_metadata), _nonce, _preEvaluationHash ?? ImmutableArray <byte> .Empty ); Dictionary headerDict = BlockMarshaler.MarshalBlockHeader( preEvalHeaderDict, StateRootHash, Signature, Hash ); var dict = Bencodex.Types.Dictionary.Empty.Add(HeaderKey, headerDict); if (TxIds.Any()) { dict = dict.Add( TransactionIdsKey, TxIds.Select(txId => (IValue)(Binary)txId.ToArray())); } return(dict); }
public void MarshalBlockMetadata() { AssertBencodexEqual( _marshaledGenesisMetadata, BlockMarshaler.MarshalBlockMetadata(_fx.Genesis) ); AssertBencodexEqual( _marshaledNextMetadata, BlockMarshaler.MarshalBlockMetadata(_fx.Next) ); AssertBencodexEqual( _marshaledHasTxMetadata, BlockMarshaler.MarshalBlockMetadata(_fx.HasTx) ); AssertBencodexEqual( Dictionary.Empty .Add(IndexKey, 0L) .Add(TimestampKey, "2021-09-06T04:46:39.123000Z") .Add(DifficultyKey, 0L) .Add(TotalDifficultyKey, 0) .Add(MinerKey, _content.BlockPv0.Miner.ByteArray), BlockMarshaler.MarshalBlockMetadata(_content.BlockPv0) ); AssertBencodexEqual( Dictionary.Empty .Add(ProtocolVersionKey, 1) .Add(IndexKey, 1L) .Add(PreviousHashKey, _content.BlockPv1.PreviousHash?.ByteArray ?? default) .Add(TimestampKey, "2021-09-06T08:01:09.045000Z") .Add(DifficultyKey, 123L) .Add(TotalDifficultyKey, 123) .Add(MinerKey, _content.BlockPv1.Miner.ByteArray) .Add(TxHashKey, _content.BlockPv1.TxHash?.ByteArray ?? default), BlockMarshaler.MarshalBlockMetadata(_content.BlockPv1) ); }