Skip to content

Commit

Permalink
Merge pull request #93 from coinbase/patrick/export-internal
Browse files Browse the repository at this point in the history
Export Internal Packages + Miscellaneous Bug Fixes
  • Loading branch information
patrick-ogrady authored Aug 8, 2020
2 parents e76f136 + 5e2bc38 commit 0edccc4
Show file tree
Hide file tree
Showing 47 changed files with 244 additions and 108 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ ADDLICENSE_CMD=go run github.com/google/addlicense
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/... ./internal/constructor/... \
./internal/logger/... ./internal/scenario/... \
./internal/statefulsyncer/... ./internal/storage/... \
./internal/tester/... ./internal/utils/...
TEST_SCRIPT=go test -v ./internal/... ./configuration/...
COVERAGE_TEST_DIRECTORIES=./configuration/... ./pkg/constructor/... \
./pkg/logger/... ./pkg/scenario/... \
./pkg/statefulsyncer/... ./pkg/storage/... \
./pkg/tester/... ./pkg/utils/...
TEST_SCRIPT=go test -v ./pkg/... ./configuration/...
COVERAGE_TEST_SCRIPT=go test -v ${COVERAGE_TEST_DIRECTORIES}

deps:
Expand Down Expand Up @@ -44,7 +44,7 @@ check-license:
${ADDLICENCE_SCRIPT} -check .

shorten-lines:
${GOLINES_CMD} -w --shorten-comments internal cmd configuration
${GOLINES_CMD} -w --shorten-comments pkg cmd configuration

salus:
docker run --rm -t -v ${PWD}:/home/repo coinbase/salus
Expand All @@ -59,4 +59,5 @@ install:

mocks:
rm -rf mocks;
mockery --dir internal/constructor --all --case underscore --outpkg constructor --output mocks/constructor;
mockery --dir pkg/constructor --all --case underscore --outpkg constructor --output mocks/constructor;
${ADDLICENCE_SCRIPT} .;
4 changes: 2 additions & 2 deletions cmd/check_construction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"os"
"time"

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

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/fatih/color"
Expand Down
4 changes: 2 additions & 2 deletions cmd/check_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"log"
"time"

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

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/spf13/cobra"
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,7 +18,7 @@ import (
"log"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-cli/internal/utils"
"github.com/coinbase/rosetta-cli/pkg/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 @@ -24,7 +24,7 @@ import (
"time"

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

"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/utils_asserter_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"log"
"time"

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

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/view_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strconv"
"time"

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

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/fetcher"
Expand Down
2 changes: 1 addition & 1 deletion cmd/view_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strconv"
"time"

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

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/parser"
Expand Down
18 changes: 15 additions & 3 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"log"
"math/big"

"github.com/coinbase/rosetta-cli/internal/scenario"
"github.com/coinbase/rosetta-cli/internal/utils"
"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/types"
Expand Down Expand Up @@ -322,6 +322,12 @@ type DataConfiguration struct {
// consistency.
BalanceTrackingDisabled bool `json:"balance_tracking_disabled"`

// CoinTrackingDisabled is a boolean that indicates coin (or UTXO) tracking
// should not be attempted. When first testing an implemenation, it can be
// useful to just try to fetch all blocks before checking for coin
// consistency.
CoinTrackingDisabled bool `json:"coin_tracking_disabled"`

// EndCondition contains the conditions for the syncer to stop
EndConditions *EndConditions `json:"end_conditions,omitempty"`
}
Expand Down Expand Up @@ -358,6 +364,10 @@ type Configuration struct {
// that uses more memory.
DisableMemoryLimit bool `json:"disable_memory_limit"`

// LogConfiguration determines if the configuration settings
// should be printed to the console when a file is loaded.
LogConfiguration bool `json:"log_configuration"`

Construction *ConstructionConfiguration `json:"construction"`
Data *DataConfiguration `json:"data"`
}
Expand Down Expand Up @@ -550,7 +560,9 @@ func LoadConfiguration(filePath string) (*Configuration, error) {
filePath,
)

log.Println(types.PrettyPrintStruct(config))
if config.LogConfiguration {
log.Println(types.PrettyPrintStruct(config))
}

return config, nil
}
2 changes: 1 addition & 1 deletion configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"os"
"testing"

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

