Skip to content

Commit 6ebb1b4

Browse files
authored
Merge pull request #126 from TrueBlocks/develop
Develop
2 parents b8cc3cf + 8c83e3f commit 6ebb1b4

File tree

214 files changed

+12215
-1246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+12215
-1246
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
*.csv
2+
changed.toml
3+
trueBlocks.toml
4+
code_gen
15
build
26
backup_other
37
.DS_Store

.markdownlint.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MD013: false
2+
MD033: false
3+
MD036: false
4+
MD041: false
5+
MD024: false

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
"javascriptreact",
88
"typescript",
99
"typescriptreact"
10-
]
10+
],
11+
"prettier.printWidth": 120,
12+
"prettier.semi": true,
13+
"prettier.trailingComma": "es5",
14+
"prettier.bracketSpacing": true,
15+
"prettier.arrowParens": "always",
16+
"prettier.endOfLine": "lf",
1117
}

app/app.go

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import (
66
"errors"
77
"log"
88
"os"
9+
"sync"
910

1011
"github.com/TrueBlocks/trueblocks-browse/pkg/config"
12+
"github.com/TrueBlocks/trueblocks-browse/pkg/daemons"
13+
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
14+
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
1115
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
1216
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
1317
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
18+
coreTypes "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
1419
"github.com/joho/godotenv"
1520
"github.com/wailsapp/wails/v2/pkg/runtime"
1621
)
@@ -19,31 +24,53 @@ import (
1924
// is executed, we keep track of the first fatal error that has happened before Startup
2025
var startupError error
2126

27+
// Find: NewViews
2228
type App struct {
2329
ctx context.Context
30+
Documents []types.Document
31+
CurrentDoc *types.Document
32+
2433
session config.Session
2534
apiKeys map[string]string
26-
namesMap map[base.Address]NameEx
27-
names []NameEx // We keep both for performance reasons
2835
ensMap map[string]base.Address
2936
renderCtxs map[base.Address][]*output.RenderCtx
30-
// Add your application's data here
37+
historyMap map[base.Address]types.HistoryContainer
38+
balanceMap sync.Map
39+
meta coreTypes.MetaData
40+
41+
// Summaries
42+
abis types.AbiContainer
43+
index types.IndexContainer
44+
manifest types.ManifestContainer
45+
monitors types.MonitorContainer
46+
names types.NameContainer
47+
status types.StatusContainer
48+
portfolio types.PortfolioContainer
49+
ScraperController *daemons.DaemonScraper
50+
FreshenController *daemons.DaemonFreshen
51+
IpfsController *daemons.DaemonIpfs
3152
}
3253

54+
// Find: NewViews
3355
func NewApp() *App {
3456
a := App{
3557
apiKeys: make(map[string]string),
36-
namesMap: make(map[base.Address]NameEx),
3758
renderCtxs: make(map[base.Address][]*output.RenderCtx),
3859
ensMap: make(map[string]base.Address),
39-
// Initialize maps here
60+
historyMap: make(map[base.Address]types.HistoryContainer),
61+
Documents: make([]types.Document, 10),
4062
}
63+
a.monitors.MonitorMap = make(map[base.Address]coreTypes.Monitor)
64+
a.names.NamesMap = make(map[base.Address]coreTypes.Name)
65+
a.CurrentDoc = &a.Documents[0]
66+
a.CurrentDoc.Filename = "Untitled"
4167

4268
// it's okay if it's not found
43-
_ = a.session.Load()
69+
a.session.MustLoadSession()
4470

4571
if err := godotenv.Load(); err != nil {
46-
a.Fatal("Error loading .env file")
72+
// a.Fatal("Error loading .env file")
73+
logger.Info("Could not load .env file") // we don't need it for this app
4774
// } else if a.apiKeys["openAi"] = os.Getenv("OPENAI_API_KEY"); a.apiKeys["openAi"] == "" {
4875
// log.Fatal("No OPENAI_API_KEY key found")
4976
}
@@ -53,18 +80,33 @@ func NewApp() *App {
5380
return &a
5481
}
5582

56-
func (a App) String() string {
83+
func (a *App) String() string {
5784
bytes, _ := json.MarshalIndent(a, "", " ")
5885
return string(bytes)
5986
}
6087

88+
func (a *App) GetContext() context.Context {
89+
return a.ctx
90+
}
91+
92+
// Find: NewViews
6193
func (a *App) Startup(ctx context.Context) {
6294
a.ctx = ctx
95+
96+
a.FreshenController = daemons.NewFreshen(a, "freshen", 7000, a.GetLastDaemon("daemon-freshen"))
97+
a.ScraperController = daemons.NewScraper(a, "scraper", 7000, a.GetLastDaemon("daemon-scraper"))
98+
a.IpfsController = daemons.NewIpfs(a, "ipfs", 10000, a.GetLastDaemon("daemon-ipfs"))
99+
go a.startDaemons()
100+
63101
if startupError != nil {
64102
a.Fatal(startupError.Error())
65103
}
66-
if err := a.loadNames(); err != nil {
67-
logger.Panic(err)
104+
105+
logger.Info("Starting freshen process...")
106+
a.Refresh(a.GetSession().LastRoute)
107+
108+
if err := a.loadConfig(nil, nil); err != nil {
109+
messages.SendError(a.ctx, err)
68110
}
69111
}
70112

@@ -90,6 +132,9 @@ func (a *App) Shutdown(ctx context.Context) {
90132
}
91133

92134
func (a *App) GetSession() *config.Session {
135+
if a.session.LastSub == nil {
136+
a.session.LastSub = make(map[string]string)
137+
}
93138
return &a.session
94139
}
95140

@@ -116,3 +161,15 @@ func (a *App) Fatal(message string) {
116161
})
117162
os.Exit(1)
118163
}
164+
165+
func (a *App) GetEnv(key string) string {
166+
return os.Getenv(key)
167+
}
168+
169+
func (a *App) SetEnv(key, value string) {
170+
os.Setenv(key, value)
171+
}
172+
173+
func (a *App) GetMeta() coreTypes.MetaData {
174+
return a.meta
175+
}

app/app_state.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/backend.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

app/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app
2+
3+
import (
4+
"sync"
5+
6+
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
7+
)
8+
9+
func (a *App) loadConfig(wg *sync.WaitGroup, errorChan chan error) error {
10+
_ = wg
11+
_ = errorChan
12+
13+
var cfg config.ConfigFile
14+
_ = config.ReadToml("/Users/jrush/Library/Application Support/TrueBlocks/trueBlocks.toml", &cfg)
15+
// _, _ = json.MarshalIndent(cfg, "", " ")
16+
// fmt.Println(string(bytes))
17+
return nil
18+
}

app/dalle.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package app
2+
3+
import (
4+
"encoding/base64"
5+
"fmt"
6+
"io/ioutil"
7+
"net/http"
8+
9+
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
10+
)
11+
12+
func (a *App) GetDalle() (string, error) {
13+
addr := a.GetLastSub("/history")
14+
url := "http://192.34.63.136:8080/dalle/simple/" + addr
15+
16+
resp, err := http.Get(url)
17+
if err != nil {
18+
logger.Info("Failed to fetch content:", err)
19+
return "", err
20+
}
21+
defer resp.Body.Close()
22+
23+
contentType := resp.Header.Get("Content-Type")
24+
bytes, err := ioutil.ReadAll(resp.Body)
25+
if err != nil {
26+
logger.Info("Failed to read response body:", err)
27+
return "", err
28+
}
29+
30+
if contentType == "image/png" || contentType == "image/jpeg" {
31+
encodedImage := base64.StdEncoding.EncodeToString(bytes)
32+
return fmt.Sprintf("data:%s;base64,%s", contentType, encodedImage), nil
33+
}
34+
35+
return string(bytes), nil
36+
}

app/data_abis.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package app
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
7+
"github.com/TrueBlocks/trueblocks-browse/pkg/messages"
8+
"github.com/TrueBlocks/trueblocks-browse/pkg/types"
9+
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
10+
sdk "github.com/TrueBlocks/trueblocks-sdk/v3"
11+
)
12+
13+
// Find: NewViews
14+
func (a *App) AbiPage(first, pageSize int) types.AbiContainer {
15+
first = base.Max(0, base.Min(first, len(a.abis.Items)-1))
16+
last := base.Min(len(a.abis.Items), first+pageSize)
17+
copy := a.abis.ShallowCopy()
18+
copy.Items = a.abis.Items[first:last]
19+
return copy
20+
}
21+
22+
func (a *App) loadAbis(wg *sync.WaitGroup, errorChan chan error) error {
23+
defer func() {
24+
if wg != nil {
25+
wg.Done()
26+
}
27+
}()
28+
29+
if !a.isConfigured() {
30+
return nil
31+
}
32+
33+
opts := sdk.AbisOptions{}
34+
if count, meta, err := opts.AbisCount(); err != nil {
35+
if errorChan != nil {
36+
errorChan <- err
37+
}
38+
return err
39+
} else if (len(count) == 0) || (count[0].Count == 0) {
40+
err = fmt.Errorf("no abis found")
41+
if errorChan != nil {
42+
errorChan <- err
43+
}
44+
return err
45+
} else {
46+
a.meta = *meta
47+
if a.abis.NItems == int(count[0].Count) {
48+
return nil
49+
}
50+
51+
opts.Globals.Verbose = true
52+
if abis, meta, err := opts.AbisList(); err != nil {
53+
if errorChan != nil {
54+
errorChan <- err
55+
}
56+
return err
57+
} else if (abis == nil) || (len(abis) == 0) {
58+
err = fmt.Errorf("no status found")
59+
if errorChan != nil {
60+
errorChan <- err
61+
}
62+
return err
63+
} else {
64+
a.meta = *meta
65+
if len(a.abis.Items) == len(abis) {
66+
return nil
67+
}
68+
a.abis = types.NewAbiContainer(abis)
69+
if err := sdk.SortAbis(a.abis.Items, a.abis.Sorts); err != nil {
70+
messages.SendError(a.ctx, err)
71+
}
72+
a.abis.Summarize()
73+
}
74+
}
75+
return nil
76+
}

0 commit comments

Comments
 (0)