Skip to content

Commit

Permalink
Merge pull request #139 from TrueBlocks/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tjayrush authored Oct 9, 2024
2 parents 96edfc2 + d973f1a commit f97259e
Show file tree
Hide file tree
Showing 110 changed files with 1,623 additions and 1,102 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cache
unchained
*.csv
changed.toml
trueBlocks.toml
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
"prettier.bracketSpacing": true,
"prettier.arrowParens": "always",
"prettier.endOfLine": "lf",
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "relative",
"typescript.suggest.autoImports": true,
"javascript.suggest.autoImports": true,
"editor.acceptSuggestionOnEnter": "on"
}
34 changes: 18 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strings"
"sync"

"github.com/TrueBlocks/trueblocks-browse/pkg/config"
Expand All @@ -32,10 +32,7 @@ type App struct {

session config.Session
apiKeys map[string]string
ensMap map[string]base.Address
renderCtxs map[base.Address][]*output.RenderCtx
historyMap map[base.Address]types.HistoryContainer
balanceMap sync.Map
meta coreTypes.MetaData
globals sdk.Globals

Expand All @@ -46,7 +43,7 @@ type App struct {
monitors types.MonitorContainer
names types.NameContainer
status types.StatusContainer
portfolio types.PortfolioContainer
project types.ProjectContainer
ScraperController *daemons.DaemonScraper
FreshenController *daemons.DaemonFreshen
IpfsController *daemons.DaemonIpfs
Expand All @@ -57,12 +54,9 @@ func NewApp() *App {
a := App{
apiKeys: make(map[string]string),
renderCtxs: make(map[base.Address][]*output.RenderCtx),
ensMap: make(map[string]base.Address),
historyMap: make(map[base.Address]types.HistoryContainer),
}
a.monitors.MonitorMap = make(map[base.Address]coreTypes.Monitor)
a.names.NamesMap = make(map[base.Address]coreTypes.Name)
a.portfolio.Filename = "Untitled"
a.project = types.NewProjectContainer("Untitled.tbx", &types.HistoryMap{}, &sync.Map{}, &sync.Map{})

// it's okay if it's not found
a.session.MustLoadSession()
Expand Down Expand Up @@ -95,7 +89,7 @@ func (a *App) GetContext() context.Context {
func (a *App) Startup(ctx context.Context) {
a.ctx = ctx

a.FreshenController = daemons.NewFreshen(a, "freshen", 4000, a.GetSessionDeamon("daemon-freshen"))
a.FreshenController = daemons.NewFreshen(a, "freshen", 3000, a.GetSessionDeamon("daemon-freshen"))
a.ScraperController = daemons.NewScraper(a, "scraper", 7000, a.GetSessionDeamon("daemon-scraper"))
a.IpfsController = daemons.NewIpfs(a, "ipfs", 10000, a.GetSessionDeamon("daemon-ipfs"))
go a.startDaemons()
Expand All @@ -105,17 +99,13 @@ func (a *App) Startup(ctx context.Context) {
}

logger.Info("Starting freshen process...")
a.Refresh(false, a.GetSession().LastRoute)
a.Refresh(a.GetSession().LastRoute)

if err := a.loadConfig(); err != nil {
messages.SendError(a.ctx, err)
}

addr := strings.ReplaceAll(a.GetSessionSubVal("/history"), "/", "")
if len(addr) > 0 {
logger.Info("Loading history for address: ", addr)
go a.HistoryPage(addr, -1, 15)
}
go a.loadHistory(a.GetLastAddress(), nil, nil)
}

func (a *App) DomReady(ctx context.Context) {
Expand Down Expand Up @@ -173,3 +163,15 @@ func (a *App) SetEnv(key, value string) {
func (a *App) GetMeta() coreTypes.MetaData {
return a.meta
}

type ModifyData struct {
Operation string `json:"operation"`
Address base.Address `json:"address"`
Value string `json:"value"`
}

func (a *App) ModifyNoop(modData *ModifyData) error {
route := a.GetSessionVal("route")
messages.Send(a.ctx, messages.Info, messages.NewInfoMessage(fmt.Sprintf("%s modify %s: %s", route, modData.Operation, modData.Address.Hex())))
return nil
}
4 changes: 2 additions & 2 deletions app/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ func (a *App) GetChainList() []string {
}

func (a *App) SetChain(chain string, address base.Address) {
a.CancleContexts() // cancel what's happening on the old chain
a.CancelAllContexts() // cancel what's happening on the old chain
a.globals.Chain = chain
a.SetSessionVal("chain", chain)
a.Reload(address)
a.abis = types.AbiContainer{}
a.index = types.IndexContainer{}
a.manifest = types.ManifestContainer{}
a.monitors = types.MonitorContainer{}
a.Refresh(false)
a.Refresh()
}
40 changes: 33 additions & 7 deletions app/data_abis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
)

Expand All @@ -24,22 +26,18 @@ var abisChain = "mainnet"
var abiLock atomic.Uint32

func (a *App) loadAbis(wg *sync.WaitGroup, errorChan chan error) error {
if !abiLock.CompareAndSwap(0, 1) {
return nil
}
defer abiLock.CompareAndSwap(1, 0)

defer func() {
if wg != nil {
wg.Done()
}
}()

if !a.isConfigured() {
if !abiLock.CompareAndSwap(0, 1) {
return nil
}
defer abiLock.CompareAndSwap(1, 0)

if !a.abis.NeedsUpdate() {
if !a.abis.NeedsUpdate(a.nameChange()) {
return nil
}

Expand Down Expand Up @@ -71,3 +69,31 @@ func (a *App) loadAbis(wg *sync.WaitGroup, errorChan chan error) error {
}
return nil
}

func (a *App) ModifyAbi(modData *ModifyData) error {
opts := sdk.AbisOptions{
Addrs: []string{modData.Address.Hex()},
Globals: a.globals,
}
opts.Globals.Decache = true

if _, _, err := opts.Abis(); err != nil {
messages.Send(a.ctx, messages.Error, messages.NewErrorMsg(err, modData.Address))
return err
} else {
newAbis := make([]coreTypes.Abi, 0, len(a.abis.Items))
for _, abi := range a.abis.Items {
if abi.Address == modData.Address {
a.abis.NItems--
a.abis.NEvents -= abi.NEvents
a.abis.NFunctions -= abi.NFunctions
continue
}
newAbis = append(newAbis, abi)
}
a.abis.LastUpdate = time.Time{}
a.abis.Items = newAbis
messages.Send(a.ctx, messages.Info, messages.NewInfoMessage(fmt.Sprintf("ModifyAbi delete: %s", modData.Address.Hex())))
return nil
}
}
Loading

0 comments on commit f97259e

Please sign in to comment.