예제 #1
0
        public override void WriteJson(JsonWriter writer, BlockParameter value, JsonSerializer serializer)
        {
            if (value.Type == BlockParameterType.BlockNumber)
            {
                _longConverter.WriteJson(writer, value.BlockNumber, serializer);
                return;
            }

            switch (value.Type)
            {
            case BlockParameterType.Earliest:
                writer.WriteValue("earliest");
                break;

            case BlockParameterType.Latest:
                writer.WriteValue("latest");
                break;

            case BlockParameterType.Pending:
                writer.WriteValue("pending");
                break;

            case BlockParameterType.BlockNumber:
                throw new InvalidOperationException("block number should be handled separately");

            default:
                throw new InvalidOperationException("unknown block parameter type");
            }
        }
예제 #2
0
        public override void WriteJson(JsonWriter writer, BlockParameter value, JsonSerializer serializer)
        {
            if (value.Type == BlockParameterType.BlockNumber)
            {
                _longConverter.WriteJson(writer, value.BlockNumber, serializer);
                return;
            }

            if (value.Type == BlockParameterType.BlockHash)
            {
                if (value.RequireCanonical)
                {
                    writer.WriteStartObject();
                    writer.WriteProperty("requireCanonical", true);
                    writer.WriteProperty("blockHash", value.BlockHash, serializer);
                    writer.WriteEndObject();
                }
                else
                {
                    _keccakConverter.WriteJson(writer, value.BlockHash, serializer);
                }

                return;
            }

            switch (value.Type)
            {
            case BlockParameterType.Earliest:
                writer.WriteValue("earliest");
                break;

            case BlockParameterType.Latest:
                writer.WriteValue("latest");
                break;

            case BlockParameterType.Pending:
                writer.WriteValue("pending");
                break;

            case BlockParameterType.BlockNumber:
                throw new InvalidOperationException("block number should be handled separately");

            case BlockParameterType.BlockHash:
                throw new InvalidOperationException("block hash should be handled separately");

            default:
                throw new InvalidOperationException("unknown block parameter type");
            }
        }