-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ethrpc: support nodes which return invalid vrs in no-strict mode (#148)
- Loading branch information
Showing
3 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/0xsequence/ethkit/ethgas" | ||
"github.com/0xsequence/ethkit/ethmonitor" | ||
"github.com/0xsequence/ethkit/ethrpc" | ||
"github.com/0xsequence/ethkit/util" | ||
"github.com/goware/logger" | ||
) | ||
|
||
var ETH_NODE_URL = "http://localhost:8545" | ||
var ETH_NODE_WSS_URL = "" | ||
|
||
func init() { | ||
testConfig, err := util.ReadTestConfig("../../ethkit-test.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if testConfig["POLYGON_MAINNET_URL"] != "" { | ||
ETH_NODE_URL = testConfig["POLYGON_MAINNET_URL"] | ||
ETH_NODE_WSS_URL = testConfig["POLYGON_MAINNET_WSS_URL"] | ||
} | ||
// if testConfig["MAINNET_URL"] != "" { | ||
// ETH_NODE_URL = testConfig["MAINNET_URL"] | ||
// ETH_NODE_WSS_URL = testConfig["MAINNET_WSS_URL"] | ||
// } | ||
|
||
// ETH_NODE_URL = "" | ||
// ETH_NODE_WSS_URL = "" | ||
} | ||
|
||
func main() { | ||
fmt.Println("chain-ethgas start") | ||
|
||
// Provider | ||
provider, err := ethrpc.NewProvider(ETH_NODE_URL, ethrpc.WithStreaming(ETH_NODE_WSS_URL)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Monitor options | ||
monitorOptions := ethmonitor.DefaultOptions | ||
monitorOptions.PollingInterval = time.Duration(1000 * time.Millisecond) | ||
// monitorOptions.DebugLogging = true | ||
monitorOptions.WithLogs = true | ||
monitorOptions.BlockRetentionLimit = 400 | ||
monitorOptions.StartBlockNumber = nil // track the head | ||
|
||
// ... | ||
monitor, err := ethmonitor.NewMonitor(provider, monitorOptions) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
go func() { | ||
err = monitor.Run(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
}() | ||
defer monitor.Stop() | ||
|
||
logger := logger.NewLogger(logger.LogLevel_INFO) | ||
|
||
gasGague, err := ethgas.NewGasGauge(logger, monitor, 1, false) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
go func() { | ||
err := gasGague.Run(ctx) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
defer gasGague.Stop() | ||
|
||
sub := gasGague.Subscribe() | ||
defer sub.Unsubscribe() | ||
|
||
for { | ||
select { | ||
case <-sub.Blocks(): | ||
prices := gasGague.SuggestedGasPrice() | ||
bids := gasGague.SuggestedGasPriceBid() | ||
fmt.Println(prices.BlockNum, prices.BlockTime, prices.Instant, prices.Fast, prices.Standard, prices.Slow) | ||
fmt.Println(bids.BlockNum, bids.BlockTime, bids.Instant, bids.Fast, bids.Standard, bids.Slow) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters