Skip to content

Commit

Permalink
Merge branch 'cache' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
scorpiotzh committed Sep 11, 2024
2 parents cdbb638 + 1126927 commit 2332012
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
29 changes: 26 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"das-account-indexer/http_server"
"das-account-indexer/http_server/handle"
"das-account-indexer/prometheus"
"encoding/json"
"fmt"
"github.com/dotbitHQ/das-lib/common"
"github.com/dotbitHQ/das-lib/core"
Expand Down Expand Up @@ -101,6 +102,7 @@ func runServer(ctx *cli.Context) error {
core.WithDasContractCodeHash(env.ContractCodeHash),
core.WithDasNetType(config.Cfg.Server.Net),
core.WithTHQCodeHash(env.THQCodeHash),
core.WithDasRedis(red),
}
dasCore := core.NewDasCore(ctxServer, &wgServer, ops...)
dasCore.InitDasContract(env.MapContract)
Expand All @@ -114,6 +116,10 @@ func runServer(ctx *cli.Context) error {
dasCore.RunAsyncDasConfigCell(time.Minute * 2) // config cell outpoint
dasCore.RunAsyncDasSoScript(time.Minute * 5) // so

dasCore.RunSetConfigCellByCache([]core.CacheConfigCellKey{
core.CacheConfigCellKeyCharSet,
core.CacheConfigCellKeyReservedAccounts,
})
log.Info("das contract ok")

// tx builder
Expand Down Expand Up @@ -202,8 +208,25 @@ func initApiServer(txBuilderBase *txbuilder.DasTxBuilderBase, dasCore *core.DasC
common.ConfigCellTypeArgsPreservedAccount19,
common.ConfigCellTypeArgsUnavailable,
)
var mapReservedAccounts = make(map[string]struct{})
var mapUnAvailableAccounts = make(map[string]struct{})
if err != nil {
return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList err: %s", err.Error())
var cacheBuilder core.CacheConfigCellReservedAccounts
strCache, errCache := dasCore.GetConfigCellByCache(core.CacheConfigCellKeyReservedAccounts)
if errCache != nil {
log.Error("GetConfigCellByCache err: %s", errCache.Error())
return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList1 err: %s", err.Error())
} else if strCache == "" {
return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList2 err: %s", err.Error())
} else if errCache = json.Unmarshal([]byte(strCache), &cacheBuilder); errCache != nil {
log.Error("json.Unmarshal err: %s", errCache.Error())
return fmt.Errorf("ConfigCellDataBuilderByTypeArgsList3 err: %s", err.Error())
}
mapReservedAccounts = cacheBuilder.MapReservedAccounts
mapUnAvailableAccounts = cacheBuilder.MapUnAvailableAccounts
} else {
mapReservedAccounts = builderConfigCell.ConfigCellPreservedAccountMap
mapUnAvailableAccounts = builderConfigCell.ConfigCellUnavailableAccountMap
}
// http server
hs := &http_server.HttpServer{
Expand All @@ -217,8 +240,8 @@ func initApiServer(txBuilderBase *txbuilder.DasTxBuilderBase, dasCore *core.DasC
DbDao: dbDao,
DasCore: dasCore,
TxBuilderBase: txBuilderBase,
MapReservedAccounts: builderConfigCell.ConfigCellPreservedAccountMap,
MapUnAvailableAccounts: builderConfigCell.ConfigCellUnavailableAccountMap,
MapReservedAccounts: mapReservedAccounts,
MapUnAvailableAccounts: mapUnAvailableAccounts,
},
}
hs.Run()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module das-account-indexer
go 1.18

require (
github.com/dotbitHQ/das-lib v1.2.1-0.20240830173826-32b0222d62cf
github.com/dotbitHQ/das-lib v1.2.1-0.20240911063826-b77c10affa8a
github.com/fsnotify/fsnotify v1.5.4
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5O
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/dop251/goja v0.0.0-20211011172007-d99e4b8cbf48/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dotbitHQ/das-lib v1.2.1-0.20240830173826-32b0222d62cf h1:1Fr72h+3FRGpT5l38bkD3F0JI6pi45GddspyMVAhSfM=
github.com/dotbitHQ/das-lib v1.2.1-0.20240830173826-32b0222d62cf/go.mod h1:XrDous4HH3jze59GLdmdKZaAQ8h3unTFUBsppph7IF8=
github.com/dotbitHQ/das-lib v1.2.1-0.20240911063826-b77c10affa8a h1:dJOMxMtVr+EGJOjXXiMva7tA2D2r9e+xlwskr1EiQNg=
github.com/dotbitHQ/das-lib v1.2.1-0.20240911063826-b77c10affa8a/go.mod h1:XrDous4HH3jze59GLdmdKZaAQ8h3unTFUBsppph7IF8=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=
Expand Down

0 comments on commit 2332012

Please sign in to comment.