From 9aab6dc5d0af4fe19a7e00759f896d1530f768d8 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Sat, 31 Aug 2019 15:31:15 -0700 Subject: [PATCH] add current to the sharding structure for sdk --- hmy/api_backend.go | 5 +++++ hmy/backend.go | 4 +++- internal/hmyapi/blockchain.go | 6 ++++-- node/rpc.go | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hmy/api_backend.go b/hmy/api_backend.go index eea27177d..24cdc69ff 100644 --- a/hmy/api_backend.go +++ b/hmy/api_backend.go @@ -228,3 +228,8 @@ func (b *APIBackend) GetEVM(ctx context.Context, msg core.Message, state *state. func (b *APIBackend) RPCGasCap() *big.Int { return b.hmy.RPCGasCap // TODO(ricl): should be hmy.config.RPCGasCap } + +// GetShardID returns the gas cap of rpc +func (b *APIBackend) GetShardID() uint32 { + return b.hmy.shardID +} diff --git a/hmy/backend.go b/hmy/backend.go index 9aca3ebee..c6a933b61 100644 --- a/hmy/backend.go +++ b/hmy/backend.go @@ -37,6 +37,7 @@ type Harmony struct { // TODO(ricl): this is never set. Will result in nil pointer bug // RPCGasCap is the global gas cap for eth-call variants. RPCGasCap *big.Int `toml:",omitempty"` + shardID uint32 } // NodeAPI is the list of functions from node used to call rpc apis. @@ -50,7 +51,7 @@ type NodeAPI interface { // New creates a new Harmony object (including the // initialisation of the common Harmony object) -func New(nodeAPI NodeAPI, txPool *core.TxPool, eventMux *event.TypeMux) (*Harmony, error) { +func New(nodeAPI NodeAPI, txPool *core.TxPool, eventMux *event.TypeMux, shardID uint32) (*Harmony, error) { chainDb := nodeAPI.Blockchain().ChainDB() hmy := &Harmony{ shutdownChan: make(chan bool), @@ -63,6 +64,7 @@ func New(nodeAPI NodeAPI, txPool *core.TxPool, eventMux *event.TypeMux) (*Harmon bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms), nodeAPI: nodeAPI, networkID: 1, // TODO(ricl): this should be from config + shardID: shardID, } hmy.APIBackend = &APIBackend{hmy} diff --git a/internal/hmyapi/blockchain.go b/internal/hmyapi/blockchain.go index a9f8219f9..d32044957 100644 --- a/internal/hmyapi/blockchain.go +++ b/internal/hmyapi/blockchain.go @@ -69,14 +69,16 @@ func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[s if core.ShardingSchedule.GetNetworkID() == shardingconfig.MainNet { return []map[string]interface{}{ map[string]interface{}{ + "current": s.b.GetShardID() == 0, "shardID": "0", "http": "http://s0.t.hmy.io:9500", "ws": "ws://s0.t.hmy.io:9800", }, map[string]interface{}{ + "current": s.b.GetShardID() == 1, "shardID": "1", "http": "http://s1.t.hmy.io:9500", - "ws": "ws://s1.t.hmy.io", + "ws": "ws://s1.t.hmy.io:9800", }, map[string]interface{}{ "shardID": "2", @@ -99,7 +101,7 @@ func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[s map[string]interface{}{ "shardID": "1", "http": "http://s1.b.hmy.io:9500", - "ws": "ws://s1.s.hmy.io", + "ws": "ws://s1.s.hmy.io:9800", }, }, nil } else { diff --git a/node/rpc.go b/node/rpc.go index 5d3cf96e8..c5c593386 100644 --- a/node/rpc.go +++ b/node/rpc.go @@ -46,7 +46,7 @@ var ( // StartRPC start RPC service func (node *Node) StartRPC(nodePort string) error { // Gather all the possible APIs to surface - harmony, _ = hmy.New(node, node.TxPool, new(event.TypeMux)) + harmony, _ = hmy.New(node, node.TxPool, new(event.TypeMux), node.Consensus.ShardID) apis := node.APIs()