github.com/gagliardetto/solana-go@v1.11.0/programs/system/accounts.go (about)

     1  // Copyright 2021 github.com/gagliardetto
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package system
    16  
    17  import (
    18  	"encoding/binary"
    19  
    20  	bin "github.com/gagliardetto/binary"
    21  	"github.com/gagliardetto/solana-go"
    22  )
    23  
    24  type NonceAccount struct {
    25  	Version          uint32
    26  	State            uint32
    27  	AuthorizedPubkey solana.PublicKey
    28  	Nonce            solana.PublicKey
    29  	FeeCalculator    FeeCalculator
    30  }
    31  
    32  type FeeCalculator struct {
    33  	LamportsPerSignature uint64
    34  }
    35  
    36  func (obj NonceAccount) MarshalWithEncoder(encoder *bin.Encoder) (err error) {
    37  	err = encoder.WriteUint32(obj.Version, binary.LittleEndian)
    38  	if err != nil {
    39  		return err
    40  	}
    41  	err = encoder.WriteUint32(obj.State, binary.LittleEndian)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	err = encoder.WriteBytes(obj.AuthorizedPubkey[:], false)
    46  	if err != nil {
    47  		return err
    48  	}
    49  	err = encoder.WriteBytes(obj.Nonce[:], false)
    50  	if err != nil {
    51  		return err
    52  	}
    53  	return obj.FeeCalculator.MarshalWithEncoder(encoder)
    54  }
    55  
    56  func (obj *NonceAccount) UnmarshalWithDecoder(decoder *bin.Decoder) (err error) {
    57  	{
    58  		obj.Version, err = decoder.ReadUint32(binary.LittleEndian)
    59  		if err != nil {
    60  			return err
    61  		}
    62  	}
    63  	{
    64  		obj.State, err = decoder.ReadUint32(binary.LittleEndian)
    65  		if err != nil {
    66  			return err
    67  		}
    68  	}
    69  	{
    70  		buf, err := decoder.ReadNBytes(32)
    71  		if err != nil {
    72  			return err
    73  		}
    74  		obj.AuthorizedPubkey = solana.PublicKeyFromBytes(buf)
    75  	}
    76  	{
    77  		buf, err := decoder.ReadNBytes(32)
    78  		if err != nil {
    79  			return err
    80  		}
    81  		obj.Nonce = solana.PublicKeyFromBytes(buf)
    82  	}
    83  	return obj.FeeCalculator.UnmarshalWithDecoder(decoder)
    84  }
    85  
    86  func (obj FeeCalculator) MarshalWithEncoder(encoder *bin.Encoder) (err error) {
    87  	return encoder.WriteUint64(obj.LamportsPerSignature, binary.LittleEndian)
    88  }
    89  
    90  func (obj *FeeCalculator) UnmarshalWithDecoder(decoder *bin.Decoder) (err error) {
    91  	obj.LamportsPerSignature, err = decoder.ReadUint64(binary.LittleEndian)
    92  	return err
    93  }