mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-08 11:56:46 +01:00
Update ethclient contracts & add wdelayer events
This commit is contained in:
63
eth/helpers.go
Normal file
63
eth/helpers.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package eth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func addBlock(url string) {
|
||||
method := "POST"
|
||||
|
||||
payload := strings.NewReader("{\n \"jsonrpc\":\"2.0\",\n \"method\":\"evm_mine\",\n \"params\":[],\n \"id\":1\n}")
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest(method, url, payload)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
fmt.Println("Error when closing:", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func addBlocks(numBlocks int64, url string) {
|
||||
for i := int64(0); i < numBlocks; i++ {
|
||||
addBlock(url)
|
||||
}
|
||||
}
|
||||
|
||||
func addTime(seconds float64, url string) {
|
||||
secondsStr := strconv.FormatFloat(seconds, 'E', -1, 32)
|
||||
|
||||
method := "POST"
|
||||
payload := strings.NewReader("{\n \"jsonrpc\":\"2.0\",\n \"method\":\"evm_increaseTime\",\n \"params\":[" + secondsStr + "],\n \"id\":1\n}")
|
||||
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest(method, url, payload)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
fmt.Println("Error when closing:", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user