github.com/gagliardetto/solana-go@v1.11.0/rpc/getSupply.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  // GetSupply returns information about the current supply.
    24  func (cl *Client) GetSupply(ctx context.Context, commitment CommitmentType) (out *GetSupplyResult, err error) {
    25  	return cl.GetSupplyWithOpts(ctx, &GetSupplyOpts{Commitment: commitment})
    26  }
    27  
    28  // GetSupply returns information about the current supply.
    29  func (cl *Client) GetSupplyWithOpts(
    30  	ctx context.Context,
    31  	opts *GetSupplyOpts,
    32  ) (out *GetSupplyResult, err error) {
    33  	obj := M{
    34  		"commitment": CommitmentConfirmed,
    35  	}
    36  	if opts != nil {
    37  		if opts.Commitment != "" {
    38  			obj["commitment"] = opts.Commitment
    39  		}
    40  		obj["excludeNonCirculatingAccountsList"] = opts.ExcludeNonCirculatingAccountsList
    41  	}
    42  
    43  	err = cl.rpcClient.CallForInto(ctx, &out, "getSupply", []interface{}{obj})
    44  	return
    45  }
    46  
    47  type GetSupplyOpts struct {
    48  	Commitment CommitmentType `json:"commitment,omitempty"`
    49  
    50  	ExcludeNonCirculatingAccountsList bool `json:"excludeNonCirculatingAccountsList,omitempty"` // exclude non circulating accounts list from response
    51  }
    52  
    53  type GetSupplyResult struct {
    54  	RPCContext
    55  	Value *SupplyResult `json:"value"`
    56  }
    57  
    58  type SupplyResult struct {
    59  	// Total supply in lamports
    60  	Total uint64 `json:"total"`
    61  
    62  	// Circulating supply in lamports.
    63  	Circulating uint64 `json:"circulating"`
    64  
    65  	// Non-circulating supply in lamports.
    66  	NonCirculating uint64 `json:"nonCirculating"`
    67  
    68  	// An array of account addresses of non-circulating accounts.
    69  	// If `excludeNonCirculatingAccountsList` is enabled, the returned array will be empty.
    70  	NonCirculatingAccounts []solana.PublicKey `json:"nonCirculatingAccounts"`
    71  }