Commit 9b7cd81c authored by vicotor's avatar vicotor

update get block time

parent c5037ac1
......@@ -56,9 +56,11 @@ func (d *Dao) GetBlockTime(chain *config.ChainConfig, height int64) (timestamp i
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
block, err := chainInfo.cli.BlockByNumber(ctx, big.NewInt(int64(height)))
header, err := chainInfo.cli.HeaderByNumber(ctx, big.NewInt(int64(height)))
if err == nil {
return int64(block.Time()), nil
return int64(header.Time), nil
} else {
time.Sleep(500 * time.Millisecond)
}
}
return
......
......@@ -11,6 +11,16 @@ import (
"testing"
)
func TestGetBlockTime(t *testing.T) {
client, _ := ethclient.Dial("https://bsctest.bitheart.org")
height := big.NewInt(65784850)
block, err := client.HeaderByNumber(context.Background(), height)
if err != nil {
t.Fatal(err)
}
fmt.Println(block.Time())
}
func TestGetReceiveToken(t *testing.T) {
client, _ := ethclient.Dial("http://rpc.hole.bitheart.org")
ct, _ := bridge.NewBridgeContract(common.HexToAddress("0xceEC8799139C698De532e363DA7395E25F409775"), client)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment