Merge pull request #1 from certusone/main

Add GetConfirmedTransactionWithOpts
This commit is contained in:
Slavomir 2021-08-28 22:10:04 +03:00 committed by GitHub
commit 7e0eaa6ef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 0 deletions

View File

@ -16,6 +16,7 @@ package rpc
import (
"context"
"fmt"
"github.com/gagliardetto/solana-go"
)
@ -182,3 +183,42 @@ func (cl *Client) GetConfirmedTransaction(
}
return
}
// GetConfirmedTransactionWithOpts returns transaction details for a confirmed transaction.
func (cl *Client) GetConfirmedTransactionWithOpts(
ctx context.Context,
signature solana.Signature,
opts *GetTransactionOpts,
) (out *TransactionWithMeta, err error) {
params := []interface{}{signature}
if opts != nil {
obj := M{}
if opts.Encoding != "" {
if !solana.IsAnyOfEncodingType(
opts.Encoding,
// Valid encodings:
solana.EncodingJSON,
// solana.EncodingJSONParsed, // TODO
solana.EncodingBase58,
solana.EncodingBase64,
) {
return nil, fmt.Errorf("provided encoding is not supported: %s", opts.Encoding)
}
obj["encoding"] = opts.Encoding
}
if opts.Commitment != "" {
obj["commitment"] = opts.Commitment
}
if len(obj) > 0 {
params = append(params, obj)
}
}
err = cl.rpcClient.CallForInto(ctx, &out, "getConfirmedTransaction", params)
if err != nil {
return nil, err
}
if out == nil {
return nil, ErrNotFound
}
return
}