1
This commit is contained in:
parent
7562a8b0d9
commit
168e1fc1a1
@ -4,6 +4,7 @@ import (
|
|||||||
"f5"
|
"f5"
|
||||||
"main/router/market"
|
"main/router/market"
|
||||||
"main/router/asset"
|
"main/router/asset"
|
||||||
|
"main/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type routerMgr struct {
|
type routerMgr struct {
|
||||||
@ -12,10 +13,7 @@ type routerMgr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *routerMgr) Init() {
|
func (this *routerMgr) Init() {
|
||||||
/*
|
|
||||||
f5.GetApp().GetGinEngine().Use(middleware.Cors())
|
f5.GetApp().GetGinEngine().Use(middleware.Cors())
|
||||||
*/
|
|
||||||
|
|
||||||
this.market.MarketRouter.InitRouter()
|
this.market.MarketRouter.InitRouter()
|
||||||
this.asset.AssetRouter.InitRouter()
|
this.asset.AssetRouter.InitRouter()
|
||||||
|
|
||||||
|
@ -1,21 +1,73 @@
|
|||||||
package mt
|
package mt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"q5"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"encoding/json"
|
||||||
|
"bufio"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Contract struct {
|
type Contract struct {
|
||||||
|
name string
|
||||||
|
address string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContractTable struct {
|
type ContractTable struct {
|
||||||
|
netIdNameHash *q5.ConcurrentMap[string, *Contract]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Contract) GetName() string {
|
||||||
|
return this.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Contract) GetAddress() string {
|
||||||
|
return this.address
|
||||||
|
}
|
||||||
|
|
||||||
func (this *ContractTable) IsNoLoad() bool {
|
func (this *ContractTable) IsNoLoad() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ContractTable) Load() {
|
func (this *ContractTable) Load() {
|
||||||
|
this.netIdNameHash = new(q5.ConcurrentMap[string, *Contract])
|
||||||
|
nets := []interface{}{}
|
||||||
|
{
|
||||||
|
if f, err := os.Open("../config/nets.json"); err == nil {
|
||||||
|
jsonStr, _ := bufio.NewReader(f).ReadString(0)
|
||||||
|
if err := json.Unmarshal([]byte(jsonStr), &nets); err != nil {
|
||||||
|
panic(fmt.Sprintf("load metafile json decode error %s %s", "nets.json", err))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("load metafile error %s %s", "nets.json", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
for _, val := range nets {
|
||||||
|
netId := q5.SafeToInt32(val)
|
||||||
|
fileName := fmt.Sprintf("../config/nets/%d/contract.json", netId)
|
||||||
|
if f, err := os.Open(fileName); err == nil {
|
||||||
|
jsonStr, _ := bufio.NewReader(f).ReadString(0)
|
||||||
|
contracts := []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal([]byte(jsonStr), &contracts); err != nil {
|
||||||
|
panic(fmt.Sprintf("load metafile json decode error %s %s", "contract.json", err))
|
||||||
|
}
|
||||||
|
for _, val2 := range contracts {
|
||||||
|
p := new(Contract)
|
||||||
|
p.name = q5.SafeToString(val2.Name)
|
||||||
|
p.address = strings.ToLower(q5.SafeToString(val2.Address))
|
||||||
|
key := fmt.Sprintf("%d_%s", netId, p.name)
|
||||||
|
this.netIdNameHash.Store(key, p)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("load metafile error %s %s", "contract.json", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ContractTable) PreInit1() {
|
func (this *ContractTable) PreInit1() {
|
||||||
@ -29,3 +81,12 @@ func (this *ContractTable) ElementsInit(int) {
|
|||||||
func (this *ContractTable) PostInit1() {
|
func (this *ContractTable) PostInit1() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ContractTable) GetByNetIdName(netId int32, name string) *Contract {
|
||||||
|
key := fmt.Sprintf("%d_%s", netId, name)
|
||||||
|
if v, ok := this.netIdNameHash.Load(key); ok {
|
||||||
|
return *v
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user