pull/1429/head
Minh Doan 5 years ago
parent 2fcf9ed8b8
commit 9c1a1d3522
  1. 12
      internal/configs/sharding/localnet.go
  2. 22
      internal/hmyapi/blockchain.go

@ -1,6 +1,7 @@
package shardingconfig package shardingconfig
import ( import (
"fmt"
"math/big" "math/big"
"time" "time"
@ -133,7 +134,16 @@ func (ls localnetSchedule) GetNetworkID() NetworkID {
// GetShardingStructure is the sharding structure for localnet. // GetShardingStructure is the sharding structure for localnet.
func (ls localnetSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} { func (ls localnetSchedule) GetShardingStructure(numShard, shardID int) []map[string]interface{} {
return genShardingStructure(numShard, shardID, LocalNetHTTPPattern, LocalNetWSPattern) res := []map[string]interface{}{}
for i := 0; i < numShard; i++ {
res = append(res, map[string]interface{}{
"current": int(shardID) == i,
"shardID": i,
"http": fmt.Sprintf("http://127.0.0.1:%d", 9500+i),
"ws": fmt.Sprintf("ws://127.0.0.1:%d", 9800+i),
})
}
return res
} }
var localnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(localnetV1Epoch), big.NewInt(localnetV2Epoch)} var localnetReshardingEpoch = []*big.Int{big.NewInt(0), big.NewInt(localnetV1Epoch), big.NewInt(localnetV2Epoch)}

@ -25,14 +25,6 @@ const (
defaultFromAddress = "0x0000000000000000000000000000000000000000" defaultFromAddress = "0x0000000000000000000000000000000000000000"
) )
// Constants for sharding structure.
const (
MainNetHTTPPattern = "http://s%d.t.hmny.io:9500"
MainNetWSPattern = "ws://s%d.t.hmny.io:9800"
TestNetHTTPPattern = "http://s%d.b.hmny.io:9500"
TestNetWSPattern = "ws://s%d.s.hmny.io:9800"
)
// PublicBlockChainAPI provides an API to access the Harmony blockchain. // PublicBlockChainAPI provides an API to access the Harmony blockchain.
// It offers only methods that operate on public data that is freely available to anyone. // It offers only methods that operate on public data that is freely available to anyone.
type PublicBlockChainAPI struct { type PublicBlockChainAPI struct {
@ -71,20 +63,6 @@ func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, blockHash comm
return nil, err return nil, err
} }
// GenShardingStructure return sharding structure, given shard number and its patterns.
func GenShardingStructure(shardNum, shardID uint32, httpPattern, wsPattern string) []map[string]interface{} {
res := []map[string]interface{}{}
for i := 0; i < int(shardNum); i++ {
res = append(res, map[string]interface{}{
"current": int(shardID) == i,
"shardID": i,
"http": fmt.Sprintf(httpPattern, i),
"ws": fmt.Sprintf(wsPattern, i),
})
}
return res
}
// GetShardingStructure returns an array of sharding structures. // GetShardingStructure returns an array of sharding structures.
func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[string]interface{}, error) { func (s *PublicBlockChainAPI) GetShardingStructure(ctx context.Context) ([]map[string]interface{}, error) {
// Get header and number of shards. // Get header and number of shards.

Loading…
Cancel
Save