Skip to content

Commit

Permalink
Add reciept status in log for graphql.
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed Aug 31, 2021
1 parent a28892f commit d0c3241
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/eth/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var (
"contractAddress": nil,
"logs": test_helpers.MockReceipts[0].Logs,
"logsBloom": test_helpers.MockReceipts[0].Bloom,
"root": hexutil.Bytes(test_helpers.MockReceipts[0].PostState),
"status": hexutil.Uint(test_helpers.MockReceipts[0].Status),
}
expectedReceipt2 = map[string]interface{}{
"blockHash": blockHash,
Expand Down
2 changes: 1 addition & 1 deletion pkg/eth/cid_retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (ecr *CIDRetriever) RetrieveFilteredGQLLogs(tx *sqlx.Tx, rctFilter ReceiptF
id := 1
pgStr := `SELECT eth.log_cids.index, eth.log_cids.receipt_id,
eth.log_cids.address, eth.log_cids.topic0, eth.log_cids.topic1, eth.log_cids.topic2, eth.log_cids.topic3,
eth.log_cids.log_data, eth.transaction_cids.tx_hash, data, eth.receipt_cids.cid
eth.log_cids.log_data, eth.transaction_cids.tx_hash, data, eth.receipt_cids.cid, eth.receipt_cids.post_status
FROM eth.log_cids, eth.receipt_cids, eth.transaction_cids, eth.header_cids, public.blocks
WHERE eth.log_cids.receipt_id = receipt_cids.id
AND receipt_cids.tx_id = transaction_cids.id
Expand Down
17 changes: 9 additions & 8 deletions pkg/eth/ipld_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,18 @@ func (f *IPLDFetcher) FetchLogs(logCIDs []customLog) ([]*types.Log, error) {
TxIndex: uint(l.TxnIndex),
BlockHash: common.HexToHash(l.BlockHash),
Index: uint(l.Index),
Removed: false, // TODO: check where to get this value
}
}

return logs, nil
}

type logsCID struct {
Log *types.Log
CID string
RctCID string
RctData []byte
Log *types.Log
CID string
RctCID string
RctData []byte
RctStatus uint64
}

// FetchGQLLogs fetches logs for graphql.
Expand Down Expand Up @@ -245,9 +245,10 @@ func (f *IPLDFetcher) FetchGQLLogs(logCIDs []customLog) ([]logsCID, error) {
Index: uint(l.Index),
TxHash: common.HexToHash(l.TxHash),
},
CID: l.LeafCID,
RctCID: l.RctCID,
RctData: l.RctData,
CID: l.LeafCID,
RctCID: l.RctCID,
RctData: l.RctData,
RctStatus: l.RctStatus,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/eth/test_helpers/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func createLegacyTransactionsAndReceipts() (types.Transactions, types.Receipts,
log.Fatal(err)
}
// make receipts
mockReceipt1 := types.NewReceipt(common.HexToHash("0x0").Bytes(), false, 50)
mockReceipt1 := types.NewReceipt(nil, false, 50)

hash1 := signedTrx1.Hash()
MockLog1.TxHash = hash1
Expand Down
1 change: 1 addition & 0 deletions pkg/eth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type customLog struct {
Topic3 string `db:"topic3"`
RctData []byte `db:"data"`
RctCID string `db:"cid"`
RctStatus uint64 `db:"post_status"`
BlockNumber string `db:"block_number"`
BlockHash string `db:"block_hash"`
TxnIndex int64 `db:"txn_index"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/graphql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type LogResponse struct {
Topics []common.Hash `json:"topics"`
Data hexutil.Bytes `json:"data"`
Transaction TransactionResp `json:"transaction"`
Status int32 `json:"status"`
}

type TransactionResp struct {
Expand Down Expand Up @@ -52,6 +53,7 @@ func (c *Client) GetLogs(ctx context.Context, hash common.Hash, address common.A
transaction {
hash
}
status
}
}
`, hash.String(), address.String())
Expand Down
6 changes: 6 additions & 0 deletions pkg/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Log struct {
cid string
receiptCID string
ipldBlock []byte
status uint64
}

func (l *Log) Transaction(ctx context.Context) *Transaction {
Expand Down Expand Up @@ -129,6 +130,10 @@ func (l *Log) IpldBlock(ctx context.Context) hexutil.Bytes {
return hexutil.Bytes(l.ipldBlock)
}

func (l *Log) Status(ctx context.Context) int32 {
return int32(l.status)
}

// Transaction represents an Ethereum transaction.
// backend and hash are mandatory; all others will be fetched when required.
type Transaction struct {
Expand Down Expand Up @@ -1039,6 +1044,7 @@ func (r *Resolver) GetLogs(ctx context.Context, args struct {
transaction: &Transaction{
hash: l.Log.TxHash,
},
status: l.RctStatus,
})
}

Expand Down
1 change: 1 addition & 0 deletions pkg/graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ var _ = Describe("GraphQL", func() {
Topics: test_helpers.MockLog1.Topics,
Data: hexutil.Bytes(test_helpers.MockLog1.Data),
Transaction: graphql.TransactionResp{Hash: test_helpers.MockTransactions[0].Hash()},
Status: int32(test_helpers.MockReceipts[0].Status),
},
}
Expect(logs).To(Equal(expectedLogs))
Expand Down
3 changes: 3 additions & 0 deletions pkg/graphql/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const schema string = `
# IPLD block data for the Receipt this Log exists in.
ipldBlock: Bytes!
# Status of the Receipt IPLD block this Log exists in.
status: Int!
}
# Transaction is an Ethereum transaction.
Expand Down

0 comments on commit d0c3241

Please sign in to comment.