commit 15c288b96137d64ab8c8cd8c66b720d67e55d813
parent 05c88d4eaded3b59def4aefa8274b1fb219e1c1c
Author: lash <dev@holbrook.no>
Date: Fri, 28 Jun 2024 18:33:52 +0100
Add server binary, fix tx hash get method name
Diffstat:
4 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,2 @@
+all:
+ go build -v -o eth-proxy ./cmd/
diff --git a/cmd/main.go b/cmd/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "flag"
+ "log"
+ "os"
+ "net/http"
+
+ "defalsify.org/go-eth-proxy/proxy"
+ "defalsify.org/go-eth-proxy/store/lmdb"
+ "github.com/ethereum/go-ethereum/rpc"
+
+)
+
+
+func main() {
+ dbpath := flag.String("cachepath", ".", "Path to lmdb data")
+ db, err := lmdb.NewStore(*dbpath)
+ if err != nil {
+ log.Printf("%s", err)
+ os.Exit(1)
+ }
+ defer db.Close()
+
+ svc := proxy.NewProxyService(db)
+ h := rpc.NewServer()
+ err = h.RegisterName("eth", svc)
+ if err != nil {
+ log.Printf("%s", err)
+ os.Exit(1)
+ }
+
+ srv := &http.Server{
+ Handler: h,
+ Addr: "0.0.0.0:8080",
+ }
+ err = srv.ListenAndServe()
+ if err != nil {
+ log.Printf("%s", err)
+ os.Exit(1)
+ }
+}
diff --git a/proxy/service.go b/proxy/service.go
@@ -2,6 +2,7 @@ package proxy
import (
"context"
+ "log"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
@@ -19,7 +20,12 @@ func NewProxyService(store store.Store) (*ProxyService) {
}
}
-func (p *ProxyService) GetTransaction(ctx context.Context, hsh string) (*types.Transaction, error) {
+func (p *ProxyService) GasPrice() (string, error) {
+ return "0x0", nil
+}
+
+func (p *ProxyService) GetTransactionByHash(ctx context.Context, hsh string) (*types.Transaction, error) {
+ log.Printf("get tx hash %s", hsh)
b := common.FromHex(hsh)
tx, err := p.store.GetTransaction(b)
if err != nil {
diff --git a/proxy/service_test.go b/proxy/service_test.go
@@ -40,7 +40,7 @@ func TestProxyServerStart(t *testing.T) {
t.Fatal(err)
}
t.Logf("mods %s", mods)
- err = client.Call(&tx, "eth_getTransaction", tx_test)
+ err = client.Call(&tx, "eth_getTransactionByHash", tx_test)
if err != nil {
t.Fatal(err)
}