Add status field for pre-byzantium blocks.

This commit is contained in:
Arijit Das
2021-09-14 17:25:48 +05:30
parent 458aae1c1e
commit 04a0f9a751
14 changed files with 258 additions and 121 deletions
+1 -45
View File
@@ -1046,7 +1046,7 @@ func (r *Resolver) GetLogs(ctx context.Context, args struct {
return nil, err
}
rctLog := decomposeGQLLogs(filteredLogs)
rctLog, err := r.backend.DecomposeGQLLogs(filteredLogs)
if err != nil {
return nil, err
}
@@ -1068,47 +1068,3 @@ func (r *Resolver) GetLogs(ctx context.Context, args struct {
return &ret, nil
}
type logsCID struct {
Log *types.Log
CID string
RctCID string
LogLeafData []byte
RctStatus uint64
}
// decomposeGQLLogs return logs for graphql.
func decomposeGQLLogs(logCIDs []eth.LogResult) []logsCID {
logs := make([]logsCID, len(logCIDs))
for i, l := range logCIDs {
topics := make([]common.Hash, 0)
if l.Topic0 != "" {
topics = append(topics, common.HexToHash(l.Topic0))
}
if l.Topic1 != "" {
topics = append(topics, common.HexToHash(l.Topic1))
}
if l.Topic2 != "" {
topics = append(topics, common.HexToHash(l.Topic2))
}
if l.Topic3 != "" {
topics = append(topics, common.HexToHash(l.Topic3))
}
logs[i] = logsCID{
Log: &types.Log{
Address: common.HexToAddress(l.Address),
Topics: topics,
Data: l.Data,
Index: uint(l.Index),
TxHash: common.HexToHash(l.TxHash),
},
CID: l.LeafCID,
RctCID: l.RctCID,
LogLeafData: l.LogLeafData,
RctStatus: l.RctStatus,
}
}
return logs
}
+21
View File
@@ -167,6 +167,11 @@ var _ = Describe("GraphQL", func() {
err = tx.Close(err)
Expect(err).ToNot(HaveOccurred())
tx, err = indexAndPublisher.PushBlock(test_helpers.MockByzantiumBlock, test_helpers.MockByzantiumReceipts, test_helpers.MockByzantiumBlock.Difficulty())
Expect(err).ToNot(HaveOccurred())
err = tx.Close(err)
Expect(err).ToNot(HaveOccurred())
graphQLServer, err = graphql.New(backend, gqlEndPoint, nil, []string{"*"}, rpc.HTTPTimeouts{})
Expect(err).ToNot(HaveOccurred())
@@ -216,6 +221,22 @@ var _ = Describe("GraphQL", func() {
Expect(logs).To(Equal(expectedLogs))
})
It("Retrieve logs for pre byzantium block", func() {
logs, err := client.GetLogs(ctx, test_helpers.MockByzantiumBlock.Hash(), nil)
Expect(err).ToNot(HaveOccurred())
expectedLogs := []graphql.LogResponse{
{
Topics: test_helpers.MockLog7.Topics,
Data: hexutil.Bytes(test_helpers.MockLog1.Data),
Transaction: graphql.TransactionResp{Hash: test_helpers.MockByzantiumTransactions[0].Hash()},
ReceiptCID: test_helpers.ByzantiumRctCID.String(),
Status: int32(test_helpers.MockByzantiumReceipts[0].Status),
},
}
Expect(logs).To(Equal(expectedLogs))
})
It("Retrieves all the logs for the receipt that matches the provided blockHash and nil contract address", func() {
logs, err := client.GetLogs(ctx, blockHash, nil)
Expect(err).ToNot(HaveOccurred())