gorge/cmd/gorge.go
Mohammed Sohail 4c2f90f16c
init: PoC
* only supports legacy transactions
2022-11-23 12:48:52 +03:00

46 lines
999 B
Go

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")
}