From 276e3917d08f4cf0134ae222ac81a10a2e275965 Mon Sep 17 00:00:00 2001 From: chirag-parmar Date: Mon, 28 Oct 2024 12:45:20 +0530 Subject: [PATCH] remove deprecated support for Option --- eth/common/base_rlp.nim | 21 ++++----------------- eth/rlp.nim | 13 ------------- eth/rlp/options.nim | 29 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/eth/common/base_rlp.nim b/eth/common/base_rlp.nim index d4c9f46..339d425 100644 --- a/eth/common/base_rlp.nim +++ b/eth/common/base_rlp.nim @@ -7,30 +7,17 @@ {.push raises: [].} -import std/typetraits, ./base, ../rlp +import + std/typetraits, ./base, ../rlp, + ../rlp/options as rlp_options -export base, rlp +export base, rlp, rlp_options -# TODO why is rlp serialization of `Opt` here and not in rlp? -proc append*[T](w: var RlpWriter, val: Opt[T]) = - mixin append - - if val.isSome: - w.append(val.get()) - else: - w.append("") template read*[T](rlp: var Rlp, val: var T) = mixin read val = rlp.read(type val) -proc read*[T](rlp: var Rlp, val: var Opt[T]) {.raises: [RlpError].} = - mixin read - if rlp.blobLen != 0: - val = Opt.some(rlp.read(T)) - else: - rlp.skipElem - proc read*(rlp: var Rlp, T: type StUint): T {.raises: [RlpError].} = if rlp.isBlob: let bytes = rlp.toBytes diff --git a/eth/rlp.nim b/eth/rlp.nim index f01214f..610e767 100644 --- a/eth/rlp.nim +++ b/eth/rlp.nim @@ -448,9 +448,6 @@ func readImpl( else: rlp.bytes.len() - template getUnderlyingType[T](_: Option[T]): untyped = - T - template getUnderlyingType[T](_: Opt[T]): untyped = T @@ -458,16 +455,6 @@ func readImpl( type FieldType {.used.} = type field when hasCustomPragmaFixed(RecordType, fieldName, rlpCustomSerialization): field = rlp.read(result, FieldType) - elif field is Option: - # this works for optional fields at the end of an object/tuple - # if the optional field is followed by a mandatory field, - # custom serialization for a field or for the parent object - # will be better - type UT = getUnderlyingType(field) - if rlp.position < payloadEnd: - field = some(rlp.read(UT)) - else: - field = none(UT) elif field is Opt: # this works for optional fields at the end of an object/tuple # if the optional field is followed by a mandatory field, diff --git a/eth/rlp/options.nim b/eth/rlp/options.nim index f67b454..546c39e 100644 --- a/eth/rlp/options.nim +++ b/eth/rlp/options.nim @@ -1,17 +1,20 @@ -import - std/options, - ../rlp +import ../rlp +import results -proc read*[T](rlp: var Rlp, O: type Option[T]): O {.inline.} = - mixin read - if not rlp.isEmpty: - result = some read(rlp, T) +proc append*[T](w: var RlpWriter, val: Opt[T]) = + mixin append -proc append*(writer: var RlpWriter, value: Option) = - if value.isSome: - writer.append value.get + if val.isSome: + w.append(val.get()) else: - writer.append "" + w.append("") -export - options, rlp +proc read*[T](rlp: var Rlp, val: var Opt[T]) {.raises: [RlpError].} = + mixin read + if rlp.blobLen != 0: + val = Opt.some(rlp.read(T)) + else: + rlp.skipElem + +export + rlp, results