Skip to content

Commit

Permalink
Merge pull request #3524 from TrueBlocks/feature/go-sdk-2
Browse files Browse the repository at this point in the history
Feature/go sdk 2
  • Loading branch information
tjayrush authored Feb 26, 2024
2 parents 2b6da55 + 7b7bc57 commit 7c8bb2e
Show file tree
Hide file tree
Showing 166 changed files with 5,981 additions and 829 deletions.
598 changes: 579 additions & 19 deletions docs/content/api/openapi.yaml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/content/chifra/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ Aliases:
Flags:
-u, --url string specify the API server's url and optionally its port (default "localhost:8080")
-g, --grpc run gRPC server to serve names
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
Expand Down
1 change: 0 additions & 1 deletion docs/readmes/admin-daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Aliases:
Flags:
-u, --url string specify the API server's url and optionally its port (default "localhost:8080")
-g, --grpc run gRPC server to serve names
-x, --fmt string export format, one of [none|json*|txt|csv]
-v, --verbose enable verbose output
-h, --help display this help screen
Expand Down
4 changes: 4 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
go 1.22

use ./src/apps/chifra

use ./src/examples/usesSDK

use ./sdk/go
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOC
github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/TrueBlocks/trueblocks-core/src/apps/chifra v0.0.0-20240221021507-efd334ebc492/go.mod h1:IsdME6/UmuLPCV5EKK1vo5yrT+qrDTouvSdfoev8lyA=
github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af h1:wVe6/Ea46ZMeNkQjjBW6xcqyQA/j5e0D6GytH95g0gQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
Expand Down
65 changes: 65 additions & 0 deletions sdk/go/abis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were generated with makeClass --run. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/

package sdk

