diff --git a/blockchain/arbitrum_one/arbitrum_one.go b/blockchain/arbitrum_one/arbitrum_one.go index 5ae4996..0af2e50 100644 --- a/blockchain/arbitrum_one/arbitrum_one.go +++ b/blockchain/arbitrum_one/arbitrum_one.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/arbitrum_sepolia/arbitrum_sepolia.go b/blockchain/arbitrum_sepolia/arbitrum_sepolia.go index bdfd94f..b83b582 100644 --- a/blockchain/arbitrum_sepolia/arbitrum_sepolia.go +++ b/blockchain/arbitrum_sepolia/arbitrum_sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/b3/b3.go b/blockchain/b3/b3.go index 602a58f..5b1efcf 100644 --- a/blockchain/b3/b3.go +++ b/blockchain/b3/b3.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/b3_sepolia/b3_sepolia.go b/blockchain/b3_sepolia/b3_sepolia.go index f881c64..9f9d7bf 100644 --- a/blockchain/b3_sepolia/b3_sepolia.go +++ b/blockchain/b3_sepolia/b3_sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/blockchain.go.tmpl b/blockchain/blockchain.go.tmpl index bbd5a70..fce259b 100644 --- a/blockchain/blockchain.go.tmpl +++ b/blockchain/blockchain.go.tmpl @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/ethereum/ethereum.go b/blockchain/ethereum/ethereum.go index a9e960c..fb58676 100644 --- a/blockchain/ethereum/ethereum.go +++ b/blockchain/ethereum/ethereum.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/game7_orbit_arbitrum_sepolia/game7_orbit_arbitrum_sepolia.go b/blockchain/game7_orbit_arbitrum_sepolia/game7_orbit_arbitrum_sepolia.go index 946c2f7..af0e3b1 100644 --- a/blockchain/game7_orbit_arbitrum_sepolia/game7_orbit_arbitrum_sepolia.go +++ b/blockchain/game7_orbit_arbitrum_sepolia/game7_orbit_arbitrum_sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/game7_testnet/game7_testnet.go b/blockchain/game7_testnet/game7_testnet.go index 9928402..e53e90a 100644 --- a/blockchain/game7_testnet/game7_testnet.go +++ b/blockchain/game7_testnet/game7_testnet.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/handlers.go b/blockchain/handlers.go index 812c575..cdef3e6 100644 --- a/blockchain/handlers.go +++ b/blockchain/handlers.go @@ -238,12 +238,6 @@ func FindDeployedBlock(client BlockchainClient, address string) (uint64, error) ctx := context.Background() - // with timeout - - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) - - defer cancel() - latestBlockNumber, err := client.GetLatestBlockNumber() if err != nil { @@ -257,6 +251,12 @@ func FindDeployedBlock(client BlockchainClient, address string) (uint64, error) for left < right { mid := (left + right) / 2 + // with timeout + + ctx, cancel := context.WithTimeout(ctx, 30*time.Second) + + defer cancel() + code, err = client.GetCode(ctx, common.HexToAddress(address), mid) if err != nil { diff --git a/blockchain/imx_zkevm/imx_zkevm.go b/blockchain/imx_zkevm/imx_zkevm.go index 986c600..641fef3 100644 --- a/blockchain/imx_zkevm/imx_zkevm.go +++ b/blockchain/imx_zkevm/imx_zkevm.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/imx_zkevm_sepolia/imx_zkevm_sepolia.go b/blockchain/imx_zkevm_sepolia/imx_zkevm_sepolia.go index 64ad7ae..5ae48de 100644 --- a/blockchain/imx_zkevm_sepolia/imx_zkevm_sepolia.go +++ b/blockchain/imx_zkevm_sepolia/imx_zkevm_sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/mantle/mantle.go b/blockchain/mantle/mantle.go index 7add238..3366ba8 100644 --- a/blockchain/mantle/mantle.go +++ b/blockchain/mantle/mantle.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/mantle_sepolia/mantle_sepolia.go b/blockchain/mantle_sepolia/mantle_sepolia.go index e85f6fa..cdf42b1 100644 --- a/blockchain/mantle_sepolia/mantle_sepolia.go +++ b/blockchain/mantle_sepolia/mantle_sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/polygon/polygon.go b/blockchain/polygon/polygon.go index 07acc96..557eb1b 100644 --- a/blockchain/polygon/polygon.go +++ b/blockchain/polygon/polygon.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/sepolia/sepolia.go b/blockchain/sepolia/sepolia.go index 097adde..e0691c5 100644 --- a/blockchain/sepolia/sepolia.go +++ b/blockchain/sepolia/sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/xai/xai.go b/blockchain/xai/xai.go index 4dbfa92..c9a640e 100644 --- a/blockchain/xai/xai.go +++ b/blockchain/xai/xai.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash. diff --git a/blockchain/xai_sepolia/xai_sepolia.go b/blockchain/xai_sepolia/xai_sepolia.go index 08bf180..23dac7d 100644 --- a/blockchain/xai_sepolia/xai_sepolia.go +++ b/blockchain/xai_sepolia/xai_sepolia.go @@ -71,25 +71,16 @@ func (c *Client) GetLatestBlockNumber() (*big.Int, error) { return blockNumber, nil } -// BlockByNumber returns the block with the given number. +// GetBlockByNumber returns the block with the given number. func (c *Client) GetBlockByNumber(ctx context.Context, number *big.Int, withTransactions bool) (*seer_common.BlockJson, error) { - - var rawResponse json.RawMessage // Use RawMessage to capture the entire JSON response - err := c.rpcClient.CallContext(ctx, &rawResponse, "eth_getBlockByNumber", "0x"+number.Text(16), withTransactions) + var block *seer_common.BlockJson + err := c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", fmt.Sprintf("0x%x", number), withTransactions) if err != nil { - fmt.Println("Error calling eth_getBlockByNumber: ", err) + fmt.Println("Error calling eth_getBlockByNumber:", err) return nil, err } - var response_json map[string]interface{} - - err = json.Unmarshal(rawResponse, &response_json) - - delete(response_json, "transactions") - - var block *seer_common.BlockJson - err = c.rpcClient.CallContext(ctx, &block, "eth_getBlockByNumber", "0x"+number.Text(16), true) // true to include transactions - return block, err + return block, nil } // BlockByHash returns the block with the given hash.