-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add current gas price resolver to API server.
- Loading branch information
Jiri Malek
committed
Apr 16, 2020
1 parent
2b5f7af
commit a957028
Showing
8 changed files
with
90 additions
and
1 deletion.
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,26 @@ | ||
# -------------------------------------------------------------------------- | ||
# Makefile for the Fantom API GaphQL Server | ||
# | ||
# v0.1 (2020/03/09) - Initial version, base API server build. | ||
# (c) Fantom Foundation, 2020 | ||
# -------------------------------------------------------------------------- | ||
|
||
# project related vars | ||
PROJECT := $(shell basename "$(PWD)") | ||
|
||
# go related vars | ||
GOBASE := $(shell pwd) | ||
GOBIN=$(CURDIR)/build | ||
|
||
## server: Make the API server as bin/frd | ||
server: | ||
go build -o $(GOBIN)/apiserver ./cmd/apiserver | ||
|
||
.PHONY: help | ||
all: help | ||
help: Makefile | ||
@echo | ||
@echo "Choose a make command in "$(PROJECT)":" | ||
@echo | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Package rpc implements bridge to Lachesis full node API interface. | ||
We recommend using local IPC for fast and the most efficient inter-process communication between the API server | ||
and an Opera/Lachesis node. Any remote RPC connection will work, but the performance may be significantly degraded | ||
by extra networking overhead of remote RPC calls. | ||
You should also consider security implications of opening Lachesis RPC interface for a remote access. | ||
If you considering it as your deployment strategy, you should establish encrypted channel between the API server | ||
and Lachesis RPC interface with connection limited to specified endpoints. | ||
We strongly discourage opening Lachesis RPC interface for unrestricted Internet access. | ||
*/ | ||
package rpc | ||
|
||
import "github.com/ethereum/go-ethereum/common/hexutil" | ||
|
||
// GasPrice resolves the current amount of WEI for single Gas. | ||
func (ftm *FtmBridge) GasPrice() (hexutil.Uint64, error) { | ||
// keep track of the operation | ||
ftm.log.Debugf("checking current gas price") | ||
|
||
// call for data | ||
var price hexutil.Big | ||
err := ftm.rpc.Call(&price, "ftm_gasPrice") | ||
if err != nil { | ||
ftm.log.Error("current gas price could not be obtained") | ||
return hexutil.Uint64(0), err | ||
} | ||
|
||
// if the price safely within the range | ||
if !price.ToInt().IsUint64() { | ||
ftm.log.Error("current gas price is too high and can not be extracted") | ||
return hexutil.Uint64(0), err | ||
} | ||
|
||
// inform and return | ||
ftm.log.Debugf("current gas price is %d", uint64(price.ToInt().Uint64())) | ||
return hexutil.Uint64(price.ToInt().Uint64()), nil | ||
} |
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