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

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
     2  //
     3  // Copyright 2020 Stafi Protocol
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package types
    18  
    19  import "github.com/stafiprotocol/go-substrate-rpc-client/pkg/scale"
    20  
    21  // OptionH160 is a structure that can store a H160 or a missing value
    22  type OptionH160 struct {
    23  	option
    24  	value H160
    25  }
    26  
    27  // NewOptionH160 creates an OptionH160 with a value
    28  func NewOptionH160(value H160) OptionH160 {
    29  	return OptionH160{option{true}, value}
    30  }
    31  
    32  // NewOptionH160Empty creates an OptionH160 without a value
    33  func NewOptionH160Empty() OptionH160 {
    34  	return OptionH160{option: option{false}}
    35  }
    36  
    37  func (o OptionH160) Encode(encoder scale.Encoder) error {
    38  	return encoder.EncodeOption(o.hasValue, o.value)
    39  }
    40  
    41  func (o *OptionH160) Decode(decoder scale.Decoder) error {
    42  	return decoder.DecodeOption(&o.hasValue, &o.value)
    43  }
    44  
    45  // SetSome sets a value
    46  func (o *OptionH160) SetSome(value H160) {
    47  	o.hasValue = true
    48  	o.value = value
    49  }
    50  
    51  // SetNone removes a value and marks it as missing
    52  func (o *OptionH160) SetNone() {
    53  	o.hasValue = false
    54  	o.value = H160{}
    55  }
    56  
    57  // Unwrap returns a flag that indicates whether a value is present and the stored value
    58  func (o OptionH160) Unwrap() (ok bool, value H160) {
    59  	return o.hasValue, o.value
    60  }
    61  
    62  // OptionH256 is a structure that can store a H256 or a missing value
    63  type OptionH256 struct {
    64  	option
    65  	value H256
    66  }
    67  
    68  // NewOptionH256 creates an OptionH256 with a value
    69  func NewOptionH256(value H256) OptionH256 {
    70  	return OptionH256{option{true}, value}
    71  }
    72  
    73  // NewOptionH256Empty creates an OptionH256 without a value
    74  func NewOptionH256Empty() OptionH256 {
    75  	return OptionH256{option: option{false}}
    76  }
    77  
    78  func (o OptionH256) Encode(encoder scale.Encoder) error {
    79  	return encoder.EncodeOption(o.hasValue, o.value)
    80  }
    81  
    82  func (o *OptionH256) Decode(decoder scale.Decoder) error {
    83  	return decoder.DecodeOption(&o.hasValue, &o.value)
    84  }
    85  
    86  // SetSome sets a value
    87  func (o *OptionH256) SetSome(value H256) {
    88  	o.hasValue = true
    89  	o.value = value
    90  }
    91  
    92  // SetNone removes a value and marks it as missing
    93  func (o *OptionH256) SetNone() {
    94  	o.hasValue = false
    95  	o.value = H256{}
    96  }
    97  
    98  // Unwrap returns a flag that indicates whether a value is present and the stored value
    99  func (o OptionH256) Unwrap() (ok bool, value H256) {
   100  	return o.hasValue, o.value
   101  }
   102  
   103  // OptionH512 is a structure that can store a H512 or a missing value
   104  type OptionH512 struct {
   105  	option
   106  	value H512
   107  }
   108  
   109  // NewOptionH512 creates an OptionH512 with a value
   110  func NewOptionH512(value H512) OptionH512 {
   111  	return OptionH512{option{true}, value}
   112  }
   113  
   114  // NewOptionH512Empty creates an OptionH512 without a value
   115  func NewOptionH512Empty() OptionH512 {
   116  	return OptionH512{option: option{false}}
   117  }
   118  
   119  func (o OptionH512) Encode(encoder scale.Encoder) error {
   120  	return encoder.EncodeOption(o.hasValue, o.value)
   121  }
   122  
   123  func (o *OptionH512) Decode(decoder scale.Decoder) error {
   124  	return decoder.DecodeOption(&o.hasValue, &o.value)
   125  }
   126  
   127  // SetSome sets a value
   128  func (o *OptionH512) SetSome(value H512) {
   129  	o.hasValue = true
   130  	o.value = value
   131  }
   132  
   133  // SetNone removes a value and marks it as missing
   134  func (o *OptionH512) SetNone() {
   135  	o.hasValue = false
   136  	o.value = H512{}
   137  }
   138  
   139  // Unwrap returns a flag that indicates whether a value is present and the stored value
   140  func (o OptionH512) Unwrap() (ok bool, value H512) {
   141  	return o.hasValue, o.value
   142  }
   143  
   144  // OptionHash is a structure that can store a Hash or a missing value
   145  type OptionHash struct {
   146  	option
   147  	value Hash
   148  }
   149  
   150  // NewOptionHash creates an OptionHash with a value
   151  func NewOptionHash(value Hash) OptionHash {
   152  	return OptionHash{option{true}, value}
   153  }
   154  
   155  // NewOptionHashEmpty creates an OptionHash without a value
   156  func NewOptionHashEmpty() OptionHash {
   157  	return OptionHash{option: option{false}}
   158  }
   159  
   160  func (o OptionHash) Encode(encoder scale.Encoder) error {
   161  	return encoder.EncodeOption(o.hasValue, o.value)
   162  }
   163  
   164  func (o *OptionHash) Decode(decoder scale.Decoder) error {
   165  	return decoder.DecodeOption(&o.hasValue, &o.value)
   166  }
   167  
   168  // SetSome sets a value
   169  func (o *OptionHash) SetSome(value Hash) {
   170  	o.hasValue = true
   171  	o.value = value
   172  }
   173  
   174  // SetNone removes a value and marks it as missing
   175  func (o *OptionHash) SetNone() {
   176  	o.hasValue = false
   177  	o.value = Hash{}
   178  }
   179  
   180  // Unwrap returns a flag that indicates whether a value is present and the stored value
   181  func (o OptionHash) Unwrap() (ok bool, value Hash) {
   182  	return o.hasValue, o.value
   183  }