wallet/pkg/eth/eth_block.go
Anton Nesterov 5efcf35dd6
[init]
2024-08-31 16:59:34 +02:00

38 lines
777 B
Go

package eth
import (
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)
func EthLastBlock() (uint64, error) {
client, err := ethclient.Dial(ethNode.rpcNode)
if err != nil {
return 0, err
}
last_eth_block, err := client.BlockNumber(context.Background())
if err != nil {
return 0, err
}
return last_eth_block, nil
}
func EthBlockByNumber(blockNumber uint64) (*types.Block, error) {
client, err := ethclient.Dial(ethNode.rpcNode)
if err != nil {
return nil, err
}
_blockNumber := big.NewInt(int64(blockNumber))
fmt.Println("Block fetch: ", _blockNumber)
block, err := client.BlockByNumber(context.Background(), _blockNumber)
if err != nil {
return nil, err
}
return block, nil
}