import (
// EXISTING_CODE
"io"
"net/url"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
abis "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)

type AbisOptions struct {
Addrs []string // allow for ENS names and addresses
Known bool
ProxyFor base.Address
Find []string
Hint []string
Encode string
Globals

// EXISTING_CODE
// EXISTING_CODE
}

// Abis implements the chifra abis command for the SDK.
func (opts *AbisOptions) Abis(w io.Writer) error {
values := make(url.Values)

// EXISTING_CODE
for _, addr := range opts.Addrs {
values.Add("addrs", addr)
}
if opts.Known {
values.Set("known", "true")
}
if !opts.ProxyFor.IsZero() {
values.Set("proxy_for", opts.ProxyFor.Hex())
}
for _, find := range opts.Find {
values.Add("find", find)
}
for _, hint := range opts.Hint {
values.Add("hint", hint)
}
if opts.Encode != "" {
values.Set("encode", opts.Encode)
}
// EXISTING_CODE
opts.Globals.mapGlobals(values)

return abis.Abis(w, values)
}

// EXISTING_CODE
// EXISTING_CODE

111 changes: 111 additions & 0 deletions sdk/go/blocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were generated with makeClass --run. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/

package sdk

import (
// EXISTING_CODE
"fmt"
"io"
"net/url"

blocks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)

type BlocksOptions struct {
BlockIds []string // allow for block ranges and steps
Hashes bool
Uncles bool
Traces bool
Uniq bool
Flow BlocksFlow
Logs bool
Emitter []string // allow for ENS names and addresses
Topic []string // topics are strings
Withdrawals bool
Articulate bool
BigRange uint64
Count bool
Globals

// EXISTING_CODE
// EXISTING_CODE
}

// Blocks implements the chifra blocks command for the SDK.
func (opts *BlocksOptions) Blocks(w io.Writer) error {
values := make(url.Values)

// EXISTING_CODE
for _, blockId := range opts.BlockIds {
values.Add("blocks", blockId)
}
if opts.Hashes {
values.Set("hashes", "true")
}
if opts.Uncles {
values.Set("uncles", "true")
}
if opts.Traces {
values.Set("traces", "true")
}
if opts.Uniq {
values.Set("uniq", "true")
}
if opts.Flow != NoBF {
values.Set("flow", opts.Flow.String())
}
if opts.Logs {
values.Set("logs", "true")
}
for _, emitter := range opts.Emitter {
values.Add("emitter", emitter)
}
for _, topic := range opts.Topic {
values.Add("topic", topic)
}
if opts.Withdrawals {
values.Set("withdrawals", "true")
}
if opts.Articulate {
values.Set("articulate", "true")
}
if opts.BigRange > 0 {
values.Set("bigRange", fmt.Sprintf("%d", opts.BigRange))
}
if opts.Count {
values.Set("count", "true")
}
// EXISTING_CODE
opts.Globals.mapGlobals(values)

return blocks.Blocks(w, values)
}

type BlocksFlow int

const (
NoBF BlocksFlow = iota
BFFrom
BFTo
BFReward
)

func (v BlocksFlow) String() string {
return []string{
"nobf",
"from",
"to",
"reward",
}[v]
}

// EXISTING_CODE
// EXISTING_CODE

124 changes: 124 additions & 0 deletions sdk/go/chunks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were generated with makeClass --run. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/

package sdk

import (
// EXISTING_CODE
"fmt"
"io"
"net/url"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
chunks "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)

type ChunksOptions struct {
Mode ChunksMode
BlockIds []string // allow for block ranges and steps
Check bool
Pin bool
Publish bool
Remote bool
Belongs []string // allow for ENS names and addresses
FirstBlock base.Blknum
LastBlock base.Blknum
MaxAddrs base.Blknum
Deep bool
Rewrite bool
Count bool
Sleep float64
Globals

// EXISTING_CODE
// EXISTING_CODE
}

// Chunks implements the chifra chunks command for the SDK.
func (opts *ChunksOptions) Chunks(w io.Writer) error {
values := make(url.Values)

// EXISTING_CODE
if opts.Mode != NoCM2 {
values.Set("mode", opts.Mode.String())
}
for _, v := range opts.BlockIds {
values.Add("blocks", v)
}
if opts.Check {
values.Set("check", "true")
}
if opts.Pin {
values.Set("pin", "true")
}
if opts.Publish {
values.Set("publish", "true")
}
if opts.Remote {
values.Set("remote", "true")
}
for _, v := range opts.Belongs {
values.Add("belongs", v)
}
if opts.FirstBlock > 0 {
values.Set("first_block", fmt.Sprint(opts.FirstBlock))
}
if opts.LastBlock > 0 {
values.Set("last_block", fmt.Sprint(opts.LastBlock))
}
if opts.MaxAddrs > 0 {
values.Set("max_addrs", fmt.Sprint(opts.MaxAddrs))
}
if opts.Deep {
values.Set("deep", "true")
}
if opts.Rewrite {
values.Set("rewrite", "true")
}
if opts.Count {
values.Set("count", "true")
}
if opts.Sleep > 0 {
values.Set("sleep", fmt.Sprint(opts.Sleep))
}
// EXISTING_CODE
opts.Globals.mapGlobals(values)

return chunks.Chunks(w, values)
}

type ChunksMode int

const (
NoCM2 ChunksMode = iota
CMManifest
CMIndex
CMBlooms
CMPins
CMAddresses
CMAppearances
CMStats
)

func (v ChunksMode) String() string {
return []string{
"nocm2",
"manifest",
"index",
"blooms",
"pins",
"addresses",
"appearances",
"stats",
}[v]
}

// EXISTING_CODE
// EXISTING_CODE

64 changes: 64 additions & 0 deletions sdk/go/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were generated with makeClass --run. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/

package sdk

import (
// EXISTING_CODE
"io"
"net/url"

config "github.com/TrueBlocks/trueblocks-core/src/apps/chifra/sdk"
// EXISTING_CODE
)

type ConfigOptions struct {
Mode ConfigMode
Paths bool
Globals

// EXISTING_CODE
// EXISTING_CODE
}

// Config implements the chifra config command for the SDK.
func (opts *ConfigOptions) Config(w io.Writer) error {
values := make(url.Values)

// EXISTING_CODE
if opts.Mode != NoCM1 {
values.Set("mode", opts.Mode.String())
}
if opts.Paths {
values.Set("paths", "true")
}
// EXISTING_CODE
opts.Globals.mapGlobals(values)

return config.Config(w, values)
}

type ConfigMode int

const (
NoCM1 ConfigMode = iota
CMShow
CMEdit
)

func (v ConfigMode) String() string {
return []string{
"nocm1",
"show",
"edit",
}[v]
}

// EXISTING_CODE
// EXISTING_CODE

Loading

0 comments on commit 7c8bb2e

Please sign in to comment.