-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_transaction.go
55 lines (51 loc) · 1.54 KB
/
client_transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package fuel
import (
"context"
"fmt"
"github.com/sentioxyz/fuel-go/query"
"github.com/sentioxyz/fuel-go/types"
)
type GetTransactionOption struct {
WithReceipts bool
WithStatus bool
WithContractBytecode bool
WithContractSalt bool
}
func (o GetTransactionOption) BuildIgnoreChecker() query.IgnoreChecker {
ignoreCheckers := []query.IgnoreChecker{
query.IgnoreField(types.Block{}, "Transactions"),
query.IgnoreField(types.SuccessStatus{}, "Transaction"),
query.IgnoreField(types.FailureStatus{}, "Transaction"),
}
if !o.WithContractBytecode {
ignoreCheckers = append(ignoreCheckers, query.IgnoreField(types.Contract{}, "Bytecode"))
}
if !o.WithContractSalt {
ignoreCheckers = append(ignoreCheckers, query.IgnoreField(types.Contract{}, "Salt"))
}
if !o.WithReceipts {
ignoreCheckers = append(ignoreCheckers, query.IgnoreObjects(types.Receipt{}))
}
if !o.WithStatus {
ignoreCheckers = append(ignoreCheckers, query.IgnoreField(types.Transaction{}, "Status"))
}
return query.MergeIgnores(ignoreCheckers...)
}
func (c *Client) GetTransaction(
ctx context.Context,
param types.QueryTransactionParams,
opt GetTransactionOption,
) (*types.Transaction, error) {
q := fmt.Sprintf("{ transaction(%s) { %s} }",
query.Simple.GenParam(param),
query.Simple.GenObjectQuery(types.Transaction{}, opt.BuildIgnoreChecker()),
)
type resultType struct {
Transaction *types.Transaction `json:"transaction"`
}
result, err := ExecuteQuery[resultType](ctx, c, q)
if err != nil {
return nil, err
}
return result.Transaction, nil
}