This commit is contained in:
aozhiwei 2024-06-22 21:25:54 +08:00
parent f3f1df3733
commit 9968b41d28
2 changed files with 20 additions and 3 deletions

View File

@ -16,6 +16,7 @@ type Contract struct {
type ContractTable struct {
netIdNameHash *q5.ConcurrentMap[string, *Contract]
netIdAddressHash *q5.ConcurrentMap[string, *Contract]
}
func (this *Contract) GetName() string {
@ -32,6 +33,7 @@ func (this *ContractTable) IsNoLoad() bool {
func (this *ContractTable) Load() {
this.netIdNameHash = new(q5.ConcurrentMap[string, *Contract])
this.netIdAddressHash = new(q5.ConcurrentMap[string, *Contract])
nets := []interface{}{}
{
if f, err := os.Open("../config/nets.json"); err == nil {
@ -60,8 +62,14 @@ func (this *ContractTable) Load() {
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)
{
key := fmt.Sprintf("%d_%s", netId, p.name)
this.netIdNameHash.Store(key, p)
}
{
key := fmt.Sprintf("%d_%s", netId, p.address)
this.netIdAddressHash.Store(key, p)
}
}
} else {
panic(fmt.Sprintf("load metafile error %s %s", "contract.json", err))
@ -90,3 +98,12 @@ func (this *ContractTable) GetByNetIdName(netId int32, name string) *Contract {
return nil
}
}
func (this *ContractTable) GetByNetIdAddress(netId int32, address string) *Contract {
key := fmt.Sprintf("%d_%s", netId, address)
if v, ok := this.netIdAddressHash.Load(key); ok {
return *v
} else {
return nil
}
}

2
third_party/q5 vendored

@ -1 +1 @@
Subproject commit a26208f76e262b5c4db46c3034cf55cb4647ae2f
Subproject commit 763b161e26e76046ee7614852ccdd4a360f15237