aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@byzantine-lab.io>2019-10-07 18:08:38 +0800
committerGitHub <noreply@github.com>2019-10-07 18:08:38 +0800
commit5244bb6d79fc118bfdabeb367b645608ea05003a (patch)
tree8ebca1a767c92c680ef3339334961ba607b5c903
parentd3e0eca00b8bf09b491b7404004dbc67e3eb904d (diff)
downloadgo-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.tar
go-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.tar.gz
go-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.tar.bz2
go-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.tar.lz
go-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.tar.xz
go-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.tar.zst
go-tangerine-5244bb6d79fc118bfdabeb367b645608ea05003a.zip
dex: add missing eth public API (#8)
-rw-r--r--dex/api.go31
-rw-r--r--dex/backend.go12
2 files changed, 43 insertions, 0 deletions
diff --git a/dex/api.go b/dex/api.go
index 1209e6583..7ca1a4622 100644
--- a/dex/api.go
+++ b/dex/api.go
@@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"io"
+ "math/big"
"os"
"strings"
@@ -38,6 +39,36 @@ import (
"github.com/tangerine-network/go-tangerine/trie"
)
+// PublicEthereumAPI provides an API to access Ethereum full node-related
+// information.
+type PublicEthereumAPI struct {
+ dex *Tangerine
+}
+
+// NewPublicEthereumAPI creates a new Ethereum protocol API for full nodes.
+func NewPublicEthereumAPI(e *Tangerine) *PublicEthereumAPI {
+ return &PublicEthereumAPI{e}
+}
+
+// Etherbase is the address that mining rewards will be send to
+func (api *PublicEthereumAPI) Etherbase() (common.Address, error) {
+ return api.dex.Etherbase(), nil
+}
+
+// Coinbase is the address that mining rewards will be send to (alias for Etherbase)
+func (api *PublicEthereumAPI) Coinbase() (common.Address, error) {
+ return api.dex.Etherbase(), nil
+}
+
+// ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.
+func (api *PublicEthereumAPI) ChainId() hexutil.Uint64 {
+ chainID := new(big.Int)
+ if config := api.dex.chainConfig; config.IsEIP155(api.dex.blockchain.CurrentBlock().Number()) {
+ chainID = config.ChainID
+ }
+ return (hexutil.Uint64)(chainID.Uint64())
+}
+
// PrivateAdminAPI is the collection of Ethereum full node-related APIs
// exposed over the private admin endpoint.
type PrivateAdminAPI struct {
diff --git a/dex/backend.go b/dex/backend.go
index 24115b116..86db59c5f 100644
--- a/dex/backend.go
+++ b/dex/backend.go
@@ -22,12 +22,14 @@ import (
"time"
"github.com/tangerine-network/go-tangerine/accounts"
+ "github.com/tangerine-network/go-tangerine/common"
"github.com/tangerine-network/go-tangerine/consensus"
"github.com/tangerine-network/go-tangerine/consensus/dexcon"
"github.com/tangerine-network/go-tangerine/core"
"github.com/tangerine-network/go-tangerine/core/bloombits"
"github.com/tangerine-network/go-tangerine/core/rawdb"
"github.com/tangerine-network/go-tangerine/core/vm"
+ "github.com/tangerine-network/go-tangerine/crypto"
"github.com/tangerine-network/go-tangerine/dex/downloader"
"github.com/tangerine-network/go-tangerine/eth/filters"
"github.com/tangerine-network/go-tangerine/eth/gasprice"
@@ -78,6 +80,8 @@ type Tangerine struct {
networkID uint64
netRPCService *ethapi.PublicNetAPI
+ etherbase common.Address
+
indexer indexer.Indexer
}
@@ -187,6 +191,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Tangerine, error) {
time.Duration(chainConfig.Recovery.Timeout)*time.Second, log.Root())
dex.bp = NewBlockProposer(dex, watchCat, dMoment)
+
+ dex.etherbase = crypto.PubkeyToAddress(config.PrivateKey.PublicKey)
return dex, nil
}
@@ -205,6 +211,11 @@ func (s *Tangerine) APIs() []rpc.API {
{
Namespace: "eth",
Version: "1.0",
+ Service: NewPublicEthereumAPI(s),
+ Public: true,
+ }, {
+ Namespace: "eth",
+ Version: "1.0",
Service: downloader.NewPublicDownloaderAPI(s.protocolManager.downloader, s.eventMux),
Public: true,
}, {
@@ -317,3 +328,4 @@ func (d *Tangerine) Engine() consensus.Engine { return d.engine }
func (d *Tangerine) ChainDb() ethdb.Database { return d.chainDb }
func (d *Tangerine) Downloader() ethapi.Downloader { return d.protocolManager.downloader }
func (d *Tangerine) NetVersion() uint64 { return d.networkID }
+func (d *Tangerine) Etherbase() common.Address { return d.etherbase }