diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..5b484c6 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,31 @@ +name: Go Code Format Check + +on: + pull_request: + types: [opened, synchronize] + +jobs: + format-check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Run gofmt to check code formatting + run: | + gofmt -l . + continue-on-error: true + + - name: Fail if formatting issues found + run: | + FORMATTED=$(gofmt -l .) + if [ -n "$FORMATTED" ]; then + echo "The following files need to be formatted:" + echo "$FORMATTED" + exit 1 + fi diff --git a/configs/config.go b/configs/config.go index 0a4536f..90256d9 100644 --- a/configs/config.go +++ b/configs/config.go @@ -14,12 +14,12 @@ type LogConfig struct { } type PollerConfig struct { - Enabled bool `mapstructure:"enabled"` - Interval int `mapstructure:"interval"` - BlocksPerPoll int `mapstructure:"blocksPerPoll"` - FromBlock int `mapstructure:"fromBlock"` - ForceFromBlock bool `mapstructure:"forceFromBlock"` - UntilBlock int `mapstructure:"untilBlock"` + Enabled bool `mapstructure:"enabled"` + Interval int `mapstructure:"interval"` + BlocksPerPoll int `mapstructure:"blocksPerPoll"` + FromBlock int `mapstructure:"fromBlock"` + ForceFromBlock bool `mapstructure:"forceFromBlock"` + UntilBlock int `mapstructure:"untilBlock"` } type CommitterConfig struct { diff --git a/internal/common/block.go b/internal/common/block.go index 2afa7ad..186f366 100644 --- a/internal/common/block.go +++ b/internal/common/block.go @@ -5,28 +5,28 @@ import ( ) type Block struct { - ChainId *big.Int `json:"chain_id"` - Number *big.Int `json:"number"` - Hash string `json:"hash"` - ParentHash string `json:"parent_hash"` - Timestamp uint64 `json:"timestamp"` - Nonce string `json:"nonce"` - Sha3Uncles string `json:"sha3_uncles"` - MixHash string `json:"mix_hash"` - Miner string `json:"miner"` - StateRoot string `json:"state_root"` - TransactionsRoot string `json:"transactions_root"` - ReceiptsRoot string `json:"receipts_root"` - LogsBloom string `json:"logs_bloom"` - Size uint64 `json:"size"` - ExtraData string `json:"extra_data"` - Difficulty *big.Int `json:"difficulty"` - TotalDifficulty *big.Int `json:"total_difficulty"` - TransactionCount uint64 `json:"transaction_count"` - GasLimit *big.Int `json:"gas_limit"` - GasUsed *big.Int `json:"gas_used"` - WithdrawalsRoot string `json:"withdrawals_root"` - BaseFeePerGas uint64 `json:"base_fee_per_gas"` + ChainId *big.Int `json:"chain_id"` + Number *big.Int `json:"number"` + Hash string `json:"hash"` + ParentHash string `json:"parent_hash"` + Timestamp uint64 `json:"timestamp"` + Nonce string `json:"nonce"` + Sha3Uncles string `json:"sha3_uncles"` + MixHash string `json:"mix_hash"` + Miner string `json:"miner"` + StateRoot string `json:"state_root"` + TransactionsRoot string `json:"transactions_root"` + ReceiptsRoot string `json:"receipts_root"` + LogsBloom string `json:"logs_bloom"` + Size uint64 `json:"size"` + ExtraData string `json:"extra_data"` + Difficulty *big.Int `json:"difficulty"` + TotalDifficulty *big.Int `json:"total_difficulty"` + TransactionCount uint64 `json:"transaction_count"` + GasLimit *big.Int `json:"gas_limit"` + GasUsed *big.Int `json:"gas_used"` + WithdrawalsRoot string `json:"withdrawals_root"` + BaseFeePerGas uint64 `json:"base_fee_per_gas"` } type BlockData struct { diff --git a/internal/common/log.go b/internal/common/log.go index 29ac500..5617ffa 100644 --- a/internal/common/log.go +++ b/internal/common/log.go @@ -5,14 +5,14 @@ import ( ) type Log struct { - ChainId *big.Int `json:"chain_id"` - BlockNumber *big.Int `json:"block_number"` - BlockHash string `json:"block_hash"` - BlockTimestamp uint64 `json:"block_timestamp"` - TransactionHash string `json:"transaction_hash"` - TransactionIndex uint64 `json:"transaction_index"` - LogIndex uint64 `json:"log_index"` - Address string `json:"address"` - Data string `json:"data"` - Topics []string `json:"topics"` + ChainId *big.Int `json:"chain_id"` + BlockNumber *big.Int `json:"block_number"` + BlockHash string `json:"block_hash"` + BlockTimestamp uint64 `json:"block_timestamp"` + TransactionHash string `json:"transaction_hash"` + TransactionIndex uint64 `json:"transaction_index"` + LogIndex uint64 `json:"log_index"` + Address string `json:"address"` + Data string `json:"data"` + Topics []string `json:"topics"` } diff --git a/internal/common/trace.go b/internal/common/trace.go index bc95fc4..e54072c 100644 --- a/internal/common/trace.go +++ b/internal/common/trace.go @@ -5,25 +5,25 @@ import ( ) type Trace struct { - ChainID *big.Int `json:"chain_id"` - BlockNumber *big.Int `json:"block_number"` - BlockHash string `json:"block_hash"` - BlockTimestamp uint64 `json:"block_timestamp"` - TransactionHash string `json:"transaction_hash"` - TransactionIndex uint64 `json:"transaction_index"` - Subtraces int64 `json:"subtraces"` - TraceAddress []uint64 `json:"trace_address"` - TraceType string `json:"trace_type"` - CallType string `json:"call_type"` - Error string `json:"error"` - FromAddress string `json:"from_address"` - ToAddress string `json:"to_address"` - Gas *big.Int `json:"gas"` - GasUsed *big.Int `json:"gas_used"` - Input string `json:"input"` - Output string `json:"output"` - Value *big.Int `json:"value"` - Author string `json:"author"` - RewardType string `json:"reward_type"` - RefundAddress string `json:"refund_address"` + ChainID *big.Int `json:"chain_id"` + BlockNumber *big.Int `json:"block_number"` + BlockHash string `json:"block_hash"` + BlockTimestamp uint64 `json:"block_timestamp"` + TransactionHash string `json:"transaction_hash"` + TransactionIndex uint64 `json:"transaction_index"` + Subtraces int64 `json:"subtraces"` + TraceAddress []uint64 `json:"trace_address"` + TraceType string `json:"trace_type"` + CallType string `json:"call_type"` + Error string `json:"error"` + FromAddress string `json:"from_address"` + ToAddress string `json:"to_address"` + Gas *big.Int `json:"gas"` + GasUsed *big.Int `json:"gas_used"` + Input string `json:"input"` + Output string `json:"output"` + Value *big.Int `json:"value"` + Author string `json:"author"` + RewardType string `json:"reward_type"` + RefundAddress string `json:"refund_address"` } diff --git a/internal/common/transaction.go b/internal/common/transaction.go index df71a7a..c7b4407 100644 --- a/internal/common/transaction.go +++ b/internal/common/transaction.go @@ -5,24 +5,24 @@ import ( ) type Transaction struct { - ChainId *big.Int `json:"chain_id"` - Hash string `json:"hash"` - Nonce uint64 `json:"nonce"` - BlockHash string `json:"block_hash"` - BlockNumber *big.Int `json:"block_number"` - BlockTimestamp uint64 `json:"block_timestamp"` - TransactionIndex uint64 `json:"transaction_index"` - FromAddress string `json:"from_address"` - ToAddress string `json:"to_address"` - Value *big.Int `json:"value"` - Gas uint64 `json:"gas"` - GasPrice *big.Int `json:"gas_price"` - Data string `json:"data"` - MaxFeePerGas *big.Int `json:"max_fee_per_gas"` - MaxPriorityFeePerGas *big.Int `json:"max_priority_fee_per_gas"` - TransactionType uint8 `json:"transaction_type"` - R *big.Int `json:"r"` - S *big.Int `json:"s"` - V *big.Int `json:"v"` - AccessListJson string `json:"access_list_json"` + ChainId *big.Int `json:"chain_id"` + Hash string `json:"hash"` + Nonce uint64 `json:"nonce"` + BlockHash string `json:"block_hash"` + BlockNumber *big.Int `json:"block_number"` + BlockTimestamp uint64 `json:"block_timestamp"` + TransactionIndex uint64 `json:"transaction_index"` + FromAddress string `json:"from_address"` + ToAddress string `json:"to_address"` + Value *big.Int `json:"value"` + Gas uint64 `json:"gas"` + GasPrice *big.Int `json:"gas_price"` + Data string `json:"data"` + MaxFeePerGas *big.Int `json:"max_fee_per_gas"` + MaxPriorityFeePerGas *big.Int `json:"max_priority_fee_per_gas"` + TransactionType uint8 `json:"transaction_type"` + R *big.Int `json:"r"` + S *big.Int `json:"s"` + V *big.Int `json:"v"` + AccessListJson string `json:"access_list_json"` } diff --git a/internal/handlers/api.go b/internal/handlers/api.go index 8d1bd0b..68cbbe2 100644 --- a/internal/handlers/api.go +++ b/internal/handlers/api.go @@ -31,4 +31,4 @@ func Handler(r *chi.Mux) { w.WriteHeader(http.StatusOK) w.Write([]byte("ok")) }) -} \ No newline at end of file +} diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 4625c24..6612093 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -53,4 +53,4 @@ var ( Name: "failure_recoverer_first_block_in_batch", Help: "The first block number in the failure recoverer batch", }) -) \ No newline at end of file +) diff --git a/internal/middleware/authorization.go b/internal/middleware/authorization.go index 96445b7..a3fc749 100644 --- a/internal/middleware/authorization.go +++ b/internal/middleware/authorization.go @@ -24,4 +24,4 @@ func Authorization(next http.Handler) http.Handler { func validateCredentials(username, password string) bool { return username == "admin" && password == "admin" -} \ No newline at end of file +}