Skip to content

Commit

Permalink
{eth,jrpc2}: new packages. support indexing from standard json rpc (#170
Browse files Browse the repository at this point in the history
)

This commit also includes a pretty large refactor. I have moved all of
the Block/Header/Tx/Receipt/Log structs from the e2pg package into the
eth package. It's cleaner.
  • Loading branch information
ryandotsmith committed Oct 2, 2023
1 parent 13cde16 commit 0d969c2
Show file tree
Hide file tree
Showing 24 changed files with 1,113 additions and 746 deletions.
29 changes: 15 additions & 14 deletions abi2/abi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/indexsupply/x/bint"
"github.com/indexsupply/x/e2pg"
"github.com/indexsupply/x/eth"
"github.com/indexsupply/x/isxhash"

"github.com/holiman/uint256"
Expand Down Expand Up @@ -618,22 +619,22 @@ func (ig Integration) Events(context.Context) [][]byte { return [][]byte{} }

func (ig Integration) Delete(context.Context, e2pg.PG, uint64) error { return nil }

func (ig Integration) Insert(ctx context.Context, pg e2pg.PG, blocks []e2pg.Block) (int64, error) {
func (ig Integration) Insert(ctx context.Context, pg e2pg.PG, blocks []eth.Block) (int64, error) {
var (
err error
rows [][]any
lwc = &logWithCtx{ctx: ctx}
)
for bidx := 0; bidx < len(blocks); bidx++ {
for bidx := range blocks {
lwc.b = &blocks[bidx]
for ridx := 0; ridx < blocks[bidx].Receipts.Len(); ridx++ {
lwc.r = lwc.b.Receipts.At(ridx)
lwc.t = lwc.b.Transactions.At(ridx)
for ridx := range blocks[bidx].Receipts {
lwc.r = &lwc.b.Receipts[ridx]
lwc.t = &lwc.b.Txs[ridx]
lwc.ridx = ridx
for lidx := 0; lidx < lwc.r.Logs.Len(); lidx++ {
lwc.l = lwc.r.Logs.At(lidx)
for lidx := range blocks[bidx].Receipts[ridx].Logs {
lwc.l = &lwc.r.Logs[lidx]
lwc.lidx = lidx
if !bytes.Equal(ig.sighash, lwc.l.Topics.At(0)) {
if !bytes.Equal(ig.sighash, lwc.l.Topics[0]) {
continue
}
rows, err = ig.process(rows, lwc)
Expand All @@ -653,10 +654,10 @@ func (ig Integration) Insert(ctx context.Context, pg e2pg.PG, blocks []e2pg.Bloc

type logWithCtx struct {
ctx context.Context
b *e2pg.Block
t *e2pg.Transaction
r *e2pg.Receipt
l *e2pg.Log
b *eth.Block
t *eth.Tx
r *eth.Receipt
l *eth.Log
ridx, lidx int
}

Expand Down Expand Up @@ -699,7 +700,7 @@ func (ig Integration) process(rows [][]any, lwc *logWithCtx) ([][]any, error) {
for i, def := range ig.coldefs {
switch {
case def.Input.Indexed:
d := dbtype(def.Input.Type, lwc.l.Topics.At(1+i))
d := dbtype(def.Input.Type, lwc.l.Topics[1+i])
if b, ok := d.([]byte); ok && !def.Column.Accept(b) {
return nil, nil
}
Expand All @@ -726,7 +727,7 @@ func (ig Integration) process(rows [][]any, lwc *logWithCtx) ([][]any, error) {
for j, def := range ig.coldefs {
switch {
case def.Input.Indexed:
d := lwc.l.Topics.At(ictr)
d := lwc.l.Topics[ictr]
row[j] = dbtype(def.Input.Type, d)
ictr++
case def.Metadata:
Expand Down
2 changes: 1 addition & 1 deletion cmd/rlps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func log(v bool, h http.Handler) http.Handler {
})
}

//Set using: go build -ldflags="-X main.Version=XXX"
// Set using: go build -ldflags="-X main.Version=XXX"
var Version string

func commit() string {
Expand Down
52 changes: 26 additions & 26 deletions contrib/erc1155/erc1155.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d969c2

Please sign in to comment.