github.com/gagliardetto/solana-go@v1.11.0/rpc/getStakeActivation.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  // GetStakeActivation returns epoch activation information for a stake account.
    24  func (cl *Client) GetStakeActivation(
    25  	ctx context.Context,
    26  	// Pubkey of stake account to query
    27  	account solana.PublicKey,
    28  
    29  	commitment CommitmentType,
    30  
    31  	// epoch for which to calculate activation details.
    32  	// If parameter not provided, defaults to current epoch.
    33  	epoch *uint64,
    34  ) (out *GetStakeActivationResult, err error) {
    35  	params := []interface{}{account}
    36  	{
    37  		obj := M{}
    38  		if commitment != "" {
    39  			obj["commitment"] = commitment
    40  		}
    41  		if epoch != nil {
    42  			obj["epoch"] = epoch
    43  		}
    44  		if len(obj) > 0 {
    45  			params = append(params, obj)
    46  		}
    47  	}
    48  	err = cl.rpcClient.CallForInto(ctx, &out, "getStakeActivation", params)
    49  	return
    50  }
    51  
    52  type GetStakeActivationResult struct {
    53  	// The stake account's activation state, one of: active, inactive, activating, deactivating.
    54  	State ActivationStateType `json:"state"`
    55  
    56  	// Stake active during the epoch.
    57  	Active uint64 `json:"active"`
    58  
    59  	// Stake inactive during the epoch.
    60  	Inactive uint64 `json:"inactive"`
    61  }
    62  
    63  type ActivationStateType string
    64  
    65  const (
    66  	ActivationStateActive       ActivationStateType = "active"
    67  	ActivationStateInactive     ActivationStateType = "inactive"
    68  	ActivationStateActivating   ActivationStateType = "activating"
    69  	ActivationStateDeactivating ActivationStateType = "deactivating"
    70  )