github.com/gagliardetto/solana-go@v1.11.0/rpc/getSignaturesForAddress.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 GetSignaturesForAddressOpts struct {
    24  	// (optional) Maximum transaction signatures to return (between 1 and 1,000, default: 1,000).
    25  	Limit *int `json:"limit,omitempty"`
    26  
    27  	// (optional) Start searching backwards from this transaction signature.
    28  	// If not provided the search starts from the top of the highest max confirmed block.
    29  	Before solana.Signature `json:"before,omitempty"`
    30  
    31  	// (optional) Search until this transaction signature, if found before limit reached.
    32  	Until solana.Signature `json:"until,omitempty"`
    33  
    34  	// (optional) Commitment; "processed" is not supported.
    35  	// If parameter not provided, the default is "finalized".
    36  	Commitment CommitmentType `json:"commitment,omitempty"`
    37  
    38  	// The minimum slot that the request can be evaluated at.
    39  	// This parameter is optional.
    40  	MinContextSlot *uint64
    41  }
    42  
    43  // GetSignaturesForAddress returns confirmed signatures for transactions
    44  // involving an address backwards in time from the provided signature
    45  // or most recent confirmed block.
    46  //
    47  // NEW: This method is only available in solana-core v1.7 or newer.
    48  // Please use `getConfirmedSignaturesForAddress2` for solana-core v1.6
    49  func (cl *Client) GetSignaturesForAddress(
    50  	ctx context.Context,
    51  	account solana.PublicKey,
    52  ) (out []*TransactionSignature, err error) {
    53  	return cl.GetSignaturesForAddressWithOpts(
    54  		ctx,
    55  		account,
    56  		nil,
    57  	)
    58  }
    59  
    60  // GetSignaturesForAddressWithOpts returns confirmed signatures for transactions
    61  // involving an address backwards in time from the provided signature
    62  // or most recent confirmed block.
    63  //
    64  // NEW: This method is only available in solana-core v1.7 or newer.
    65  // Please use `getConfirmedSignaturesForAddress2` for solana-core v1.6
    66  func (cl *Client) GetSignaturesForAddressWithOpts(
    67  	ctx context.Context,
    68  	account solana.PublicKey,
    69  	opts *GetSignaturesForAddressOpts,
    70  ) (out []*TransactionSignature, err error) {
    71  	params := []interface{}{account}
    72  	if opts != nil {
    73  		obj := M{}
    74  		if opts.Limit != nil {
    75  			obj["limit"] = opts.Limit
    76  		}
    77  		if !opts.Before.IsZero() {
    78  			obj["before"] = opts.Before
    79  		}
    80  		if !opts.Until.IsZero() {
    81  			obj["until"] = opts.Until
    82  		}
    83  		if opts.Commitment != "" {
    84  			obj["commitment"] = opts.Commitment
    85  		}
    86  		if opts.MinContextSlot != nil {
    87  			obj["minContextSlot"] = *opts.MinContextSlot
    88  		}
    89  		if len(obj) > 0 {
    90  			params = append(params, obj)
    91  		}
    92  	}
    93  
    94  	err = cl.rpcClient.CallForInto(ctx, &out, "getSignaturesForAddress", params)
    95  	return
    96  }