diff --git a/CHANGES.md b/CHANGES.md
index c8f14b1298..ddd0579953 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -821,7 +821,7 @@ The following existing data models were either added, removed, or modified by ha
- For any data model with a `Timestamp`, that data model now also has an (automatically-generated) `Date` field.
### New data models:
-- `ChunkPinReport`: Added `ChunkPinReport` data model. Used by the `chifra chunks` command.
+- `ChunkPin`: Added `ChunkPin` data model. Used by the `chifra chunks` command.
- `Slurp`: Added `Slurp` data model. Used by the `chifra slurp` command.
### Remove data models
diff --git a/docs/content/api/openapi.yaml b/docs/content/api/openapi.yaml
index 0d5810b2f5..1417a2644c 100644
--- a/docs/content/api/openapi.yaml
+++ b/docs/content/api/openapi.yaml
@@ -2691,7 +2691,7 @@ paths:
schema:
properties:
data:
- description: Produces Appearance, AppearanceTable, ChunkAddress, ChunkBloom, ChunkIndex, ChunkPinReport, ChunkRecord, ChunkStats, IpfsPin, Manifest or ReportCheck data. Corresponds to the chifra chunks command line.
+ description: Produces Appearance, AppearanceTable, ChunkAddress, ChunkBloom, ChunkIndex, ChunkPin, ChunkRecord, ChunkStats, IpfsPin, Manifest or ReportCheck data. Corresponds to the chifra chunks command line.
type: array
items:
oneOf:
@@ -2700,7 +2700,7 @@ paths:
- $ref: "#/components/schemas/chunkAddress"
- $ref: "#/components/schemas/chunkBloom"
- $ref: "#/components/schemas/chunkIndex"
- - $ref: "#/components/schemas/chunkPinReport"
+ - $ref: "#/components/schemas/chunkPin"
- $ref: "#/components/schemas/chunkRecord"
- $ref: "#/components/schemas/chunkStats"
- $ref: "#/components/schemas/ipfsPin"
@@ -4398,7 +4398,7 @@ components:
type: string
format: string
description: "the reason for the test"
- chunkPinReport:
+ chunkPin:
description: "a JSON object containing the results of pinning the Unchained Index"
type: object
properties:
diff --git a/docs/content/chifra/admin.md b/docs/content/chifra/admin.md
index b6a00661f5..d850710986 100644
--- a/docs/content/chifra/admin.md
+++ b/docs/content/chifra/admin.md
@@ -343,7 +343,7 @@ Data models produced by this tool:
- [chunkaddress](/data-model/admin/#chunkaddress)
- [chunkbloom](/data-model/admin/#chunkbloom)
- [chunkindex](/data-model/admin/#chunkindex)
-- [chunkpinreport](/data-model/admin/#chunkpinreport)
+- [chunkpin](/data-model/admin/#chunkpin)
- [chunkrecord](/data-model/admin/#chunkrecord)
- [chunkstats](/data-model/admin/#chunkstats)
- [ipfspin](/data-model/admin/#ipfspin)
diff --git a/docs/content/data-model/admin.md b/docs/content/data-model/admin.md
index 4f63f33f74..fa2d03f6fe 100644
--- a/docs/content/data-model/admin.md
+++ b/docs/content/data-model/admin.md
@@ -268,15 +268,15 @@ ReportChecks consist of the following fields:
| msgStrings | an array of messages explaining failed checks | string[] |
| reason | the reason for the test | string |
-## ChunkPinReport
+## ChunkPin
Reports on the result of the command `chifra chunks manifest --pin [--deep]`.
-The following commands produce and manage ChunkPinReports:
+The following commands produce and manage ChunkPins:
- [chifra chunks](/chifra/admin/#chifra-chunks)
-ChunkPinReports consist of the following fields:
+ChunkPins consist of the following fields:
| Field | Description | Type |
| ------------- | ------------------------------------------------------- | -------- |
diff --git a/examples/findFirst/main.go b/examples/findFirst/main.go
index 01574186c3..64b9320ffa 100644
--- a/examples/findFirst/main.go
+++ b/examples/findFirst/main.go
@@ -88,7 +88,6 @@ func worker(blknumChan <-chan uint64, wg *sync.WaitGroup, mu *sync.Mutex, minBlo
for blknum := range blknumChan {
opts := sdk.BlocksOptions{
BlockIds: []string{fmt.Sprintf("%d", blknum)},
- Count: true,
}
blocks, _, err := opts.BlocksCount()
diff --git a/examples/usesSdk/blocks.go b/examples/usesSdk/blocks.go
index 424cce0e58..7de4ad71f4 100644
--- a/examples/usesSdk/blocks.go
+++ b/examples/usesSdk/blocks.go
@@ -28,7 +28,6 @@ func DoBlocks() {
}
}
- opts.Hashes = true
if blocksHashes, _, err := opts.BlocksHashes(); err != nil {
logger.Error(err)
} else {
@@ -40,8 +39,6 @@ func DoBlocks() {
}
}
- opts.Hashes = false
- opts.Traces = true
if blockTraces, _, err := opts.BlocksTraces(); err != nil {
logger.Error(err)
} else {
@@ -53,8 +50,6 @@ func DoBlocks() {
}
}
- opts.Traces = false
- opts.Uniq = true
// if blockApps, _, err := opts.BlocksUniq(); err != nil {
// logger.Error(err)
// } else {
@@ -66,8 +61,6 @@ func DoBlocks() {
// }
// }
- opts.Uniq = false
- opts.Logs = true
if blocksLogs, _, err := opts.BlocksLogs(); err != nil {
logger.Error(err)
} else {
@@ -79,8 +72,6 @@ func DoBlocks() {
}
}
- opts.Logs = false
- opts.Withdrawals = true
if blocksWithdrawals, _, err := opts.BlocksWithdrawals(); err != nil {
logger.Error(err)
} else {
@@ -92,8 +83,6 @@ func DoBlocks() {
}
}
- opts.Withdrawals = false
- opts.Count = false
if blocksCounts, _, err := opts.BlocksCount(); err != nil {
logger.Error(err)
} else {
diff --git a/examples/usesSdk/chunks.go b/examples/usesSdk/chunks.go
index aeb3f7cf97..be87b2c16d 100644
--- a/examples/usesSdk/chunks.go
+++ b/examples/usesSdk/chunks.go
@@ -10,13 +10,11 @@ func DoChunks() {
logger.Info("DoChunks")
opts := sdk.ChunksOptions{
- Mode: sdk.CMManifest,
FirstBlock: 1000,
LastBlock: 2000,
}
logger.Info("ChunksManifest")
- opts.Mode = sdk.CMManifest
if chunksManifest, _, err := opts.ChunksManifest(); err != nil {
logger.Error(err)
} else {
@@ -26,7 +24,6 @@ func DoChunks() {
}
logger.Info("ChunksIndex")
- opts.Mode = sdk.CMIndex
if chunksIndex, _, err := opts.ChunksIndex(); err != nil {
logger.Error(err)
} else {
@@ -36,7 +33,6 @@ func DoChunks() {
}
logger.Info("ChunksBlooms")
- opts.Mode = sdk.CMBlooms
if chunksBlooms, _, err := opts.ChunksBlooms(); err != nil {
logger.Error(err)
} else {
@@ -47,7 +43,6 @@ func DoChunks() {
logger.Info("ChunksPins")
opts.List = true
- opts.Mode = sdk.CMPins
if chunksPins, _, err := opts.ChunksPins(); err != nil {
logger.Error(err)
} else {
@@ -58,7 +53,6 @@ func DoChunks() {
logger.Info("ChunksAddresses")
opts.List = false
- opts.Mode = sdk.CMAddresses
// if chunksAddresses, _, err := opts.ChunksAddresses(); err != nil {
// logger.Error(err)
// } else {
@@ -68,7 +62,6 @@ func DoChunks() {
// }
logger.Info("ChunksAppearances")
- opts.Mode = sdk.CMAppearances
// if chunksAppearances, _, err := opts.ChunksAppearances(); err != nil {
// logger.Error(err)
// } else {
@@ -81,8 +74,7 @@ func DoChunks() {
// }
logger.Info("ChunksStats")
- opts.Mode = sdk.CMStats
- if chunkStats, _, err := opts.ChunkStats(); err != nil {
+ if chunkStats, _, err := opts.ChunksStats(); err != nil {
logger.Error(err)
} else {
if err := SaveToFile("usesSDK/chunkStats.json", chunkStats); err != nil {
diff --git a/examples/usesSdk/export.go b/examples/usesSdk/export.go
index fffa9a8070..3e33bd4ca7 100644
--- a/examples/usesSdk/export.go
+++ b/examples/usesSdk/export.go
@@ -1,11 +1,6 @@
package main
import (
- "bytes"
- "fmt"
-
- "github.com/TrueBlocks/trueblocks-core/sdk"
- "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
)
@@ -13,17 +8,17 @@ import (
func DoExport() {
logger.Info("DoExport")
- opts := sdk.ExportOptions{
- Addrs: []string{testAddrs[0]},
- }
+ // opts := sdk.ExportOptions{
+ // Addrs: []string{testAddrs[0]},
+ // }
- buf := bytes.Buffer{}
- if err := opts.ExportBytes(&buf); err != nil {
- logger.Error(err)
- }
+ // buf := bytes.Buffer{}
+ // if err := opts.ExportBytes(&buf); err != nil {
+ // logger.Error(err)
+ // }
- file.StringToAsciiFile("usesSDK/export.json", buf.String())
- fmt.Println(buf.String())
+ // file.StringToAsciiFile("usesSDK/export.json", buf.String())
+ // fmt.Println(buf.String())
}
// func (opts *ExportOptions) Export() ([]types.Transaction, *types.MetaData, error) {
diff --git a/examples/usesSdk/init.go b/examples/usesSdk/init.go
index 43e80d2478..5e2fc6fd78 100644
--- a/examples/usesSdk/init.go
+++ b/examples/usesSdk/init.go
@@ -1,11 +1,6 @@
package main
import (
- "bytes"
- "fmt"
-
- "github.com/TrueBlocks/trueblocks-core/sdk"
- "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/file"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
)
@@ -13,17 +8,16 @@ import (
func DoInit() {
logger.Info("DoInit")
- opts := sdk.InitOptions{
- All: true,
- }
+ // opts := sdk.InitOptions{
+ // }
- buf := bytes.Buffer{}
- if err := opts.InitBytes(&buf); err != nil {
- logger.Error(err)
- }
+ // buf := bytes.Buffer{}
+ // if err := opts.InitBytes(&buf); err != nil {
+ // logger.Error(err)
+ // }
- file.StringToAsciiFile("usesSDK/init.json", buf.String())
- fmt.Println(buf.String())
+ // file.StringToAsciiFile("usesSDK/init.json", buf.String())
+ // fmt.Println(buf.String())
}
// func (opts *InitOptions) InitAll() ([]bool, *types.MetaData, error) {
diff --git a/examples/usesSdk/monitors.go b/examples/usesSdk/monitors.go
index b5ab84a3d3..598fea1d15 100644
--- a/examples/usesSdk/monitors.go
+++ b/examples/usesSdk/monitors.go
@@ -12,7 +12,6 @@ func DoMonitors() {
opts := sdk.MonitorsOptions{
Addrs: []string{testAddrs[0]},
- List: true,
}
if monitors, _, err := opts.MonitorsList(); err != nil {
diff --git a/examples/usesSdk/slurp.go b/examples/usesSdk/slurp.go
index 91b5b007dd..98220eb6cb 100644
--- a/examples/usesSdk/slurp.go
+++ b/examples/usesSdk/slurp.go
@@ -26,7 +26,6 @@ func DoSlurp() {
}
}
- opts.Appearances = true
if appearances, _, err := opts.SlurpAppearances(); err != nil {
logger.Error(err)
} else {
@@ -38,8 +37,6 @@ func DoSlurp() {
}
}
- opts.Appearances = true
- opts.Count = true
if counts, _, err := opts.SlurpCount(); err != nil {
logger.Error(err)
} else {
diff --git a/examples/usesSdk/state.go b/examples/usesSdk/state.go
index dd95d678ad..107af08985 100644
--- a/examples/usesSdk/state.go
+++ b/examples/usesSdk/state.go
@@ -31,12 +31,12 @@ func DoState() {
}
opts.Articulate = true
- opts.Call = "manifestHashMap(0x02f2b09b33fdbd406ead954a31f98bd29a2a3492,\"mainnet\")"
- if stateResult, _, err := opts.StateCall(); err != nil {
+ call := "manifestHashMap(0x02f2b09b33fdbd406ead954a31f98bd29a2a3492,\"mainnet\")"
+ if stateResult, _, err := opts.StateCall(call); err != nil {
logger.Error(err)
} else {
if err := SaveAndClean[types.Result]("usesSDK/stateResult.json", stateResult, &opts, func() error {
- _, _, err := opts.StateCall()
+ _, _, err := opts.StateCall(call)
return err
}); err != nil {
logger.Error(err)
diff --git a/examples/usesSdk/transactions.go b/examples/usesSdk/transactions.go
index 67265ebb61..060ca33731 100644
--- a/examples/usesSdk/transactions.go
+++ b/examples/usesSdk/transactions.go
@@ -25,7 +25,6 @@ func DoTransactions() {
}
}
- opts.Traces = true
if transactionsTraces, _, err := opts.TransactionsTraces(); err != nil {
logger.Error(err)
} else {
@@ -37,8 +36,6 @@ func DoTransactions() {
}
}
- opts.Traces = false
- opts.Uniq = true
if transactionsUniq, _, err := opts.TransactionsUniq(); err != nil {
logger.Error(err)
} else {
@@ -50,8 +47,6 @@ func DoTransactions() {
}
}
- opts.Uniq = false
- opts.Logs = true
opts.Articulate = true
if transactionsLogs, _, err := opts.TransactionsLogs(); err != nil {
logger.Error(err)
diff --git a/examples/usesSdk/when.go b/examples/usesSdk/when.go
index d31e27a51b..393d281669 100644
--- a/examples/usesSdk/when.go
+++ b/examples/usesSdk/when.go
@@ -26,7 +26,6 @@ func DoWhen() {
}
}
- opts.Timestamps = true
if whenTimestamps, _, err := opts.WhenTimestamps(); err != nil {
logger.Error(err)
} else {
@@ -38,8 +37,6 @@ func DoWhen() {
}
}
- // opts.Timestamps = false
- opts.Count = true
if whenCount, _, err := opts.WhenCount(); err != nil {
logger.Error(err)
} else {
diff --git a/sdk/abis.go b/sdk/abis.go
index 98aecf3c23..88a8c3042a 100644
--- a/sdk/abis.go
+++ b/sdk/abis.go
@@ -10,14 +10,11 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
+
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- abis "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -37,67 +34,10 @@ func (opts *AbisOptions) String() string {
return string(bytes)
}
-// AbisBytes implements the chifra abis command for the SDK.
-func (opts *AbisOptions) AbisBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting abis struct to URL values: %v", err)
- }
-
- return abis.Abis(w, values)
-}
-
-// abisParseFunc handles special cases such as structs and enums (if any).
-func abisParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*AbisOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(abis): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- if key == "proxyFor" {
- opts, _ := target.(*AbisOptions)
- opts.ProxyFor = base.HexToAddress(value)
- return base.IsValidAddress(value), nil
- }
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetAbisOptions returns a filled-in options instance given a string array of arguments.
-func GetAbisOptions(args []string) (*AbisOptions, error) {
- var opts AbisOptions
- if err := assignValuesFromArgs(args, abisParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type abisGeneric interface {
- types.Function
-}
-
-func queryAbis[T abisGeneric](opts *AbisOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.AbisBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Abis implements the chifra abis command.
func (opts *AbisOptions) Abis() ([]types.Function, *types.MetaData, error) {
- return queryAbis[types.Function](opts)
+ in := opts.toInternal()
+ return queryAbis[types.Function](in)
}
// No enums
diff --git a/sdk/abis_internal.go b/sdk/abis_internal.go
new file mode 100644
index 0000000000..bfc7ca0107
--- /dev/null
+++ b/sdk/abis_internal.go
@@ -0,0 +1,112 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ abis "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type abisOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ Known bool `json:"known,omitempty"`
+ ProxyFor base.Address `json:"proxyFor,omitempty"`
+ Find []string `json:"find,omitempty"`
+ Hint []string `json:"hint,omitempty"`
+ Encode string `json:"encode,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *abisOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// AbisBytes implements the chifra abis command for the SDK.
+func (opts *abisOptionsInternal) AbisBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting abis struct to URL values: %v", err)
+ }
+
+ return abis.Abis(w, values)
+}
+
+// abisParseFunc handles special cases such as structs and enums (if any).
+func abisParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*abisOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(abis): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ if key == "proxyFor" {
+ opts, _ := target.(*abisOptionsInternal)
+ opts.ProxyFor = base.HexToAddress(value)
+ return base.IsValidAddress(value), nil
+ }
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetAbisOptions returns a filled-in options instance given a string array of arguments.
+func GetAbisOptions(args []string) (*abisOptionsInternal, error) {
+ var opts abisOptionsInternal
+ if err := assignValuesFromArgs(args, abisParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type abisGeneric interface {
+ types.Function
+}
+
+func queryAbis[T abisGeneric](opts *abisOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.AbisBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *AbisOptions) toInternal() *abisOptionsInternal {
+ return &abisOptionsInternal{
+ Addrs: opts.Addrs,
+ Known: opts.Known,
+ ProxyFor: opts.ProxyFor,
+ Find: opts.Find,
+ Hint: opts.Hint,
+ Encode: opts.Encode,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/blocks.go b/sdk/blocks.go
index e125ba19cc..74f090ef54 100644
--- a/sdk/blocks.go
+++ b/sdk/blocks.go
@@ -10,32 +10,22 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- blocks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type BlocksOptions struct {
BlockIds []string `json:"blocks,omitempty"`
- Hashes bool `json:"hashes,omitempty"`
- Uncles bool `json:"uncles,omitempty"`
- Traces bool `json:"traces,omitempty"`
- Uniq bool `json:"uniq,omitempty"`
Flow BlocksFlow `json:"flow,omitempty"`
- Logs bool `json:"logs,omitempty"`
Emitter []string `json:"emitter,omitempty"`
Topic []string `json:"topic,omitempty"`
- Withdrawals bool `json:"withdrawals,omitempty"`
Articulate bool `json:"articulate,omitempty"`
BigRange uint64 `json:"bigRange,omitempty"`
- Count bool `json:"count,omitempty"`
CacheTxs bool `json:"cacheTxs,omitempty"`
CacheTraces bool `json:"cacheTraces,omitempty"`
List base.Blknum `json:"list,omitempty"`
@@ -49,107 +39,59 @@ func (opts *BlocksOptions) String() string {
return string(bytes)
}
-// BlocksBytes implements the chifra blocks command for the SDK.
-func (opts *BlocksOptions) BlocksBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting blocks struct to URL values: %v", err)
- }
-
- return blocks.Blocks(w, values)
-}
-
-// blocksParseFunc handles special cases such as structs and enums (if any).
-func blocksParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*BlocksOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(blocks): target is not of correct type")
- }
-
- if key == "flow" {
- var err error
- values := strings.Split(value, ",")
- if opts.Flow, err = enumFromBlocksFlow(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetBlocksOptions returns a filled-in options instance given a string array of arguments.
-func GetBlocksOptions(args []string) (*BlocksOptions, error) {
- var opts BlocksOptions
- if err := assignValuesFromArgs(args, blocksParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type blocksGeneric interface {
- types.Block[types.Transaction] |
- types.Block[string] |
- types.Trace |
- types.Appearance |
- types.Log |
- types.Withdrawal |
- types.BlockCount
-}
-
-func queryBlocks[T blocksGeneric](opts *BlocksOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.BlocksBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Blocks implements the chifra blocks command.
func (opts *BlocksOptions) Blocks() ([]types.Block[types.Transaction], *types.MetaData, error) {
- return queryBlocks[types.Block[types.Transaction]](opts)
+ in := opts.toInternal()
+ return queryBlocks[types.Block[types.Transaction]](in)
}
// BlocksHashes implements the chifra blocks --hashes command.
func (opts *BlocksOptions) BlocksHashes() ([]types.Block[string], *types.MetaData, error) {
- return queryBlocks[types.Block[string]](opts)
+ in := opts.toInternal()
+ in.Hashes = true
+ return queryBlocks[types.Block[string]](in)
+}
+
+// BlocksUncles implements the chifra blocks --uncles command.
+func (opts *BlocksOptions) BlocksUncles() ([]types.Block[string], *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Uncles = true
+ return queryBlocks[types.Block[string]](in)
}
// BlocksTraces implements the chifra blocks --traces command.
func (opts *BlocksOptions) BlocksTraces() ([]types.Trace, *types.MetaData, error) {
- return queryBlocks[types.Trace](opts)
+ in := opts.toInternal()
+ in.Traces = true
+ return queryBlocks[types.Trace](in)
}
// BlocksUniq implements the chifra blocks --uniq command.
func (opts *BlocksOptions) BlocksUniq() ([]types.Appearance, *types.MetaData, error) {
- return queryBlocks[types.Appearance](opts)
+ in := opts.toInternal()
+ in.Uniq = true
+ return queryBlocks[types.Appearance](in)
}
// BlocksLogs implements the chifra blocks --logs command.
func (opts *BlocksOptions) BlocksLogs() ([]types.Log, *types.MetaData, error) {
- return queryBlocks[types.Log](opts)
+ in := opts.toInternal()
+ in.Logs = true
+ return queryBlocks[types.Log](in)
}
// BlocksWithdrawals implements the chifra blocks --withdrawals command.
func (opts *BlocksOptions) BlocksWithdrawals() ([]types.Withdrawal, *types.MetaData, error) {
- return queryBlocks[types.Withdrawal](opts)
+ in := opts.toInternal()
+ in.Withdrawals = true
+ return queryBlocks[types.Withdrawal](in)
}
// BlocksCount implements the chifra blocks --count command.
func (opts *BlocksOptions) BlocksCount() ([]types.BlockCount, *types.MetaData, error) {
- return queryBlocks[types.BlockCount](opts)
+ in := opts.toInternal()
+ in.Count = true
+ return queryBlocks[types.BlockCount](in)
}
type BlocksFlow int
diff --git a/sdk/blocks_internal.go b/sdk/blocks_internal.go
new file mode 100644
index 0000000000..1c878501a7
--- /dev/null
+++ b/sdk/blocks_internal.go
@@ -0,0 +1,138 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ blocks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type blocksOptionsInternal struct {
+ BlockIds []string `json:"blocks,omitempty"`
+ Hashes bool `json:"hashes,omitempty"`
+ Uncles bool `json:"uncles,omitempty"`
+ Traces bool `json:"traces,omitempty"`
+ Uniq bool `json:"uniq,omitempty"`
+ Flow BlocksFlow `json:"flow,omitempty"`
+ Logs bool `json:"logs,omitempty"`
+ Emitter []string `json:"emitter,omitempty"`
+ Topic []string `json:"topic,omitempty"`
+ Withdrawals bool `json:"withdrawals,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ BigRange uint64 `json:"bigRange,omitempty"`
+ Count bool `json:"count,omitempty"`
+ CacheTxs bool `json:"cacheTxs,omitempty"`
+ CacheTraces bool `json:"cacheTraces,omitempty"`
+ List base.Blknum `json:"list,omitempty"`
+ ListCount base.Blknum `json:"listCount,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *blocksOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// BlocksBytes implements the chifra blocks command for the SDK.
+func (opts *blocksOptionsInternal) BlocksBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting blocks struct to URL values: %v", err)
+ }
+
+ return blocks.Blocks(w, values)
+}
+
+// blocksParseFunc handles special cases such as structs and enums (if any).
+func blocksParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*blocksOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(blocks): target is not of correct type")
+ }
+
+ if key == "flow" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Flow, err = enumFromBlocksFlow(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetBlocksOptions returns a filled-in options instance given a string array of arguments.
+func GetBlocksOptions(args []string) (*blocksOptionsInternal, error) {
+ var opts blocksOptionsInternal
+ if err := assignValuesFromArgs(args, blocksParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type blocksGeneric interface {
+ types.Block[types.Transaction] |
+ types.Block[string] |
+ types.Trace |
+ types.Appearance |
+ types.Log |
+ types.Withdrawal |
+ types.BlockCount
+}
+
+func queryBlocks[T blocksGeneric](opts *blocksOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.BlocksBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *BlocksOptions) toInternal() *blocksOptionsInternal {
+ return &blocksOptionsInternal{
+ BlockIds: opts.BlockIds,
+ Flow: opts.Flow,
+ Emitter: opts.Emitter,
+ Topic: opts.Topic,
+ Articulate: opts.Articulate,
+ BigRange: opts.BigRange,
+ CacheTxs: opts.CacheTxs,
+ CacheTraces: opts.CacheTraces,
+ List: opts.List,
+ ListCount: opts.ListCount,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/chunks.go b/sdk/chunks.go
index 7b55813d34..b7faa1a83b 100644
--- a/sdk/chunks.go
+++ b/sdk/chunks.go
@@ -10,20 +10,16 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- chunks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type ChunksOptions struct {
- Mode ChunksMode `json:"mode,omitempty"`
BlockIds []string `json:"blocks,omitempty"`
Check bool `json:"check,omitempty"`
Pin bool `json:"pin,omitempty"`
@@ -52,65 +48,53 @@ func (opts *ChunksOptions) String() string {
return string(bytes)
}
-// ChunksBytes implements the chifra chunks command for the SDK.
-func (opts *ChunksOptions) ChunksBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting chunks struct to URL values: %v", err)
- }
-
- return chunks.Chunks(w, values)
+// ChunksManifest implements the chifra chunks manifest command.
+func (opts *ChunksOptions) ChunksManifest() ([]types.ChunkManifest, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMManifest
+ return queryChunks[types.ChunkManifest](in)
}
-// chunksParseFunc handles special cases such as structs and enums (if any).
-func chunksParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*ChunksOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(chunks): target is not of correct type")
- }
-
- if key == "mode" {
- var err error
- values := strings.Split(value, ",")
- if opts.Mode, err = enumFromChunksMode(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
+// ChunksIndex implements the chifra chunks index command.
+func (opts *ChunksOptions) ChunksIndex() ([]types.ChunkIndex, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMIndex
+ return queryChunks[types.ChunkIndex](in)
}
-// GetChunksOptions returns a filled-in options instance given a string array of arguments.
-func GetChunksOptions(args []string) (*ChunksOptions, error) {
- var opts ChunksOptions
- if err := assignValuesFromArgs(args, chunksParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
+// ChunksBlooms implements the chifra chunks blooms command.
+func (opts *ChunksOptions) ChunksBlooms() ([]types.ChunkBloom, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMBlooms
+ return queryChunks[types.ChunkBloom](in)
+}
- return &opts, nil
+// ChunksPins implements the chifra chunks pins command.
+func (opts *ChunksOptions) ChunksPins() ([]types.ChunkPin, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMPins
+ return queryChunks[types.ChunkPin](in)
}
-type chunksGeneric interface {
+// ChunksAddresses implements the chifra chunks addresses command.
+func (opts *ChunksOptions) ChunksAddresses() ([]types.ChunkAddress, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMAddresses
+ return queryChunks[types.ChunkAddress](in)
}
-func queryChunks[T chunksGeneric](opts *ChunksOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.ChunksBytes(&buffer); err != nil {
- return nil, nil, err
- }
+// ChunksAppearances implements the chifra chunks appearances command.
+func (opts *ChunksOptions) ChunksAppearances() ([]types.ChunkAppearance, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMAppearances
+ return queryChunks[types.ChunkAppearance](in)
+}
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
+// ChunksStats implements the chifra chunks stats command.
+func (opts *ChunksOptions) ChunksStats() ([]types.ChunkStats, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Mode = CMStats
+ return queryChunks[types.ChunkStats](in)
}
type ChunksMode int
@@ -183,39 +167,4 @@ func enumFromChunksMode(values []string) (ChunksMode, error) {
}
// EXISTING_CODE
-// ChunksManifest implements the chifra chunks manifest command.
-func (opts *ChunksOptions) ChunksManifest() ([]types.ChunkRecord, *types.MetaData, error) {
- return queryChunks[types.ChunkRecord](opts)
-}
-
-// ChunksIndex implements the chifra chunks index command.
-func (opts *ChunksOptions) ChunksIndex() ([]types.ChunkIndex, *types.MetaData, error) {
- return queryChunks[types.ChunkIndex](opts)
-}
-
-// ChunksBlooms implements the chifra chunks blooms command.
-func (opts *ChunksOptions) ChunksBlooms() ([]types.ChunkBloom, *types.MetaData, error) {
- return queryChunks[types.ChunkBloom](opts)
-}
-
-// ChunksPins implements the chifra chunks pins command.
-func (opts *ChunksOptions) ChunksPins() ([]types.ChunkPinReport, *types.MetaData, error) {
- return queryChunks[types.ChunkPinReport](opts)
-}
-
-// ChunksAddresses implements the chifra chunks addresses command.
-func (opts *ChunksOptions) ChunksAddresses() ([]types.ChunkAddress, *types.MetaData, error) {
- return queryChunks[types.ChunkAddress](opts)
-}
-
-// // ChunksAppearances implements the chifra chunks appearance command.
-// func (opts *ChunksOptions) ChunksAppearances() ([]types.ChunkAppearance, *types.MetaData, error) {
-// return queryChunks[types.ChunkAppearance](opts)
-// }
-
-// ChunkStats implements the chifra chunks stats command.
-func (opts *ChunksOptions) ChunkStats() ([]types.ChunkStats, *types.MetaData, error) {
- return queryChunks[types.ChunkStats](opts)
-}
-
// EXISTING_CODE
diff --git a/sdk/chunks_internal.go b/sdk/chunks_internal.go
new file mode 100644
index 0000000000..0087e2c562
--- /dev/null
+++ b/sdk/chunks_internal.go
@@ -0,0 +1,150 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ chunks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type chunksOptionsInternal struct {
+ Mode ChunksMode `json:"mode,omitempty"`
+ BlockIds []string `json:"blocks,omitempty"`
+ Check bool `json:"check,omitempty"`
+ Pin bool `json:"pin,omitempty"`
+ Publish bool `json:"publish,omitempty"`
+ Publisher base.Address `json:"publisher,omitempty"`
+ Truncate base.Blknum `json:"truncate,omitempty"`
+ Remote bool `json:"remote,omitempty"`
+ Belongs []string `json:"belongs,omitempty"`
+ Diff bool `json:"diff,omitempty"`
+ FirstBlock base.Blknum `json:"firstBlock,omitempty"`
+ LastBlock base.Blknum `json:"lastBlock,omitempty"`
+ MaxAddrs base.Blknum `json:"maxAddrs,omitempty"`
+ Deep bool `json:"deep,omitempty"`
+ Rewrite bool `json:"rewrite,omitempty"`
+ List bool `json:"list,omitempty"`
+ Unpin bool `json:"unpin,omitempty"`
+ Count bool `json:"count,omitempty"`
+ Tag string `json:"tag,omitempty"`
+ Sleep float64 `json:"sleep,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *chunksOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// ChunksBytes implements the chifra chunks command for the SDK.
+func (opts *chunksOptionsInternal) ChunksBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting chunks struct to URL values: %v", err)
+ }
+
+ return chunks.Chunks(w, values)
+}
+
+// chunksParseFunc handles special cases such as structs and enums (if any).
+func chunksParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*chunksOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(chunks): target is not of correct type")
+ }
+
+ if key == "mode" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Mode, err = enumFromChunksMode(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetChunksOptions returns a filled-in options instance given a string array of arguments.
+func GetChunksOptions(args []string) (*chunksOptionsInternal, error) {
+ var opts chunksOptionsInternal
+ if err := assignValuesFromArgs(args, chunksParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type chunksGeneric interface {
+ types.ChunkManifest |
+ types.ChunkIndex |
+ types.ChunkBloom |
+ types.ChunkPin |
+ types.ChunkAddress |
+ types.ChunkAppearance |
+ types.ChunkStats
+}
+
+func queryChunks[T chunksGeneric](opts *chunksOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.ChunksBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *ChunksOptions) toInternal() *chunksOptionsInternal {
+ return &chunksOptionsInternal{
+ BlockIds: opts.BlockIds,
+ Check: opts.Check,
+ Pin: opts.Pin,
+ Publish: opts.Publish,
+ Publisher: opts.Publisher,
+ Truncate: opts.Truncate,
+ Remote: opts.Remote,
+ Belongs: opts.Belongs,
+ Diff: opts.Diff,
+ FirstBlock: opts.FirstBlock,
+ LastBlock: opts.LastBlock,
+ MaxAddrs: opts.MaxAddrs,
+ Deep: opts.Deep,
+ Rewrite: opts.Rewrite,
+ List: opts.List,
+ Unpin: opts.Unpin,
+ Count: opts.Count,
+ Tag: opts.Tag,
+ Sleep: opts.Sleep,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/config.go b/sdk/config.go
index 6f8267d5e9..c6e3caac65 100644
--- a/sdk/config.go
+++ b/sdk/config.go
@@ -10,14 +10,9 @@ 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
)
@@ -33,67 +28,6 @@ func (opts *ConfigOptions) String() string {
return string(bytes)
}
-// ConfigBytes implements the chifra config command for the SDK.
-func (opts *ConfigOptions) ConfigBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting config struct to URL values: %v", err)
- }
-
- return config.Config(w, values)
-}
-
-// configParseFunc handles special cases such as structs and enums (if any).
-func configParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*ConfigOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(config): target is not of correct type")
- }
-
- if key == "mode" {
- var err error
- values := strings.Split(value, ",")
- if opts.Mode, err = enumFromConfigMode(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetConfigOptions returns a filled-in options instance given a string array of arguments.
-func GetConfigOptions(args []string) (*ConfigOptions, error) {
- var opts ConfigOptions
- if err := assignValuesFromArgs(args, configParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type configGeneric interface {
-}
-
-func queryConfig[T configGeneric](opts *ConfigOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.ConfigBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
type ConfigMode int
const (
diff --git a/sdk/config_internal.go b/sdk/config_internal.go
new file mode 100644
index 0000000000..fea7b6ddcd
--- /dev/null
+++ b/sdk/config_internal.go
@@ -0,0 +1,79 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ config "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type configOptionsInternal struct {
+ Mode ConfigMode `json:"mode,omitempty"`
+ Paths bool `json:"paths,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *configOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// ConfigBytes implements the chifra config command for the SDK.
+func (opts *configOptionsInternal) ConfigBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting config struct to URL values: %v", err)
+ }
+
+ return config.Config(w, values)
+}
+
+// configParseFunc handles special cases such as structs and enums (if any).
+func configParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*configOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(config): target is not of correct type")
+ }
+
+ if key == "mode" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Mode, err = enumFromConfigMode(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetConfigOptions returns a filled-in options instance given a string array of arguments.
+func GetConfigOptions(args []string) (*configOptionsInternal, error) {
+ var opts configOptionsInternal
+ if err := assignValuesFromArgs(args, configParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/daemon.go b/sdk/daemon.go
index f76982485c..8e1fc9073f 100644
--- a/sdk/daemon.go
+++ b/sdk/daemon.go
@@ -13,13 +13,10 @@ import (
"bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"time"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
- "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- daemon "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -40,76 +37,6 @@ func (opts *DaemonOptions) String() string {
return string(bytes)
}
-// DaemonBytes implements the chifra daemon command for the SDK.
-func (opts *DaemonOptions) DaemonBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting daemon struct to URL values: %v", err)
- }
-
- return daemon.Daemon(w, values)
-}
-
-// daemonParseFunc handles special cases such as structs and enums (if any).
-func daemonParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*DaemonOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(daemon): target is not of correct type")
- }
-
- if key == "api" {
- var err error
- values := strings.Split(value, ",")
- if opts.Api, err = enumFromDaemonApi(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
- if key == "scrape" {
- var err error
- values := strings.Split(value, ",")
- if opts.Scrape, err = enumFromDaemonScrape(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetDaemonOptions returns a filled-in options instance given a string array of arguments.
-func GetDaemonOptions(args []string) (*DaemonOptions, error) {
- var opts DaemonOptions
- if err := assignValuesFromArgs(args, daemonParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type daemonGeneric interface {
-}
-
-func queryDaemon[T daemonGeneric](opts *DaemonOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.DaemonBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
type DaemonApi int
const (
@@ -215,8 +142,9 @@ func enumFromDaemonScrape(values []string) (DaemonScrape, error) {
// EXISTING_CODE
func (opts *DaemonOptions) Start(ready chan<- bool) {
go func() {
+ in := opts.toInternal()
buffer := bytes.Buffer{}
- if err := opts.DaemonBytes(&buffer); err != nil {
+ if err := in.DaemonBytes(&buffer); err != nil {
logger.Fatal(err)
}
}()
diff --git a/sdk/daemon_internal.go b/sdk/daemon_internal.go
new file mode 100644
index 0000000000..36a02c1a3e
--- /dev/null
+++ b/sdk/daemon_internal.go
@@ -0,0 +1,106 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ daemon "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type daemonOptionsInternal struct {
+ Url string `json:"url,omitempty"`
+ Api DaemonApi `json:"api,omitempty"`
+ Scrape DaemonScrape `json:"scrape,omitempty"`
+ Monitor bool `json:"monitor,omitempty"`
+ Grpc bool `json:"grpc,omitempty"`
+ Port string `json:"port,omitempty"`
+ Silent bool `json:"silent,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *daemonOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// DaemonBytes implements the chifra daemon command for the SDK.
+func (opts *daemonOptionsInternal) DaemonBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting daemon struct to URL values: %v", err)
+ }
+
+ return daemon.Daemon(w, values)
+}
+
+// daemonParseFunc handles special cases such as structs and enums (if any).
+func daemonParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*daemonOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(daemon): target is not of correct type")
+ }
+
+ if key == "api" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Api, err = enumFromDaemonApi(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+ if key == "scrape" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Scrape, err = enumFromDaemonScrape(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetDaemonOptions returns a filled-in options instance given a string array of arguments.
+func GetDaemonOptions(args []string) (*daemonOptionsInternal, error) {
+ var opts daemonOptionsInternal
+ if err := assignValuesFromArgs(args, daemonParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+// EXISTING_CODE
+func (opts *DaemonOptions) toInternal() *daemonOptionsInternal {
+ return &daemonOptionsInternal{
+ Url: opts.Url,
+ Api: opts.Api,
+ Scrape: opts.Scrape,
+ Monitor: opts.Monitor,
+ Grpc: opts.Grpc,
+ Port: opts.Port,
+ Silent: opts.Silent,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
diff --git a/sdk/export.go b/sdk/export.go
index 4bdb47c5f9..9abb027d6b 100644
--- a/sdk/export.go
+++ b/sdk/export.go
@@ -10,15 +10,12 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- export "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -26,18 +23,9 @@ type ExportOptions struct {
Addrs []string `json:"addrs,omitempty"`
Topics []string `json:"topics,omitempty"`
Fourbytes []string `json:"fourbytes,omitempty"`
- Appearances bool `json:"appearances,omitempty"`
- Receipts bool `json:"receipts,omitempty"`
- Logs bool `json:"logs,omitempty"`
- Traces bool `json:"traces,omitempty"`
- Neighbors bool `json:"neighbors,omitempty"`
Accounting bool `json:"accounting,omitempty"`
- Statements bool `json:"statements,omitempty"`
- Balances bool `json:"balances,omitempty"`
- Withdrawals bool `json:"withdrawals,omitempty"`
Articulate bool `json:"articulate,omitempty"`
CacheTraces bool `json:"cacheTraces,omitempty"`
- Count bool `json:"count,omitempty"`
FirstRecord uint64 `json:"firstRecord,omitempty"`
MaxRecords uint64 `json:"maxRecords,omitempty"`
Relevant bool `json:"relevant,omitempty"`
@@ -62,119 +50,73 @@ func (opts *ExportOptions) String() string {
return string(bytes)
}
-// ExportBytes implements the chifra export command for the SDK.
-func (opts *ExportOptions) ExportBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting export struct to URL values: %v", err)
- }
-
- return export.Export(w, values)
-}
-
-// exportParseFunc handles special cases such as structs and enums (if any).
-func exportParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*ExportOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(export): target is not of correct type")
- }
-
- if key == "flow" {
- var err error
- values := strings.Split(value, ",")
- if opts.Flow, err = enumFromExportFlow(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetExportOptions returns a filled-in options instance given a string array of arguments.
-func GetExportOptions(args []string) (*ExportOptions, error) {
- var opts ExportOptions
- if err := assignValuesFromArgs(args, exportParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type exportGeneric interface {
- types.Transaction |
- types.Appearance |
- types.Receipt |
- types.Log |
- types.Trace |
- types.Statement |
- types.State |
- types.Withdrawal |
- types.AppearanceCount
-}
-
-func queryExport[T exportGeneric](opts *ExportOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.ExportBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Export implements the chifra export command.
func (opts *ExportOptions) Export() ([]types.Transaction, *types.MetaData, error) {
- return queryExport[types.Transaction](opts)
+ in := opts.toInternal()
+ return queryExport[types.Transaction](in)
}
// ExportAppearances implements the chifra export --appearances command.
func (opts *ExportOptions) ExportAppearances() ([]types.Appearance, *types.MetaData, error) {
- return queryExport[types.Appearance](opts)
+ in := opts.toInternal()
+ in.Appearances = true
+ return queryExport[types.Appearance](in)
}
// ExportReceipts implements the chifra export --receipts command.
func (opts *ExportOptions) ExportReceipts() ([]types.Receipt, *types.MetaData, error) {
- return queryExport[types.Receipt](opts)
+ in := opts.toInternal()
+ in.Receipts = true
+ return queryExport[types.Receipt](in)
}
// ExportLogs implements the chifra export --logs command.
func (opts *ExportOptions) ExportLogs() ([]types.Log, *types.MetaData, error) {
- return queryExport[types.Log](opts)
+ in := opts.toInternal()
+ in.Logs = true
+ return queryExport[types.Log](in)
}
// ExportTraces implements the chifra export --traces command.
func (opts *ExportOptions) ExportTraces() ([]types.Trace, *types.MetaData, error) {
- return queryExport[types.Trace](opts)
+ in := opts.toInternal()
+ in.Traces = true
+ return queryExport[types.Trace](in)
+}
+
+// ExportNeighbors implements the chifra export --neighbors command.
+func (opts *ExportOptions) ExportNeighbors() ([]bool, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Neighbors = true
+ return queryExport[bool](in)
}
// ExportStatements implements the chifra export --statements command.
func (opts *ExportOptions) ExportStatements() ([]types.Statement, *types.MetaData, error) {
- return queryExport[types.Statement](opts)
+ in := opts.toInternal()
+ in.Statements = true
+ return queryExport[types.Statement](in)
}
// ExportBalances implements the chifra export --balances command.
func (opts *ExportOptions) ExportBalances() ([]types.State, *types.MetaData, error) {
- return queryExport[types.State](opts)
+ in := opts.toInternal()
+ in.Balances = true
+ return queryExport[types.State](in)
}
// ExportWithdrawals implements the chifra export --withdrawals command.
func (opts *ExportOptions) ExportWithdrawals() ([]types.Withdrawal, *types.MetaData, error) {
- return queryExport[types.Withdrawal](opts)
+ in := opts.toInternal()
+ in.Withdrawals = true
+ return queryExport[types.Withdrawal](in)
}
// ExportCount implements the chifra export --count command.
func (opts *ExportOptions) ExportCount() ([]types.AppearanceCount, *types.MetaData, error) {
- return queryExport[types.AppearanceCount](opts)
+ in := opts.toInternal()
+ in.Count = true
+ return queryExport[types.AppearanceCount](in)
}
type ExportFlow int
diff --git a/sdk/export_internal.go b/sdk/export_internal.go
new file mode 100644
index 0000000000..da3a011c91
--- /dev/null
+++ b/sdk/export_internal.go
@@ -0,0 +1,165 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ export "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type exportOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ Topics []string `json:"topics,omitempty"`
+ Fourbytes []string `json:"fourbytes,omitempty"`
+ Appearances bool `json:"appearances,omitempty"`
+ Receipts bool `json:"receipts,omitempty"`
+ Logs bool `json:"logs,omitempty"`
+ Traces bool `json:"traces,omitempty"`
+ Neighbors bool `json:"neighbors,omitempty"`
+ Accounting bool `json:"accounting,omitempty"`
+ Statements bool `json:"statements,omitempty"`
+ Balances bool `json:"balances,omitempty"`
+ Withdrawals bool `json:"withdrawals,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ CacheTraces bool `json:"cacheTraces,omitempty"`
+ Count bool `json:"count,omitempty"`
+ FirstRecord uint64 `json:"firstRecord,omitempty"`
+ MaxRecords uint64 `json:"maxRecords,omitempty"`
+ Relevant bool `json:"relevant,omitempty"`
+ Emitter []string `json:"emitter,omitempty"`
+ Topic []string `json:"topic,omitempty"`
+ Reverted bool `json:"reverted,omitempty"`
+ Asset []string `json:"asset,omitempty"`
+ Flow ExportFlow `json:"flow,omitempty"`
+ Factory bool `json:"factory,omitempty"`
+ Unripe bool `json:"unripe,omitempty"`
+ Load string `json:"load,omitempty"`
+ Reversed bool `json:"reversed,omitempty"`
+ NoZero bool `json:"noZero,omitempty"`
+ FirstBlock base.Blknum `json:"firstBlock,omitempty"`
+ LastBlock base.Blknum `json:"lastBlock,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *exportOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// ExportBytes implements the chifra export command for the SDK.
+func (opts *exportOptionsInternal) ExportBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting export struct to URL values: %v", err)
+ }
+
+ return export.Export(w, values)
+}
+
+// exportParseFunc handles special cases such as structs and enums (if any).
+func exportParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*exportOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(export): target is not of correct type")
+ }
+
+ if key == "flow" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Flow, err = enumFromExportFlow(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetExportOptions returns a filled-in options instance given a string array of arguments.
+func GetExportOptions(args []string) (*exportOptionsInternal, error) {
+ var opts exportOptionsInternal
+ if err := assignValuesFromArgs(args, exportParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type exportGeneric interface {
+ types.Transaction |
+ types.Appearance |
+ types.Receipt |
+ types.Log |
+ types.Trace |
+ bool |
+ types.Statement |
+ types.State |
+ types.Withdrawal |
+ types.AppearanceCount
+}
+
+func queryExport[T exportGeneric](opts *exportOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.ExportBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *ExportOptions) toInternal() *exportOptionsInternal {
+ return &exportOptionsInternal{
+ Addrs: opts.Addrs,
+ Topics: opts.Topics,
+ Fourbytes: opts.Fourbytes,
+ Accounting: opts.Accounting,
+ Articulate: opts.Articulate,
+ CacheTraces: opts.CacheTraces,
+ FirstRecord: opts.FirstRecord,
+ MaxRecords: opts.MaxRecords,
+ Relevant: opts.Relevant,
+ Emitter: opts.Emitter,
+ Topic: opts.Topic,
+ Reverted: opts.Reverted,
+ Asset: opts.Asset,
+ Flow: opts.Flow,
+ Factory: opts.Factory,
+ Unripe: opts.Unripe,
+ Load: opts.Load,
+ Reversed: opts.Reversed,
+ NoZero: opts.NoZero,
+ FirstBlock: opts.FirstBlock,
+ LastBlock: opts.LastBlock,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/init.go b/sdk/init.go
index 7f5c27ed54..c119dc5515 100644
--- a/sdk/init.go
+++ b/sdk/init.go
@@ -10,21 +10,14 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- initPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type InitOptions struct {
- All bool `json:"all,omitempty"`
- Example string `json:"example,omitempty"`
- DryRun bool `json:"dryRun,omitempty"`
Publisher base.Address `json:"publisher,omitempty"`
FirstBlock base.Blknum `json:"firstBlock,omitempty"`
Sleep float64 `json:"sleep,omitempty"`
@@ -37,62 +30,25 @@ func (opts *InitOptions) String() string {
return string(bytes)
}
-// InitBytes implements the chifra init command for the SDK.
-func (opts *InitOptions) InitBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting init struct to URL values: %v", err)
- }
-
- return initPkg.Init(w, values)
-}
-
-// initParseFunc handles special cases such as structs and enums (if any).
-func initParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*InitOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(init): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetInitOptions returns a filled-in options instance given a string array of arguments.
-func GetInitOptions(args []string) (*InitOptions, error) {
- var opts InitOptions
- if err := assignValuesFromArgs(args, initParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type initGeneric interface {
- bool
+// InitAll implements the chifra init --all command.
+func (opts *InitOptions) InitAll() ([]bool, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.All = true
+ return queryInit[bool](in)
}
-func queryInit[T initGeneric](opts *InitOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.InitBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
+// InitExample implements the chifra init --example command.
+func (opts *InitOptions) InitExample(val string) ([]bool, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Example = val
+ return queryInit[bool](in)
}
-// InitAll implements the chifra init --all command.
-func (opts *InitOptions) InitAll() ([]bool, *types.MetaData, error) {
- return queryInit[bool](opts)
+// InitDryRun implements the chifra init --dry_run command.
+func (opts *InitOptions) InitDry_run() ([]bool, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.DryRun = true
+ return queryInit[bool](in)
}
// No enums
diff --git a/sdk/init_internal.go b/sdk/init_internal.go
new file mode 100644
index 0000000000..88bf281691
--- /dev/null
+++ b/sdk/init_internal.go
@@ -0,0 +1,104 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ initPkg "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type initOptionsInternal struct {
+ All bool `json:"all,omitempty"`
+ Example string `json:"example,omitempty"`
+ DryRun bool `json:"dryRun,omitempty"`
+ Publisher base.Address `json:"publisher,omitempty"`
+ FirstBlock base.Blknum `json:"firstBlock,omitempty"`
+ Sleep float64 `json:"sleep,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *initOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// InitBytes implements the chifra init command for the SDK.
+func (opts *initOptionsInternal) InitBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting init struct to URL values: %v", err)
+ }
+
+ return initPkg.Init(w, values)
+}
+
+// initParseFunc handles special cases such as structs and enums (if any).
+func initParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*initOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(init): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetInitOptions returns a filled-in options instance given a string array of arguments.
+func GetInitOptions(args []string) (*initOptionsInternal, error) {
+ var opts initOptionsInternal
+ if err := assignValuesFromArgs(args, initParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type initGeneric interface {
+ bool
+}
+
+func queryInit[T initGeneric](opts *initOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.InitBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *InitOptions) toInternal() *initOptionsInternal {
+ return &initOptionsInternal{
+ Publisher: opts.Publisher,
+ FirstBlock: opts.FirstBlock,
+ Sleep: opts.Sleep,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/list.go b/sdk/list.go
index d845b94390..0283db89ae 100644
--- a/sdk/list.go
+++ b/sdk/list.go
@@ -10,22 +10,16 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- list "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type ListOptions struct {
Addrs []string `json:"addrs,omitempty"`
- Count bool `json:"count,omitempty"`
NoZero bool `json:"noZero,omitempty"`
- Bounds bool `json:"bounds,omitempty"`
Unripe bool `json:"unripe,omitempty"`
Silent bool `json:"silent,omitempty"`
FirstRecord uint64 `json:"firstRecord,omitempty"`
@@ -43,74 +37,24 @@ func (opts *ListOptions) String() string {
return string(bytes)
}
-// ListBytes implements the chifra list command for the SDK.
-func (opts *ListOptions) ListBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting list struct to URL values: %v", err)
- }
-
- return list.List(w, values)
-}
-
-// listParseFunc handles special cases such as structs and enums (if any).
-func listParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*ListOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(list): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetListOptions returns a filled-in options instance given a string array of arguments.
-func GetListOptions(args []string) (*ListOptions, error) {
- var opts ListOptions
- if err := assignValuesFromArgs(args, listParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type listGeneric interface {
- types.Appearance |
- types.AppearanceCount |
- types.Bounds
-}
-
-func queryList[T listGeneric](opts *ListOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.ListBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// List implements the chifra list command.
func (opts *ListOptions) List() ([]types.Appearance, *types.MetaData, error) {
- return queryList[types.Appearance](opts)
+ in := opts.toInternal()
+ return queryList[types.Appearance](in)
}
// ListCount implements the chifra list --count command.
func (opts *ListOptions) ListCount() ([]types.AppearanceCount, *types.MetaData, error) {
- return queryList[types.AppearanceCount](opts)
+ in := opts.toInternal()
+ in.Count = true
+ return queryList[types.AppearanceCount](in)
}
// ListBounds implements the chifra list --bounds command.
func (opts *ListOptions) ListBounds() ([]types.Bounds, *types.MetaData, error) {
- return queryList[types.Bounds](opts)
+ in := opts.toInternal()
+ in.Bounds = true
+ return queryList[types.Bounds](in)
}
// No enums
diff --git a/sdk/list_internal.go b/sdk/list_internal.go
new file mode 100644
index 0000000000..0399994473
--- /dev/null
+++ b/sdk/list_internal.go
@@ -0,0 +1,119 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ list "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type listOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ Count bool `json:"count,omitempty"`
+ NoZero bool `json:"noZero,omitempty"`
+ Bounds bool `json:"bounds,omitempty"`
+ Unripe bool `json:"unripe,omitempty"`
+ Silent bool `json:"silent,omitempty"`
+ FirstRecord uint64 `json:"firstRecord,omitempty"`
+ MaxRecords uint64 `json:"maxRecords,omitempty"`
+ Reversed bool `json:"reversed,omitempty"`
+ Publisher base.Address `json:"publisher,omitempty"`
+ FirstBlock base.Blknum `json:"firstBlock,omitempty"`
+ LastBlock base.Blknum `json:"lastBlock,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *listOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// ListBytes implements the chifra list command for the SDK.
+func (opts *listOptionsInternal) ListBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting list struct to URL values: %v", err)
+ }
+
+ return list.List(w, values)
+}
+
+// listParseFunc handles special cases such as structs and enums (if any).
+func listParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*listOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(list): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetListOptions returns a filled-in options instance given a string array of arguments.
+func GetListOptions(args []string) (*listOptionsInternal, error) {
+ var opts listOptionsInternal
+ if err := assignValuesFromArgs(args, listParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type listGeneric interface {
+ types.Appearance |
+ types.AppearanceCount |
+ types.Bounds
+}
+
+func queryList[T listGeneric](opts *listOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.ListBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *ListOptions) toInternal() *listOptionsInternal {
+ return &listOptionsInternal{
+ Addrs: opts.Addrs,
+ NoZero: opts.NoZero,
+ Unripe: opts.Unripe,
+ Silent: opts.Silent,
+ FirstRecord: opts.FirstRecord,
+ MaxRecords: opts.MaxRecords,
+ Reversed: opts.Reversed,
+ Publisher: opts.Publisher,
+ FirstBlock: opts.FirstBlock,
+ LastBlock: opts.LastBlock,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/logs.go b/sdk/logs.go
index 0316b00d36..0033cd249c 100644
--- a/sdk/logs.go
+++ b/sdk/logs.go
@@ -10,13 +10,9 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- logs "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -34,62 +30,10 @@ func (opts *LogsOptions) String() string {
return string(bytes)
}
-// LogsBytes implements the chifra logs command for the SDK.
-func (opts *LogsOptions) LogsBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting logs struct to URL values: %v", err)
- }
-
- return logs.Logs(w, values)
-}
-
-// logsParseFunc handles special cases such as structs and enums (if any).
-func logsParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*LogsOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(logs): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetLogsOptions returns a filled-in options instance given a string array of arguments.
-func GetLogsOptions(args []string) (*LogsOptions, error) {
- var opts LogsOptions
- if err := assignValuesFromArgs(args, logsParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type logsGeneric interface {
- types.Log
-}
-
-func queryLogs[T logsGeneric](opts *LogsOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.LogsBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Logs implements the chifra logs command.
func (opts *LogsOptions) Logs() ([]types.Log, *types.MetaData, error) {
- return queryLogs[types.Log](opts)
+ in := opts.toInternal()
+ return queryLogs[types.Log](in)
}
// No enums
diff --git a/sdk/logs_internal.go b/sdk/logs_internal.go
new file mode 100644
index 0000000000..985f0b8ff4
--- /dev/null
+++ b/sdk/logs_internal.go
@@ -0,0 +1,102 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ logs "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type logsOptionsInternal struct {
+ TransactionIds []string `json:"transactions,omitempty"`
+ Emitter []string `json:"emitter,omitempty"`
+ Topic []string `json:"topic,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *logsOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// LogsBytes implements the chifra logs command for the SDK.
+func (opts *logsOptionsInternal) LogsBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting logs struct to URL values: %v", err)
+ }
+
+ return logs.Logs(w, values)
+}
+
+// logsParseFunc handles special cases such as structs and enums (if any).
+func logsParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*logsOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(logs): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetLogsOptions returns a filled-in options instance given a string array of arguments.
+func GetLogsOptions(args []string) (*logsOptionsInternal, error) {
+ var opts logsOptionsInternal
+ if err := assignValuesFromArgs(args, logsParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type logsGeneric interface {
+ types.Log
+}
+
+func queryLogs[T logsGeneric](opts *logsOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.LogsBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *LogsOptions) toInternal() *logsOptionsInternal {
+ return &logsOptionsInternal{
+ TransactionIds: opts.TransactionIds,
+ Emitter: opts.Emitter,
+ Topic: opts.Topic,
+ Articulate: opts.Articulate,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/meta.go b/sdk/meta.go
index 40393f580e..7a887ba3ec 100644
--- a/sdk/meta.go
+++ b/sdk/meta.go
@@ -5,8 +5,7 @@ import "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
func GetMetaData() (*types.MetaData, error) {
unused := BlocksOptions{
BlockIds: []string{"1"},
- Hashes: true,
}
- _, meta, err := unused.Blocks()
+ _, meta, err := unused.BlocksHashes()
return meta, err
}
diff --git a/sdk/monitors.go b/sdk/monitors.go
index ece3c21e9e..5bdee89bd4 100644
--- a/sdk/monitors.go
+++ b/sdk/monitors.go
@@ -10,13 +10,9 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- monitors "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -25,8 +21,6 @@ type MonitorsOptions struct {
Delete bool `json:"delete,omitempty"`
Undelete bool `json:"undelete,omitempty"`
Remove bool `json:"remove,omitempty"`
- Clean bool `json:"clean,omitempty"`
- List bool `json:"list,omitempty"`
Watch bool `json:"watch,omitempty"`
Watchlist string `json:"watchlist,omitempty"`
Commands string `json:"commands,omitempty"`
@@ -42,74 +36,24 @@ func (opts *MonitorsOptions) String() string {
return string(bytes)
}
-// MonitorsBytes implements the chifra monitors command for the SDK.
-func (opts *MonitorsOptions) MonitorsBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting monitors struct to URL values: %v", err)
- }
-
- return monitors.Monitors(w, values)
-}
-
-// monitorsParseFunc handles special cases such as structs and enums (if any).
-func monitorsParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*MonitorsOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(monitors): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetMonitorsOptions returns a filled-in options instance given a string array of arguments.
-func GetMonitorsOptions(args []string) (*MonitorsOptions, error) {
- var opts MonitorsOptions
- if err := assignValuesFromArgs(args, monitorsParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type monitorsGeneric interface {
- bool |
- types.MonitorClean |
- types.Monitor
-}
-
-func queryMonitors[T monitorsGeneric](opts *MonitorsOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.MonitorsBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Monitors implements the chifra monitors command.
func (opts *MonitorsOptions) Monitors() ([]bool, *types.MetaData, error) {
- return queryMonitors[bool](opts)
+ in := opts.toInternal()
+ return queryMonitors[bool](in)
}
// MonitorsClean implements the chifra monitors --clean command.
func (opts *MonitorsOptions) MonitorsClean() ([]types.MonitorClean, *types.MetaData, error) {
- return queryMonitors[types.MonitorClean](opts)
+ in := opts.toInternal()
+ in.Clean = true
+ return queryMonitors[types.MonitorClean](in)
}
// MonitorsList implements the chifra monitors --list command.
func (opts *MonitorsOptions) MonitorsList() ([]types.Monitor, *types.MetaData, error) {
- return queryMonitors[types.Monitor](opts)
+ in := opts.toInternal()
+ in.List = true
+ return queryMonitors[types.Monitor](in)
}
// No enums
diff --git a/sdk/monitors_internal.go b/sdk/monitors_internal.go
new file mode 100644
index 0000000000..f1727c13e4
--- /dev/null
+++ b/sdk/monitors_internal.go
@@ -0,0 +1,118 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ monitors "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type monitorsOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ Delete bool `json:"delete,omitempty"`
+ Undelete bool `json:"undelete,omitempty"`
+ Remove bool `json:"remove,omitempty"`
+ Clean bool `json:"clean,omitempty"`
+ List bool `json:"list,omitempty"`
+ Watch bool `json:"watch,omitempty"`
+ Watchlist string `json:"watchlist,omitempty"`
+ Commands string `json:"commands,omitempty"`
+ BatchSize uint64 `json:"batchSize,omitempty"`
+ RunCount uint64 `json:"runCount,omitempty"`
+ Sleep float64 `json:"sleep,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *monitorsOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// MonitorsBytes implements the chifra monitors command for the SDK.
+func (opts *monitorsOptionsInternal) MonitorsBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting monitors struct to URL values: %v", err)
+ }
+
+ return monitors.Monitors(w, values)
+}
+
+// monitorsParseFunc handles special cases such as structs and enums (if any).
+func monitorsParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*monitorsOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(monitors): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetMonitorsOptions returns a filled-in options instance given a string array of arguments.
+func GetMonitorsOptions(args []string) (*monitorsOptionsInternal, error) {
+ var opts monitorsOptionsInternal
+ if err := assignValuesFromArgs(args, monitorsParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type monitorsGeneric interface {
+ bool |
+ types.MonitorClean |
+ types.Monitor
+}
+
+func queryMonitors[T monitorsGeneric](opts *monitorsOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.MonitorsBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *MonitorsOptions) toInternal() *monitorsOptionsInternal {
+ return &monitorsOptionsInternal{
+ Addrs: opts.Addrs,
+ Delete: opts.Delete,
+ Undelete: opts.Undelete,
+ Remove: opts.Remove,
+ Watch: opts.Watch,
+ Watchlist: opts.Watchlist,
+ Commands: opts.Commands,
+ BatchSize: opts.BatchSize,
+ RunCount: opts.RunCount,
+ Sleep: opts.Sleep,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/names.go b/sdk/names.go
index 596242b42d..afefef0859 100644
--- a/sdk/names.go
+++ b/sdk/names.go
@@ -10,14 +10,10 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- names "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -28,8 +24,6 @@ type NamesOptions struct {
All bool `json:"all,omitempty"`
Custom bool `json:"custom,omitempty"`
Prefund bool `json:"prefund,omitempty"`
- Addr bool `json:"addr,omitempty"`
- Tags bool `json:"tags,omitempty"`
Clean bool `json:"clean,omitempty"`
Regular bool `json:"regular,omitempty"`
DryRun bool `json:"dryRun,omitempty"`
@@ -48,74 +42,24 @@ func (opts *NamesOptions) String() string {
return string(bytes)
}
-// NamesBytes implements the chifra names command for the SDK.
-func (opts *NamesOptions) NamesBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting names struct to URL values: %v", err)
- }
-
- return names.Names(w, values)
-}
-
-// namesParseFunc handles special cases such as structs and enums (if any).
-func namesParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*NamesOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(names): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetNamesOptions returns a filled-in options instance given a string array of arguments.
-func GetNamesOptions(args []string) (*NamesOptions, error) {
- var opts NamesOptions
- if err := assignValuesFromArgs(args, namesParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type namesGeneric interface {
- types.Name |
- base.Address |
- string
-}
-
-func queryNames[T namesGeneric](opts *NamesOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.NamesBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Names implements the chifra names command.
func (opts *NamesOptions) Names() ([]types.Name, *types.MetaData, error) {
- return queryNames[types.Name](opts)
+ in := opts.toInternal()
+ return queryNames[types.Name](in)
}
// NamesAddr implements the chifra names --addr command.
func (opts *NamesOptions) NamesAddr() ([]base.Address, *types.MetaData, error) {
- return queryNames[base.Address](opts)
+ in := opts.toInternal()
+ in.Addr = true
+ return queryNames[base.Address](in)
}
// NamesTags implements the chifra names --tags command.
func (opts *NamesOptions) NamesTags() ([]string, *types.MetaData, error) {
- return queryNames[string](opts)
+ in := opts.toInternal()
+ in.Tags = true
+ return queryNames[string](in)
}
// No enums
diff --git a/sdk/names_internal.go b/sdk/names_internal.go
new file mode 100644
index 0000000000..0340d47c21
--- /dev/null
+++ b/sdk/names_internal.go
@@ -0,0 +1,129 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ names "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type namesOptionsInternal struct {
+ Terms []string `json:"terms,omitempty"`
+ Expand bool `json:"expand,omitempty"`
+ MatchCase bool `json:"matchCase,omitempty"`
+ All bool `json:"all,omitempty"`
+ Custom bool `json:"custom,omitempty"`
+ Prefund bool `json:"prefund,omitempty"`
+ Addr bool `json:"addr,omitempty"`
+ Tags bool `json:"tags,omitempty"`
+ Clean bool `json:"clean,omitempty"`
+ Regular bool `json:"regular,omitempty"`
+ DryRun bool `json:"dryRun,omitempty"`
+ Autoname base.Address `json:"autoname,omitempty"`
+ Create bool `json:"create,omitempty"`
+ Update bool `json:"update,omitempty"`
+ Delete bool `json:"delete,omitempty"`
+ Undelete bool `json:"undelete,omitempty"`
+ Remove bool `json:"remove,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *namesOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// NamesBytes implements the chifra names command for the SDK.
+func (opts *namesOptionsInternal) NamesBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting names struct to URL values: %v", err)
+ }
+
+ return names.Names(w, values)
+}
+
+// namesParseFunc handles special cases such as structs and enums (if any).
+func namesParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*namesOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(names): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetNamesOptions returns a filled-in options instance given a string array of arguments.
+func GetNamesOptions(args []string) (*namesOptionsInternal, error) {
+ var opts namesOptionsInternal
+ if err := assignValuesFromArgs(args, namesParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type namesGeneric interface {
+ types.Name |
+ base.Address |
+ string
+}
+
+func queryNames[T namesGeneric](opts *namesOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.NamesBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *NamesOptions) toInternal() *namesOptionsInternal {
+ return &namesOptionsInternal{
+ Terms: opts.Terms,
+ Expand: opts.Expand,
+ MatchCase: opts.MatchCase,
+ All: opts.All,
+ Custom: opts.Custom,
+ Prefund: opts.Prefund,
+ Clean: opts.Clean,
+ Regular: opts.Regular,
+ DryRun: opts.DryRun,
+ Autoname: opts.Autoname,
+ Create: opts.Create,
+ Update: opts.Update,
+ Delete: opts.Delete,
+ Undelete: opts.Undelete,
+ Remove: opts.Remove,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/receipts.go b/sdk/receipts.go
index 571ea33400..fb9198ac21 100644
--- a/sdk/receipts.go
+++ b/sdk/receipts.go
@@ -10,13 +10,9 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- receipts "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -32,62 +28,10 @@ func (opts *ReceiptsOptions) String() string {
return string(bytes)
}
-// ReceiptsBytes implements the chifra receipts command for the SDK.
-func (opts *ReceiptsOptions) ReceiptsBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting receipts struct to URL values: %v", err)
- }
-
- return receipts.Receipts(w, values)
-}
-
-// receiptsParseFunc handles special cases such as structs and enums (if any).
-func receiptsParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*ReceiptsOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(receipts): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetReceiptsOptions returns a filled-in options instance given a string array of arguments.
-func GetReceiptsOptions(args []string) (*ReceiptsOptions, error) {
- var opts ReceiptsOptions
- if err := assignValuesFromArgs(args, receiptsParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type receiptsGeneric interface {
- types.Receipt
-}
-
-func queryReceipts[T receiptsGeneric](opts *ReceiptsOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.ReceiptsBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Receipts implements the chifra receipts command.
func (opts *ReceiptsOptions) Receipts() ([]types.Receipt, *types.MetaData, error) {
- return queryReceipts[types.Receipt](opts)
+ in := opts.toInternal()
+ return queryReceipts[types.Receipt](in)
}
// No enums
diff --git a/sdk/receipts_internal.go b/sdk/receipts_internal.go
new file mode 100644
index 0000000000..ec841b1a38
--- /dev/null
+++ b/sdk/receipts_internal.go
@@ -0,0 +1,98 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ receipts "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type receiptsOptionsInternal struct {
+ TransactionIds []string `json:"transactions,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *receiptsOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// ReceiptsBytes implements the chifra receipts command for the SDK.
+func (opts *receiptsOptionsInternal) ReceiptsBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting receipts struct to URL values: %v", err)
+ }
+
+ return receipts.Receipts(w, values)
+}
+
+// receiptsParseFunc handles special cases such as structs and enums (if any).
+func receiptsParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*receiptsOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(receipts): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetReceiptsOptions returns a filled-in options instance given a string array of arguments.
+func GetReceiptsOptions(args []string) (*receiptsOptionsInternal, error) {
+ var opts receiptsOptionsInternal
+ if err := assignValuesFromArgs(args, receiptsParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type receiptsGeneric interface {
+ types.Receipt
+}
+
+func queryReceipts[T receiptsGeneric](opts *receiptsOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.ReceiptsBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *ReceiptsOptions) toInternal() *receiptsOptionsInternal {
+ return &receiptsOptionsInternal{
+ TransactionIds: opts.TransactionIds,
+ Articulate: opts.Articulate,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/slurp.go b/sdk/slurp.go
index 2c44814a16..b6479f66ba 100644
--- a/sdk/slurp.go
+++ b/sdk/slurp.go
@@ -10,28 +10,23 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- slurp "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type SlurpOptions struct {
- Addrs []string `json:"addrs,omitempty"`
- BlockIds []string `json:"blocks,omitempty"`
- Types SlurpTypes `json:"types,omitempty"`
- Appearances bool `json:"appearances,omitempty"`
- Articulate bool `json:"articulate,omitempty"`
- Source SlurpSource `json:"source,omitempty"`
- Count bool `json:"count,omitempty"`
- Page uint64 `json:"page,omitempty"`
- PerPage uint64 `json:"perPage,omitempty"`
- Sleep float64 `json:"sleep,omitempty"`
+ Addrs []string `json:"addrs,omitempty"`
+ BlockIds []string `json:"blocks,omitempty"`
+ Types SlurpTypes `json:"types,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ Source SlurpSource `json:"source,omitempty"`
+ Page uint64 `json:"page,omitempty"`
+ PerPage uint64 `json:"perPage,omitempty"`
+ Sleep float64 `json:"sleep,omitempty"`
Globals
}
@@ -41,92 +36,24 @@ func (opts *SlurpOptions) String() string {
return string(bytes)
}
-// SlurpBytes implements the chifra slurp command for the SDK.
-func (opts *SlurpOptions) SlurpBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting slurp struct to URL values: %v", err)
- }
-
- return slurp.Slurp(w, values)
-}
-
-// slurpParseFunc handles special cases such as structs and enums (if any).
-func slurpParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*SlurpOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(slurp): target is not of correct type")
- }
-
- if key == "types" {
- var err error
- values := strings.Split(value, ",")
- if opts.Types, err = enumFromSlurpTypes(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
- if key == "source" {
- var err error
- values := strings.Split(value, ",")
- if opts.Source, err = enumFromSlurpSource(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetSlurpOptions returns a filled-in options instance given a string array of arguments.
-func GetSlurpOptions(args []string) (*SlurpOptions, error) {
- var opts SlurpOptions
- if err := assignValuesFromArgs(args, slurpParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type slurpGeneric interface {
- types.Slurp |
- types.Appearance |
- types.SlurpCount
-}
-
-func querySlurp[T slurpGeneric](opts *SlurpOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.SlurpBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Slurp implements the chifra slurp command.
func (opts *SlurpOptions) Slurp() ([]types.Slurp, *types.MetaData, error) {
- return querySlurp[types.Slurp](opts)
+ in := opts.toInternal()
+ return querySlurp[types.Slurp](in)
}
// SlurpAppearances implements the chifra slurp --appearances command.
func (opts *SlurpOptions) SlurpAppearances() ([]types.Appearance, *types.MetaData, error) {
- return querySlurp[types.Appearance](opts)
+ in := opts.toInternal()
+ in.Appearances = true
+ return querySlurp[types.Appearance](in)
}
// SlurpCount implements the chifra slurp --count command.
func (opts *SlurpOptions) SlurpCount() ([]types.SlurpCount, *types.MetaData, error) {
- return querySlurp[types.SlurpCount](opts)
+ in := opts.toInternal()
+ in.Count = true
+ return querySlurp[types.SlurpCount](in)
}
type SlurpTypes int
diff --git a/sdk/slurp_internal.go b/sdk/slurp_internal.go
new file mode 100644
index 0000000000..5dc194fe41
--- /dev/null
+++ b/sdk/slurp_internal.go
@@ -0,0 +1,133 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ slurp "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type slurpOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ BlockIds []string `json:"blocks,omitempty"`
+ Types SlurpTypes `json:"types,omitempty"`
+ Appearances bool `json:"appearances,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ Source SlurpSource `json:"source,omitempty"`
+ Count bool `json:"count,omitempty"`
+ Page uint64 `json:"page,omitempty"`
+ PerPage uint64 `json:"perPage,omitempty"`
+ Sleep float64 `json:"sleep,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *slurpOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// SlurpBytes implements the chifra slurp command for the SDK.
+func (opts *slurpOptionsInternal) SlurpBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting slurp struct to URL values: %v", err)
+ }
+
+ return slurp.Slurp(w, values)
+}
+
+// slurpParseFunc handles special cases such as structs and enums (if any).
+func slurpParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*slurpOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(slurp): target is not of correct type")
+ }
+
+ if key == "types" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Types, err = enumFromSlurpTypes(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+ if key == "source" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Source, err = enumFromSlurpSource(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetSlurpOptions returns a filled-in options instance given a string array of arguments.
+func GetSlurpOptions(args []string) (*slurpOptionsInternal, error) {
+ var opts slurpOptionsInternal
+ if err := assignValuesFromArgs(args, slurpParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type slurpGeneric interface {
+ types.Slurp |
+ types.Appearance |
+ types.SlurpCount
+}
+
+func querySlurp[T slurpGeneric](opts *slurpOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.SlurpBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *SlurpOptions) toInternal() *slurpOptionsInternal {
+ return &slurpOptionsInternal{
+ Addrs: opts.Addrs,
+ BlockIds: opts.BlockIds,
+ Types: opts.Types,
+ Articulate: opts.Articulate,
+ Source: opts.Source,
+ Page: opts.Page,
+ PerPage: opts.PerPage,
+ Sleep: opts.Sleep,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/state.go b/sdk/state.go
index ef0f4ad899..4dd0d79165 100644
--- a/sdk/state.go
+++ b/sdk/state.go
@@ -10,15 +10,12 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- state "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -28,7 +25,6 @@ type StateOptions struct {
Parts StateParts `json:"parts,omitempty"`
Changes bool `json:"changes,omitempty"`
NoZero bool `json:"noZero,omitempty"`
- Call string `json:"call,omitempty"`
Articulate bool `json:"articulate,omitempty"`
ProxyFor base.Address `json:"proxyFor,omitempty"`
Globals
@@ -40,81 +36,17 @@ func (opts *StateOptions) String() string {
return string(bytes)
}
-// StateBytes implements the chifra state command for the SDK.
-func (opts *StateOptions) StateBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting state struct to URL values: %v", err)
- }
-
- return state.State(w, values)
-}
-
-// stateParseFunc handles special cases such as structs and enums (if any).
-func stateParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*StateOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(state): target is not of correct type")
- }
-
- if key == "parts" {
- var err error
- values := strings.Split(value, ",")
- if opts.Parts, err = enumFromStateParts(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- if key == "proxyFor" {
- opts.ProxyFor = base.HexToAddress(value)
- return base.IsValidAddress(value), nil
- }
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetStateOptions returns a filled-in options instance given a string array of arguments.
-func GetStateOptions(args []string) (*StateOptions, error) {
- var opts StateOptions
- if err := assignValuesFromArgs(args, stateParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type stateGeneric interface {
- types.State |
- types.Result
-}
-
-func queryState[T stateGeneric](opts *StateOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.StateBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// State implements the chifra state command.
func (opts *StateOptions) State() ([]types.State, *types.MetaData, error) {
- return queryState[types.State](opts)
+ in := opts.toInternal()
+ return queryState[types.State](in)
}
// StateCall implements the chifra state --call command.
-func (opts *StateOptions) StateCall() ([]types.Result, *types.MetaData, error) {
- return queryState[types.Result](opts)
+func (opts *StateOptions) StateCall(val string) ([]types.Result, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Call = val
+ return queryState[types.Result](in)
}
type StateParts int
diff --git a/sdk/state_internal.go b/sdk/state_internal.go
new file mode 100644
index 0000000000..2a258f8317
--- /dev/null
+++ b/sdk/state_internal.go
@@ -0,0 +1,125 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ state "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type stateOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ BlockIds []string `json:"blocks,omitempty"`
+ Parts StateParts `json:"parts,omitempty"`
+ Changes bool `json:"changes,omitempty"`
+ NoZero bool `json:"noZero,omitempty"`
+ Call string `json:"call,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ ProxyFor base.Address `json:"proxyFor,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *stateOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// StateBytes implements the chifra state command for the SDK.
+func (opts *stateOptionsInternal) StateBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting state struct to URL values: %v", err)
+ }
+
+ return state.State(w, values)
+}
+
+// stateParseFunc handles special cases such as structs and enums (if any).
+func stateParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*stateOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(state): target is not of correct type")
+ }
+
+ if key == "parts" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Parts, err = enumFromStateParts(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ if key == "proxyFor" {
+ opts.ProxyFor = base.HexToAddress(value)
+ return base.IsValidAddress(value), nil
+ }
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetStateOptions returns a filled-in options instance given a string array of arguments.
+func GetStateOptions(args []string) (*stateOptionsInternal, error) {
+ var opts stateOptionsInternal
+ if err := assignValuesFromArgs(args, stateParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type stateGeneric interface {
+ types.State |
+ types.Result
+}
+
+func queryState[T stateGeneric](opts *stateOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.StateBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *StateOptions) toInternal() *stateOptionsInternal {
+ return &stateOptionsInternal{
+ Addrs: opts.Addrs,
+ BlockIds: opts.BlockIds,
+ Parts: opts.Parts,
+ Changes: opts.Changes,
+ NoZero: opts.NoZero,
+ Articulate: opts.Articulate,
+ ProxyFor: opts.ProxyFor,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/status.go b/sdk/status.go
index 4ff30f5102..53513b369e 100644
--- a/sdk/status.go
+++ b/sdk/status.go
@@ -10,23 +10,18 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- status "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type StatusOptions struct {
- Modes StatusModes `json:"modes,omitempty"`
- Diagnose bool `json:"diagnose,omitempty"`
- FirstRecord uint64 `json:"firstRecord,omitempty"`
- MaxRecords uint64 `json:"maxRecords,omitempty"`
- Chains bool `json:"chains,omitempty"`
+ FirstRecord uint64 `json:"firstRecord,omitempty"`
+ MaxRecords uint64 `json:"maxRecords,omitempty"`
+ Chains bool `json:"chains,omitempty"`
Globals
}
@@ -36,65 +31,144 @@ func (opts *StatusOptions) String() string {
return string(bytes)
}
-// StatusBytes implements the chifra status command for the SDK.
-func (opts *StatusOptions) StatusBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting status struct to URL values: %v", err)
- }
+// StatusIndex implements the chifra status index command.
+func (opts *StatusOptions) StatusIndex() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMIndex
+ return queryStatus[types.Status](in)
+}
- return status.Status(w, values)
+// StatusBlooms implements the chifra status blooms command.
+func (opts *StatusOptions) StatusBlooms() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMBlooms
+ return queryStatus[types.Status](in)
}
-// statusParseFunc handles special cases such as structs and enums (if any).
-func statusParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*StatusOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(status): target is not of correct type")
- }
+// StatusBlocks implements the chifra status blocks command.
+func (opts *StatusOptions) StatusBlocks() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMBlocks
+ return queryStatus[types.Status](in)
+}
- if key == "modes" {
- var err error
- values := strings.Split(value, ",")
- if opts.Modes, err = enumFromStatusModes(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
+// StatusTransactions implements the chifra status transactions command.
+func (opts *StatusOptions) StatusTransactions() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMTransactions
+ return queryStatus[types.Status](in)
+}
- // EXISTING_CODE
- // EXISTING_CODE
+// StatusTraces implements the chifra status traces command.
+func (opts *StatusOptions) StatusTraces() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMTraces
+ return queryStatus[types.Status](in)
+}
- return found, nil
+// StatusLogs implements the chifra status logs command.
+func (opts *StatusOptions) StatusLogs() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMLogs
+ return queryStatus[types.Status](in)
}
-// GetStatusOptions returns a filled-in options instance given a string array of arguments.
-func GetStatusOptions(args []string) (*StatusOptions, error) {
- var opts StatusOptions
- if err := assignValuesFromArgs(args, statusParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
+// StatusStatements implements the chifra status statements command.
+func (opts *StatusOptions) StatusStatements() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMStatements
+ return queryStatus[types.Status](in)
+}
- return &opts, nil
+// StatusResults implements the chifra status results command.
+func (opts *StatusOptions) StatusResults() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMResults
+ return queryStatus[types.Status](in)
}
-type statusGeneric interface {
+// StatusState implements the chifra status state command.
+func (opts *StatusOptions) StatusState() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMState
+ return queryStatus[types.Status](in)
}
-func queryStatus[T statusGeneric](opts *StatusOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.StatusBytes(&buffer); err != nil {
- return nil, nil, err
- }
+// StatusTokens implements the chifra status tokens command.
+func (opts *StatusOptions) StatusTokens() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMTokens
+ return queryStatus[types.Status](in)
+}
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
+// StatusMonitors implements the chifra status monitors command.
+func (opts *StatusOptions) StatusMonitors() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMMonitors
+ return queryStatus[types.Status](in)
+}
+
+// StatusNames implements the chifra status names command.
+func (opts *StatusOptions) StatusNames() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMNames
+ return queryStatus[types.Status](in)
+}
+
+// StatusAbis implements the chifra status abis command.
+func (opts *StatusOptions) StatusAbis() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMAbis
+ return queryStatus[types.Status](in)
+}
+
+// StatusSlurps implements the chifra status slurps command.
+func (opts *StatusOptions) StatusSlurps() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMSlurps
+ return queryStatus[types.Status](in)
+}
+
+// StatusStaging implements the chifra status staging command.
+func (opts *StatusOptions) StatusStaging() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMStaging
+ return queryStatus[types.Status](in)
+}
+
+// StatusUnripe implements the chifra status unripe command.
+func (opts *StatusOptions) StatusUnripe() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMUnripe
+ return queryStatus[types.Status](in)
+}
+
+// StatusMaps implements the chifra status maps command.
+func (opts *StatusOptions) StatusMaps() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMMaps
+ return queryStatus[types.Status](in)
+}
+
+// StatusSome implements the chifra status some command.
+func (opts *StatusOptions) StatusSome() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMSome
+ return queryStatus[types.Status](in)
+}
+
+// StatusAll implements the chifra status all command.
+func (opts *StatusOptions) StatusAll() ([]types.Status, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Modes = SMAll
+ return queryStatus[types.Status](in)
+}
+
+// StatusDiagnose implements the chifra status --diagnose command.
+func (opts *StatusOptions) StatusDiagnose() ([]bool, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Diagnose = true
+ return queryStatus[bool](in)
}
type StatusModes int
diff --git a/sdk/status_internal.go b/sdk/status_internal.go
new file mode 100644
index 0000000000..6da97f4c03
--- /dev/null
+++ b/sdk/status_internal.go
@@ -0,0 +1,114 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ status "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type statusOptionsInternal struct {
+ Modes StatusModes `json:"modes,omitempty"`
+ Diagnose bool `json:"diagnose,omitempty"`
+ FirstRecord uint64 `json:"firstRecord,omitempty"`
+ MaxRecords uint64 `json:"maxRecords,omitempty"`
+ Chains bool `json:"chains,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *statusOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// StatusBytes implements the chifra status command for the SDK.
+func (opts *statusOptionsInternal) StatusBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting status struct to URL values: %v", err)
+ }
+
+ return status.Status(w, values)
+}
+
+// statusParseFunc handles special cases such as structs and enums (if any).
+func statusParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*statusOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(status): target is not of correct type")
+ }
+
+ if key == "modes" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Modes, err = enumFromStatusModes(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetStatusOptions returns a filled-in options instance given a string array of arguments.
+func GetStatusOptions(args []string) (*statusOptionsInternal, error) {
+ var opts statusOptionsInternal
+ if err := assignValuesFromArgs(args, statusParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type statusGeneric interface {
+ types.Status |
+ bool
+}
+
+func queryStatus[T statusGeneric](opts *statusOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.StatusBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *StatusOptions) toInternal() *statusOptionsInternal {
+ return &statusOptionsInternal{
+ FirstRecord: opts.FirstRecord,
+ MaxRecords: opts.MaxRecords,
+ Chains: opts.Chains,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/tokens.go b/sdk/tokens.go
index bd7176ed6d..19e5fd5744 100644
--- a/sdk/tokens.go
+++ b/sdk/tokens.go
@@ -10,14 +10,11 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- tokens "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -37,71 +34,10 @@ func (opts *TokensOptions) String() string {
return string(bytes)
}
-// TokensBytes implements the chifra tokens command for the SDK.
-func (opts *TokensOptions) TokensBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting tokens struct to URL values: %v", err)
- }
-
- return tokens.Tokens(w, values)
-}
-
-// tokensParseFunc handles special cases such as structs and enums (if any).
-func tokensParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*TokensOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(tokens): target is not of correct type")
- }
-
- if key == "parts" {
- var err error
- values := strings.Split(value, ",")
- if opts.Parts, err = enumFromTokensParts(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetTokensOptions returns a filled-in options instance given a string array of arguments.
-func GetTokensOptions(args []string) (*TokensOptions, error) {
- var opts TokensOptions
- if err := assignValuesFromArgs(args, tokensParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type tokensGeneric interface {
- types.Token
-}
-
-func queryTokens[T tokensGeneric](opts *TokensOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.TokensBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Tokens implements the chifra tokens command.
func (opts *TokensOptions) Tokens() ([]types.Token, *types.MetaData, error) {
- return queryTokens[types.Token](opts)
+ in := opts.toInternal()
+ return queryTokens[types.Token](in)
}
type TokensParts int
diff --git a/sdk/tokens_internal.go b/sdk/tokens_internal.go
new file mode 100644
index 0000000000..ec9a751d34
--- /dev/null
+++ b/sdk/tokens_internal.go
@@ -0,0 +1,116 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ tokens "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type tokensOptionsInternal struct {
+ Addrs []string `json:"addrs,omitempty"`
+ BlockIds []string `json:"blocks,omitempty"`
+ Parts TokensParts `json:"parts,omitempty"`
+ ByAcct bool `json:"byAcct,omitempty"`
+ Changes bool `json:"changes,omitempty"`
+ NoZero bool `json:"noZero,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *tokensOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// TokensBytes implements the chifra tokens command for the SDK.
+func (opts *tokensOptionsInternal) TokensBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting tokens struct to URL values: %v", err)
+ }
+
+ return tokens.Tokens(w, values)
+}
+
+// tokensParseFunc handles special cases such as structs and enums (if any).
+func tokensParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*tokensOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(tokens): target is not of correct type")
+ }
+
+ if key == "parts" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Parts, err = enumFromTokensParts(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetTokensOptions returns a filled-in options instance given a string array of arguments.
+func GetTokensOptions(args []string) (*tokensOptionsInternal, error) {
+ var opts tokensOptionsInternal
+ if err := assignValuesFromArgs(args, tokensParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type tokensGeneric interface {
+ types.Token
+}
+
+func queryTokens[T tokensGeneric](opts *tokensOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.TokensBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *TokensOptions) toInternal() *tokensOptionsInternal {
+ return &tokensOptionsInternal{
+ Addrs: opts.Addrs,
+ BlockIds: opts.BlockIds,
+ Parts: opts.Parts,
+ ByAcct: opts.ByAcct,
+ Changes: opts.Changes,
+ NoZero: opts.NoZero,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/traces.go b/sdk/traces.go
index 4d165adb48..fe8e23bc68 100644
--- a/sdk/traces.go
+++ b/sdk/traces.go
@@ -10,13 +10,9 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- traces "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
@@ -24,7 +20,6 @@ type TracesOptions struct {
TransactionIds []string `json:"transactions,omitempty"`
Articulate bool `json:"articulate,omitempty"`
Filter string `json:"filter,omitempty"`
- Count bool `json:"count,omitempty"`
Globals
}
@@ -34,68 +29,17 @@ func (opts *TracesOptions) String() string {
return string(bytes)
}
-// TracesBytes implements the chifra traces command for the SDK.
-func (opts *TracesOptions) TracesBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting traces struct to URL values: %v", err)
- }
-
- return traces.Traces(w, values)
-}
-
-// tracesParseFunc handles special cases such as structs and enums (if any).
-func tracesParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*TracesOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(traces): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetTracesOptions returns a filled-in options instance given a string array of arguments.
-func GetTracesOptions(args []string) (*TracesOptions, error) {
- var opts TracesOptions
- if err := assignValuesFromArgs(args, tracesParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type tracesGeneric interface {
- types.Trace |
- types.TraceCount
-}
-
-func queryTraces[T tracesGeneric](opts *TracesOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.TracesBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Traces implements the chifra traces command.
func (opts *TracesOptions) Traces() ([]types.Trace, *types.MetaData, error) {
- return queryTraces[types.Trace](opts)
+ in := opts.toInternal()
+ return queryTraces[types.Trace](in)
}
// TracesCount implements the chifra traces --count command.
func (opts *TracesOptions) TracesCount() ([]types.TraceCount, *types.MetaData, error) {
- return queryTraces[types.TraceCount](opts)
+ in := opts.toInternal()
+ in.Count = true
+ return queryTraces[types.TraceCount](in)
}
// No enums
diff --git a/sdk/traces_internal.go b/sdk/traces_internal.go
new file mode 100644
index 0000000000..68dcb3fb27
--- /dev/null
+++ b/sdk/traces_internal.go
@@ -0,0 +1,102 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ traces "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type tracesOptionsInternal struct {
+ TransactionIds []string `json:"transactions,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ Filter string `json:"filter,omitempty"`
+ Count bool `json:"count,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *tracesOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// TracesBytes implements the chifra traces command for the SDK.
+func (opts *tracesOptionsInternal) TracesBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting traces struct to URL values: %v", err)
+ }
+
+ return traces.Traces(w, values)
+}
+
+// tracesParseFunc handles special cases such as structs and enums (if any).
+func tracesParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*tracesOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(traces): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetTracesOptions returns a filled-in options instance given a string array of arguments.
+func GetTracesOptions(args []string) (*tracesOptionsInternal, error) {
+ var opts tracesOptionsInternal
+ if err := assignValuesFromArgs(args, tracesParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type tracesGeneric interface {
+ types.Trace |
+ types.TraceCount
+}
+
+func queryTraces[T tracesGeneric](opts *tracesOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.TracesBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *TracesOptions) toInternal() *tracesOptionsInternal {
+ return &tracesOptionsInternal{
+ TransactionIds: opts.TransactionIds,
+ Articulate: opts.Articulate,
+ Filter: opts.Filter,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/transactions.go b/sdk/transactions.go
index 1a3dff204c..d01814153c 100644
--- a/sdk/transactions.go
+++ b/sdk/transactions.go
@@ -10,28 +10,21 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
"fmt"
- "io"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- transactions "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type TransactionsOptions struct {
TransactionIds []string `json:"transactions,omitempty"`
Articulate bool `json:"articulate,omitempty"`
- Traces bool `json:"traces,omitempty"`
- Uniq bool `json:"uniq,omitempty"`
Flow TransactionsFlow `json:"flow,omitempty"`
- Logs bool `json:"logs,omitempty"`
Emitter []string `json:"emitter,omitempty"`
Topic []string `json:"topic,omitempty"`
CacheTraces bool `json:"cacheTraces,omitempty"`
- Seed bool `json:"seed,omitempty"`
Globals
}
@@ -41,89 +34,38 @@ func (opts *TransactionsOptions) String() string {
return string(bytes)
}
-// TransactionsBytes implements the chifra transactions command for the SDK.
-func (opts *TransactionsOptions) TransactionsBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting transactions struct to URL values: %v", err)
- }
-
- return transactions.Transactions(w, values)
-}
-
-// transactionsParseFunc handles special cases such as structs and enums (if any).
-func transactionsParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- opts, ok := target.(*TransactionsOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(transactions): target is not of correct type")
- }
-
- if key == "flow" {
- var err error
- values := strings.Split(value, ",")
- if opts.Flow, err = enumFromTransactionsFlow(values); err != nil {
- return false, err
- } else {
- found = true
- }
- }
-
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetTransactionsOptions returns a filled-in options instance given a string array of arguments.
-func GetTransactionsOptions(args []string) (*TransactionsOptions, error) {
- var opts TransactionsOptions
- if err := assignValuesFromArgs(args, transactionsParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type transactionsGeneric interface {
- types.Transaction |
- types.Trace |
- types.Appearance |
- types.Log
-}
-
-func queryTransactions[T transactionsGeneric](opts *TransactionsOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.TransactionsBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// Transactions implements the chifra transactions command.
func (opts *TransactionsOptions) Transactions() ([]types.Transaction, *types.MetaData, error) {
- return queryTransactions[types.Transaction](opts)
+ in := opts.toInternal()
+ return queryTransactions[types.Transaction](in)
}
// TransactionsTraces implements the chifra transactions --traces command.
func (opts *TransactionsOptions) TransactionsTraces() ([]types.Trace, *types.MetaData, error) {
- return queryTransactions[types.Trace](opts)
+ in := opts.toInternal()
+ in.Traces = true
+ return queryTransactions[types.Trace](in)
}
// TransactionsUniq implements the chifra transactions --uniq command.
func (opts *TransactionsOptions) TransactionsUniq() ([]types.Appearance, *types.MetaData, error) {
- return queryTransactions[types.Appearance](opts)
+ in := opts.toInternal()
+ in.Uniq = true
+ return queryTransactions[types.Appearance](in)
}
// TransactionsLogs implements the chifra transactions --logs command.
func (opts *TransactionsOptions) TransactionsLogs() ([]types.Log, *types.MetaData, error) {
- return queryTransactions[types.Log](opts)
+ in := opts.toInternal()
+ in.Logs = true
+ return queryTransactions[types.Log](in)
+}
+
+// TransactionsSeed implements the chifra transactions --seed command.
+func (opts *TransactionsOptions) TransactionsSeed() ([]bool, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.Seed = true
+ return queryTransactions[bool](in)
}
type TransactionsFlow int
diff --git a/sdk/transactions_internal.go b/sdk/transactions_internal.go
new file mode 100644
index 0000000000..1d700c67be
--- /dev/null
+++ b/sdk/transactions_internal.go
@@ -0,0 +1,124 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ transactions "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type transactionsOptionsInternal struct {
+ TransactionIds []string `json:"transactions,omitempty"`
+ Articulate bool `json:"articulate,omitempty"`
+ Traces bool `json:"traces,omitempty"`
+ Uniq bool `json:"uniq,omitempty"`
+ Flow TransactionsFlow `json:"flow,omitempty"`
+ Logs bool `json:"logs,omitempty"`
+ Emitter []string `json:"emitter,omitempty"`
+ Topic []string `json:"topic,omitempty"`
+ CacheTraces bool `json:"cacheTraces,omitempty"`
+ Seed bool `json:"seed,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *transactionsOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// TransactionsBytes implements the chifra transactions command for the SDK.
+func (opts *transactionsOptionsInternal) TransactionsBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting transactions struct to URL values: %v", err)
+ }
+
+ return transactions.Transactions(w, values)
+}
+
+// transactionsParseFunc handles special cases such as structs and enums (if any).
+func transactionsParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ opts, ok := target.(*transactionsOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(transactions): target is not of correct type")
+ }
+
+ if key == "flow" {
+ var err error
+ values := strings.Split(value, ",")
+ if opts.Flow, err = enumFromTransactionsFlow(values); err != nil {
+ return false, err
+ } else {
+ found = true
+ }
+ }
+
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetTransactionsOptions returns a filled-in options instance given a string array of arguments.
+func GetTransactionsOptions(args []string) (*transactionsOptionsInternal, error) {
+ var opts transactionsOptionsInternal
+ if err := assignValuesFromArgs(args, transactionsParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type transactionsGeneric interface {
+ types.Transaction |
+ types.Trace |
+ types.Appearance |
+ types.Log |
+ bool
+}
+
+func queryTransactions[T transactionsGeneric](opts *transactionsOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.TransactionsBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *TransactionsOptions) toInternal() *transactionsOptionsInternal {
+ return &transactionsOptionsInternal{
+ TransactionIds: opts.TransactionIds,
+ Articulate: opts.Articulate,
+ Flow: opts.Flow,
+ Emitter: opts.Emitter,
+ Topic: opts.Topic,
+ CacheTraces: opts.CacheTraces,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/sdk/typescript/src/paths/chunks.ts b/sdk/typescript/src/paths/chunks.ts
index 9e39855eb8..9b26d305d8 100644
--- a/sdk/typescript/src/paths/chunks.ts
+++ b/sdk/typescript/src/paths/chunks.ts
@@ -7,7 +7,7 @@
* This file was auto generated. DO NOT EDIT.
*/
import * as ApiCallers from '../lib/api_callers';
-import { address, Appearance, blknum, ChunkAddress, ChunkBloom, ChunkIndex, ChunkPinReport, ChunkRecord, ChunkStats, double, IpfsPin, Manifest, ReportCheck } from '../types';
+import { address, Appearance, blknum, ChunkAddress, ChunkBloom, ChunkIndex, ChunkPin, ChunkRecord, ChunkStats, double, IpfsPin, Manifest, ReportCheck } from '../types';
export function getChunks(
parameters?: {
@@ -31,7 +31,7 @@ export function getChunks(
},
options?: RequestInit,
) {
- return ApiCallers.fetch(
+ return ApiCallers.fetch(
{ endpoint: '/chunks', method: 'get', parameters, options },
);
}
diff --git a/sdk/typescript/src/types/chunkPinReport.ts b/sdk/typescript/src/types/chunkPin.ts
similarity index 90%
rename from sdk/typescript/src/types/chunkPinReport.ts
rename to sdk/typescript/src/types/chunkPin.ts
index cee437c38f..e0d78cb799 100644
--- a/sdk/typescript/src/types/chunkPinReport.ts
+++ b/sdk/typescript/src/types/chunkPin.ts
@@ -5,11 +5,10 @@
*/
import { ipfshash } from '.';
-export type ChunkPinReport = {
+export type ChunkPin = {
version: string
chain: string
timestampHash: ipfshash
manifestHash: ipfshash
specHash: ipfshash
}
-
diff --git a/sdk/typescript/src/types/index.ts b/sdk/typescript/src/types/index.ts
index 7f334f7185..a35806dc6f 100644
--- a/sdk/typescript/src/types/index.ts
+++ b/sdk/typescript/src/types/index.ts
@@ -10,7 +10,7 @@ export * from './chain';
export * from './chunkAddress';
export * from './chunkBloom';
export * from './chunkIndex';
-export * from './chunkPinReport';
+export * from './chunkPin';
export * from './chunkRecord';
export * from './chunkStats';
export * from './config';
@@ -41,4 +41,3 @@ export * from './traceResult';
export * from './transaction';
export * from './withdrawal';
export * from './upgrades';
-
diff --git a/sdk/when.go b/sdk/when.go
index 684b90f635..f5b6090890 100644
--- a/sdk/when.go
+++ b/sdk/when.go
@@ -10,27 +10,20 @@ package sdk
import (
// EXISTING_CODE
- "bytes"
"encoding/json"
- "fmt"
- "io"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
- when "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)
type WhenOptions struct {
- BlockIds []string `json:"blocks,omitempty"`
- List bool `json:"list,omitempty"`
- Timestamps bool `json:"timestamps,omitempty"`
- Count bool `json:"count,omitempty"`
- Truncate base.Blknum `json:"truncate,omitempty"`
- Repair bool `json:"repair,omitempty"`
- Check bool `json:"check,omitempty"`
- Update bool `json:"update,omitempty"`
- Deep bool `json:"deep,omitempty"`
+ BlockIds []string `json:"blocks,omitempty"`
+ Truncate base.Blknum `json:"truncate,omitempty"`
+ Repair bool `json:"repair,omitempty"`
+ Check bool `json:"check,omitempty"`
+ Update bool `json:"update,omitempty"`
+ Deep bool `json:"deep,omitempty"`
Globals
}
@@ -40,79 +33,31 @@ func (opts *WhenOptions) String() string {
return string(bytes)
}
-// WhenBytes implements the chifra when command for the SDK.
-func (opts *WhenOptions) WhenBytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting when struct to URL values: %v", err)
- }
-
- return when.When(w, values)
-}
-
-// whenParseFunc handles special cases such as structs and enums (if any).
-func whenParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- _, ok := target.(*WhenOptions)
- if !ok {
- return false, fmt.Errorf("parseFunc(when): target is not of correct type")
- }
-
- // No enums
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// GetWhenOptions returns a filled-in options instance given a string array of arguments.
-func GetWhenOptions(args []string) (*WhenOptions, error) {
- var opts WhenOptions
- if err := assignValuesFromArgs(args, whenParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type whenGeneric interface {
- types.NamedBlock |
- types.Timestamp |
- types.TimestampCount
-}
-
-func queryWhen[T whenGeneric](opts *WhenOptions) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.WhenBytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
// When implements the chifra when command.
func (opts *WhenOptions) When() ([]types.NamedBlock, *types.MetaData, error) {
- return queryWhen[types.NamedBlock](opts)
+ in := opts.toInternal()
+ return queryWhen[types.NamedBlock](in)
}
// WhenList implements the chifra when --list command.
func (opts *WhenOptions) WhenList() ([]types.NamedBlock, *types.MetaData, error) {
- return queryWhen[types.NamedBlock](opts)
+ in := opts.toInternal()
+ in.List = true
+ return queryWhen[types.NamedBlock](in)
}
// WhenTimestamps implements the chifra when --timestamps command.
func (opts *WhenOptions) WhenTimestamps() ([]types.Timestamp, *types.MetaData, error) {
- return queryWhen[types.Timestamp](opts)
+ in := opts.toInternal()
+ in.Timestamps = true
+ return queryWhen[types.Timestamp](in)
}
// WhenCount implements the chifra when --count command.
func (opts *WhenOptions) WhenCount() ([]types.TimestampCount, *types.MetaData, error) {
- return queryWhen[types.TimestampCount](opts)
+ in := opts.toInternal()
+ in.Count = true
+ return queryWhen[types.TimestampCount](in)
}
// No enums
diff --git a/sdk/when_internal.go b/sdk/when_internal.go
new file mode 100644
index 0000000000..bfc28ca1b1
--- /dev/null
+++ b/sdk/when_internal.go
@@ -0,0 +1,112 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
+ "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
+ when "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
+ // EXISTING_CODE
+)
+
+type whenOptionsInternal struct {
+ BlockIds []string `json:"blocks,omitempty"`
+ List bool `json:"list,omitempty"`
+ Timestamps bool `json:"timestamps,omitempty"`
+ Count bool `json:"count,omitempty"`
+ Truncate base.Blknum `json:"truncate,omitempty"`
+ Repair bool `json:"repair,omitempty"`
+ Check bool `json:"check,omitempty"`
+ Update bool `json:"update,omitempty"`
+ Deep bool `json:"deep,omitempty"`
+ Globals
+}
+
+// String implements the stringer interface
+func (opts *whenOptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// WhenBytes implements the chifra when command for the SDK.
+func (opts *whenOptionsInternal) WhenBytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting when struct to URL values: %v", err)
+ }
+
+ return when.When(w, values)
+}
+
+// whenParseFunc handles special cases such as structs and enums (if any).
+func whenParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ _, ok := target.(*whenOptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc(when): target is not of correct type")
+ }
+
+ // No enums
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// GetWhenOptions returns a filled-in options instance given a string array of arguments.
+func GetWhenOptions(args []string) (*whenOptionsInternal, error) {
+ var opts whenOptionsInternal
+ if err := assignValuesFromArgs(args, whenParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+type whenGeneric interface {
+ types.NamedBlock |
+ types.Timestamp |
+ types.TimestampCount
+}
+
+func queryWhen[T whenGeneric](opts *whenOptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.WhenBytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *WhenOptions) toInternal() *whenOptionsInternal {
+ return &whenOptionsInternal{
+ BlockIds: opts.BlockIds,
+ Truncate: opts.Truncate,
+ Repair: opts.Repair,
+ Check: opts.Check,
+ Update: opts.Update,
+ Deep: opts.Deep,
+ Globals: opts.Globals,
+ }
+}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/src/apps/chifra/internal/blocks/handle_hashes.go b/src/apps/chifra/internal/blocks/handle_hashes.go
index a08e49b8fd..f9e389d588 100644
--- a/src/apps/chifra/internal/blocks/handle_hashes.go
+++ b/src/apps/chifra/internal/blocks/handle_hashes.go
@@ -52,6 +52,8 @@ func (opts *BlocksOptions) HandleHashes() error {
iterFunc := func(app types.Appearance, value *types.Block[string]) error {
bn := uint64(app.BlockNumber)
if block, err := opts.Conn.GetBlockHeaderByNumber(bn); err != nil {
+ errMutex.Lock()
+ defer errMutex.Unlock()
delete(thisMap, app)
return err
} else {
diff --git a/src/apps/chifra/internal/blocks/handle_show.go b/src/apps/chifra/internal/blocks/handle_show.go
index c6c70650e1..4cd15c5313 100644
--- a/src/apps/chifra/internal/blocks/handle_show.go
+++ b/src/apps/chifra/internal/blocks/handle_show.go
@@ -8,6 +8,7 @@ import (
"context"
"fmt"
"sort"
+ "sync"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/logger"
@@ -16,6 +17,8 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
)
+var errMutex sync.Mutex
+
func (opts *BlocksOptions) HandleShow() error {
chain := opts.Globals.Chain
testMode := opts.Globals.TestMode
@@ -52,6 +55,8 @@ func (opts *BlocksOptions) HandleShow() error {
iterFunc := func(app types.Appearance, value *types.Block[types.Transaction]) error {
bn := uint64(app.BlockNumber)
if block, err := opts.Conn.GetBlockBodyByNumber(bn); err != nil {
+ errMutex.Lock()
+ defer errMutex.Unlock()
delete(thisMap, app)
return err
} else {
diff --git a/src/apps/chifra/internal/chunks/README.md b/src/apps/chifra/internal/chunks/README.md
index c4f040d87c..72fe8ab0c0 100644
--- a/src/apps/chifra/internal/chunks/README.md
+++ b/src/apps/chifra/internal/chunks/README.md
@@ -55,7 +55,7 @@ Data models produced by this tool:
- [chunkaddress](/data-model/admin/#chunkaddress)
- [chunkbloom](/data-model/admin/#chunkbloom)
- [chunkindex](/data-model/admin/#chunkindex)
-- [chunkpinreport](/data-model/admin/#chunkpinreport)
+- [chunkpin](/data-model/admin/#chunkpin)
- [chunkrecord](/data-model/admin/#chunkrecord)
- [chunkstats](/data-model/admin/#chunkstats)
- [ipfspin](/data-model/admin/#ipfspin)
diff --git a/src/apps/chifra/internal/chunks/handle_pin.go b/src/apps/chifra/internal/chunks/handle_pin.go
index 641f5d1f56..7335735b04 100644
--- a/src/apps/chifra/internal/chunks/handle_pin.go
+++ b/src/apps/chifra/internal/chunks/handle_pin.go
@@ -52,9 +52,9 @@ func (opts *ChunksOptions) HandlePin(blockNums []uint64) error {
}
ctx, cancel := context.WithCancel(context.Background())
- fetchData := func(modelChan chan types.Modeler[types.RawChunkPinReport], errorChan chan error) {
+ fetchData := func(modelChan chan types.Modeler[types.RawChunkPin], errorChan chan error) {
hash := base.BytesToHash(config.HeaderHash(config.ExpectedVersion()))
- report := types.ChunkPinReport{
+ report := types.ChunkPin{
Version: config.VersionTags[hash.Hex()],
Chain: chain,
SpecHash: base.IpfsHash(manifest.Specification()),
diff --git a/src/apps/chifra/pkg/types/types_appearance.go b/src/apps/chifra/pkg/types/types_appearance.go
index 6ce7f548ec..265bfbc9ff 100644
--- a/src/apps/chifra/pkg/types/types_appearance.go
+++ b/src/apps/chifra/pkg/types/types_appearance.go
@@ -30,6 +30,8 @@ const (
TxFeeReward base.Txnum = 99993
)
+type ChunkAppearance = Appearance
+
// EXISTING_CODE
type RawAppearance struct {
diff --git a/src/apps/chifra/pkg/types/types_chunkpinreport.go b/src/apps/chifra/pkg/types/types_chunkpin.go
similarity index 67%
rename from src/apps/chifra/pkg/types/types_chunkpinreport.go
rename to src/apps/chifra/pkg/types/types_chunkpin.go
index 2dc89a69a1..da46c4fd09 100644
--- a/src/apps/chifra/pkg/types/types_chunkpinreport.go
+++ b/src/apps/chifra/pkg/types/types_chunkpin.go
@@ -17,7 +17,7 @@ import (
// EXISTING_CODE
-type RawChunkPinReport struct {
+type RawChunkPin struct {
Chain string `json:"chain"`
ManifestHash string `json:"manifestHash"`
SpecHash string `json:"specHash"`
@@ -27,31 +27,31 @@ type RawChunkPinReport struct {
// EXISTING_CODE
}
-type ChunkPinReport struct {
- Chain string `json:"chain"`
- ManifestHash base.IpfsHash `json:"manifestHash"`
- SpecHash base.IpfsHash `json:"specHash"`
- TimestampHash base.IpfsHash `json:"timestampHash"`
- Version string `json:"version"`
- raw *RawChunkPinReport `json:"-"`
+type ChunkPin struct {
+ Chain string `json:"chain"`
+ ManifestHash base.IpfsHash `json:"manifestHash"`
+ SpecHash base.IpfsHash `json:"specHash"`
+ TimestampHash base.IpfsHash `json:"timestampHash"`
+ Version string `json:"version"`
+ raw *RawChunkPin `json:"-"`
// EXISTING_CODE
// EXISTING_CODE
}
-func (s ChunkPinReport) String() string {
+func (s ChunkPin) String() string {
bytes, _ := json.Marshal(s)
return string(bytes)
}
-func (s *ChunkPinReport) Raw() *RawChunkPinReport {
+func (s *ChunkPin) Raw() *RawChunkPin {
return s.raw
}
-func (s *ChunkPinReport) SetRaw(raw *RawChunkPinReport) {
+func (s *ChunkPin) SetRaw(raw *RawChunkPin) {
s.raw = raw
}
-func (s *ChunkPinReport) Model(chain, format string, verbose bool, extraOptions map[string]any) Model {
+func (s *ChunkPin) Model(chain, format string, verbose bool, extraOptions map[string]any) Model {
var model = map[string]interface{}{}
var order = []string{}
@@ -79,7 +79,7 @@ func (s *ChunkPinReport) Model(chain, format string, verbose bool, extraOptions
}
// FinishUnmarshal is used by the cache. It may be unused depending on auto-code-gen
-func (s *ChunkPinReport) FinishUnmarshal() {
+func (s *ChunkPin) FinishUnmarshal() {
// EXISTING_CODE
// EXISTING_CODE
}
diff --git a/src/apps/chifra/pkg/types/types_manifest.go b/src/apps/chifra/pkg/types/types_manifest.go
index 554864e32b..3f197e0b2a 100644
--- a/src/apps/chifra/pkg/types/types_manifest.go
+++ b/src/apps/chifra/pkg/types/types_manifest.go
@@ -15,6 +15,8 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
)
+type ChunkManifest = Manifest
+
// EXISTING_CODE
type RawManifest struct {
diff --git a/src/dev_tools/goMaker/main.go b/src/dev_tools/goMaker/main.go
index 259328597b..60f49a7990 100644
--- a/src/dev_tools/goMaker/main.go
+++ b/src/dev_tools/goMaker/main.go
@@ -34,6 +34,7 @@ var cbTemplates = []types.Generator{
Templates: []string{
"src_dev+tools_goMaker_generated_readme+route.md.tmpl",
"sdk_route.go.tmpl",
+ "sdk_route+internal.go.tmpl",
"sdk_python_src_+route.py.tmpl",
// "sdk_typescript_src_paths_route.ts.tmpl",
"src_apps_chifra_cmd_route.go.tmpl",
diff --git a/src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml b/src/dev_tools/goMaker/templates/classDefinitions/chunkpin.toml
similarity index 69%
rename from src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml
rename to src/dev_tools/goMaker/templates/classDefinitions/chunkpin.toml
index e52cbda9ae..b8b25e01fd 100644
--- a/src/dev_tools/goMaker/templates/classDefinitions/chunkpinreport.toml
+++ b/src/dev_tools/goMaker/templates/classDefinitions/chunkpin.toml
@@ -1,6 +1,6 @@
[settings]
- class = "ChunkPinReport"
+ class = "ChunkPin"
doc_group = "04-Admin"
doc_descr = "a JSON object containing the results of pinning the Unchained Index"
- doc_route = "436-chunkPinReport"
+ doc_route = "436-chunkPin"
produced_by = "chunks"
diff --git a/src/dev_tools/goMaker/templates/classDefinitions/fields/chunkpinreport.csv b/src/dev_tools/goMaker/templates/classDefinitions/fields/chunkpin.csv
similarity index 100%
rename from src/dev_tools/goMaker/templates/classDefinitions/fields/chunkpinreport.csv
rename to src/dev_tools/goMaker/templates/classDefinitions/fields/chunkpin.csv
diff --git a/src/dev_tools/goMaker/templates/cmd-line-options.csv b/src/dev_tools/goMaker/templates/cmd-line-options.csv
index 248c40402c..f69bcaa8c1 100644
--- a/src/dev_tools/goMaker/templates/cmd-line-options.csv
+++ b/src/dev_tools/goMaker/templates/cmd-line-options.csv
@@ -25,7 +25,7 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,option_type,data_
13060,apps,Accounts,export,acctExport,receipts,r,,visible|docs,switch,,receipt,,,,export receipts instead of transactional data
13070,apps,Accounts,export,acctExport,logs,l,,visible|docs,switch,,log,,,,export logs instead of transactional data
13080,apps,Accounts,export,acctExport,traces,t,,visible|docs,switch,,trace,,,,export traces instead of transactional data
-13090,apps,Accounts,export,acctExport,neighbors,n,,visible|docs,switch,,,,,,export the neighbors of the given address
+13090,apps,Accounts,export,acctExport,neighbors,n,,visible|docs,switch,,bool,,,,export the neighbors of the given address
13100,apps,Accounts,export,acctExport,accounting,C,,visible|docs,switch,,,,,,attach accounting records to the exported data (applies to transactions export only)
13110,apps,Accounts,export,acctExport,statements,A,,visible|docs,switch,,statement,,,,for the accounting options only, export only statements
13120,apps,Accounts,export,acctExport,balances,b,,visible|docs,switch,,state,,,,traverse the transaction history and show each change in ETH balances
@@ -114,7 +114,7 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,option_type,data_
22000,tools,Chain Data,blocks,getBlocks,,,,visible|docs,command,,,Get blocks,[flags] [block...],default|caching|ether|raw|,Retrieve one or more blocks from the chain or local cache.
22020,tools,Chain Data,blocks,getBlocks,blocks,,,required|visible|docs,positional,list,block[types.Transaction],,,,a space-separated list of one or more block identifiers
22030,tools,Chain Data,blocks,getBlocks,hashes,e,,visible|docs,switch,,block[string],,,,display only transaction hashes, default is to display full transaction detail
-22040,tools,Chain Data,blocks,getBlocks,uncles,c,,visible|docs,switch,,,,,,display uncle blocks (if any) instead of the requested block
+22040,tools,Chain Data,blocks,getBlocks,uncles,c,,visible|docs,switch,,block[string],,,,display uncle blocks (if any) instead of the requested block
22050,tools,Chain Data,blocks,getBlocks,traces,t,,visible|docs,switch,,trace,,,,export the traces from the block as opposed to the block data
22060,tools,Chain Data,blocks,getBlocks,uniq,u,,visible|docs,switch,,appearance,,,,display a list of uniq address appearances per transaction
22070,tools,Chain Data,blocks,getBlocks,flow,f,,visible|docs,flag,enum[from|to|reward],,,,,for the --uniq option only, export only from or to (including trace from or to)
@@ -149,7 +149,7 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,option_type,data_
23080,tools,Chain Data,transactions,getTrans,emitter,m,,visible|docs,flag,list,,,,,for the --logs option only, filter logs to show only those logs emitted by the given address(es)
23090,tools,Chain Data,transactions,getTrans,topic,B,,visible|docs,flag,list,,,,,for the --logs option only, filter logs to show only those with this topic(s)
23100,tools,Chain Data,transactions,getTrans,cache_traces,,,,switch,,,,,,force the transaction's traces into the cache
-23110,tools,Chain Data,transactions,getTrans,seed,S,,,switch,,,,,,find the source of the funds sent to the receiver
+23110,tools,Chain Data,transactions,getTrans,seed,S,,,switch,,bool,,,,find the source of the funds sent to the receiver
23120,tools,Chain Data,transactions,getTrans,n1,,,,note,,,,,,The `transactions` list may be one or more transaction hashes, blockNumber.transactionID pairs, or a blockHash.transactionID pairs.
23130,tools,Chain Data,transactions,getTrans,n2,,,,note,,,,,,This tool checks for valid input syntax, but does not check that the transaction requested actually exists.
23140,tools,Chain Data,transactions,getTrans,n3,,,,note,,,,,,If the queried node does not store historical state, the results for most older transactions are undefined.
@@ -236,8 +236,8 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,option_type,data_
42030,apps,Admin,config,config,paths,a,,visible|docs,switch,,,,,,show the configuration paths for the system
#
43000,apps,Admin,status,cacheStatus,,,,visible|docs,command,,,Get status on caches, [mode...] [flags],default|,Report on the state of the internal binary caches.
-43020,apps,Admin,status,cacheStatus,modes,,,visible|docs,positional,list,,,,,the (optional) name of the binary cache to report on, terse otherwise
-43030,apps,Admin,status,cacheStatus,diagnose,d,,visible|docs,switch,,,,,,same as the default but with additional diagnostics
+43020,apps,Admin,status,cacheStatus,modes,,,visible|docs,positional,list,Status,,,,the (optional) name of the binary cache to report on, terse otherwise
+43030,apps,Admin,status,cacheStatus,diagnose,d,,visible|docs,switch,,bool,,,,same as the default but with additional diagnostics
43040,apps,Admin,status,cacheStatus,first_record,c,,visible|docs,flag,,,,,,the first record to process
43050,apps,Admin,status,cacheStatus,max_records,e,10000,visible|docs,flag,,,,,,the maximum number of records to process
43060,apps,Admin,status,cacheStatus,chains,a,,visible|docs,switch,,,,,,include a list of chain configurations in the output
@@ -272,7 +272,7 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,option_type,data_
45140,apps,Admin,scrape,blockScrape,n1,,,,note,,,,,,The --touch option may only be used for blocks after the latest scraped block (if any). It will be snapped back to the latest snap_to block.
#
46000,apps,Admin,chunks,chunkMan,,,,visible|docs,command,,,Manage chunks, [flags] [blocks...] [address...],default|,Manage, investigate, and display the Unchained Index.
-46020,apps,Admin,chunks,chunkMan,mode,,,required|visible|docs,positional,enum[manifest|index|blooms|pins|addresses|appearances|stats],,,,,the type of data to process
+46020,apps,Admin,chunks,chunkMan,mode,,,required|visible|docs,positional,enum[manifest|index|blooms|pins|addresses|appearances|stats],mode,,,,the type of data to process
46030,apps,Admin,chunks,chunkMan,blocks,,,visible|docs,positional,list,,,,,an optional list of blocks to intersect with chunk ranges
46040,apps,Admin,chunks,chunkMan,check,c,,visible|docs,switch,,,,,,check the manifest, index, or blooms for internal consistency
46050,apps,Admin,chunks,chunkMan,pin,i,,visible|docs,switch,,,,,,pin the manifest or each index chunk and bloom
@@ -305,8 +305,8 @@ num,folder,group,route,tool,longName,hotKey,def_val,attributes,option_type,data_
#
47000,apps,Admin,init,init,,,,visible|docs,command,,,Initialize index,[flags],verbose|version|noop|noColor|chain|,Initialize the TrueBlocks system by downloading the Unchained Index from IPFS.
47020,apps,Admin,init,init,all,a,,visible|docs,switch,,bool,,,,in addition to Bloom filters, download full index chunks (recommended)
-47025,apps,Admin,init,init,example,e,,visible,flag,,,,,,create an example for the SDK with the given name
-47030,apps,Admin,init,init,dry_run,d,,visible|docs,switch,,,,,,display the results of the download without actually downloading
+47025,apps,Admin,init,init,example,e,,visible,flag,,bool,,,,create an example for the SDK with the given name
+47030,apps,Admin,init,init,dry_run,d,,visible|docs,switch,,bool,,,,display the results of the download without actually downloading
47040,apps,Admin,init,init,publisher,P,,,flag,,,,,,the publisher of the index to download
47050,apps,Admin,init,init,first_block,F,,visible|docs,flag,,,,,,do not download any chunks earlier than this block
47060,apps,Admin,init,init,sleep,s,,visible|docs,flag,,,,,,seconds to sleep between downloads
diff --git a/src/dev_tools/goMaker/templates/model-intros/chunkPinReport.md b/src/dev_tools/goMaker/templates/model-intros/chunkPin.md
similarity index 100%
rename from src/dev_tools/goMaker/templates/model-intros/chunkPinReport.md
rename to src/dev_tools/goMaker/templates/model-intros/chunkPin.md
diff --git a/src/dev_tools/goMaker/templates/sdk_route+internal.go.tmpl b/src/dev_tools/goMaker/templates/sdk_route+internal.go.tmpl
new file mode 100644
index 0000000000..baf7d6f596
--- /dev/null
+++ b/src/dev_tools/goMaker/templates/sdk_route+internal.go.tmpl
@@ -0,0 +1,89 @@
+// 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 auto generated. Edit only those parts of
+ * the code inside of 'EXISTING_CODE' tags.
+ */
+
+package sdk
+
+import (
+ // EXISTING_CODE
+ // EXISTING_CODE
+)
+
+type {{toCamel .Route}}OptionsInternal struct {
+{{range .Options}} {{.GoSdkName}} {{.GoSdkType}} {{.JsonTag}}
+{{end}} Globals
+}
+
+// String implements the stringer interface
+func (opts *{{toCamel .Route}}OptionsInternal) String() string {
+ bytes, _ := json.Marshal(opts)
+ return string(bytes)
+}
+
+// {{toProper .Route}}Bytes implements the chifra {{toLower .Route}} command for the SDK.
+func (opts *{{toCamel .Route}}OptionsInternal) {{toProper .Route}}Bytes(w io.Writer) error {
+ values, err := structToValues(*opts)
+ if err != nil {
+ return fmt.Errorf("error converting {{toLower .Route}} struct to URL values: %v", err)
+ }
+
+ return {{.Pkg}}.{{toProper .Route}}(w, values)
+}
+
+// {{toLower .Route}}ParseFunc handles special cases such as structs and enums (if any).
+func {{toLower .Route}}ParseFunc(target interface{}, key, value string) (bool, error) {
+ var found bool
+ {{.Enums3}}, ok := target.(*{{toCamel .Route}}OptionsInternal)
+ if !ok {
+ return false, fmt.Errorf("parseFunc({{toLower .Route}}): target is not of correct type")
+ }
+
+{{.Enums1}}
+ // EXISTING_CODE
+ // EXISTING_CODE
+
+ return found, nil
+}
+
+// Get{{toProper .Route}}Options returns a filled-in options instance given a string array of arguments.
+func Get{{toProper .Route}}Options(args []string) (*{{toCamel .Route}}OptionsInternal, error) {
+ var opts {{toCamel .Route}}OptionsInternal
+ if err := assignValuesFromArgs(args, {{toLower .Route}}ParseFunc, &opts, &opts.Globals); err != nil {
+ return nil, err
+ }
+
+ return &opts, nil
+}
+
+{{if .HasSdkEndpoints}}type {{toCamel .Route}}Generic interface {
+ {{.ReturnTypes}}
+}
+
+func query{{toProper .Route}}[T {{toCamel .Route}}Generic](opts *{{toCamel .Route}}OptionsInternal) ([]T, *types.MetaData, error) {
+ buffer := bytes.Buffer{}
+ if err := opts.{{toProper .Route}}Bytes(&buffer); err != nil {
+ return nil, nil, err
+ }
+
+ var result Result[T]
+ if err := json.Unmarshal(buffer.Bytes(), &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 *{{toProper .Route}}Options) toInternal() *{{toCamel .Route}}OptionsInternal {
+ return &{{toCamel .Route}}OptionsInternal{
+{{range .Options}}{{if .IsPublicEndpoint}} {{.GoSdkName}}: opts.{{.GoSdkName}},
+{{end}}{{end}} Globals: opts.Globals,
+ }
+}{{end}}
+
+// EXISTING_CODE
+// EXISTING_CODE
diff --git a/src/dev_tools/goMaker/templates/sdk_route.go.tmpl b/src/dev_tools/goMaker/templates/sdk_route.go.tmpl
index e30a7ddf43..1a6e754138 100644
--- a/src/dev_tools/goMaker/templates/sdk_route.go.tmpl
+++ b/src/dev_tools/goMaker/templates/sdk_route.go.tmpl
@@ -14,8 +14,8 @@ import (
)
type {{toProper .Route}}Options struct {
-{{range .Options}} {{.GoSdkName}} {{.GoSdkType}} {{.JsonTag}}
-{{end}} Globals
+{{range .Options}}{{if .IsPublicEndpoint}} {{.GoSdkName}} {{.GoSdkType}} {{.JsonTag}}
+{{end}}{{end}} Globals
}
// String implements the stringer interface
@@ -24,59 +24,6 @@ func (opts *{{toProper .Route}}Options) String() string {
return string(bytes)
}
-// {{toProper .Route}}Bytes implements the chifra {{toLower .Route}} command for the SDK.
-func (opts *{{toProper .Route}}Options) {{toProper .Route}}Bytes(w io.Writer) error {
- values, err := structToValues(*opts)
- if err != nil {
- return fmt.Errorf("error converting {{toLower .Route}} struct to URL values: %v", err)
- }
-
- return {{.Pkg}}.{{toProper .Route}}(w, values)
-}
-
-// {{toLower .Route}}ParseFunc handles special cases such as structs and enums (if any).
-func {{toLower .Route}}ParseFunc(target interface{}, key, value string) (bool, error) {
- var found bool
- {{.Enums3}}, ok := target.(*{{toProper .Route}}Options)
- if !ok {
- return false, fmt.Errorf("parseFunc({{toLower .Route}}): target is not of correct type")
- }
-
-{{.Enums1}}
- // EXISTING_CODE
- // EXISTING_CODE
-
- return found, nil
-}
-
-// Get{{toProper .Route}}Options returns a filled-in options instance given a string array of arguments.
-func Get{{toProper .Route}}Options(args []string) (*{{toProper .Route}}Options, error) {
- var opts {{toProper .Route}}Options
- if err := assignValuesFromArgs(args, {{toLower .Route}}ParseFunc, &opts, &opts.Globals); err != nil {
- return nil, err
- }
-
- return &opts, nil
-}
-
-type {{toCamel .Route}}Generic interface {
- {{.ReturnTypes}}
-}
-
-func query{{toProper .Route}}[T {{toCamel .Route}}Generic](opts *{{toProper .Route}}Options) ([]T, *types.MetaData, error) {
- buffer := bytes.Buffer{}
- if err := opts.{{toProper .Route}}Bytes(&buffer); err != nil {
- return nil, nil, err
- }
-
- var result Result[T]
- if err := json.Unmarshal(buffer.Bytes(), &result); err != nil {
- return nil, nil, err
- } else {
- return result.Data, &result.Meta, nil
- }
-}
-
{{if .HasSdkEndpoints}}{{.SdkEndpoints}}{{end}}
{{.Enums2}}
diff --git a/src/dev_tools/goMaker/types/load.go b/src/dev_tools/goMaker/types/load.go
index 46fc3b1a63..4b4849a29c 100644
--- a/src/dev_tools/goMaker/types/load.go
+++ b/src/dev_tools/goMaker/types/load.go
@@ -235,5 +235,5 @@ func (cb *CodeBase) FinishLoad(baseTypes []Structure, options []Option, structMa
return nil
}
- return fmt.Errorf("Quitting: codebase.json has changed. Rerun the command to ignore this warning.")
+ return fmt.Errorf("quitting: codebase.json has changed. Rerun the command to ignore this warning")
}
diff --git a/src/dev_tools/goMaker/types/templates.go b/src/dev_tools/goMaker/types/templates.go
index d06f5303f6..cd4b54c23d 100644
--- a/src/dev_tools/goMaker/types/templates.go
+++ b/src/dev_tools/goMaker/types/templates.go
@@ -33,6 +33,7 @@ func executeTemplate(receiver interface{}, tmplPrefix, name, tmplCode string) st
}
func getFuncMap() template.FuncMap {
+ toSingular := func(s string) string { return Singular(s) }
toProper := func(s string) string { return Proper(s) }
toPlural := func(s string) string { return Plural(s) }
toCamel := func(s string) string { return CamelCase(s) }
@@ -40,6 +41,7 @@ func getFuncMap() template.FuncMap {
firstLower := func(s string) string { return FirstLower(s) }
firstUpper := func(s string) string { return FirstUpper(s) }
return template.FuncMap{
+ "toSingular": toSingular,
"toProper": toProper,
"toCamel": toCamel,
"toPlural": toPlural,
diff --git a/src/dev_tools/goMaker/types/types_command.go b/src/dev_tools/goMaker/types/types_command.go
index dd998b66bb..88635bb58e 100644
--- a/src/dev_tools/goMaker/types/types_command.go
+++ b/src/dev_tools/goMaker/types/types_command.go
@@ -318,7 +318,6 @@ func (c *Command) AddCaps() string {
return strings.Replace(strings.Replace(str, "[{CAPS}]", strings.Join(ret, "\n"), -1), "[{ROUTE}]", c.Route, -1)
}
-// src_apps_chifra_internal_route_options.go
// DefaultsApi for tag {{.DefaultsApi}}
func (c *Command) DefaultsApi() string {
ret := []string{}
@@ -637,22 +636,17 @@ func (c *Command) BaseTypes() string {
return MarkdownTable([]string{"Type", "Description", "Notes"}, ret)
}
-func (c *Command) HasSdkEndpoints() bool {
- for _, op := range c.Options {
- if len(op.ReturnType) > 0 {
- return true
- }
- }
- return false
-}
-
func (c *Command) ReturnTypes() string {
present := map[string]bool{}
ret := []string{}
for _, op := range c.Options {
if len(op.ReturnType) > 0 {
if !present[op.RetType()] {
- ret = append(ret, op.RetType())
+ if op.LongName == "mode" {
+ ret = append(ret, op.EnumTypes()...)
+ } else {
+ ret = append(ret, op.RetType())
+ }
}
present[op.RetType()] = true
}
@@ -660,6 +654,15 @@ func (c *Command) ReturnTypes() string {
return strings.Join(ret, "|\n")
}
+func (c *Command) HasSdkEndpoints() bool {
+ for _, op := range c.Options {
+ if len(op.ReturnType) > 0 {
+ return true
+ }
+ }
+ return false
+}
+
func (c *Command) SdkEndpoints() string {
ret := []string{}
for _, op := range c.Options {
@@ -672,50 +675,3 @@ func (c *Command) SdkEndpoints() string {
}
return strings.Join(ret, "\n")
}
-
-func (c *Command) ReturnTypeFunc() string {
- return c.ReturnTypeInner()
-}
-
-func (c *Command) ReturnTypeInner() string {
- switch c.Route {
- case "abis":
- return "types.Function"
- case "blocks":
- return "types.Block[types.Transaction]"
- case "chunks":
- return "bool"
- case "config":
- return "bool"
- case "export":
- return "types.Transaction"
- case "init":
- return "bool"
- case "list":
- return "types.Appearance"
- case "logs":
- return "types.Log"
- case "monitors":
- return "types.Monitor"
- case "names":
- return "types.Name"
- case "receipts":
- return "types.Receipt"
- case "slurp":
- return "types.Slurp"
- case "state":
- return "types.State"
- case "status":
- return "bool"
- case "tokens":
- return "bool"
- case "traces":
- return "types.Trace"
- case "transactions":
- return "types.Transaction"
- case "when":
- return "types.NamedBlock"
- default:
- return "unknown return type"
- }
-}
diff --git a/src/dev_tools/goMaker/types/types_option.go b/src/dev_tools/goMaker/types/types_option.go
index c615b4cbaf..44278e0d1f 100644
--- a/src/dev_tools/goMaker/types/types_option.go
+++ b/src/dev_tools/goMaker/types/types_option.go
@@ -372,6 +372,14 @@ func (op *Option) SomeCases() string {
return op.executeTemplate(tmplName, tmpl)
}
+func (op *Option) EnumTypes() []string {
+ ret := []string{}
+ for _, e := range op.Enums {
+ ret = append(ret, "types."+Singular(Proper(op.Route))+Singular(Proper(e)))
+ }
+ return ret
+}
+
func (op *Option) EnumCases() string {
ret := []string{}
for _, e := range op.Enums {
@@ -760,6 +768,36 @@ func (op *Option) ToolTurd() string {
return "--" + Lower(op.Tool) + " "
}
+func (op *Option) ToolParameters() string {
+ if len(op.ReturnType) == 0 {
+ return ""
+ } else if strings.Contains(op.DataType, "string") {
+ return "val string"
+ } else {
+ return ""
+ }
+}
+
+func (op *Option) ToolAssignment() string {
+ if len(op.ReturnType) == 0 {
+ return ""
+ } else if strings.Contains(op.DataType, "string") {
+ return "val"
+ } else {
+ return "true"
+ }
+}
+
+func (op *Option) SdkEndpointName() string {
+ if len(op.ReturnType) == 0 {
+ return ""
+ } else if op.OptionType == "positional" {
+ return ""
+ } else {
+ return op.GoName
+ }
+}
+
func (op *Option) SdkEndpoint() string {
if len(op.ReturnType) == 0 {
return ""
@@ -773,12 +811,109 @@ func (op *Option) SdkEndpoint() string {
Route: FirstUpper(op.Route),
Tool: longName,
ReturnType: op.RetType(),
+ OptionType: op.OptionType,
+ DataType: op.DataType,
+ GoName: op.GoName,
+ }
+
+ if op.IsMode() {
+ opp = *op
+ return opp.renderModeEndpoints()
+
+ } else if op.OptionType == "positional" {
+ return opp.renderPositionalEndpoint()
+
+ } else {
+ return opp.renderRegularEndpoint()
+ }
+}
+
+func (op *Option) renderModeEndpoint() string {
+ tmplName := "modeFunc"
+ tmpl := `// {{toProper .Route}}++E++ implements the chifra {{toLower .Route}} ++EE++ command.
+func (opts *{{toProper .Route}}Options) {{toProper .Route}}++E++() ([]++EEEE++, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.{{.GoName}} = ++EEE++
+ return query{{toProper .Route}}[++EEEE++](in)
+}
+
+`
+ ret := []string{}
+ for _, e := range op.Enums {
+ tN := tmplName + e
+ pp := Proper(e)
+ ll := Lower(e)
+ tt := op.EnumTag() + pp
+ ty := "types." + Singular(Proper(op.Route)) + Singular(pp)
+ tE := strings.ReplaceAll(tmpl, "++E++", pp)
+ tE = strings.ReplaceAll(tE, "++EE++", ll)
+ tE = strings.ReplaceAll(tE, "++EEE++", tt)
+ tE = strings.ReplaceAll(tE, "++EEEE++", ty)
+ ret = append(ret, op.executeTemplate(tN, tE))
}
+
+ return strings.Join(ret, "\n")
+}
+
+func (op *Option) renderModesEndpoint() string {
+ tmplName := "modesFunc"
+ tmpl := `// {{toProper .Route}}++E++ implements the chifra {{toLower .Route}} ++EE++ command.
+func (opts *{{toProper .Route}}Options) {{toProper .Route}}++E++() ([]types.{{.ReturnType}}, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.{{.GoName}} = ++EEE++
+ return query{{toProper .Route}}[types.{{.ReturnType}}](in)
+}
+
+`
+ ret := []string{}
+ for _, e := range op.Enums {
+ tE := strings.ReplaceAll(tmpl, "++E++", Proper(e))
+ tE = strings.ReplaceAll(tE, "++EE++", Lower(e))
+ tE = strings.ReplaceAll(tE, "++EEE++", op.EnumTag()+Proper(e))
+ ret = append(ret, op.executeTemplate(tmplName+e, tE))
+ }
+
+ return strings.Join(ret, "\n")
+}
+
+func (op *Option) renderModeEndpoints() string {
+ if op.LongName == "mode" {
+ return op.renderModeEndpoint()
+ } else if op.LongName == "modes" {
+ return op.renderModesEndpoint()
+ }
+ return op.renderPositionalEndpoint()
+}
+
+func (op *Option) renderRegularEndpoint() string {
tmplName := "returnTypes"
- tmpl := ` // {{.Route}}{{.Tool}} implements the chifra {{toLower .Route}} {{.ToolTurd}}command.
+ tmpl := ` // {{.Route}}{{.SdkEndpointName}} implements the chifra {{toLower .Route}} {{.ToolTurd}}command.
+func (opts *{{.Route}}Options) {{.Route}}{{.Tool}}({{.ToolParameters}}) ([]{{.ReturnType}}, *types.MetaData, error) {
+ in := opts.toInternal()
+ in.{{.SdkEndpointName}} = {{.ToolAssignment}}
+ return query{{.Route}}[{{.ReturnType}}](in)
+}
+`
+ return op.executeTemplate(tmplName, tmpl)
+}
+
+func (op *Option) renderPositionalEndpoint() string {
+ tmplName := "sdkEndpointPos"
+ tmpl := ` // {{.Route}}{{.SdkEndpointName}} implements the chifra {{toLower .Route}} {{.ToolTurd}}command.
func (opts *{{.Route}}Options) {{.Route}}{{.Tool}}() ([]{{.ReturnType}}, *types.MetaData, error) {
- return query{{.Route}}[{{.ReturnType}}](opts)
+ in := opts.toInternal()
+ return query{{.Route}}[{{.ReturnType}}](in)
}
`
- return opp.executeTemplate(tmplName, tmpl)
+ return op.executeTemplate(tmplName, tmpl)
+}
+
+func (op *Option) IsPublicEndpoint() bool {
+ return len(op.ReturnType) == 0 ||
+ (op.IsPositional() && !op.IsMode()) // && (op.LongName == "mode" || op.LongName == "modes"))
+}
+
+func (op *Option) IsMode() bool {
+ return (op.LongName == "mode" && op.ReturnType == "mode") ||
+ (op.LongName == "modes" && op.ReturnType == "Status")
}
diff --git a/src/dev_tools/goMaker/types/utils.go b/src/dev_tools/goMaker/types/utils.go
index 4e6890a6cb..48de0d7fcc 100644
--- a/src/dev_tools/goMaker/types/utils.go
+++ b/src/dev_tools/goMaker/types/utils.go
@@ -47,6 +47,7 @@ func convertToDestPath(source, routeTag, typeTag, groupTag, reason string) strin
dest := strings.Replace(source, templateFolder, "", -1)
dest = strings.Replace(dest, ".tmpl", "", -1)
dest = strings.Replace(dest, "_route_", "/"+routeTag+"/", -1)
+ dest = strings.Replace(dest, "route+internal", routeTag+"+internal", -1)
dest = strings.Replace(dest, "route.go", routeTag+".go", -1)
dest = strings.Replace(dest, "route.md", routeTag+".md", -1)
dest = strings.Replace(dest, "route.py", routeTag+".py", -1)
@@ -126,6 +127,18 @@ func Proper(s string) string {
return titleCaser.String(s)
}
+func Singular(s string) string {
+ if s == "Addresses" {
+ return "Address"
+ }
+
+ if s != "Status" && s != "Stats" && strings.HasSuffix(s, "s") {
+ return s[:len(s)-1]
+ }
+
+ return s
+}
+
func Lower(s string) string {
return strings.ToLower(s)
}