Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/more examples 8 #3661

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3423,7 +3423,7 @@ components:
description: "the zero-indexed position of the transaction in the block"
nonce:
type: number
format: uint64
format: nonce
description: "sequence number of the transactions sent by the sender"
timestamp:
type: number
Expand Down Expand Up @@ -3960,7 +3960,7 @@ components:
description: "for smart contracts only, the block number at which the contract was deployed"
nonce:
type: number
format: uint64
format: nonce
description: "the nonce of the account at the given block"
proxy:
type: string
Expand Down Expand Up @@ -4599,7 +4599,7 @@ components:
description: "the zero-indexed position of the transaction in the block"
nonce:
type: number
format: uint64
format: nonce
description: "sequence number of the transactions sent by the sender"
timestamp:
type: number
Expand Down
3 changes: 2 additions & 1 deletion docs/content/data-model/chaindata.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Transactions consist of the following fields:
| blockHash | the hash of the block containing this transaction | hash |
| blockNumber | the number of the block | blknum |
| transactionIndex | the zero-indexed position of the transaction in the block | txnum |
| nonce | sequence number of the transactions sent by the sender | uint64 |
| nonce | sequence number of the transactions sent by the sender | nonce |
| timestamp | the Unix timestamp of the object | timestamp |
| date | the timestamp as a date (calculated) | datetime |
| from | address from which the transaction was sent | address |
Expand Down Expand Up @@ -414,6 +414,7 @@ This documentation mentions the following basic data types.
| hash | an '0x'-prefixed 32-byte hex string | lowercase |
| int64 | a 64-bit signed integer | |
| lognum | an alias for a uint64 | |
| nonce | a 64-bit unsigned integer | |
| numeral | an alias for a uint64 | |
| string | a normal character string | |
| timestamp | a 64-bit unsigned integer | Unix timestamp |
Expand Down
3 changes: 2 additions & 1 deletion docs/content/data-model/chainstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ States consist of the following fields:
| ether | if --ether is specified, the balance in ether (calculated) | ether |
| code | the code of the account | string |
| deployed | for smart contracts only, the block number at which the contract was deployed | blknum |
| nonce | the nonce of the account at the given block | uint64 |
| nonce | the nonce of the account at the given block | nonce |
| proxy | the proxy address of the account at the given block | address |

## Token
Expand Down Expand Up @@ -109,6 +109,7 @@ This documentation mentions the following basic data types.
| datetime | a JSON formatted date | as a string |
| ether | a big number float | as a string |
| int256 | a signed big number | as a string |
| nonce | a 64-bit unsigned integer | |
| string | a normal character string | |
| timestamp | a 64-bit unsigned integer | Unix timestamp |
| txnum | an alias for a uint64 | |
Expand Down
3 changes: 2 additions & 1 deletion docs/content/data-model/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Slurps consist of the following fields:
| blockHash | the hash of the block containing this transaction | hash |
| blockNumber | the number of the block | blknum |
| transactionIndex | the zero-indexed position of the transaction in the block | txnum |
| nonce | sequence number of the transactions sent by the sender | uint64 |
| nonce | sequence number of the transactions sent by the sender | nonce |
| timestamp | the Unix timestamp of the object | timestamp |
| date | the timestamp as a date (calculated) | datetime |
| from | address from which the transaction was sent | address |
Expand Down Expand Up @@ -199,6 +199,7 @@ This documentation mentions the following basic data types.
| gas | a 64-bit unsigned integer | |
| hash | an '0x'-prefixed 32-byte hex string | lowercase |
| int64 | a 64-bit signed integer | |
| nonce | a 64-bit unsigned integer | |
| numeral | an alias for a uint64 | |
| string | a normal character string | |
| timestamp | a 64-bit unsigned integer | Unix timestamp |
Expand Down
12 changes: 10 additions & 2 deletions sdk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"encoding/json"
"fmt"
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
// EXISTING_CODE
)

type ConfigOptions struct {
Mode ConfigMode `json:"mode,omitempty"`
Paths bool `json:"paths,omitempty"`
Mode ConfigMode `json:"mode,omitempty"`
Globals
}

Expand All @@ -28,6 +29,13 @@ func (opts ConfigOptions) String() string {
return string(bytes)
}

