1
This commit is contained in:
parent
f3f1df3733
commit
9968b41d28
@ -16,6 +16,7 @@ type Contract struct {
|
|||||||
|
|
||||||
type ContractTable struct {
|
type ContractTable struct {
|
||||||
netIdNameHash *q5.ConcurrentMap[string, *Contract]
|
netIdNameHash *q5.ConcurrentMap[string, *Contract]
|
||||||
|
netIdAddressHash *q5.ConcurrentMap[string, *Contract]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Contract) GetName() string {
|
func (this *Contract) GetName() string {
|
||||||
@ -32,6 +33,7 @@ func (this *ContractTable) IsNoLoad() bool {
|
|||||||
|
|
||||||
func (this *ContractTable) Load() {
|
func (this *ContractTable) Load() {
|
||||||
this.netIdNameHash = new(q5.ConcurrentMap[string, *Contract])
|
this.netIdNameHash = new(q5.ConcurrentMap[string, *Contract])
|
||||||
|
this.netIdAddressHash = new(q5.ConcurrentMap[string, *Contract])
|
||||||
nets := []interface{}{}
|
nets := []interface{}{}
|
||||||
{
|
{
|
||||||
if f, err := os.Open("../config/nets.json"); err == nil {
|
if f, err := os.Open("../config/nets.json"); err == nil {
|
||||||
@ -60,8 +62,14 @@ func (this *ContractTable) Load() {
|
|||||||
p := new(Contract)
|
p := new(Contract)
|
||||||
p.name = q5.SafeToString(val2.Name)
|
p.name = q5.SafeToString(val2.Name)
|
||||||
p.address = strings.ToLower(q5.SafeToString(val2.Address))
|
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 {
|
} else {
|
||||||
panic(fmt.Sprintf("load metafile error %s %s", "contract.json", err))
|
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
|
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
2
third_party/q5
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a26208f76e262b5c4db46c3034cf55cb4647ae2f
|
Subproject commit 763b161e26e76046ee7614852ccdd4a360f15237
|
Loading…
x
Reference in New Issue
Block a user