Skip to content

Commit

Permalink
Add kzgpad util for using grpcurl to test eigenda
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyknox committed Apr 8, 2024
1 parent 08d8781 commit eddfb8e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ build:
cd node && make build
cd retriever && make build
cd tools/traffic && make build
cd tools/kzgpad && make build

dataapi-build:
cd disperser && go build -o ./bin/dataapi ./cmd/dataapi
Expand Down
6 changes: 6 additions & 0 deletions tools/kzgpad/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
clean:
rm -rf ./bin

build: clean
go mod tidy
go build -o ./bin/kzgpad ./cmd
55 changes: 55 additions & 0 deletions tools/kzgpad/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"bufio"
"encoding/base64"
"fmt"
"os"

"github.com/Layr-Labs/eigenda/encoding/utils/codec"
)

func main() {
if len(os.Args) < 3 {
fmt.Fprintln(os.Stderr, "Usage: go run main.go [-e|-d] [input]")
os.Exit(1)
}

mode := os.Args[1]
input := os.Args[2]

if input == "-" {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
processInput(mode, scanner.Text())
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "Error reading stdin:", err)
os.Exit(1)
}
} else {
processInput(mode, input)
}
}

func processInput(mode, text string) {
switch mode {
case "-e":
// Encode the input to base64
bz := []byte(text)
padded := codec.ConvertByPaddingEmptyByte(bz)
encoded := base64.StdEncoding.EncodeToString(padded)
fmt.Println(encoded)
case "-d":
// Decode the base64 input
decoded, err := base64.StdEncoding.DecodeString(text)
if err != nil {
fmt.Fprintln(os.Stderr, "Error decoding base64:", err)
return
}
unpadded := codec.RemoveEmptyByteFromPaddedBytes(decoded)
fmt.Println(string(unpadded))
default:
fmt.Fprintln(os.Stderr, "Invalid mode. Use -e for encoding or -d for decoding.")
}
}

0 comments on commit eddfb8e

Please sign in to comment.