"github.com/coinbase/rosetta-sdk-go/types"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion mocks/constructor/helper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"time"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-cli/internal/logger"
"github.com/coinbase/rosetta-cli/internal/scenario"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/internal/utils"
"github.com/coinbase/rosetta-cli/pkg/logger"
"github.com/coinbase/rosetta-cli/pkg/scenario"
"github.com/coinbase/rosetta-cli/pkg/storage"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/keys"
"github.com/coinbase/rosetta-sdk-go/parser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"time"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-cli/internal/scenario"
"github.com/coinbase/rosetta-cli/internal/storage"
mocks "github.com/coinbase/rosetta-cli/mocks/constructor"
"github.com/coinbase/rosetta-cli/pkg/scenario"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/parser"
Expand Down
6 changes: 3 additions & 3 deletions internal/logger/logger.go → pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"os"
"path"

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

"github.com/coinbase/rosetta-sdk-go/parser"
"github.com/coinbase/rosetta-sdk-go/reconciler"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package processor
import (
"context"

"github.com/coinbase/rosetta-cli/internal/logger"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/logger"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/parser"
"github.com/coinbase/rosetta-sdk-go/reconciler"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"fmt"

"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/fetcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"math/big"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/parser"
"github.com/coinbase/rosetta-sdk-go/types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"fmt"

"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/types"
Expand Down
45 changes: 45 additions & 0 deletions pkg/processor/coin_storage_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2020 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package processor

import (
"context"

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

"github.com/coinbase/rosetta-sdk-go/types"
)

var _ storage.CoinStorageHelper = (*CoinStorageHelper)(nil)

// CoinStorageHelper implements the storage.CoinStorageHelper
// interface.
type CoinStorageHelper struct {
blockStorage *storage.BlockStorage
}

// NewCoinStorageHelper returns a new *CoinStorageHelper.
func NewCoinStorageHelper(blockStorage *storage.BlockStorage) *CoinStorageHelper {
return &CoinStorageHelper{blockStorage: blockStorage}
}

// CurrentBlockIdentifier returns the head *types.BlockIdentifier in
// the context of a storage.DatabaseTransaction.
func (c *CoinStorageHelper) CurrentBlockIdentifier(
ctx context.Context,
transaction storage.DatabaseTransaction,
) (*types.BlockIdentifier, error) {
return c.blockStorage.GetHeadBlockIdentifierTransactional(ctx, transaction)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"context"
"math/big"

"github.com/coinbase/rosetta-cli/internal/constructor"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/constructor"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/types"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"fmt"
"math/big"

"github.com/coinbase/rosetta-cli/internal/constructor"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/internal/utils"
"github.com/coinbase/rosetta-cli/pkg/constructor"
"github.com/coinbase/rosetta-cli/pkg/storage"
"github.com/coinbase/rosetta-cli/pkg/utils"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/keys"
Expand Down Expand Up @@ -216,7 +216,13 @@ func (c *ConstructorHelper) CoinBalance(
accountIdentifier *types.AccountIdentifier,
currency *types.Currency,
) (*big.Int, *types.CoinIdentifier, error) {
return c.coinStorage.GetLargestCoin(ctx, accountIdentifier, currency)
coinValue, coinIdentifier, _, err := c.coinStorage.GetLargestCoin(
ctx,
accountIdentifier,
currency,
)

return coinValue, coinIdentifier, err
}

// LockedAddresses returns a slice of all addresses currently sending or receiving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"errors"
"math/big"

"github.com/coinbase/rosetta-cli/internal/logger"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/logger"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/reconciler"
"github.com/coinbase/rosetta-sdk-go/types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"errors"

"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/types"
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"math/big"
"time"

"github.com/coinbase/rosetta-cli/internal/logger"
"github.com/coinbase/rosetta-cli/internal/storage"
"github.com/coinbase/rosetta-cli/pkg/logger"
"github.com/coinbase/rosetta-cli/pkg/storage"

"github.com/coinbase/rosetta-sdk-go/fetcher"
"github.com/coinbase/rosetta-sdk-go/syncer"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"testing"

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

"github.com/stretchr/testify/assert"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"log"
"math/big"

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

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/parser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"path"
"testing"

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

"github.com/coinbase/rosetta-sdk-go/asserter"
"github.com/coinbase/rosetta-sdk-go/parser"
Expand Down
Loading

0 comments on commit 0edccc4

Please sign in to comment.