The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/rpc/net.go

70 lines
1.9 KiB

Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
package rpc
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
)
// PublicNetService offers network related RPC methods
type PublicNetService struct {
net p2p.Host
chainID uint64
version Version
}
// NewPublicNetAPI creates a new net API instance.
func NewPublicNetAPI(net p2p.Host, chainID uint64, version Version) rpc.API {
// manually set different namespace to preserve legacy behavior
var namespace string
switch version {
case V1:
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
namespace = netV1Namespace
case V2:
namespace = netV2Namespace
case Eth:
namespace = netNamespace
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
default:
utils.Logger().Error().Msgf("Unknown version %v, ignoring API.", version)
return rpc.API{}
}
return rpc.API{
Namespace: namespace,
Version: APIVersion,
Service: &PublicNetService{net, chainID, version},
Public: true,
}
}
// PeerCount returns the number of connected peers
// Note that the return type is an interface to account for the different versions
func (s *PublicNetService) PeerCount(ctx context.Context) (interface{}, error) {
timer := DoMetricRPCRequest(PeerCount)
defer timer.ObserveDuration()
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
// Format response according to version
switch s.version {
case V1, Eth:
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
return hexutil.Uint(s.net.GetPeerCount()), nil
case V2:
return s.net.GetPeerCount(), nil
default:
return nil, ErrUnknownRPCVersion
}
}
// Version returns the network version, i.e. ChainID identifying which network we are using
func (s *PublicNetService) Version(ctx context.Context) interface{} {
switch s.version {
case Eth:
return hexutil.Uint64(nodeconfig.GetDefaultConfig().GetNetworkType().ChainConfig().EthCompatibleChainID.Uint64())
default:
return fmt.Sprintf("%d", s.chainID)
}
Node API Refactor - pt2 (Stage 2.2 of Node API Overhaul) (#3259) * [rpc] Refactor - expose RPC functions in rpc package Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt1 * Move apiv1 into rpc package as baseline * Create version enum * Refactor API creation to use version enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rejoin GetBlockByNumber & GetBlockByHash * Both RPC versions are supported in 1 function * Created types directory for v1 & v2 response types * Added framework to make rpc layer more clear and legible Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt2 * Rejoin blockchain.go functions * Create legacy service * Improve inline documentation Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Use StructuredResponse when returning an exposed type from RPC * Remove addrlock.go * Add RPCBlock creation with exposed struct for easy utility from consumers * Update blockchain.go to reflect changes of RPCBlock Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt3 * Create types for RPCs that are returned. * Reorganize types to appropriate v1 & v2 package. Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt4 * Add context to all RPCs * Add response switches based on different versions of the API * Add debug logs for RPC that don't return errors Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt5 * Add versions switches to all transaction related RPCs * Integrate response with newly defined structures * Add debug messages for RPCs that don't return errors * Add inline documentation for all transaction related RPCs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt6 * Remove apiv2 * Move StructuredResponse & TxHistoryArgs to main rpc types.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Undo v1 & v2 code duplication pt7 * Create contract, pool, staking & transaction services * Move apis into correct services * Remove util.go (functions are now baked into RPCs in pool.go) * Remove transaction.go (functions/methods are distributed among created services) * Update changes for StructuredResponse Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Add rpc server start/stop to pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Refactor - use new RPC start / stop for servers Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [hmy] Refactor - rename network.go to net.go to match rpc * Change names for consistency with rpc pkg Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * fix go lint & go imports Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Fix GetTransactionReceipt for staking txs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - Rename v1 & v2 struct to not have leading 'RPC' * Update comments Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rpc] Refactor - make defaultBlocksPeriod be the num blocks per epoch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
}