init: PoC
* only supports legacy transactions
This commit is contained in:
45
cmd/gorge.go
Normal file
45
cmd/gorge.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"git.grassecon.net/chaintool/gorge/pkg/block"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/lmittmann/w3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client := w3.MustDial("https://rpc.ankr.com/eth")
|
||||
defer client.Close()
|
||||
|
||||
defer traceExecTime(time.Now())
|
||||
blockFetcher := block.NewBlockFetcher(block.BlockFetcherOpts{
|
||||
W3Client: client,
|
||||
Signer: types.NewEIP155Signer(big.NewInt(1)),
|
||||
})
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
// https://etherscan.io/block/16031266
|
||||
res, err := blockFetcher.FetchBlock(ctx, big.NewInt(5000000))
|
||||
if err != nil {
|
||||
log.Fatalf("Could not fetch block: %v", err)
|
||||
}
|
||||
|
||||
resJson, err := json.Marshal(res)
|
||||
if err != nil {
|
||||
log.Fatalf("json.Marshal failed: %v", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile("block.json", resJson, 0644); err != nil {
|
||||
log.Fatalf("Write file failed: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Block successfully obtained")
|
||||
}
|
||||
12
cmd/trace.go
Normal file
12
cmd/trace.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func traceExecTime(start time.Time) {
|
||||
elapsed := time.Since(start)
|
||||
|
||||
log.Printf("Exec time: %s", elapsed)
|
||||
}
|
||||
Reference in New Issue
Block a user