github.com/stafiprotocol/go-substrate-rpc-client@v1.4.7/client/option_timepoint.go (about)

     1  package client
     2  
     3  import (
     4  	"github.com/stafiprotocol/go-substrate-rpc-client/pkg/scale"
     5  	"github.com/stafiprotocol/go-substrate-rpc-client/types"
     6  )
     7  
     8  type option struct {
     9  	hasValue bool
    10  }
    11  
    12  // IsNone returns true if the value is missing
    13  func (o option) IsNone() bool {
    14  	return !o.hasValue
    15  }
    16  
    17  // IsNone returns true if a value is present
    18  func (o option) IsSome() bool {
    19  	return o.hasValue
    20  }
    21  
    22  type OptionTimePoint struct {
    23  	option
    24  	value types.TimePoint
    25  }
    26  
    27  func NewOptionTimePoint(value types.TimePoint) *OptionTimePoint {
    28  	return &OptionTimePoint{option{true}, value}
    29  }
    30  
    31  func NewOptionTimePointEmpty() *OptionTimePoint {
    32  	return &OptionTimePoint{option: option{false}}
    33  }
    34  
    35  func (o OptionTimePoint) Encode(encoder scale.Encoder) error {
    36  	return encoder.EncodeOption(o.hasValue, o.value)
    37  }
    38  
    39  func (o *OptionTimePoint) Decode(decoder scale.Decoder) error {
    40  	return decoder.DecodeOption(&o.hasValue, &o.value)
    41  }
    42  
    43  // SetSome sets a value
    44  func (o *OptionTimePoint) SetSome(value types.TimePoint) {
    45  	o.hasValue = true
    46  	o.value = value
    47  }
    48  
    49  // SetNone removes a value and marks it as missing
    50  func (o *OptionTimePoint) SetNone() {
    51  	o.hasValue = false
    52  	o.value = types.TimePoint{}
    53  }