Skip to content

Commit 93b050a

Browse files
committed
Cleaning
1 parent fadfa19 commit 93b050a

File tree

14 files changed

+321
-97
lines changed

14 files changed

+321
-97
lines changed

docs/content/data-model/chaindata.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ The following commands produce and manage Logs:
150150

151151
Logs consist of the following fields:
152152

153-
| Field | Description | Type |
154-
| ---------------- | -------------------------------------------------------------------------- | --------------------------------------- |
155-
| blockNumber | the number of the block | blknum |
156-
| transactionIndex | the zero-indexed position of the transaction in the block | txnum |
157-
| logIndex | the zero-indexed position of this log relative to the block | lognum |
158-
| timestamp | the timestamp of the block this log appears in | timestamp |
159-
| date | the timestamp as a date (calculated) | datetime |
160-
| address | the smart contract that emitted this log | address |
161-
| topics | first topic event signature up to 3 additional index parameters may appear | topic[] |
162-
| data | any remaining un-indexed parameters to the event | bytes |
163-
| transactionHash | the hash of the transction | hash |
164-
| blockHash | the hash of the block | hash |
165-
| articulatedLog | a human-readable version of the topic and data fields | [Function](/data-model/other/#function) |
166-
| compressedLog | a truncated, more readable version of the articulation (calculated) | string |
167-
| isNFT | true if the log is an NFT transfer (calculated) | bool |
153+
| Field | Description | Type |
154+
| ---------------- | ------------------------------------------------------------------------------------------------- | --------------------------------------- |
155+
| blockNumber | the number of the block | blknum |
156+
| transactionIndex | the zero-indexed position of the transaction in the block | txnum |
157+
| logIndex | the zero-indexed position of this log relative to the block | lognum |
158+
| timestamp | the timestamp of the block this log appears in | timestamp |
159+
| date | the timestamp as a date (calculated) | datetime |
160+
| address | the smart contract that emitted this log | address |
161+
| topics | the first topic hashes event signature of the log, up to 3 additional index parameters may appear | topic[] |
162+
| data | any remaining un-indexed parameters to the event | bytes |
163+
| transactionHash | the hash of the transction | hash |
164+
| blockHash | the hash of the block | hash |
165+
| articulatedLog | a human-readable version of the topic and data fields | [Function](/data-model/other/#function) |
166+
| compressedLog | a truncated, more readable version of the articulation (calculated) | string |
167+
| isNFT | true if the log is an NFT transfer (calculated) | bool |
168168

169169
## Trace
170170

src/dev_tools/goMaker/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## goMaker
1+
# goMaker
22

33
`goMaker` is development-only tool that aids in various aspects of building TrueBlocks. The program is
44
disabled for most users, but for core developers it can be used to automatically generate help files,
55
API interface specs, command line options parsers and many of the test case files. Generally, regular
66
users will not use `goMaker`.
77

8-
### Usage
8+
## Usage
99

1010
`Usage:` goMaker
1111
`Purpose:` Automatically writes files for various purposes.
@@ -56,7 +56,7 @@ with the following fields:
5656
- `note` - a note (used for documentation only, this appears in the notes section of the READMEs)
5757
- `alias` - an alias (used for the Hugo website only, this aliases old pages)
5858

59-
### Notes on Data Models
59+
## Notes on Data Models
6060

6161
The `goMaker` program also generates a huge number of source code files and documentation related to the various data models produced or consumed by the various TrueBlocks tools. These data models are stored in `.toml` files in the `./src/dev_tools/goMaker/templates/classDefinitions` folder and the model's fields (in a `.csv`) are stored in a subfolder called `fields`. There are two files for each data model (a `.toml` and a `.csv`) names identically to the data model's name.
6262

@@ -75,10 +75,10 @@ The `.toml` file contains the following fields:
7575
| cache_by | the fields by which to identify cache items | (one of \[ `address` \| `address,block` \| `address,block,fourbyte` \| `address,tx` \| `block` \| `tx` \] |
7676
| cache_type | one of \[ `cacheable` \| `marshal_only` \] | |
7777

78-
### Notes on Templates
78+
## Notes on Templates
7979

8080
The `./src/dev_tools/goMaker/templates` folder also contains a number of templates used by the `goMaker` program. The names of these templates corresponds to the location in the repo's paths the generated files will be written. For example, the `./sdk_route.go.tmpl` writes files to the `./sdk` folder. The filename of the file is `<route>.go` where `<route>` is the route of the subcommand. The template name may contain the word "route" or the word "type" which is sequentially replaced with either the routes or the data model types.
8181

82-
### Fin
82+
## Fin
8383

8484
Enough already. Experiment if you must.

src/dev_tools/goMaker/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "goMaker",
3+
"version": "1.0.0",
4+
"description": "A development tool that aids in various aspects of building TrueBlocks by automatically generating help files, API interface specs, command line options parsers and test case files",
5+
"main": "main.go",
6+
"scripts": {
7+
"build": "mkdir -p bin && go build -o bin/goMaker main.go",
8+
"deploy": "yarn build && cp bin/goMaker /usr/local/bin/ && echo '✅ Installed to /usr/local/bin/goMaker' && which goMaker && echo '✅ Installation verified'",
9+
"lint": "golangci-lint run && markdownlint README.md",
10+
"clean": "rm -rf bin/",
11+
"test": "go test ./..."
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/TrueBlocks/trueblocks-minidapps.git"
16+
},
17+
"keywords": [
18+
"go",
19+
"trueblocks",
20+
"codegen",
21+
"development-tool",
22+
"code-generation",
23+
"template",
24+
"cli"
25+
],
26+
"author": "TrueBlocks",
27+
"license": "GPL-3.0",
28+
"bugs": {
29+
"url": "https://github.com/TrueBlocks/trueblocks-minidapps/issues"
30+
},
31+
"homepage": "https://github.com/TrueBlocks/trueblocks-minidapps#readme",
32+
"engines": {
33+
"node": ">=16.0.0"
34+
},
35+
"devDependencies": {
36+
"markdownlint-cli": "^0.45.0"
37+
}
38+
}

src/dev_tools/goMaker/types/code_writer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func WriteCode(existingFn, newCode string) (bool, error) {
6767
return false, fmt.Errorf("error applying template: %v %s", err, existingFn)
6868
}
6969

70+
existingFn = strings.Replace(existingFn, "/Users/jrush/Development", "./", 1)
7071
msg := LogMessage{
7172
MessageType: "Progress",
7273
Message: existingFn,

src/dev_tools/goMaker/types/load.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,19 @@ func (cb *CodeBase) LoadStructures(thePath string, callBack func(*Structure, *an
104104
f.Facets[i].NormalizeActions()
105105
}
106106
for i := range f.Facets {
107-
// TODO: BOGUS - THIS SHOULD SPLIT AND KEEP THE LAST ITEM ONLY
108-
f.Facets[i].Store = strings.ReplaceAll(f.Facets[i].Store, "dalle.", "")
107+
// Parse store into StoreSource and StoreName
108+
if strings.Contains(f.Facets[i].Store, ".") {
109+
parts := strings.Split(f.Facets[i].Store, ".")
110+
if len(parts) >= 2 {
111+
f.Facets[i].StoreSource = parts[0]
112+
f.Facets[i].StoreName = parts[1]
113+
}
114+
} else {
115+
// Default to "sdk" if no prefix specified
116+
f.Facets[i].StoreSource = "sdk"
117+
f.Facets[i].StoreName = f.Facets[i].Store
118+
}
119+
f.Facets[i].Store = "NOT NEEDED AFTER LOAD - THIS MESSAGE PROVES IT"
109120
}
110121
for i := 0; i < len(f.Facets); i++ {
111122
if len(f.Facets[i].DisplayName) == 0 {
@@ -117,7 +128,6 @@ func (cb *CodeBase) LoadStructures(thePath string, callBack func(*Structure, *an
117128
structMap[mapKey] = f.Settings
118129
}
119130
return nil
120-
121131
}); err != nil {
122132
return err
123133
}

src/dev_tools/goMaker/types/types_codebase.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,19 @@ func (cb *CodeBase) Validate() error {
212212
for _, st := range cb.Structures {
213213
for _, f := range st.Facets {
214214
pwd, _ := os.Getwd()
215-
tomlFile := filepath.Join(pwd, "code_gen/templates/classDefinitions", strings.ToLower(f.Store)+".toml")
216-
csvFile := filepath.Join(pwd, "code_gen/templates/classDefinitions/fields", strings.ToLower(f.Store)+".csv")
215+
tomlFile := filepath.Join(pwd, "code_gen/templates/classDefinitions", strings.ToLower(f.StoreName)+".toml")
216+
csvFile := filepath.Join(pwd, "code_gen/templates/classDefinitions/fields", strings.ToLower(f.StoreName)+".csv")
217217

218-
if !structureNames[f.Store] {
218+
if !structureNames[f.StoreName] {
219219
var msg string
220220
if !file.FileExists(tomlFile) {
221-
msg = fmt.Sprintf("facet store %s in structure %s not found. Missing .toml file? %s.", f.Store, st.Class, tomlFile)
221+
msg = fmt.Sprintf("facet store %s in structure %s not found. Missing .toml file? %s.", f.StoreName, st.Class, tomlFile)
222222
logger.InfoBR("TOML file missing:", tomlFile)
223223
} else {
224224
logger.InfoBR("TOML file found:", tomlFile)
225225
}
226226
if !file.FileExists(csvFile) {
227-
msg = fmt.Sprintf("facet store %s in structure %s not found. Missing .csv file? %s.", f.Store, st.Class, csvFile)
227+
msg = fmt.Sprintf("facet store %s in structure %s not found. Missing .csv file? %s.", f.StoreName, st.Class, csvFile)
228228
logger.InfoBR("CSV file missing:", csvFile)
229229
} else {
230230
logger.InfoBR("CSV file found:", csvFile)
@@ -241,7 +241,6 @@ func (cb *CodeBase) Validate() error {
241241
}
242242

243243
return nil
244-
245244
}
246245

247246
func (op *Option) Stripped() string {

src/dev_tools/goMaker/types/types_command.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ func (c *Command) HelpIntro() string {
517517
if tmpl == "" {
518518
logger.Fatal("Could not read template file: ", readmePath)
519519
}
520+
if err := ValidateTemplate(tmpl, readmePath); err != nil {
521+
logger.Fatal(err)
522+
}
520523
return strings.Trim(c.executeTemplate(tmplName, tmpl), ws)
521524
}
522525

src/dev_tools/goMaker/types/types_facet.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
type Facet struct {
99
DisplayName string `toml:"display_name" json:"display_name"`
1010
Name string `json:"name"`
11-
Store string `json:"store"`
11+
Store string `json:"store"` // This will be parsed into StoreName and StoreSource
12+
StoreName string `json:"storeName"`
13+
StoreSource string `json:"storeSource"`
1214
Actions []string `toml:"actions" json:"actions"`
1315
Confirms map[string]bool `json:"-" toml:"-"` // actions requiring confirmation (parsed from -confirm suffix)
1416
ViewType string `toml:"viewType" json:"viewType"`
@@ -32,7 +34,10 @@ func (f *Facet) SingleStore() string {
3234
if f == nil {
3335
return ""
3436
}
35-
return Singular(f.Store)
37+
if f.StoreName != "Dresses" {
38+
return Singular(f.StoreName)
39+
}
40+
return f.StoreName
3641
}
3742

3843
func (f *Facet) ValidateViewType() error {

src/dev_tools/goMaker/types/types_member.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,66 @@ func (m *Member) Align() string {
597597
func (m *Member) ReadOnly() bool {
598598
return m.UiType() == "address"
599599
}
600+
601+
// GetFormatter returns the appropriate formatter string for this field
602+
func (m *Member) GetFormatter() string {
603+
name := m.Name
604+
fieldType := m.Type
605+
description := m.Description
606+
607+
// Handle "no formatter" cases
608+
if strings.HasPrefix(name, "n") ||
609+
strings.HasSuffix(name, "Bytes") ||
610+
strings.Contains(name, "Per") {
611+
return ""
612+
}
613+
614+
// Handle specific types
615+
switch fieldType {
616+
case "address":
617+
return "address"
618+
case "ether":
619+
return "ether"
620+
case "wei", "int256", "uint256":
621+
if strings.HasSuffix(name, "Eth") {
622+
return "ether"
623+
}
624+
return "wei"
625+
case "blkrange":
626+
return "blkrange"
627+
case "timestamp":
628+
return "datetime"
629+
case "hash", "ipfshash":
630+
return "hash"
631+
case "bool":
632+
// Boolean formatter only if name doesn't start with "is" or "has"
633+
if !strings.HasPrefix(name, "is") && !strings.HasPrefix(name, "has") {
634+
return "boolean"
635+
}
636+
}
637+
638+
// Handle name patterns
639+
if strings.HasSuffix(name, "Eth") {
640+
return "ether"
641+
}
642+
if strings.HasSuffix(name, "num") || strings.HasSuffix(fieldType, "num") || name == "count" {
643+
return "number"
644+
}
645+
if strings.HasPrefix(fieldType, "uint") || strings.HasPrefix(fieldType, "float") {
646+
return "number"
647+
}
648+
if strings.HasSuffix(strings.ToLower(name), "url") {
649+
return "url"
650+
}
651+
if name == "fileName" || strings.HasSuffix(name, "Path") || name == "path" {
652+
return "path"
653+
}
654+
if strings.HasSuffix(name, "Date") {
655+
return "datetime"
656+
}
657+
if name == "size" && strings.Contains(description, "on disc") {
658+
return "calc.fileSize"
659+
}
660+
661+
return ""
662+
}

src/dev_tools/goMaker/types/types_notes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func (c *Command) HelpNotes() string {
2121
if tmpl == "" {
2222
logger.Fatal("Could not read template file: ", readmePath)
2323
}
24+
if err := ValidateTemplate(tmpl, readmePath); err != nil {
25+
logger.Fatal(err)
26+
}
2427
return "\n\n" + strings.Trim(c.executeTemplate(tmplName, tmpl), ws)
2528
}
2629
return ""

0 commit comments

Comments
 (0)