From 5244bb6d79fc118bfdabeb367b645608ea05003a Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Mon, 7 Oct 2019 18:08:38 +0800 Subject: dex: add missing eth public API (#8) --- dex/api.go | 31 +++++++++++++++++++++++++++++++ dex/backend.go | 12 ++++++++++++ 2 files changed, 43 insertions(+) (limited to 'dex') 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 } @@ -203,6 +209,11 @@ func (s *Tangerine) APIs() []rpc.API { // Append all the local APIs and return return append(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), @@ -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 } -- cgit v1.2.3