// ConfigPaths implements the chifra config --paths command.
func (opts *ConfigOptions) ConfigPaths() ([]types.CacheItem, *types.MetaData, error) {
in := opts.toInternal()
in.Paths = true
return queryConfig[types.CacheItem](in)
}

type ConfigMode int

const (
Expand Down
35 changes: 35 additions & 0 deletions sdk/config_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ package sdk

import (
// EXISTING_CODE
"bytes"
"encoding/json"
"fmt"
"io"
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
config "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
Expand Down Expand Up @@ -75,5 +77,38 @@ func GetConfigOptions(args []string) (*configOptionsInternal, error) {
return &opts, nil
}

type configGeneric interface {
types.CacheItem
}

func queryConfig[T configGeneric](opts *configOptionsInternal) ([]T, *types.MetaData, error) {
// EXISTING_CODE
// EXISTING_CODE

buffer := bytes.Buffer{}
if err := opts.ConfigBytes(&buffer); err != nil {
return nil, nil, err
}

str := buffer.String()
// EXISTING_CODE
// EXISTING_CODE

var result Result[T]
if err := json.Unmarshal([]byte(str), &result); err != nil {
return nil, nil, err
} else {
return result.Data, &result.Meta, nil
}
}

// toInternal converts the SDK options to the internal options format.
func (opts *ConfigOptions) toInternal() *configOptionsInternal {
return &configOptionsInternal{
Mode: opts.Mode,
Globals: opts.Globals,
}
}

// EXISTING_CODE
// EXISTING_CODE
22 changes: 0 additions & 22 deletions sdk/python/src/_scrape.py

This file was deleted.

21 changes: 0 additions & 21 deletions sdk/typescript/src/paths/scrape.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/apps/chifra/internal/abis/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (opts *AbisOptions) validateAbis() error {

if opts.Globals.Decache {
if opts.Globals.IsApiMode() {
return validate.Usage("The {0} option is not available{1}.", "--decache", " in API mode")
return validate.Usage("The {0} option is not available{1}.", "--decache", " in api mode")
}
if len(opts.Encode) > 0 {
return validate.Usage("Please choose only one of {0}.", "--decache or --encode")
Expand Down
16 changes: 8 additions & 8 deletions src/apps/chifra/internal/chunks/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func (opts *ChunksOptions) validateChunks() error {

if opts.Globals.IsApiMode() {
if len(opts.Tag) > 0 {
return validate.Usage("The {0} option is not available {1}.", "--tag", "in api mode")
return validate.Usage("The {0} option is not available{1}.", "--tag", " in api mode")
}
if opts.Truncate != base.NOPOSN {
return validate.Usage("The {0} option is not available {1}.", "--truncate", "in api mode")
return validate.Usage("The {0} option is not available{1}.", "--truncate", " in api mode")
}
if opts.Mode == "pins" {
return validate.Usage("The {0} mode is not available {1}.", "pins", "in api mode")
return validate.Usage("The {0} mode is not available{1}.", "pins", " in api mode")
}
} else if len(opts.Tag) > 0 {
if !version.IsValidVersion(opts.Tag) {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (opts *ChunksOptions) validateChunks() error {
}

if opts.Check {
return validate.Usage("The {0} option is not available in {1} mode.", "--check", opts.Mode)
return validate.Usage("The {0} option is not available{1}.", "--check", " in "+opts.Mode+" mode")
}
}

Expand Down Expand Up @@ -255,16 +255,16 @@ func (opts *ChunksOptions) validateChunks() error {
func (opts *ChunksOptions) isDisallowed(test bool, mode string) error {
if test {
if opts.Pin {
return validate.Usage("The {0} option is not available in {1} mode.", "--pin", mode)
return validate.Usage("The {0} option is not available{1}.", "--pin", " in "+mode+" mode")
}
if opts.Publish {
return validate.Usage("The {0} option is not available in {1} mode.", "--publish", mode)
return validate.Usage("The {0} option is not available{1}.", "--publish", " in "+mode+" mode")
}
if opts.Remote {
return validate.Usage("The {0} option is not available in {1} mode.", "--remote", mode)
return validate.Usage("The {0} option is not available{1}.", "--remote", " in "+mode+" mode")
}
if opts.Truncate != base.NOPOSN {
return validate.Usage("The {0} option is not available in {1} mode.", "--truncate", mode)
return validate.Usage("The {0} option is not available{1}.", "--truncate", " in "+mode+" mode")
}
}
return nil
Expand Down
13 changes: 6 additions & 7 deletions src/apps/chifra/internal/config/handle_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import (
)

func (opts *ConfigOptions) HandleEdit() error {
testMode := opts.Globals.TestMode
if testMode {
logger.Info("would have opened config file for edit")
} else {
editor := os.Getenv("EDITOR")
configFile := config.PathToConfigFile()
utils.System(editor + " \"" + configFile + "\"")
if opts.Globals.TestMode {
logger.Info("Can not process this command in test mode.")
return nil
}

editor := os.Getenv("EDITOR")
configFile := config.PathToConfigFile()
utils.System(editor + " \"" + configFile + "\"")
return nil
}
48 changes: 36 additions & 12 deletions src/apps/chifra/internal/config/handle_paths.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
package configPkg

import (
"fmt"
"context"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/colors"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/bykof/gostradamus"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
)

// HandlePaths handles the paths command for the command line. Returns error only as per cobra.
func (opts *ConfigOptions) HandlePaths() error {
chain := opts.Globals.Chain
testMode := opts.Globals.TestMode

// TODO: This needs to be a Type and use StreamMany
dateStr := gostradamus.Now().Format("02-01|15:04:05.000")
fmt.Printf("\nchifra status --paths:\n")
fmt.Println(dateStr, colors.Green+"Config Path: "+colors.Off, config.PathToRootConfig())
fmt.Println(dateStr, colors.Green+"Cache Path: "+colors.Off, config.PathToCache(chain))
fmt.Println(dateStr, colors.Green+"Index Path: "+colors.Off, config.PathToIndex(chain))
fmt.Println()
return nil
ctx := context.Background()
fetchData := func(modelChan chan types.Modeler[types.RawCacheItem], errorChan chan error) {
root, cache, index := config.PathToRootConfig(),
config.PathToCache(opts.Globals.Chain),
config.PathToIndex(opts.Globals.Chain)
if testMode {
root, cache, index = "--path--", "--path--", "--path--"
}

paths := []types.CacheItem{
{
Path: root,
CacheItemType: "configPath",
},
{
Path: cache,
CacheItemType: "cachePath",
},
{
Path: index,
CacheItemType: "indexPath",
},
}
for _, s := range paths {
modelChan <- &s
}
}

extra := map[string]interface{}{
"configPaths": true,
}
return output.StreamMany(ctx, fetchData, opts.Globals.OutputOptsWithExtra(extra))
}
9 changes: 7 additions & 2 deletions src/apps/chifra/internal/config/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import (

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/config"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
)

func (opts *ConfigOptions) HandleShow() error {
configFile := config.PathToConfigFile()
fmt.Printf("%s", file.AsciiFileToString(configFile))
if opts.Globals.TestMode {
logger.Info("Can not process this command in test mode.")
return nil
}

fmt.Printf("%s", file.AsciiFileToString(config.PathToConfigFile()))
return nil
}
8 changes: 3 additions & 5 deletions src/apps/chifra/internal/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ func configFinishParse(args []string) *ConfigOptions {
opts.Conn = opts.Globals.FinishParse(args, opts.getCaches())

// EXISTING_CODE
defFmt = ""
defFmt = "txt"
for _, arg := range args {
if arg == "show" || arg == "edit" {
opts.Mode = arg
}
opts.Mode = arg
}
if len(opts.Mode) == 0 {
opts.Mode = "show"
opts.Mode = "<empty>"
}
// EXISTING_CODE
if len(opts.Globals.Format) == 0 || opts.Globals.Format == "none" {
Expand Down
10 changes: 8 additions & 2 deletions src/apps/chifra/internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ func (opts *ConfigOptions) validateConfig() error {
return validate.Usage("chain {0} is not properly configured.", chain)
}

if err := validate.ValidateEnum("modes", opts.Mode, "[show|edit]"); err != nil {
return err
if opts.Paths {
if len(opts.Mode) > 0 && opts.Mode != "<empty>" {
return validate.Usage("You must supply either {0} or {1}.", "a mode", "--paths")
}
} else {
if err := validate.ValidateEnum("modes", opts.Mode, "[show|edit]"); err != nil {
return err
}
}

if !opts.Globals.TestMode && opts.Mode == "edit" && os.Getenv("EDITOR") == "" {
Expand Down
Loading
Loading