@@ -11,7 +11,6 @@ import (
11
11
"github.com/onflow/flow-go/access"
12
12
commonmodels "github.com/onflow/flow-go/engine/access/rest/common/models"
13
13
"github.com/onflow/flow-go/engine/access/rest/common/parser"
14
- "github.com/onflow/flow-go/engine/access/rest/http/request"
15
14
"github.com/onflow/flow-go/engine/access/rest/websockets/models"
16
15
"github.com/onflow/flow-go/engine/access/subscription"
17
16
"github.com/onflow/flow-go/model/flow"
@@ -20,13 +19,6 @@ import (
20
19
"github.com/onflow/flow/protobuf/go/flow/entities"
21
20
)
22
21
23
- // transactionStatusesArguments contains the arguments required for subscribing to transaction statuses
24
- type transactionStatusesArguments struct {
25
- TxID flow.Identifier // ID of the transaction to monitor.
26
- StartBlockID flow.Identifier // ID of the block to start subscription from
27
- StartBlockHeight uint64 // Height of the block to start subscription from
28
- }
29
-
30
22
// TransactionStatusesDataProvider is responsible for providing tx statuses
31
23
type TransactionStatusesDataProvider struct {
32
24
* baseDataProvider
@@ -54,8 +46,8 @@ func NewTransactionStatusesDataProvider(
54
46
linkGenerator : linkGenerator ,
55
47
}
56
48
57
- // Initialize arguments passed to the provider.
58
- txStatusesArgs , err := parseTransactionStatusesArguments (arguments )
49
+ // Initialize txID passed to the provider.
50
+ txID , err := parseTransactionID (arguments )
59
51
if err != nil {
60
52
return nil , fmt .Errorf ("invalid arguments for tx statuses data provider: %w" , err )
61
53
}
@@ -68,7 +60,7 @@ func NewTransactionStatusesDataProvider(
68
60
arguments ,
69
61
cancel ,
70
62
send ,
71
- p .createSubscription (subCtx , txStatusesArgs ), // Set up a subscription to tx statuses based on arguments.
63
+ p .createSubscription (subCtx , txID ), // Set up a subscription to tx statuses based on arguments.
72
64
)
73
65
74
66
return p , nil
@@ -84,17 +76,9 @@ func (p *TransactionStatusesDataProvider) Run() error {
84
76
// createSubscription creates a new subscription using the specified input arguments.
85
77
func (p * TransactionStatusesDataProvider ) createSubscription (
86
78
ctx context.Context ,
87
- args transactionStatusesArguments ,
79
+ txID flow. Identifier ,
88
80
) subscription.Subscription {
89
- if args .StartBlockID != flow .ZeroID {
90
- return p .api .SubscribeTransactionStatusesFromStartBlockID (ctx , args .TxID , args .StartBlockID , entities .EventEncodingVersion_JSON_CDC_V0 )
91
- }
92
-
93
- if args .StartBlockHeight != request .EmptyHeight {
94
- return p .api .SubscribeTransactionStatusesFromStartHeight (ctx , args .TxID , args .StartBlockHeight , entities .EventEncodingVersion_JSON_CDC_V0 )
95
- }
96
-
97
- return p .api .SubscribeTransactionStatusesFromLatest (ctx , args .TxID , entities .EventEncodingVersion_JSON_CDC_V0 )
81
+ return p .api .SubscribeTransactionStatuses (ctx , txID , entities .EventEncodingVersion_JSON_CDC_V0 )
98
82
}
99
83
100
84
// handleResponse processes a tx statuses and sends the formatted response.
@@ -123,42 +107,30 @@ func (p *TransactionStatusesDataProvider) handleResponse() func(txResults []*acc
123
107
}
124
108
}
125
109
126
- // parseAccountStatusesArguments validates and initializes the account statuses arguments .
127
- func parseTransactionStatusesArguments (
110
+ // parseTransactionID validates and initializes the transaction ID argument .
111
+ func parseTransactionID (
128
112
arguments models.Arguments ,
129
- ) (transactionStatusesArguments , error ) {
113
+ ) (flow. Identifier , error ) {
130
114
allowedFields := []string {
131
- "start_block_id" ,
132
- "start_block_height" ,
133
115
"tx_id" ,
134
116
}
135
117
err := ensureAllowedFields (arguments , allowedFields )
136
118
if err != nil {
137
- return transactionStatusesArguments {}, err
138
- }
139
-
140
- var args transactionStatusesArguments
141
-
142
- // Parse block arguments
143
- startBlockID , startBlockHeight , err := parseStartBlock (arguments )
144
- if err != nil {
145
- return transactionStatusesArguments {}, err
119
+ return flow .ZeroID , err
146
120
}
147
- args .StartBlockID = startBlockID
148
- args .StartBlockHeight = startBlockHeight
149
121
150
122
if txIDIn , ok := arguments ["tx_id" ]; ok && txIDIn != "" {
151
123
result , ok := txIDIn .(string )
152
124
if ! ok {
153
- return transactionStatusesArguments {} , fmt .Errorf ("'tx_id' must be a string" )
125
+ return flow . ZeroID , fmt .Errorf ("'tx_id' must be a string" )
154
126
}
155
- var txID parser.ID
156
- err := txID .Parse (result )
127
+ var txIDParsed parser.ID
128
+ err := txIDParsed .Parse (result )
157
129
if err != nil {
158
- return transactionStatusesArguments {} , fmt .Errorf ("invalid 'tx_id': %w" , err )
130
+ return flow . ZeroID , fmt .Errorf ("invalid 'tx_id': %w" , err )
159
131
}
160
- args . TxID = txID .Flow ()
132
+ return txIDParsed .Flow (), nil
161
133
}
162
134
163
- return args , nil
135
+ return flow . ZeroID , fmt . Errorf ( "arguments are invalid" )
164
136
}
0 commit comments