From e1fb5f20f727aefdaa0778a8ad5242764a959ce3 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Wed, 13 Dec 2023 05:52:22 +0000 Subject: [PATCH] feat: add Firehose logs --- blockchain/blockchain.go | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 75d5175aee..836780f2d0 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -339,6 +339,48 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit if err := verifyBlock(txn, block); err != nil { return err } + + // Firehose integration + // TODO: add runtime option to toggle this on and off + { + fmt.Printf("FIRE BLOCK_BEGIN %d\n", block.Number) + + for indTx, tx := range block.Transactions { + fmt.Printf("FIRE BEGIN_TRX 0x%X ", tx.Hash().Bytes()) + + switch tx.(type) { + case *core.DeployTransaction: + fmt.Println("DEPLOY") + case *core.InvokeTransaction: + fmt.Println("INVOKE_FUNCTION") + case *core.DeclareTransaction: + fmt.Println("DECLARE") + case *core.DeployAccountTransaction: + fmt.Println("DEPLOY_ACCOUNT") + case *core.L1HandlerTransaction: + fmt.Println("L1_HANDLER") + default: + panic("not a transaction") + } + + receipt := block.Receipts[indTx] + + for indEvent, event := range receipt.Events { + fmt.Printf("FIRE TRX_BEGIN_EVENT 0x%X 0x%X\n", tx.Hash().Bytes(), event.From.Bytes()) + + for _, key := range event.Keys { + fmt.Printf("FIRE TRX_EVENT_KEY 0x%X %d 0x%X\n", tx.Hash().Bytes(), indEvent, key.Bytes()) + } + + for _, data := range event.Data { + fmt.Printf("FIRE TRX_EVENT_DATA 0x%X %d 0x%X\n", tx.Hash().Bytes(), indEvent, data.Bytes()) + } + } + } + + fmt.Printf("FIRE BLOCK_END %d 0x%X 0x%X %d %d\n", block.Number, block.Hash.Bytes(), block.ParentHash.Bytes(), block.Timestamp, len(block.Transactions)) + } + if err := core.NewState(txn).Update(block.Number, stateUpdate, newClasses); err != nil { return err }