Skip to content

Commit

Permalink
Makes types.Message a full auto-gen type (#3627)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjayrush authored Apr 29, 2024
1 parent 367d95e commit 224f3bb
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 22 deletions.
18 changes: 16 additions & 2 deletions docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,12 @@ paths:
schema:
properties:
data:
description: Produces <a href="/data-model/accounts/#name">Name</a> data. Corresponds to the <a href="/chifra/accounts/#chifra-names">chifra names</a> command line.
description: Produces <a href="/data-model/other/#message">Message</a> or <a href="/data-model/accounts/#name">Name</a> data. Corresponds to the <a href="/chifra/accounts/#chifra-names">chifra names</a> command line.
type: array
items:
$ref: "#/components/schemas/name"
oneOf:
- $ref: "#/components/schemas/message"
- $ref: "#/components/schemas/name"
example:
[
{
Expand Down Expand Up @@ -4611,6 +4613,18 @@ components:
type: number
format: uint64
description: "the number of records known by the API for this address"
message:
description: "used for various responses when no real data is generated"
type: object
properties:
msg:
type: string
format: string
description: "the message"
num:
type: string
format: int
description: "a number if needed"
response:
required:
- result
Expand Down
1 change: 1 addition & 0 deletions docs/content/chifra/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Notes:

Data models produced by this tool:

- [message](/data-model/other/#message)
- [name](/data-model/accounts/#name)

Links:
Expand Down
15 changes: 15 additions & 0 deletions docs/content/data-model/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ SlurpCounts consist of the following fields:
| address | the address used to query the API | address |
| count | the number of records known by the API for this address | uint64 |

## Message

The Message type is used in various places to return information about a command. For example, when using the `chifra names --autoname` feature in the SDK, a Message type is returned.

The following commands produce and manage Messages:

- [chifra names](/chifra/accounts/#chifra-names)

Messages consist of the following fields:

| Field | Description | Type |
| ----- | ------------------ | ------ |
| msg | the message | string |
| num | a number if needed | int |

## Base types

This documentation mentions the following basic data types.
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/blocks/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (opts *BlocksOptions) HandleDecache() error {
}

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
if msg, err := decache.Decache(opts.Conn, itemsToRemove, silent, opts.getCacheType()); err != nil {
errorChan <- err
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (opts *ChunksOptions) HandleDiff(blockNums []uint64) error {
testMode := opts.Globals.TestMode

ctx, cancel := context.WithCancel(context.Background())
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
walker := walk.NewCacheWalker(
chain,
testMode,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (opts *ChunksOptions) HandleTag(blockNums []uint64) error {
userHitCtrlC := false
ctx, cancel := context.WithCancel(context.Background())

fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
nChunksTagged := 0
man, err := manifest.ReadManifest(chain, opts.PublisherAddr, manifest.LocalCache)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (opts *ChunksOptions) HandleTruncate(blockNums []uint64) error {
})

ctx, cancel := context.WithCancel(context.Background())
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {

// First, we will remove the chunks and update the manifest. We do this separately for
// each chunk, so that if we get interrupted, we have a relatively sane state (although,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/export/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (opts *ExportOptions) HandleDecache(monitorArray []monitor.Monitor) error {
silent := opts.Globals.TestMode || len(opts.Globals.File) > 0

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
for _, mon := range monitorArray {
if !opts.Globals.IsApiMode() && !usage.QueryUser(getWarning(mon.Address.Hex(), mon.Count()), "Not decaching") {
continue
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/logs/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (opts *LogsOptions) HandleDecache() error {
}

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
if msg, err := decache.Decache(opts.Conn, itemsToRemove, silent, walk.Cache_Logs); err != nil {
errorChan <- err
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/monitors/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (opts *MonitorsOptions) HandleDecache() error {
message := "Decaching complete"
logger.Info(message)
if opts.Globals.IsApiMode() {
_ = output.StreamMany(context.Background(), func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
_ = output.StreamMany(context.Background(), func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
modelChan <- &types.Message{
Msg: message,
}
Expand Down
1 change: 1 addition & 0 deletions src/apps/chifra/internal/names/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Notes:

Data models produced by this tool:

- [message](/data-model/other/#message)
- [name](/data-model/accounts/#name)

### Other Options
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/names/handle_autoname.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (opts *NamesOptions) HandleAutoname() error {
logger.Info(message)

if opts.Globals.IsApiMode() {
_ = output.StreamMany(context.Background(), func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
_ = output.StreamMany(context.Background(), func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
modelChan <- &types.Message{
Msg: message,
}
Expand Down
7 changes: 5 additions & 2 deletions src/apps/chifra/internal/names/handle_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ func (opts *NamesOptions) HandleClean() error {
message = fmt.Sprintf("The %s names database was not cleaned", label)
logger.Warn(message)
} else {
message = fmt.Sprintf("The %s names database was cleaned. %d name(s) has been modified", label, modifiedCount)
message = fmt.Sprintf("The %s names database was cleaned. %d names have been modified", label, modifiedCount)
if modifiedCount == 1 {
message = strings.Replace(message, "names have been", "name has been", 1)
}
logger.Info(message)
}

if opts.Globals.IsApiMode() {
_ = output.StreamMany(context.Background(), func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
_ = output.StreamMany(context.Background(), func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
modelChan <- &types.Message{
Msg: message,
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/state/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (opts *StateOptions) HandleDecache() error {
}

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
if msg, err := decache.Decache(opts.Conn, itemsToRemove, silent, walk.Cache_State); err != nil {
errorChan <- err
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/traces/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (opts *TracesOptions) HandleDecache() error {
}

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
if msg, err := decache.Decache(opts.Conn, itemsToRemove, silent, walk.Cache_Traces); err != nil {
errorChan <- err
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/transactions/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (opts *TransactionsOptions) HandleDecache() error {
}

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
if msg, err := decache.Decache(opts.Conn, itemsToRemove, silent, walk.Cache_Transactions); err != nil {
errorChan <- err
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/when/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (opts *WhenOptions) HandleDecache() error {
}

ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawModeler], errorChan chan error) {
fetchData := func(modelChan chan types.Modeler[types.RawMessage], errorChan chan error) {
if msg, err := decache.Decache(opts.Conn, itemsToRemove, silent, walk.Cache_Blocks); err != nil {
errorChan <- err
} else {
Expand Down
32 changes: 26 additions & 6 deletions src/apps/chifra/pkg/types/types_message.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
// Copyright 2021 The TrueBlocks Authors. All rights reserved.
// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were generated with makeClass --run. Edit only those parts of
* Parts of this file were auto generated. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/

package types

// EXISTING_CODE
import "encoding/json"

// EXISTING_CODE

type RawMessage struct {
Msg string `json:"msg"`
Num string `json:"num"`
// EXISTING_CODE
// EXISTING_CODE
}

type Message struct {
Msg string `json:"msg,omitempty"`
Num int `json:"num,omitempty"`
Msg string `json:"msg,omitempty"`
Num int `json:"num,omitempty"`
raw *RawMessage `json:"-"`
// EXISTING_CODE
// EXISTING_CODE
}

func (s Message) String() string {
bytes, _ := json.Marshal(s)
return string(bytes)
}

func (s *Message) Raw() *RawMessage {
return s.raw
}

func (s *Message) Raw() *RawModeler {
return nil
func (s *Message) SetRaw(raw *RawMessage) {
s.raw = raw
}

func (s *Message) Model(chain, format string, verbose bool, extraOptions map[string]any) Model {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name ,type ,strDefault ,attributes ,docOrder ,description
msg ,string , ,omitempty , 1 ,the message
num ,int , ,omitempty , 2 ,a number if needed
6 changes: 6 additions & 0 deletions src/dev_tools/goMaker/templates/classDefinitions/message.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
class = "Message"
doc_group = "05-Other"
doc_descr = "used for various responses when no real data is generated"
doc_route = "518-message"
produced_by = "names"
1 change: 1 addition & 0 deletions src/dev_tools/goMaker/templates/model-intros/message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Message type is used in various places to return information about a command. For example, when using the `chifra names --autoname` feature in the SDK, a Message type is returned.

0 comments on commit 224f3bb

Please sign in to comment.