diff --git a/cmd/bootstrap/main.go b/cmd/bootstrap/main.go index f664537..974e5f4 100644 --- a/cmd/bootstrap/main.go +++ b/cmd/bootstrap/main.go @@ -230,12 +230,12 @@ func bootstrapCache() error { } for _, address := range ko.MustStrings("bootstrap.watchlist") { - if err := cache.Add(ctx, address); err != nil { + if err := cache.Add(ctx, ethutils.HexToAddress(address).Hex()); err != nil { return err } } for _, address := range ko.MustStrings("bootstrap.blacklist") { - if err := cache.Remove(ctx, address); err != nil { + if err := cache.Remove(ctx, ethutils.HexToAddress(address).Hex()); err != nil { return err } } diff --git a/internal/handler/contract_creation.go b/internal/handler/contract_creation.go index c45207b..0c44695 100644 --- a/internal/handler/contract_creation.go +++ b/internal/handler/contract_creation.go @@ -17,6 +17,7 @@ func HandleContractCreation() router.ContractCreationHandlerFunc { Success: ccp.Success, Timestamp: ccp.Timestamp, TxHash: ccp.TxHash, + TxType: contractCreationEventName, Payload: map[string]any{ "from": ccp.From, }, diff --git a/internal/processor/processor.go b/internal/processor/processor.go index 5a16e38..271a108 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -88,14 +88,13 @@ func (p *Processor) ProcessBlock(ctx context.Context, blockNumber uint64) error if err != nil { return err } - - if exists && tx.To() != nil { + if exists { if err := p.router.ProcessContractCreation( ctx, router.ContractCreationPayload{ From: from.Hex(), Block: blockNumber, - ContractAddress: tx.To().Hex(), + ContractAddress: receipt.ContractAddress.Hex(), Timestamp: block.Time(), TxHash: receipt.TxHash.Hex(), Success: true, @@ -105,63 +104,62 @@ func (p *Processor) ProcessBlock(ctx context.Context, blockNumber uint64) error } } } + } - if receipt.Status == 0 { - tx, err := p.chain.GetTransaction(ctx, receipt.TxHash) - if err != nil && !errors.Is(err, context.Canceled) { - return fmt.Errorf("get transaction error: tx %s: %v", receipt.TxHash.Hex(), err) + if receipt.Status == 0 { + tx, err := p.chain.GetTransaction(ctx, receipt.TxHash) + if err != nil && !errors.Is(err, context.Canceled) { + return fmt.Errorf("get transaction error: tx %s: %v", receipt.TxHash.Hex(), err) + } + if tx.To() == nil { + from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx) + if err != nil { + return fmt.Errorf("transaction decode error: tx %s: %v", receipt.TxHash.Hex(), err) } - if tx.To() == nil { + exists, err := p.cache.Exists(ctx, from.Hex()) + if err != nil { + return err + } + + if exists { + if err := p.router.ProcessContractCreation( + ctx, + router.ContractCreationPayload{ + From: from.Hex(), + Block: blockNumber, + ContractAddress: receipt.ContractAddress.Hex(), + Timestamp: block.Time(), + TxHash: receipt.TxHash.Hex(), + Success: false, + }, + ); err != nil && !errors.Is(err, context.Canceled) { + return fmt.Errorf("route reverted contract creation error: tx %s: %v", receipt.TxHash.Hex(), err) + } + } + } else { + exists, err := p.cache.Exists(ctx, tx.To().Hex()) + if err != nil { + return err + } + if exists { from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx) if err != nil { return fmt.Errorf("transaction decode error: tx %s: %v", receipt.TxHash.Hex(), err) } - exists, err := p.cache.Exists(ctx, from.Hex()) - if err != nil { - return err - } - - if exists { - if err := p.router.ProcessContractCreation( - ctx, - router.ContractCreationPayload{ - From: from.Hex(), - Block: blockNumber, - ContractAddress: tx.To().Hex(), - Timestamp: block.Time(), - TxHash: receipt.TxHash.Hex(), - Success: false, - }, - ); err != nil && !errors.Is(err, context.Canceled) { - return fmt.Errorf("route reverted contract creation error: tx %s: %v", receipt.TxHash.Hex(), err) - } - } - } else { - exists, err := p.cache.Exists(ctx, tx.To().Hex()) - if err != nil { - return err - } - if exists { - from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx) - if err != nil { - return fmt.Errorf("transaction decode error: tx %s: %v", receipt.TxHash.Hex(), err) - } - - if err := p.router.ProcessInputData( - ctx, - router.InputDataPayload{ - From: from.Hex(), - InputData: common.Bytes2Hex(tx.Data()), - Block: blockNumber, - ContractAddress: tx.To().Hex(), - Timestamp: block.Time(), - TxHash: receipt.TxHash.Hex(), - }, - ); err != nil && !errors.Is(err, context.Canceled) { - return fmt.Errorf("route revert transaction error: tx %s: %v", receipt.TxHash.Hex(), err) - } + if err := p.router.ProcessInputData( + ctx, + router.InputDataPayload{ + From: from.Hex(), + InputData: common.Bytes2Hex(tx.Data()), + Block: blockNumber, + ContractAddress: tx.To().Hex(), + Timestamp: block.Time(), + TxHash: receipt.TxHash.Hex(), + }, + ); err != nil && !errors.Is(err, context.Canceled) { + return fmt.Errorf("route revert transaction error: tx %s: %v", receipt.TxHash.Hex(), err) } } }