Skip to content

Commit

Permalink
Merge pull request #144 from TrueBlocks/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tjayrush authored Oct 11, 2024
2 parents f97259e + 4ef145e commit 4cc34ae
Show file tree
Hide file tree
Showing 47 changed files with 610 additions and 359 deletions.
15 changes: 7 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,22 @@ func (a *App) GetContext() context.Context {
func (a *App) Startup(ctx context.Context) {
a.ctx = ctx

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

go a.loadHistory(a.GetLastAddress(), nil, nil)

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()

if startupError != nil {
a.Fatal(startupError.Error())
}

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

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

go a.loadHistory(a.GetLastAddress(), nil, nil)
}

func (a *App) DomReady(ctx context.Context) {
Expand Down Expand Up @@ -172,6 +171,6 @@ type ModifyData struct {

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())))
messages.Send(a.ctx, messages.Info, messages.NewInfoMessage(fmt.Sprintf("%s modify NO-OP %s: %s", route, modData.Operation, modData.Address.Hex())))
return nil
}
56 changes: 21 additions & 35 deletions app/data_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"sort"
"sync"
"sync/atomic"

"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
Expand All @@ -15,10 +14,6 @@ import (
)

func (a *App) HistoryPage(addr string, first, pageSize int) *types.HistoryContainer {
if !a.isConfigured() {
return &types.HistoryContainer{}
}

address, ok := a.ConvertToAddress(addr)
if !ok {
messages.Send(a.ctx, messages.Error, messages.NewErrorMsg(fmt.Errorf("Invalid address: "+addr)))
Expand All @@ -27,14 +22,6 @@ func (a *App) HistoryPage(addr string, first, pageSize int) *types.HistoryContai

_, exists := a.project.HistoryMap.Load(address)
if !exists {
if err := a.Thing(address, base.Max(pageSize, 1)); err != nil {
messages.Send(a.ctx, messages.Error, messages.NewErrorMsg(err, address))
return &types.HistoryContainer{}
}
a.loadProject(nil, nil)
}

if first == -1 {
return &types.HistoryContainer{}
}

Expand Down Expand Up @@ -105,12 +92,12 @@ func (a *App) txCount(address base.Address) int {
}
}

var historyLock atomic.Uint32
// var historyLock atomic.Uint32

func (a *App) loadHistory(address base.Address, wg *sync.WaitGroup, errorChan chan error) error {
// if wg != nil {
// defer wg.Done()
// }
if wg != nil {
defer wg.Done()
}

if address.IsZero() {
return nil
Expand All @@ -121,16 +108,15 @@ func (a *App) loadHistory(address base.Address, wg *sync.WaitGroup, errorChan ch
// }
// defer historyLock.CompareAndSwap(1, 0)

// history, exists := a.project.HistoryMap.Load(address)
// if exists {
// if !history.NeedsUpdate(a.nameChange()) {
// return nil
// }
// }
history, exists := a.project.HistoryMap.Load(address)
if exists {
if !history.NeedsUpdate(a.nameChange()) {
return nil
}
}

logger.Info("Loading history for address: ", address.Hex())
// _ = a.HistoryPage(address.Hex(), -1, 15)
if err := a.Thing(address, 15); err != nil {
if err := a.thing(address, 15); err != nil {
messages.Send(a.ctx, messages.Error, messages.NewErrorMsg(err, address))
return err
}
Expand All @@ -139,7 +125,7 @@ func (a *App) loadHistory(address base.Address, wg *sync.WaitGroup, errorChan ch
return nil
}

func (a *App) Thing(address base.Address, freq int) error {
func (a *App) thing(address base.Address, freq int) error {
rCtx := a.RegisterCtx(address)
opts := sdk.ExportOptions{
Addrs: []string{address.Hex()},
Expand Down Expand Up @@ -174,7 +160,7 @@ func (a *App) Thing(address base.Address, freq int) error {
})
messages.Send(a.ctx,
messages.Progress,
messages.NewProgressMsg(int64(len(summary.Items)), int64(nItems), address),
messages.NewProgressMsg(len(summary.Items), nItems, address),
)
}

Expand All @@ -201,18 +187,18 @@ func (a *App) Thing(address base.Address, freq int) error {
}
a.meta = *meta

summary, _ := a.project.HistoryMap.Load(address)
sort.Slice(summary.Items, func(i, j int) bool {
if summary.Items[i].BlockNumber == summary.Items[j].BlockNumber {
return summary.Items[i].TransactionIndex > summary.Items[j].TransactionIndex
history, _ := a.project.HistoryMap.Load(address)
sort.Slice(history.Items, func(i, j int) bool {
if history.Items[i].BlockNumber == history.Items[j].BlockNumber {
return history.Items[i].TransactionIndex > history.Items[j].TransactionIndex
}
return summary.Items[i].BlockNumber > summary.Items[j].BlockNumber
return history.Items[i].BlockNumber > history.Items[j].BlockNumber
})
summary.Summarize()
a.project.HistoryMap.Store(address, summary)
history.Summarize()
a.project.HistoryMap.Store(address, history)
messages.Send(a.ctx,
messages.Completed,
messages.NewProgressMsg(int64(a.txCount(address)), int64(a.txCount(address)), address),
messages.NewProgressMsg(a.txCount(address), a.txCount(address), address),
)
return nil
}
55 changes: 55 additions & 0 deletions app/data_monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/crud"
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
)

var monitorMutex sync.Mutex

// Find: NewViews
func (a *App) MonitorPage(first, pageSize int) *types.MonitorContainer {
first = base.Max(0, base.Min(first, len(a.monitors.Monitors)-1))
Expand Down Expand Up @@ -74,3 +78,54 @@ func (a *App) loadMonitors(wg *sync.WaitGroup, errorChan chan error) error {
}
return nil
}

func (a *App) ModifyMonitors(modData *ModifyData) error {
if !monitorLock.CompareAndSwap(0, 1) {
return nil
}
defer monitorLock.CompareAndSwap(1, 0)

opFromString := func(op string) crud.Operation {
m := map[string]crud.Operation{
"delete": crud.Delete,
"undelete": crud.Undelete,
"remove": crud.Remove,
}
return m[op]
}

op := opFromString(modData.Operation)
opts := sdk.MonitorsOptions{
Addrs: []string{modData.Address.Hex()},
Delete: op == crud.Delete,
Undelete: op == crud.Undelete,
Remove: op == crud.Remove,
Globals: a.globals,
}

if _, _, err := opts.Monitors(); err != nil {
messages.SendError(a.ctx, err)
return err
}

newArray := []coreTypes.Monitor{}
for _, mon := range a.monitors.Monitors {
if mon.Address == modData.Address {
switch op {
case crud.Delete:
mon.Deleted = true
case crud.Undelete:
mon.Deleted = false
case crud.Remove:
continue
}
}
newArray = append(newArray, mon)
}
monitorMutex.Lock()
defer monitorMutex.Unlock()

a.monitors.Monitors = newArray
a.monitors.Summarize()
return nil
}
2 changes: 1 addition & 1 deletion app/data_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (a *App) Reload(address base.Address) {
Operation: "reload",
Address: address,
})
a.HistoryPage(address.Hex(), 0, 15)
a.loadHistory(a.GetLastAddress(), nil, nil)
a.Refresh()
a.loadProject(nil, nil)
}
19 changes: 8 additions & 11 deletions app/menu_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,21 @@ func (a *App) FileOpen(cd *menu.CallbackData) {
save := a.FreshenController.Sleep
defer func() { a.FreshenController.Sleep = save }()
a.FreshenController.Sleep = 1000
a.SetSessionVal("file", file)

a.CancelAllContexts()
a.project = types.NewProjectContainer(file, &types.HistoryMap{}, &sync.Map{}, &sync.Map{})
newProject := types.ProjectContainer{
Filename: file,
}
newProject.Load()
a.session = newProject.Session
var wg sync.WaitGroup
for _, history := range newProject.Items {
history.Balance = a.getBalance(history.Address)
if loaded, ok := a.project.HistoryMap.Load(history.Address); ok && loaded.NItems == loaded.NTotal {
history.Items = loaded.Items
newProject.HistoryMap.Store(history.Address, history)
messages.Send(a.ctx,
messages.Completed,
messages.NewProgressMsg(int64(a.txCount(history.Address)), int64(a.txCount(history.Address)), history.Address),
)
} else {
go a.HistoryPage(history.Address.Hex(), -1, 15)
}
wg.Add(1)
go a.loadHistory(history.Address, &wg, nil)
}
wg.Wait()

messages.Send(a.ctx, messages.Navigate, messages.NewNavigateMsg("/"))
messages.Send(a.ctx, messages.Document, messages.NewDocumentMsg(a.project.Filename, "Opened"))
Expand Down
2 changes: 1 addition & 1 deletion app/proc_ctxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (a *App) CancelContext(address base.Address) {
defer ctxMutex.Unlock()
if ctxArrays, ok := a.renderCtxs[address]; ok {
for _, ctx := range ctxArrays {
messages.Send(a.ctx, messages.Cancelled, messages.NewProgressMsg(-1, -1, address))
messages.Send(a.ctx, messages.Cancelled, messages.NewCancelMsg(address))
ctx.Cancel()
}
delete(a.renderCtxs, address)
Expand Down
4 changes: 4 additions & 0 deletions app/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

func (a *App) GetSessionVal(which string) string {
switch which {
case "file":
return a.GetSession().LastFile
case "route":
if !a.isConfigured() {
return "/wizard"
Expand All @@ -26,6 +28,8 @@ func (a *App) GetSessionVal(which string) string {

func (a *App) SetSessionVal(which, value string) {
switch which {
case "file":
a.GetSession().LastFile = value
case "route":
parts := strings.Split(value, "/")
if len(parts) > 2 {
Expand Down
8 changes: 8 additions & 0 deletions app/util_explore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package app

import (
"fmt"
"os"

"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
)

func (a *App) GetExploreUrl(term string, google, dalle bool) string {
if len(term) != 42 {
google = false
dalle = false
}

opts := sdk.ExploreOptions{
Terms: []string{term},
Google: google,
Expand All @@ -16,6 +22,8 @@ func (a *App) GetExploreUrl(term string, google, dalle bool) string {
Globals: a.globals,
}

// TODO: Expose this to the user and/or put it in trueBlocks.toml
os.Setenv("TB_DALLE_SERIES", "five-tone-postal-protozoa")
if result, meta, err := opts.Explore(); err != nil {
messages.Send(a.ctx, messages.Error, messages.NewErrorMsg(err))
return ""
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"serve": "vite preview"
},
"dependencies": {
"@mantine/notifications": "^7.13.2",
"@tabler/icons-react": "3.11.0",
"@tanstack/react-table": "^8.19.2",
"dirname": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
391913b6e357db82588bd20c70d3bd03
8e5135546ea2780cb1d7b9981e7e4272
20 changes: 20 additions & 0 deletions frontend/src/components/buttons/BaseButton.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.baseButton {
background-color: red !important;
width: 8rem !important;
}

.actionButton {
background-color: green !important;
}

.closeButton {
background-color: transparent !important;
color: white !important;
border: none !important;
font-size: 16px !important;
cursor: pointer !important;
padding: 0 !important;
position: absolute !important;
top: 10px !important;
right: 10px !important;
}
Loading

0 comments on commit 4cc34ae

Please sign in to comment.