go-eth-proxy

Transparent proxy server for eth-cache
Info | Log | Files | Refs

commit 22d7a2594811c22eed04a6846f7f47180cc3d189
parent d57f85a0e69e6926b817a9c2935cb86fd6caf4f6
Author: lash <dev@holbrook.no>
Date:   Thu,  4 Jul 2024 16:56:23 +0100

Add block get to literal service

Diffstat:
Mstore/lmdb/lmdb.go | 33+++++++++++++++++++++++++++------
Mstore/store.go | 1-
2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/store/lmdb/lmdb.go b/store/lmdb/lmdb.go @@ -1,6 +1,7 @@ package lmdb import ( + "encoding/binary" "log" "github.com/ledgerwatch/lmdb-go/lmdb" @@ -47,16 +48,16 @@ func NewStore(path string) (*LmdbStore, error) { return o, nil } - -func (l *LmdbStore) GetTransaction(k []byte) ([]byte, error) { +func (l *LmdbStore) get(pfx string, k []byte) ([]byte, error) { var b []byte - kp := make([]byte, len(k) + 7) - copy(kp, []byte("tx/src/")) - copy(kp[7:], k) + n := len(pfx) + kp := make([]byte, len(k) + n) + copy(kp, []byte(pfx)) + copy(kp[n:], k) err := l.env.View(func(txn *lmdb.Txn) (error) { - log.Printf("gettx %x %v", kp, txn) + log.Printf("get %x %v", kp, txn) v, err := txn.Get(l.dbi, kp) if err != nil { return err @@ -73,6 +74,26 @@ func (l *LmdbStore) GetTransaction(k []byte) ([]byte, error) { } +func (l *LmdbStore) GetTransaction(k []byte) ([]byte, error) { + return l.get("tx/src/", k) +} + +func (l *LmdbStore) GetBlockNumber(n uint64) ([]byte, error) { + var err error + b := make([]byte, 8) + binary.BigEndian.PutUint64(b, n) + + b, err = l.get("block/num/", b) + if err != nil { + return nil, err + } + return l.get("block/hash/", b) +} + +func (l *LmdbStore) GetBlockHash(k []byte) ([]byte, error) { + return l.get("block/hash/", k) +} + func (l *LmdbStore) Close() { l.env.Close() } diff --git a/store/store.go b/store/store.go @@ -1,7 +1,6 @@ package store type Store interface { - //GetTransaction(b []byte) (*types.Transaction, error) GetTransaction(b []byte) ([]byte, error) Close() }