Skip to content

Commit

Permalink
Merge pull request #81 from moonstream-to/fix-request-duplication
Browse files Browse the repository at this point in the history
Add duplication fix.
  • Loading branch information
Andrei-Dolgolev authored Oct 2, 2024
2 parents 966fdab + 90c4cfb commit 619e223
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 230 deletions.
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

0 comments on commit 619e223

Please sign in to comment.