Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duplication fix. #81

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions blockchain/arbitrum_one/arbitrum_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/arbitrum_sepolia/arbitrum_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/b3/b3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/b3_sepolia/b3_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/blockchain.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/game7_testnet/game7_testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions blockchain/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
19 changes: 5 additions & 14 deletions blockchain/imx_zkevm/imx_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/imx_zkevm_sepolia/imx_zkevm_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/mantle/mantle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 5 additions & 14 deletions blockchain/mantle_sepolia/mantle_sepolia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading
Loading