github.com/gagliardetto/solana-go@v1.11.0/rpc/getInflationReward.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 rpc
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/gagliardetto/solana-go"
    21  )
    22  
    23  type GetInflationRewardOpts struct {
    24  	Commitment CommitmentType
    25  
    26  	// An epoch for which the reward occurs.
    27  	// If omitted, the previous epoch will be used.
    28  	Epoch *uint64
    29  }
    30  
    31  // GetInflationReward returns the inflation / staking reward for a list of addresses for an epoch.
    32  func (cl *Client) GetInflationReward(
    33  	ctx context.Context,
    34  
    35  	// An array of addresses to query.
    36  	addresses []solana.PublicKey,
    37  
    38  	opts *GetInflationRewardOpts,
    39  
    40  ) (out []*GetInflationRewardResult, err error) {
    41  	params := []interface{}{addresses}
    42  	if opts != nil {
    43  		obj := M{}
    44  		if opts.Commitment != "" {
    45  			obj["commitment"] = opts.Commitment
    46  		}
    47  		if opts.Epoch != nil {
    48  			obj["epoch"] = opts.Epoch
    49  		}
    50  		if len(obj) > 0 {
    51  			params = append(params, obj)
    52  		}
    53  	}
    54  	// TODO: check
    55  	err = cl.rpcClient.CallForInto(ctx, &out, "getInflationReward", params)
    56  	return
    57  }
    58  
    59  type GetInflationRewardResult struct {
    60  	// Epoch for which reward occured.
    61  	Epoch uint64 `json:"epoch"`
    62  
    63  	// The slot in which the rewards are effective.
    64  	EffectiveSlot uint64 `json:"effectiveSlot"`
    65  
    66  	// Reward amount in lamports.
    67  	Amount uint64 `json:"amount"`
    68  
    69  	// Post balance of the account in lamports.
    70  	PostBalance uint64 `json:"postBalance"`
    71  
    72  	// Vote account commission when the reward was credited.
    73  	Commission *uint8 `json:"commission,omitempty"`
    74  }