Skip to content

Commit 97d3a3e

Browse files
authored
feat: maestro backend w/ turbo tx support (#180)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent ae26e2e commit 97d3a3e

File tree

4 files changed

+89
-9
lines changed

4 files changed

+89
-9
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/gin-contrib/zap v1.1.4
1111
github.com/gin-gonic/gin v1.10.0
1212
github.com/kelseyhightower/envconfig v1.4.0
13+
github.com/maestro-org/go-sdk v1.2.0
1314
go.uber.org/automaxprocs v1.6.0
1415
go.uber.org/zap v1.27.0
1516
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
5959
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
6060
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
6161
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
62+
github.com/maestro-org/go-sdk v1.2.0 h1:0YbC5bwRWklV25L1Z4p2pg2VQYasZGDaC9Epfxwd3a0=
63+
github.com/maestro-org/go-sdk v1.2.0/go.mod h1:EYaRwFT8nkwFzZsN6xK256j+r7ASUUn9p44RlaqYjE8=
6264
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
6365
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
6466
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=

internal/api/api.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package api
1717
import (
1818
"bytes"
1919
"context"
20+
"encoding/hex"
2021
"fmt"
2122
"io"
2223
"net/http"
@@ -30,6 +31,7 @@ import (
3031
cors "github.com/gin-contrib/cors"
3132
ginzap "github.com/gin-contrib/zap"
3233
"github.com/gin-gonic/gin"
34+
maestro "github.com/maestro-org/go-sdk/client"
3335

3436
"github.com/blinklabs-io/tx-submit-api-mirror/internal/config"
3537
"github.com/blinklabs-io/tx-submit-api-mirror/internal/logging"
@@ -196,10 +198,74 @@ func handleSubmitTx(c *gin.Context) {
196198
connReused,
197199
)
198200
} 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+
)
200213
}
201214
}(backend)
202215
}
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+
}
203269
// Return transaction ID
204270
c.String(202, tx.Hash())
205271
}

internal/config/config.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,48 @@ import (
2323
)
2424

2525
type Config struct {
26-
Logging LoggingConfig `yaml:"logging"`
2726
Api ApiConfig `yaml:"api"`
27+
Logging LoggingConfig `yaml:"logging"`
28+
Maestro MaestroConfig `yaml:"maestro"`
2829
Tls TlsConfig `yaml:"tls"`
2930
Backends []string `yaml:"backends" envconfig:"BACKENDS"`
3031
}
3132

32-
type LoggingConfig struct {
33-
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
34-
}
35-
3633
type ApiConfig struct {
3734
ListenAddress string `yaml:"address" envconfig:"API_LISTEN_ADDRESS"`
3835
ListenPort uint `yaml:"port" envconfig:"API_LISTEN_PORT"`
3936
ClientTimeout uint `yaml:"client_timeout" envconfig:"CLIENT_TIMEOUT"`
4037
}
4138

39+
type LoggingConfig struct {
40+
Level string `yaml:"level" envconfig:"LOGGING_LEVEL"`
41+
}
42+
43+
type MaestroConfig struct {
44+
ApiKey string `yaml:"apiKey" envconfig:"MAESTRO_API_KEY"`
45+
Network string `yaml:"network" envconfig:"MAESTRO_NETWORK"`
46+
TurboTx bool `yaml:"turboTx" envconfig:"MAESTRO_TURBO_TX"`
47+
}
48+
4249
type TlsConfig struct {
4350
CertFilePath string `yaml:"certFilePath" envconfig:"TLS_CERT_FILE_PATH"`
4451
KeyFilePath string `yaml:"keyFilePath" envconfig:"TLS_KEY_FILE_PATH"`
4552
}
4653

4754
// Singleton config instance with default values
4855
var globalConfig = &Config{
49-
Logging: LoggingConfig{
50-
Level: "info",
51-
},
5256
Api: ApiConfig{
5357
ListenAddress: "",
5458
ListenPort: 8090,
5559
ClientTimeout: 60000, // [ms]
5660
},
61+
Logging: LoggingConfig{
62+
Level: "info",
63+
},
64+
Maestro: MaestroConfig{
65+
Network: "mainnet",
66+
TurboTx: false,
67+
},
5768
}
5869

5970
func Load(configFile string) (*Config, error) {

0 commit comments

Comments
 (0)