mirror of https://github.com/status-im/nim-eth.git
remove deprecated support for Option
This commit is contained in:
parent
72a88720c4
commit
276e3917d0
|
@ -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
|
||||
|
|
13
eth/rlp.nim
13
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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue