@@ -17,6 +17,7 @@ package api
17
17
import (
18
18
"bytes"
19
19
"context"
20
+ "encoding/hex"
20
21
"fmt"
21
22
"io"
22
23
"net/http"
@@ -30,6 +31,7 @@ import (
30
31
cors "github.com/gin-contrib/cors"
31
32
ginzap "github.com/gin-contrib/zap"
32
33
"github.com/gin-gonic/gin"
34
+ maestro "github.com/maestro-org/go-sdk/client"
33
35
34
36
"github.com/blinklabs-io/tx-submit-api-mirror/internal/config"
35
37
"github.com/blinklabs-io/tx-submit-api-mirror/internal/logging"
@@ -196,10 +198,74 @@ func handleSubmitTx(c *gin.Context) {
196
198
connReused ,
197
199
)
198
200
} else {
199
- logger .Errorw (fmt .Sprintf ("failed to send request to backend %s: got response %d, %s" , backend , resp .StatusCode , string (respBody )), "latency" , elapsedTime .Seconds (), "connReused" , connReused )
201
+ logger .Errorw (
202
+ fmt .Sprintf (
203
+ "failed to send request to backend %s: got response %d, %s" ,
204
+ backend ,
205
+ resp .StatusCode ,
206
+ string (respBody ),
207
+ ),
208
+ "latency" ,
209
+ elapsedTime .Seconds (),
210
+ "connReused" ,
211
+ connReused ,
212
+ )
200
213
}
201
214
}(backend )
202
215
}
216
+ // Optional Maestro
217
+ if cfg .Maestro .ApiKey != "" {
218
+ go func (cfg * config.Config , rawTx []byte ) {
219
+ txHex := hex .EncodeToString (rawTx )
220
+ maestroClient := maestro .NewClient (cfg .Maestro .ApiKey , cfg .Maestro .Network )
221
+ startTime := time .Now ()
222
+ if cfg .Maestro .TurboTx {
223
+ _ , err := maestroClient .TxManagerSubmitTurbo (txHex )
224
+ elapsedTime := time .Since (startTime )
225
+ if err != nil {
226
+ logger .Errorw (
227
+ fmt .Sprintf (
228
+ "failed to send request to Maestro: got response %v" ,
229
+ err ,
230
+ ),
231
+ "latency" ,
232
+ elapsedTime .Seconds (),
233
+ )
234
+ return
235
+ }
236
+ logger .Infow (
237
+ fmt .Sprintf (
238
+ "successfully submitted transaction %s to Maestro TurboTx" ,
239
+ tx .Hash (),
240
+ ),
241
+ "latency" ,
242
+ elapsedTime .Seconds (),
243
+ )
244
+ return
245
+ }
246
+ _ , err := maestroClient .TxManagerSubmit (txHex )
247
+ elapsedTime := time .Since (startTime )
248
+ if err != nil {
249
+ logger .Errorw (
250
+ fmt .Sprintf (
251
+ "failed to send request to Maestro: got response %v" ,
252
+ err ,
253
+ ),
254
+ "latency" ,
255
+ elapsedTime .Seconds (),
256
+ )
257
+ return
258
+ }
259
+ logger .Infow (
260
+ fmt .Sprintf (
261
+ "successfully submitted transaction %s to Maestro" ,
262
+ tx .Hash (),
263
+ ),
264
+ "latency" ,
265
+ elapsedTime .Seconds (),
266
+ )
267
+ }(cfg , rawTx )
268
+ }
203
269
// Return transaction ID
204
270
c .String (202 , tx .Hash ())
205
271
}
0 commit comments