Skip to content

Commit 410786f

Browse files
Refactor DAaaSh (#1)
* refactor: read CELESTIA_AUTH_TOKEN from .env * refactor: single POST endpoint * fix(main): error handling for .env read --------- Co-authored-by: prampey <[email protected]>
1 parent 4510d62 commit 410786f

File tree

7 files changed

+47
-56
lines changed

7 files changed

+47
-56
lines changed

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CELESTIA_AUTH_TOKEN=your_auth_token

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![cover](./assets/cover.png)
44

5-
Unified interaction API for Data Availibility chains initially designed to work with Vulcan (Stackr's Verification Layer)
5+
Unified interaction API for Data Availability chains initially designed to work with Vulcan (Stackr's Verification Layer)
66

77
This unified API for data availability services provides a scalable, secure, and efficient way for Vulcan to interact with different DA networks. It aims to standardize data access patterns, reduce complexity, and enhance the overall experience of using data availability services.
88

@@ -47,10 +47,10 @@ Each micro-rollup should be easily able to switch
4747
Avail and EigenDA runs via external RPC providers however Celestia requires a running light node to be able to post blobs through `go-daash`.
4848

4949
You can find the instructions to run the light node [here](https://docs.celestia.org/developers/node-tutorial).
50-
Also export auth token as environment variable:
50+
You need an auth token to run your Celestia light node. Copy the `.env.example` file to `.env` and set the `CELESTIA_AUTH_TOKEN` environment variable to the auth token.
5151

5252
```bash
53-
export CELESTIA_AUTH_TOKEN=<your_auth_token>
53+
cp .env.example .env
5454
```
5555

5656
## Installation/Running

avail.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ func (c *AvailDA) MaxBlobSize(ctx context.Context) (uint64, error) {
131131
// Currently, we submit to a trusted RPC Avail node. In the future, we will submit via an Avail light client.
132132
func (a *AvailDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) {
133133
// TODO: Add support for multiple blobs
134-
log.Println("data", zap.Any("data", daBlobs[0]))
135-
log.Println("⚡️ Preparing to post data to Avail:%d bytes", zap.Int("data_size", len(daBlobs[0])))
134+
daBlob := daBlobs[0]
135+
log.Println("data", zap.Any("data", daBlob))
136+
log.Println("⚡️ Preparing to post data to Avail:%d bytes", zap.Int("data_size", len(daBlob)))
136137
fmt.Println(*a)
137-
newCall, err := types.NewCall(a.Meta, "DataAvailability.submit_data", types.NewBytes(daBlobs[0]))
138+
newCall, err := types.NewCall(a.Meta, "DataAvailability.submit_data", types.NewBytes(daBlob))
138139
if err != nil {
139140
return nil, nil, fmt.Errorf("cannot create new call", err)
140141
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ require (
191191
github.com/jbenet/goprocess v0.1.4 // indirect
192192
github.com/jmespath/go-jmespath v0.4.0 // indirect
193193
github.com/jmhodges/levigo v1.0.0 // indirect
194+
github.com/joho/godotenv v1.5.1 // indirect
194195
github.com/json-iterator/go v1.1.12 // indirect
195196
github.com/klauspost/compress v1.17.2 // indirect
196197
github.com/klauspost/cpuid/v2 v2.2.6 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
12921292
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
12931293
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
12941294
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
1295+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
1296+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
12951297
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
12961298
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
12971299
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=

main.go

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,49 @@ import (
66
"fmt"
77
"log"
88
"net/http"
9-
"os"
109
"time"
1110

1211
rpc "github.com/celestiaorg/celestia-node/api/rpc/client"
1312
"github.com/celestiaorg/celestia-node/share"
13+
"github.com/joho/godotenv"
1414
"github.com/rollkit/go-da"
1515

1616
"github.com/cenkalti/backoff/v4"
1717
"github.com/gin-gonic/gin"
1818
)
1919

20+
// Constants
21+
const (
22+
CelestiaClientUrl = "http://localhost:26658"
23+
EigenDaRpcUrl = "disperser-goerli.eigenda.xyz:443"
24+
)
25+
2026
func main() {
2127
// initiates a gin Engine with the default logger and recovery middleware
2228
router := gin.Default()
29+
ctx := context.Background()
30+
31+
envFile, err := godotenv.Read(".env")
32+
if err != nil {
33+
fmt.Println("Error reading .env file")
34+
35+
return
36+
}
37+
2338
// Initialise Avail DA client
2439
avail, err := NewAvailDA()
2540
if err != nil {
2641
fmt.Printf("failed to create avail client: %v", err)
2742
}
2843

29-
ctx := context.Background()
3044
// Initialise Celestia DA client
3145
// Read auth token from env
32-
authToken := os.Getenv("CELESTIA_AUTH_TOKEN")
46+
authToken := envFile["CELESTIA_AUTH_TOKEN"]
3347
if authToken == "" {
3448
fmt.Println("AUTH_TOKEN is not set")
3549
return
3650
}
37-
client, err := rpc.NewClient(ctx, "http://localhost:26658", authToken)
51+
client, err := rpc.NewClient(ctx, CelestiaClientUrl, authToken)
3852
if err != nil {
3953
fmt.Printf("failed to create rpc client: %v", err)
4054
}
@@ -49,59 +63,28 @@ func main() {
4963
celestia := NewCelestiaDA(client, namespace, -1, ctx)
5064

5165
// Initalise EigenDA client
52-
eigen, err := NewEigendaDAClient("disperser-goerli.eigenda.xyz:443", time.Second*90, time.Second*5)
66+
eigen, err := NewEigendaDAClient(EigenDaRpcUrl, time.Second*90, time.Second*5)
5367
if err != nil {
5468
fmt.Printf("failed to create eigen client: %v", err)
5569
}
56-
router.POST("/Avail", func(c *gin.Context) {
57-
// Get the data in []byte from the request body
58-
data, err := c.GetRawData()
59-
if err != nil {
60-
c.JSON(http.StatusBadRequest, gin.H{
61-
"message": fmt.Sprintf("get raw data: %v", err),
62-
})
63-
return
64-
}
65-
// Post the data to DA
66-
ids, proofs, err := postToDA(c, data, avail)
67-
if err != nil {
68-
c.JSON(http.StatusInternalServerError, gin.H{
69-
"message": fmt.Sprintf("post to DA: %v", err),
70-
})
71-
return
72-
}
73-
c.JSON(http.StatusOK, gin.H{
74-
"message": "Daaaash",
75-
"ids": ids,
76-
"proofs": proofs,
77-
})
78-
})
7970

80-
router.POST("/Celestia", func(c *gin.Context) {
81-
// Get the data in []byte from the request body
82-
data, err := c.GetRawData()
83-
if err != nil {
71+
// Map of DA clients
72+
daClients := map[string]da.DA{
73+
"avail": avail,
74+
"celestia": celestia,
75+
"eigen": eigen,
76+
}
77+
78+
router.POST("/:daName", func(c *gin.Context) {
79+
daName := c.Param("daName")
80+
81+
if _, ok := daClients[daName]; !ok {
8482
c.JSON(http.StatusBadRequest, gin.H{
85-
"message": fmt.Sprintf("get raw data: %v", err),
83+
"message": fmt.Sprintf("DA %s not found", daName),
8684
})
8785
return
8886
}
89-
// Post the data to DA
90-
ids, proofs, err := postToDA(c, data, celestia)
91-
if err != nil {
92-
c.JSON(http.StatusInternalServerError, gin.H{
93-
"message": fmt.Sprintf("post to DA: %v", err),
94-
})
95-
return
96-
}
97-
c.JSON(http.StatusOK, gin.H{
98-
"message": "Daaaash",
99-
"ids": ids,
100-
"proofs": proofs,
101-
})
102-
})
10387

104-
router.POST("/Eigen", func(c *gin.Context) {
10588
// Get the data in []byte from the request body
10689
data, err := c.GetRawData()
10790
if err != nil {
@@ -110,20 +93,22 @@ func main() {
11093
})
11194
return
11295
}
96+
11397
// Post the data to DA
114-
ids, proofs, err := postToDA(c, data, eigen)
98+
ids, proofs, err := postToDA(c, data, daClients[daName])
11599
if err != nil {
116100
c.JSON(http.StatusInternalServerError, gin.H{
117101
"message": fmt.Sprintf("post to DA: %v", err),
118102
})
119103
return
120104
}
121105
c.JSON(http.StatusOK, gin.H{
122-
"message": "Daaaash",
106+
"message": "DAaaaSh",
123107
"ids": ids,
124108
"proofs": proofs,
125109
})
126110
})
111+
127112
// Run implements a http.ListenAndServe() and takes in an optional Port number
128113
// The default port is :8080
129114
router.Run()

0 commit comments

Comments
 (0)