Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Move statefulsyncer, storage, and utils to rosetta-sdk-go #110

Merged
merged 1 commit into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ ADDLICENCE_SCRIPT=${ADDLICENSE_CMD} -c "Coinbase, Inc." -l "apache" -v
GOLINES_CMD=go run github.com/segmentio/golines
GOVERALLS_CMD=go run github.com/mattn/goveralls
COVERAGE_TEST_DIRECTORIES=./configuration/... ./pkg/constructor/... \
./pkg/logger/... ./pkg/scenario/... \
./pkg/statefulsyncer/... ./pkg/storage/... \
./pkg/utils/...
./pkg/logger/... ./pkg/scenario/...
TEST_SCRIPT=go test -v ./pkg/... ./configuration/...
COVERAGE_TEST_SCRIPT=go test -v ${COVERAGE_TEST_DIRECTORIES}

Expand Down
10 changes: 5 additions & 5 deletions cmd/check_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"time"

"github.com/coinbase/rosetta-cli/pkg/tester"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/fatih/color"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -64,12 +64,12 @@ func runCheckConstructionCmd(cmd *cobra.Command, args []string) {
fetcher.WithTimeout(time.Duration(Config.HTTPTimeout)*time.Second),
)

_, _, err := fetcher.InitializeAsserter(ctx)
if err != nil {
log.Fatalf("%s: unable to initialize asserter", err.Error())
_, _, fetchErr := fetcher.InitializeAsserter(ctx)
if fetchErr != nil {
log.Fatalf("%s: unable to initialize asserter", fetchErr.Err.Error())
}

_, err = utils.CheckNetworkSupported(ctx, Config.Network, fetcher)
_, err := utils.CheckNetworkSupported(ctx, Config.Network, fetcher)
if err != nil {
log.Fatalf("%s: unable to confirm network is supported", err.Error())
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/check_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"time"

"github.com/coinbase/rosetta-cli/pkg/tester"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -80,13 +80,13 @@ func runCheckDataCmd(cmd *cobra.Command, args []string) {
fetcher.WithTimeout(time.Duration(Config.HTTPTimeout)*time.Second),
)

_, _, err := fetcher.InitializeAsserter(ctx)
if err != nil {
_, _, fetchErr := fetcher.InitializeAsserter(ctx)
if fetchErr != nil {
tester.Exit(
Config,
nil,
nil,
fmt.Errorf("%w: unable to initialize asserter", err),
fmt.Errorf("%w: unable to initialize asserter", fetchErr.Err),
1,
"",
"",
Expand Down
2 changes: 1 addition & 1 deletion cmd/configuration_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"log"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"syscall"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
Expand Down
9 changes: 4 additions & 5 deletions cmd/utils_asserter_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"log"
"time"

"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,9 +52,9 @@ func runCreateConfigurationCmd(cmd *cobra.Command, args []string) {
)

// Initialize the fetcher's asserter
_, _, err := newFetcher.InitializeAsserter(ctx)
if err != nil {
log.Fatalf("%s: failed to initialize asserter", err.Error())
_, _, fetchErr := newFetcher.InitializeAsserter(ctx)
if fetchErr != nil {
log.Fatalf("%s: failed to initialize asserter", fetchErr.Err.Error())
}

configuration, err := newFetcher.Asserter.ClientConfiguration()
Expand Down
17 changes: 8 additions & 9 deletions cmd/view_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import (
"strconv"
"time"

"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -67,12 +66,12 @@ func runViewAccountCmd(cmd *cobra.Command, args []string) {
)

// Initialize the fetcher's asserter
_, _, err := newFetcher.InitializeAsserter(ctx)
if err != nil {
log.Fatal(err)
_, _, fetchErr := newFetcher.InitializeAsserter(ctx)
if fetchErr != nil {
log.Fatal(fetchErr.Err)
}

_, err = utils.CheckNetworkSupported(ctx, Config.Network, newFetcher)
_, err := utils.CheckNetworkSupported(ctx, Config.Network, newFetcher)
if err != nil {
log.Fatalf("%s: unable to confirm network is supported", err.Error())
}
Expand All @@ -87,14 +86,14 @@ func runViewAccountCmd(cmd *cobra.Command, args []string) {
lookupBlock = &types.PartialBlockIdentifier{Index: &index}
}

block, amounts, coins, metadata, err := newFetcher.AccountBalanceRetry(
block, amounts, coins, metadata, fetchErr := newFetcher.AccountBalanceRetry(
ctx,
Config.Network,
account,
lookupBlock,
)
if err != nil {
log.Fatal(fmt.Errorf("%w: unable to fetch account %+v", err, account))
if fetchErr != nil {
log.Fatal(fmt.Errorf("%w: unable to fetch account %+v", fetchErr.Err, account))
}

log.Printf("Amounts: %s\n", types.PrettyPrintStruct(amounts))
Expand Down
15 changes: 7 additions & 8 deletions cmd/view_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import (
"strconv"
"time"

"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/parser"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -66,9 +65,9 @@ func runViewBlockCmd(cmd *cobra.Command, args []string) {
// Behind the scenes this makes a call to get the
// network status and uses the response to inform
// the asserter what are valid responses.
_, _, err = newFetcher.InitializeAsserter(ctx)
if err != nil {
log.Fatal(err)
_, _, fetchErr := newFetcher.InitializeAsserter(ctx)
if fetchErr != nil {
log.Fatal(fetchErr.Err)
}

_, err = utils.CheckNetworkSupported(ctx, Config.Network, newFetcher)
Expand All @@ -85,15 +84,15 @@ func runViewBlockCmd(cmd *cobra.Command, args []string) {
// the client directly, you will need to implement a mechanism
// to fully populate the block by fetching all these
// transactions.
block, err := newFetcher.BlockRetry(
block, fetchErr := newFetcher.BlockRetry(
ctx,
Config.Network,
&types.PartialBlockIdentifier{
Index: &index,
},
)
if err != nil {
log.Fatal(fmt.Errorf("%w: unable to fetch block", err))
if fetchErr != nil {
log.Fatal(fmt.Errorf("%w: unable to fetch block", fetchErr.Err))
}

log.Printf("Current Block: %s\n", types.PrettyPrintStruct(block))
Expand Down
18 changes: 9 additions & 9 deletions cmd/view_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func runViewNetworksCmd(cmd *cobra.Command, args []string) {
)

// Attempt to fetch network list
networkList, err := f.NetworkListRetry(ctx, nil)
if err != nil {
log.Fatalf("%s: unable to fetch network list", err.Error())
networkList, fetchErr := f.NetworkListRetry(ctx, nil)
if fetchErr != nil {
log.Fatalf("%s: unable to fetch network list", fetchErr.Err.Error())
}

if len(networkList.NetworkIdentifiers) == 0 {
Expand All @@ -60,24 +60,24 @@ func runViewNetworksCmd(cmd *cobra.Command, args []string) {

for _, network := range networkList.NetworkIdentifiers {
color.Cyan(types.PrettyPrintStruct(network))
networkOptions, err := f.NetworkOptions(
networkOptions, fetchErr := f.NetworkOptions(
ctx,
network,
nil,
)
if err != nil {
log.Fatalf("%s: unable to get network options", err.Error())
if fetchErr != nil {
log.Fatalf("%s: unable to get network options", fetchErr.Err.Error())
}

log.Printf("Network options: %s\n", types.PrettyPrintStruct(networkOptions))

networkStatus, err := f.NetworkStatusRetry(
networkStatus, fetchErr := f.NetworkStatusRetry(
ctx,
network,
nil,
)
if err != nil {
log.Fatalf("%s: unable to get network status", err.Error())
if fetchErr != nil {
log.Fatalf("%s: unable to get network status", fetchErr.Err.Error())
}

log.Printf("Network status: %s\n", types.PrettyPrintStruct(networkStatus))
Expand Down
11 changes: 3 additions & 8 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"math/big"

"github.com/coinbase/rosetta-cli/pkg/scenario"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/storage"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/fatih/color"
)

Expand Down Expand Up @@ -224,13 +225,7 @@ type ConstructionConfiguration struct {

// PrefundedAccounts is an array of prefunded accounts
// to use while testing.
PrefundedAccounts []*PrefundedAccount `json:"prefunded_accounts"`
}

type PrefundedAccount struct {
PrivateKeyHex string `json:"privkey"`
Address string `json:"address"`
CurveType types.CurveType `json:"curve_type"`
PrefundedAccounts []*storage.PrefundedAccount `json:"prefunded_accounts"`
}

// DefaultConstructionConfiguration returns the *ConstructionConfiguration
Expand Down
8 changes: 4 additions & 4 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"os"
"testing"

"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/storage"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/coinbase/rosetta-sdk-go/utils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -108,8 +108,8 @@ var (

invalidPrefundedAccounts = &Configuration{
Construction: &ConstructionConfiguration{
PrefundedAccounts: []*PrefundedAccount{
&PrefundedAccount{
PrefundedAccounts: []*storage.PrefundedAccount{
{
PrivateKeyHex: "hello",
},
},
Expand Down
12 changes: 2 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@ module github.com/coinbase/rosetta-cli
go 1.13

require (
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200812042923-73d638d69870
github.com/dgraph-io/badger/v2 v2.0.1-rc1.0.20200811071800-b22eccb04321
github.com/ethereum/go-ethereum v1.9.18
github.com/coinbase/rosetta-sdk-go v0.3.5-0.20200817175934-2ce9b255ab7d
github.com/fatih/color v1.9.0
github.com/golang/protobuf v1.4.2 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/kr/pretty v0.2.0 // indirect
github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.6.1
github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
)
Loading