github.com/algorand/go-algorand-sdk@v1.24.0/client/v2/indexer/searchForTransactions.go (about)

     1  package indexer
     2  
     3  import (
     4  	"context"
     5  	"encoding/base64"
     6  	"time"
     7  
     8  	"github.com/algorand/go-algorand-sdk/client/v2/common"
     9  	"github.com/algorand/go-algorand-sdk/client/v2/common/models"
    10  )
    11  
    12  // SearchForTransactionsParams contains all of the query parameters for url serialization.
    13  type SearchForTransactionsParams struct {
    14  
    15  	// AddressString only include transactions with this address in one of the
    16  	// transaction fields.
    17  	AddressString string `url:"address,omitempty"`
    18  
    19  	// AddressRole combine with the address parameter to define what type of address to
    20  	// search for.
    21  	AddressRole string `url:"address-role,omitempty"`
    22  
    23  	// AfterTime include results after the given time. Must be an RFC 3339 formatted
    24  	// string.
    25  	AfterTime string `url:"after-time,omitempty"`
    26  
    27  	// ApplicationId application ID
    28  	ApplicationId uint64 `url:"application-id,omitempty"`
    29  
    30  	// AssetID asset ID
    31  	AssetID uint64 `url:"asset-id,omitempty"`
    32  
    33  	// BeforeTime include results before the given time. Must be an RFC 3339 formatted
    34  	// string.
    35  	BeforeTime string `url:"before-time,omitempty"`
    36  
    37  	// CurrencyGreaterThan results should have an amount greater than this value.
    38  	// MicroAlgos are the default currency unless an asset-id is provided, in which
    39  	// case the asset will be used.
    40  	CurrencyGreaterThan uint64 `url:"currency-greater-than,omitempty"`
    41  
    42  	// CurrencyLessThan results should have an amount less than this value. MicroAlgos
    43  	// are the default currency unless an asset-id is provided, in which case the asset
    44  	// will be used.
    45  	CurrencyLessThan uint64 `url:"currency-less-than,omitempty"`
    46  
    47  	// ExcludeCloseTo combine with address and address-role parameters to define what
    48  	// type of address to search for. The close to fields are normally treated as a
    49  	// receiver, if you would like to exclude them set this parameter to true.
    50  	ExcludeCloseTo bool `url:"exclude-close-to,omitempty"`
    51  
    52  	// Limit maximum number of results to return. There could be additional pages even
    53  	// if the limit is not reached.
    54  	Limit uint64 `url:"limit,omitempty"`
    55  
    56  	// MaxRound include results at or before the specified max-round.
    57  	MaxRound uint64 `url:"max-round,omitempty"`
    58  
    59  	// MinRound include results at or after the specified min-round.
    60  	MinRound uint64 `url:"min-round,omitempty"`
    61  
    62  	// NextToken the next page of results. Use the next token provided by the previous
    63  	// results.
    64  	NextToken string `url:"next,omitempty"`
    65  
    66  	// NotePrefix specifies a prefix which must be contained in the note field.
    67  	NotePrefix string `url:"note-prefix,omitempty"`
    68  
    69  	// RekeyTo include results which include the rekey-to field.
    70  	RekeyTo bool `url:"rekey-to,omitempty"`
    71  
    72  	// Round include results for the specified round.
    73  	Round uint64 `url:"round,omitempty"`
    74  
    75  	// SigType sigType filters just results using the specified type of signature:
    76  	// * sig - Standard
    77  	// * msig - MultiSig
    78  	// * lsig - LogicSig
    79  	SigType string `url:"sig-type,omitempty"`
    80  
    81  	// TxType
    82  	TxType string `url:"tx-type,omitempty"`
    83  
    84  	// TXID lookup the specific transaction by ID.
    85  	TXID string `url:"txid,omitempty"`
    86  }
    87  
    88  // SearchForTransactions search for transactions. Transactions are returned oldest
    89  // to newest unless the address parameter is used, in which case results are
    90  // returned newest to oldest.
    91  type SearchForTransactions struct {
    92  	c *Client
    93  
    94  	p SearchForTransactionsParams
    95  }
    96  
    97  // AddressString only include transactions with this address in one of the
    98  // transaction fields.
    99  func (s *SearchForTransactions) AddressString(AddressString string) *SearchForTransactions {
   100  	s.p.AddressString = AddressString
   101  
   102  	return s
   103  }
   104  
   105  // AddressRole combine with the address parameter to define what type of address to
   106  // search for.
   107  func (s *SearchForTransactions) AddressRole(AddressRole string) *SearchForTransactions {
   108  	s.p.AddressRole = AddressRole
   109  
   110  	return s
   111  }
   112  
   113  // AfterTimeString include results after the given time. Must be an RFC 3339
   114  // formatted string.
   115  func (s *SearchForTransactions) AfterTimeString(AfterTime string) *SearchForTransactions {
   116  	s.p.AfterTime = AfterTime
   117  
   118  	return s
   119  }
   120  
   121  // AfterTime include results after the given time. Must be an RFC 3339 formatted
   122  // string.
   123  func (s *SearchForTransactions) AfterTime(AfterTime time.Time) *SearchForTransactions {
   124  	AfterTimeStr := AfterTime.Format(time.RFC3339)
   125  
   126  	return s.AfterTimeString(AfterTimeStr)
   127  }
   128  
   129  // ApplicationId application ID
   130  func (s *SearchForTransactions) ApplicationId(ApplicationId uint64) *SearchForTransactions {
   131  	s.p.ApplicationId = ApplicationId
   132  
   133  	return s
   134  }
   135  
   136  // AssetID asset ID
   137  func (s *SearchForTransactions) AssetID(AssetID uint64) *SearchForTransactions {
   138  	s.p.AssetID = AssetID
   139  
   140  	return s
   141  }
   142  
   143  // BeforeTimeString include results before the given time. Must be an RFC 3339
   144  // formatted string.
   145  func (s *SearchForTransactions) BeforeTimeString(BeforeTime string) *SearchForTransactions {
   146  	s.p.BeforeTime = BeforeTime
   147  
   148  	return s
   149  }
   150  
   151  // BeforeTime include results before the given time. Must be an RFC 3339 formatted
   152  // string.
   153  func (s *SearchForTransactions) BeforeTime(BeforeTime time.Time) *SearchForTransactions {
   154  	BeforeTimeStr := BeforeTime.Format(time.RFC3339)
   155  
   156  	return s.BeforeTimeString(BeforeTimeStr)
   157  }
   158  
   159  // CurrencyGreaterThan results should have an amount greater than this value.
   160  // MicroAlgos are the default currency unless an asset-id is provided, in which
   161  // case the asset will be used.
   162  func (s *SearchForTransactions) CurrencyGreaterThan(CurrencyGreaterThan uint64) *SearchForTransactions {
   163  	s.p.CurrencyGreaterThan = CurrencyGreaterThan
   164  
   165  	return s
   166  }
   167  
   168  // CurrencyLessThan results should have an amount less than this value. MicroAlgos
   169  // are the default currency unless an asset-id is provided, in which case the asset
   170  // will be used.
   171  func (s *SearchForTransactions) CurrencyLessThan(CurrencyLessThan uint64) *SearchForTransactions {
   172  	s.p.CurrencyLessThan = CurrencyLessThan
   173  
   174  	return s
   175  }
   176  
   177  // ExcludeCloseTo combine with address and address-role parameters to define what
   178  // type of address to search for. The close to fields are normally treated as a
   179  // receiver, if you would like to exclude them set this parameter to true.
   180  func (s *SearchForTransactions) ExcludeCloseTo(ExcludeCloseTo bool) *SearchForTransactions {
   181  	s.p.ExcludeCloseTo = ExcludeCloseTo
   182  
   183  	return s
   184  }
   185  
   186  // Limit maximum number of results to return. There could be additional pages even
   187  // if the limit is not reached.
   188  func (s *SearchForTransactions) Limit(Limit uint64) *SearchForTransactions {
   189  	s.p.Limit = Limit
   190  
   191  	return s
   192  }
   193  
   194  // MaxRound include results at or before the specified max-round.
   195  func (s *SearchForTransactions) MaxRound(MaxRound uint64) *SearchForTransactions {
   196  	s.p.MaxRound = MaxRound
   197  
   198  	return s
   199  }
   200  
   201  // MinRound include results at or after the specified min-round.
   202  func (s *SearchForTransactions) MinRound(MinRound uint64) *SearchForTransactions {
   203  	s.p.MinRound = MinRound
   204  
   205  	return s
   206  }
   207  
   208  // NextToken the next page of results. Use the next token provided by the previous
   209  // results.
   210  func (s *SearchForTransactions) NextToken(NextToken string) *SearchForTransactions {
   211  	s.p.NextToken = NextToken
   212  
   213  	return s
   214  }
   215  
   216  // NotePrefix specifies a prefix which must be contained in the note field.
   217  func (s *SearchForTransactions) NotePrefix(NotePrefix []byte) *SearchForTransactions {
   218  	s.p.NotePrefix = base64.StdEncoding.EncodeToString(NotePrefix)
   219  
   220  	return s
   221  }
   222  
   223  // RekeyTo include results which include the rekey-to field.
   224  func (s *SearchForTransactions) RekeyTo(RekeyTo bool) *SearchForTransactions {
   225  	s.p.RekeyTo = RekeyTo
   226  
   227  	return s
   228  }
   229  
   230  // Round include results for the specified round.
   231  func (s *SearchForTransactions) Round(Round uint64) *SearchForTransactions {
   232  	s.p.Round = Round
   233  
   234  	return s
   235  }
   236  
   237  // SigType sigType filters just results using the specified type of signature:
   238  // * sig - Standard
   239  // * msig - MultiSig
   240  // * lsig - LogicSig
   241  func (s *SearchForTransactions) SigType(SigType string) *SearchForTransactions {
   242  	s.p.SigType = SigType
   243  
   244  	return s
   245  }
   246  
   247  // TxType
   248  func (s *SearchForTransactions) TxType(TxType string) *SearchForTransactions {
   249  	s.p.TxType = TxType
   250  
   251  	return s
   252  }
   253  
   254  // TXID lookup the specific transaction by ID.
   255  func (s *SearchForTransactions) TXID(TXID string) *SearchForTransactions {
   256  	s.p.TXID = TXID
   257  
   258  	return s
   259  }
   260  
   261  // Do performs the HTTP request
   262  func (s *SearchForTransactions) Do(ctx context.Context, headers ...*common.Header) (response models.TransactionsResponse, err error) {
   263  	err = s.c.get(ctx, &response, "/v2/transactions", s.p, headers)
   264  	return
   265  }