From 18266c4f9d47fa9f3879c8cdd7a85d5d6dd9eb25 Mon Sep 17 00:00:00 2001 From: Ashwin Phatak Date: Fri, 21 May 2021 09:00:38 +0530 Subject: [PATCH] Get receipt CID and block data for logs. --- pkg/eth/backend.go | 9 +++++---- pkg/graphql/graphql.go | 10 ++++++++++ pkg/graphql/schema.go | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pkg/eth/backend.go b/pkg/eth/backend.go index 4d578dd6..999174b6 100644 --- a/pkg/eth/backend.go +++ b/pkg/eth/backend.go @@ -41,7 +41,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/trie" - "github.com/vulcanize/ipfs-ethdb" + ipfsethdb "github.com/vulcanize/ipfs-ethdb" "github.com/vulcanize/ipld-eth-indexer/pkg/ipfs" "github.com/vulcanize/ipld-eth-indexer/pkg/postgres" shared2 "github.com/vulcanize/ipld-eth-indexer/pkg/shared" @@ -59,10 +59,10 @@ var ( const ( RetrieveCanonicalBlockHashByNumber = `SELECT block_hash FROM eth.header_cids INNER JOIN public.blocks ON (header_cids.mh_key = blocks.key) - WHERE id = (SELECT canonical_header_id($1))` + WHERE id = (SELECT public.canonical_header($1))` RetrieveCanonicalHeaderByNumber = `SELECT cid, data FROM eth.header_cids INNER JOIN public.blocks ON (header_cids.mh_key = blocks.key) - WHERE id = (SELECT canonical_header_id($1))` + WHERE id = (SELECT public.canonical_header($1))` RetrieveTD = `SELECT td FROM eth.header_cids WHERE header_cids.block_hash = $1` RetrieveRPCTransaction = `SELECT blocks.data, block_hash, block_number, index FROM public.blocks, eth.transaction_cids, eth.header_cids @@ -76,7 +76,7 @@ const ( AND block_number <= (SELECT block_number FROM eth.header_cids WHERE block_hash = $2) - AND header_cids.id = (SELECT canonical_header_id(block_number)) + AND header_cids.id = (SELECT public.canonical_header(block_number)) ORDER BY block_number DESC LIMIT 1` RetrieveCodeByMhKey = `SELECT data FROM public.blocks WHERE key = $1` @@ -509,6 +509,7 @@ func (b *Backend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log if err := rlp.DecodeBytes(rctBytes, &rct); err != nil { return nil, err } + logs[i] = rct.Logs } return logs, nil diff --git a/pkg/graphql/graphql.go b/pkg/graphql/graphql.go index 12533016..19dfabc7 100644 --- a/pkg/graphql/graphql.go +++ b/pkg/graphql/graphql.go @@ -91,6 +91,8 @@ type Log struct { backend *eth.Backend transaction *Transaction log *types.Log + cid string + ipldBlock []byte } func (l *Log) Transaction(ctx context.Context) *Transaction { @@ -117,6 +119,14 @@ func (l *Log) Data(ctx context.Context) hexutil.Bytes { return hexutil.Bytes(l.log.Data) } +func (l *Log) Cid(ctx context.Context) string { + return l.cid +} + +func (l *Log) IpldBlock(ctx context.Context) hexutil.Bytes { + return hexutil.Bytes(l.ipldBlock) +} + // Transaction represents an Ethereum transaction. // backend and hash are mandatory; all others will be fetched when required. type Transaction struct { diff --git a/pkg/graphql/schema.go b/pkg/graphql/schema.go index 8057eac9..de989e74 100644 --- a/pkg/graphql/schema.go +++ b/pkg/graphql/schema.go @@ -66,6 +66,12 @@ const schema string = ` data: Bytes! # Transaction is the transaction that generated this log entry. transaction: Transaction! + + # CID for the Receipt IPLD block this Log exists in. + cid: String! + + # IPLD block data for the Receipt this Log exists in. + ipldBlock: Bytes! } # Transaction is an Ethereum transaction.