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

goMaker-5 #3911

Merged
merged 14 commits into from
Dec 12, 2024
2 changes: 1 addition & 1 deletion node
Submodule node updated 2 files
+8 −5 go.mod
+22 −10 go.sum
2 changes: 1 addition & 1 deletion sdk
7 changes: 5 additions & 2 deletions src/apps/chifra/cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ Notes:
- Balance is the default mode. To select a single mode use none first, followed by that mode.
- Valid parameters for --call include Solidity-like syntax: balanceOf(0x316b...183d), a four-byte followed by parameters: 0x70a08231(0x316b...183d), or encoded input data.
- You may specify multiple parts on a single line.
- In the --call string, you may separate multiple calls with a colon.`
- In the --call string, you may separate multiple calls with a colon.
- Your use of the unaudited --send option legally absolves, in any jurisdiction, TrueBlocks, LLC or any associated parties from liability or loss related to such use.
- The --send option does not validate its input before sending your transaction to the network. If you provide invalid data, you may lose your funds. Be warned.`

func init() {
var capabilities caps.Capability // capabilities for chifra state
Expand All @@ -69,7 +71,8 @@ func init() {
One or more of [ balance | nonce | code | proxy | deployed | accttype | some | all ]`)
stateCmd.Flags().BoolVarP(&statePkg.GetOptions().Changes, "changes", "c", false, `only report a balance when it changes from one block to the next`)
stateCmd.Flags().BoolVarP(&statePkg.GetOptions().NoZero, "no_zero", "z", false, `suppress the display of zero balance accounts`)
stateCmd.Flags().StringVarP(&statePkg.GetOptions().Call, "call", "l", "", `call a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings`)
stateCmd.Flags().StringVarP(&statePkg.GetOptions().Call, "call", "l", "", `write-only call to a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings`)
stateCmd.Flags().StringVarP(&statePkg.GetOptions().Send, "send", "s", "", `send a transaction to a smart contract using a solidity function, a four-byte plus parameters, or an encoded call data string`)
stateCmd.Flags().BoolVarP(&statePkg.GetOptions().Articulate, "articulate", "a", false, `for the --call option only, articulate the retrieved data if ABIs can be found`)
stateCmd.Flags().StringVarP(&statePkg.GetOptions().ProxyFor, "proxy_for", "r", "", `for the --call option only, redirects calls to this implementation`)
globals.InitGlobals("state", stateCmd, &statePkg.GetOptions().Globals, capabilities)
Expand Down
10 changes: 5 additions & 5 deletions src/apps/chifra/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ require (
github.com/pelletier/go-toml/v2 v2.2.2
github.com/spf13/cobra v1.7.0
github.com/wealdtech/go-ens/v3 v3.5.2
golang.org/x/crypto v0.25.0
golang.org/x/term v0.22.0
golang.org/x/crypto v0.31.0
golang.org/x/term v0.27.0
golang.org/x/time v0.3.0
)

Expand Down Expand Up @@ -77,9 +77,9 @@ require (
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/protobuf v1.33.0 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
Expand Down
20 changes: 10 additions & 10 deletions src/apps/chifra/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220213190939-1e6e3497d506/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -819,8 +819,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -879,13 +879,13 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -894,8 +894,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
1 change: 1 addition & 0 deletions src/apps/chifra/internal/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Arguments:

Flags:
-a, --paths show the configuration paths for the system
-d, --dump dump the configuration to stdout
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
Expand Down
1 change: 1 addition & 0 deletions src/apps/chifra/internal/config/handle_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// HandleDump dumps a config to the screen
func (opts *ConfigOptions) HandleDump(rCtx *output.RenderCtx) error {
config.ReloadConfig()
fetchData := func(modelChan chan types.Modeler, errorChan chan error) {
config := *config.GetRootConfig()
s := types.Config{
Expand Down
5 changes: 4 additions & 1 deletion src/apps/chifra/internal/state/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Flags:
One or more of [ balance | nonce | code | proxy | deployed | accttype | some | all ]
-c, --changes only report a balance when it changes from one block to the next
-z, --no_zero suppress the display of zero balance accounts
-l, --call string call a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings
-l, --call string write-only call to a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings
-s, --send string send a transaction to a smart contract using a solidity function, a four-byte plus parameters, or an encoded call data string
-a, --articulate for the --call option only, articulate the retrieved data if ABIs can be found
-r, --proxy_for string for the --call option only, redirects calls to this implementation
-H, --ether specify value in ether
Expand All @@ -42,6 +43,8 @@ Notes:
- Valid parameters for --call include Solidity-like syntax: balanceOf(0x316b...183d), a four-byte followed by parameters: 0x70a08231(0x316b...183d), or encoded input data.
- You may specify multiple parts on a single line.
- In the --call string, you may separate multiple calls with a colon.
- Your use of the unaudited --send option legally absolves, in any jurisdiction, TrueBlocks, LLC or any associated parties from liability or loss related to such use.
- The --send option does not validate its input before sending your transaction to the network. If you provide invalid data, you may lose your funds. Be warned.
```

Data models produced by this tool:
Expand Down
15 changes: 15 additions & 0 deletions src/apps/chifra/internal/state/handle_send.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2021 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.

package statePkg

import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
)

func (opts *StateOptions) HandleSend(rCtx *output.RenderCtx) error {
logger.Info("HandleSend was called.")
return nil
}
6 changes: 5 additions & 1 deletion src/apps/chifra/internal/state/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type StateOptions struct {
Parts []string `json:"parts,omitempty"` // Control which state to export
Changes bool `json:"changes,omitempty"` // Only report a balance when it changes from one block to the next
NoZero bool `json:"noZero,omitempty"` // Suppress the display of zero balance accounts
Call string `json:"call,omitempty"` // Call a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings
Call string `json:"call,omitempty"` // Write-only call to a smart contract with one or more solidity calls, four-byte plus parameters, or encoded call data strings
Send string `json:"send,omitempty"` // Send a transaction to a smart contract using a solidity function, a four-byte plus parameters, or an encoded call data string
Articulate bool `json:"articulate,omitempty"` // For the --call option only, articulate the retrieved data if ABIs can be found
ProxyFor string `json:"proxyFor,omitempty"` // For the --call option only, redirects calls to this implementation
Globals globals.GlobalOptions `json:"globals,omitempty"` // The global options
Expand All @@ -56,6 +57,7 @@ func (opts *StateOptions) testLog() {
logger.TestLog(opts.Changes, "Changes: ", opts.Changes)
logger.TestLog(opts.NoZero, "NoZero: ", opts.NoZero)
logger.TestLog(len(opts.Call) > 0, "Call: ", opts.Call)
logger.TestLog(len(opts.Send) > 0, "Send: ", opts.Send)
logger.TestLog(opts.Articulate, "Articulate: ", opts.Articulate)
logger.TestLog(len(opts.ProxyFor) > 0, "ProxyFor: ", opts.ProxyFor)
opts.Conn.TestLog(opts.getCaches())
Expand Down Expand Up @@ -104,6 +106,8 @@ func StateFinishParseInternal(w io.Writer, values url.Values) *StateOptions {
opts.NoZero = true
case "call":
opts.Call = value[0]
case "send":
opts.Send = value[0]
case "articulate":
opts.Articulate = true
case "proxyFor":
Expand Down
2 changes: 2 additions & 0 deletions src/apps/chifra/internal/state/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (opts *StateOptions) StateInternal(rCtx *output.RenderCtx) error {
err = opts.HandleDecache(rCtx)
} else if len(opts.Call) > 0 {
err = opts.HandleCall(rCtx)
} else if len(opts.Send) > 0 {
err = opts.HandleSend(rCtx)
} else {
err = opts.HandleShow(rCtx)
}
Expand Down
10 changes: 8 additions & 2 deletions src/apps/chifra/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func GetRootConfig() *configtypes.Config {
return &trueBlocksConfig
}

// ReloadConfig clears the config cache so that the next time ReadToml is
// called the config will reload
func ReloadConfig() {
configLoaded = false
}

// PathToConfigFile returns the path where to find the configuration file
func PathToConfigFile() string {
configFolder := PathToRootConfig()
Expand Down Expand Up @@ -186,10 +192,10 @@ func pathFromXDG(envVar string) (string, error) {
return "", nil // it's okay if it's empty
}

absXDGPath, err := filepath.Abs(xdg);
absXDGPath, err := filepath.Abs(xdg)
if err != nil {
return "", usage.Usage("The {0} value ({1}), could not be interpreted as an absolute path.", envVar, xdg)
}
}

if _, err := os.Stat(absXDGPath); err != nil {
return "", usage.Usage("The {0} folder ({1}) must exist.", envVar, absXDGPath)
Expand Down
4 changes: 3 additions & 1 deletion src/apps/chifra/pkg/index/checkVersion.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ func IsInitialized(chain, required string) error {
(and allow it to complete) or 'chifra scrape' before using this command.

Error: %w
Chain: %s
Path: %s

`
return fmt.Errorf(indexNotInitialized, ErrNotInitialized)
return fmt.Errorf(indexNotInitialized, ErrNotInitialized, chain, fileName)
}

var err error
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/ledger/stmnt_from_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (l *Ledger) GetStatements(conn *rpc.Connection, filter *filter.AppearanceFi
// We need this below...
l.theTx = trans

if false && conn.StoreReadable() {
if conn.StoreReadable() {
// walk.Cache_Statements
statementGroup := &types.StatementGroup{
BlockNumber: trans.BlockNumber,
Expand Down Expand Up @@ -131,7 +131,7 @@ func (l *Ledger) GetStatements(conn *rpc.Connection, filter *filter.AppearanceFi
}

isFinal := base.IsFinal(conn.LatestBlockTimestamp, trans.Timestamp)
if false && isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Statements] {
if isFinal && conn.StoreWritable() && conn.EnabledMap[walk.Cache_Statements] {
statementGroup := &types.StatementGroup{
BlockNumber: trans.BlockNumber,
TransactionIndex: trans.TransactionIndex,
Expand Down
90 changes: 90 additions & 0 deletions src/apps/chifra/pkg/types/types_cacheitem_sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package types

type CacheItemField string

// Fields in the CacheItem struct available for sorting.
const (
CacheItemLastCached CacheItemField = "lastCached"
CacheItemNFiles CacheItemField = "nFiles"
CacheItemNFolders CacheItemField = "nFolders"
CacheItemPath CacheItemField = "path"
CacheItemSizeInBytes CacheItemField = "sizeInBytes"
CacheItemType CacheItemField = "type"
)

// IsValidCacheItemField returns true if the given field is a valid sortable CacheItem field.
func IsValidCacheItemField(field string) bool {
switch field {
case "lastCached", "nFiles", "nFolders", "path", "sizeInBytes", "type":
return true
}
return false
}

// CacheItemBy returns a comparison function for sorting CacheItem instances by the given field.
// These comparison functions may be strung together by the CmdCacheItems function.
func CacheItemBy(field CacheItemField, order SortOrder) func(p1, p2 CacheItem) bool {
switch field {
case CacheItemLastCached: // string
return func(p1, p2 CacheItem) bool {
if order == Ascending {
return p1.LastCached < p2.LastCached
}
return p1.LastCached > p2.LastCached
}
case CacheItemNFiles: // uint64
return func(p1, p2 CacheItem) bool {
if order == Ascending {
return p1.NFiles < p2.NFiles
}
return p1.NFiles > p2.NFiles
}
case CacheItemNFolders: // uint64
return func(p1, p2 CacheItem) bool {
if order == Ascending {
return p1.NFolders < p2.NFolders
}
return p1.NFolders > p2.NFolders
}
case CacheItemPath: // string
return func(p1, p2 CacheItem) bool {
if order == Ascending {
return p1.Path < p2.Path
}
return p1.Path > p2.Path
}
case CacheItemSizeInBytes: // int64
return func(p1, p2 CacheItem) bool {
if order == Ascending {
return p1.SizeInBytes < p2.SizeInBytes
}
return p1.SizeInBytes > p2.SizeInBytes
}
case CacheItemType: // string
return func(p1, p2 CacheItem) bool {
if order == Ascending {
return p1.CacheItemType < p2.CacheItemType
}
return p1.CacheItemType > p2.CacheItemType
}

}
panic("Should not happen in CacheItemBy")
}

// CacheItemCmp accepts a slice and variadic comparison functions and returns a functions
// that can be used to sort the slice.
func CacheItemCmp(slice []CacheItem, orders ...func(p1, p2 CacheItem) bool) func(i, j int) bool {
return func(i, j int) bool {
p1, p2 := slice[i], slice[j]
for _, order := range orders {
if order(p1, p2) {
return true
}
if order(p2, p1) {
return false
}
}
return false
}
}
Loading
Loading