2024-07-23 10:57:24 +00:00
|
|
|
import std/options
|
|
|
|
import ../common/protobuf, ../waku_core, ./rpc
|
2024-03-26 17:25:42 +00:00
|
|
|
|
|
|
|
# Codec for EligibilityProof
|
|
|
|
|
2024-07-23 10:57:24 +00:00
|
|
|
proc encode*(epRpc: EligibilityProof): ProtoBuffer =
|
2024-03-26 17:25:42 +00:00
|
|
|
var pb = initProtoBuffer()
|
|
|
|
if epRpc.proofOfPayment.isSome():
|
|
|
|
let proofOfPayment = epRpc.proofOfPayment.get()
|
|
|
|
pb.write3(1, proofOfPayment)
|
|
|
|
else:
|
|
|
|
# there is no proof
|
|
|
|
discard
|
|
|
|
pb
|
|
|
|
|
2024-07-23 10:57:24 +00:00
|
|
|
proc decode*(T: type EligibilityProof, buffer: seq[byte]): ProtobufResult[T] =
|
2024-03-26 17:25:42 +00:00
|
|
|
let pb = initProtoBuffer(buffer)
|
|
|
|
var epRpc = EligibilityProof()
|
|
|
|
var proofOfPayment = newSeq[byte]()
|
|
|
|
if not ?pb.getField(1, proofOfPayment):
|
|
|
|
epRpc.proofOfPayment = none(seq[byte])
|
|
|
|
else:
|
|
|
|
epRpc.proofOfPayment = some(proofOfPayment)
|
|
|
|
ok(epRpc)
|
|
|
|
|
|
|
|
# Codec for EligibilityStatus
|
|
|
|
|
2024-07-23 10:57:24 +00:00
|
|
|
proc encode*(esRpc: EligibilityStatus): ProtoBuffer =
|
2024-03-26 17:25:42 +00:00
|
|
|
var pb = initProtoBuffer()
|
|
|
|
pb.write3(1, esRpc.statusCode)
|
|
|
|
if esRpc.statusDesc.isSome():
|
|
|
|
pb.write3(2, esRpc.statusDesc.get())
|
|
|
|
pb
|
|
|
|
|
2024-07-23 10:57:24 +00:00
|
|
|
proc decode*(T: type EligibilityStatus, buffer: seq[byte]): ProtobufResult[T] =
|
2024-03-26 17:25:42 +00:00
|
|
|
let pb = initProtoBuffer(buffer)
|
|
|
|
var esRpc = EligibilityStatus()
|
|
|
|
# status code
|
|
|
|
var code = uint32(0)
|
|
|
|
if not ?pb.getField(1, code):
|
|
|
|
# status code is mandatory
|
|
|
|
return err(ProtobufError.missingRequiredField("status_code"))
|
|
|
|
else:
|
|
|
|
esRpc.statusCode = code
|
|
|
|
# status description
|
|
|
|
var description = ""
|
|
|
|
if not ?pb.getField(2, description):
|
|
|
|
esRpc.statusDesc = none(string)
|
|
|
|
else:
|
|
|
|
esRpc.statusDesc = some(description)
|
|
|
|
ok(esRpc)
|