github.com/gagliardetto/solana-go@v1.11.0/rpc/deprecated.go (about)

     1  // Copyright 2021 github.com/gagliardetto
     2  // This file has been modified by github.com/gagliardetto
     3  //
     4  // Copyright 2020 dfuse Platform Inc.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //      http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package rpc
    19  
    20  import (
    21  	"context"
    22  	"fmt"
    23  
    24  	"github.com/gagliardetto/solana-go"
    25  )
    26  
    27  // GetConfirmedBlock returns identity and transaction information about a confirmed block in the ledger.
    28  //
    29  // DEPRECATED: Please use `getBlock` instead.
    30  // This method is expected to be removed in solana-core v1.8
    31  func (cl *Client) GetConfirmedBlock(
    32  	ctx context.Context,
    33  	slot uint64,
    34  ) (out *GetConfirmedBlockResult, err error) {
    35  	return cl.GetConfirmedBlockWithOpts(
    36  		ctx,
    37  		slot,
    38  		nil,
    39  	)
    40  }
    41  
    42  type GetConfirmedBlockOpts struct {
    43  	Encoding solana.EncodingType
    44  
    45  	// Level of transaction detail to return.
    46  	TransactionDetails TransactionDetailsType
    47  
    48  	// Whether to populate the rewards array. If parameter not provided, the default includes rewards.
    49  	Rewards *bool
    50  
    51  	// Desired commitment; "processed" is not supported.
    52  	// If parameter not provided, the default is "finalized".
    53  	Commitment CommitmentType
    54  }
    55  
    56  // GetConfirmedBlock returns identity and transaction information about a confirmed block in the ledger.
    57  //
    58  // DEPRECATED: Please use `getBlock` instead.
    59  // This method is expected to be removed in solana-core v1.8
    60  func (cl *Client) GetConfirmedBlockWithOpts(
    61  	ctx context.Context,
    62  	slot uint64,
    63  	opts *GetConfirmedBlockOpts,
    64  ) (out *GetConfirmedBlockResult, err error) {
    65  
    66  	params := []interface{}{slot}
    67  	if opts != nil {
    68  		obj := M{}
    69  		if opts.Encoding != "" {
    70  			obj["encoding"] = opts.Encoding
    71  		}
    72  		if opts.TransactionDetails != "" {
    73  			obj["transactionDetails"] = opts.TransactionDetails
    74  		}
    75  		if opts.Rewards != nil {
    76  			obj["rewards"] = opts.Rewards
    77  		}
    78  		if opts.Commitment != "" {
    79  			obj["commitment"] = opts.Commitment
    80  		}
    81  		if len(obj) != 0 {
    82  			params = append(params, obj)
    83  		}
    84  	}
    85  
    86  	err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedBlock", params)
    87  	return
    88  }
    89  
    90  // GetConfirmedBlocks returns a list of confirmed blocks between two slots.
    91  //
    92  // The result field will be an array of u64 integers listing confirmed blocks between
    93  // start_slot and either end_slot, if provided, or latest confirmed block, inclusive.
    94  // Max range allowed is 500,000 slots.
    95  //
    96  // DEPRECATED: Please use `getBlocks` instead.
    97  // This method is expected to be removed in solana-core v1.8
    98  func (cl *Client) GetConfirmedBlocks(
    99  	ctx context.Context,
   100  	startSlot uint64,
   101  	endSlot *uint64,
   102  	commitment CommitmentType,
   103  ) (out []uint64, err error) {
   104  
   105  	params := []interface{}{startSlot}
   106  	if endSlot != nil {
   107  		params = append(params, endSlot)
   108  	}
   109  	if commitment != "" {
   110  		params = append(params, M{"commitment": string(commitment)})
   111  	}
   112  
   113  	err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedBlocks", params)
   114  	return
   115  }
   116  
   117  // GetConfirmedBlocksWithLimit returns a list of confirmed blocks starting at the given slot.
   118  //
   119  // DEPRECATED: Please use `getBlocksWithLimit` instead.
   120  // This method is expected to be removed in solana-core v1.8
   121  func (cl *Client) GetConfirmedBlocksWithLimit(
   122  	ctx context.Context,
   123  	startSlot uint64,
   124  	limit uint64,
   125  	commitment CommitmentType,
   126  ) (out []uint64, err error) {
   127  
   128  	params := []interface{}{startSlot, limit}
   129  	if commitment != "" {
   130  		params = append(params, M{"commitment": string(commitment)})
   131  	}
   132  
   133  	err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedBlocksWithLimit", params)
   134  	return
   135  }
   136  
   137  // GetConfirmedSignaturesForAddress2 returns confirmed signatures for transactions involving an
   138  // address backwards in time from the provided signature or most recent confirmed block.
   139  //
   140  // DEPRECATED: Please use getSignaturesForAddress instead.
   141  // This method is expected to be removed in solana-core v1.8
   142  func (cl *Client) GetConfirmedSignaturesForAddress2(
   143  	ctx context.Context,
   144  	address solana.PublicKey,
   145  	opts *GetConfirmedSignaturesForAddress2Opts,
   146  ) (out GetConfirmedSignaturesForAddress2Result, err error) {
   147  
   148  	params := []interface{}{address}
   149  
   150  	if opts != nil {
   151  		obj := M{}
   152  		if opts.Limit != nil {
   153  			obj["limit"] = opts.Limit
   154  		}
   155  		if !opts.Before.IsZero() {
   156  			obj["before"] = opts.Before
   157  		}
   158  		if !opts.Until.IsZero() {
   159  			obj["until"] = opts.Until
   160  		}
   161  		if opts.Commitment != "" {
   162  			obj["commitment"] = opts.Commitment
   163  		}
   164  		if len(obj) > 0 {
   165  			params = append(params, obj)
   166  		}
   167  	}
   168  
   169  	err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedSignaturesForAddress2", params)
   170  	return
   171  }
   172  
   173  // GetConfirmedTransaction returns transaction details for a confirmed transaction.
   174  func (cl *Client) GetConfirmedTransaction(
   175  	ctx context.Context,
   176  	signature solana.Signature,
   177  ) (out *TransactionWithMeta, err error) {
   178  	params := []interface{}{signature, "json"}
   179  
   180  	err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedTransaction", params)
   181  	if err != nil {
   182  		return nil, err
   183  	}
   184  	if out == nil {
   185  		return nil, ErrNotFound
   186  	}
   187  	return
   188  }
   189  
   190  // GetConfirmedTransactionWithOpts returns transaction details for a confirmed transaction.
   191  func (cl *Client) GetConfirmedTransactionWithOpts(
   192  	ctx context.Context,
   193  	signature solana.Signature,
   194  	opts *GetTransactionOpts,
   195  ) (out *TransactionWithMeta, err error) {
   196  	params := []interface{}{signature}
   197  	if opts != nil {
   198  		obj := M{}
   199  		if opts.Encoding != "" {
   200  			if !solana.IsAnyOfEncodingType(
   201  				opts.Encoding,
   202  				// Valid encodings:
   203  				// solana.EncodingJSON, // TODO
   204  				// solana.EncodingJSONParsed, // TODO
   205  				solana.EncodingBase58,
   206  				solana.EncodingBase64,
   207  				solana.EncodingBase64Zstd,
   208  			) {
   209  				return nil, fmt.Errorf("provided encoding is not supported: %s", opts.Encoding)
   210  			}
   211  			obj["encoding"] = opts.Encoding
   212  		}
   213  		if opts.Commitment != "" {
   214  			obj["commitment"] = opts.Commitment
   215  		}
   216  		if len(obj) > 0 {
   217  			params = append(params, obj)
   218  		}
   219  	}
   220  	err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedTransaction", params)
   221  	if err != nil {
   222  		return nil, err
   223  	}
   224  	if out == nil {
   225  		return nil, ErrNotFound
   226  	}
   227  	return
   228  }