Skip to content

Commit

Permalink
Use types not models
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Apr 10, 2020
1 parent d542597 commit 68ba2cd
Show file tree
Hide file tree
Showing 82 changed files with 613 additions and 626 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: deps gen lint format check-format test test-coverage add-license \
check-license shorten-lines shellcheck salus release
LICENCE_SCRIPT=addlicense -c "Coinbase, Inc." -l "apache" -v
GO_PACKAGES=./asserter/... ./fetcher/... ./models/... ./client/... ./server/...
GO_PACKAGES=./asserter/... ./fetcher/... ./types/... ./client/... ./server/...
GO_FOLDERS=$(shell echo ${GO_PACKAGES} | sed -e "s/\.\///g" | sed -e "s/\/\.\.\.//g")
TEST_SCRIPT=go test -v ${GO_PACKAGES}
LINT_SETTINGS=golint,misspell,gocyclo,gocritic,whitespace,goconst,gocognit,bodyclose,unconvert,lll,unparam
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ and wallets to integrate with much less communication overhead
and network-specific work.

## Packages
* [Models](models): Auto-generated Rosetta models
* [Types](types): Auto-generated Rosetta types
* [Client](client): Low-level communication with any Rosetta server
* [Server](server): Simplified Rosetta server development
* [Asserter](asserter): Validation of Rosetta models
* [Asserter](asserter): Validation of Rosetta types
* [Fetcher](fetcher): Simplified and validated communication with
any Rosetta server

Expand All @@ -33,7 +33,7 @@ The packages listed above are demoed extensively in

## Development
* `make deps` to install dependencies
* `make gen` to generate models and helpers
* `make gen` to generate types and helpers
* `make test` to run tests
* `make lint` to lint the source code (including generated code)
* `make release` to check if code passes all tests run by CircleCI
Expand Down
2 changes: 1 addition & 1 deletion asserter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GoDoc](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=shield)](https://pkg.go.dev/github.com/coinbase/rosetta-sdk-go/asserter?tab=doc)

The Asserter package is used to validate the correctness of Rosetta models. It is
The Asserter package is used to validate the correctness of Rosetta types. It is
important to note that this validation only ensures that required fields are
populated, fields are in the correct format, and transaction operations only
contain types and statuses specified in the /network/status endpoint.
Expand Down
42 changes: 21 additions & 21 deletions asserter/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import (
"fmt"
"reflect"

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

// containsAccountIdentifier returns a boolean indicating if a
// *models.AccountIdentifier is contained within a slice of
// *models.AccountIdentifier. The check for equality takes
// into account everything within the models.AccountIdentifier
// *types.AccountIdentifier is contained within a slice of
// *types.AccountIdentifier. The check for equality takes
// into account everything within the types.AccountIdentifier
// struct (including the SubAccountIdentifier).
func containsAccountIdentifier(
identifiers []*models.AccountIdentifier,
identifier *models.AccountIdentifier,
identifiers []*types.AccountIdentifier,
identifier *types.AccountIdentifier,
) bool {
for _, ident := range identifiers {
if reflect.DeepEqual(ident, identifier) {
Expand All @@ -40,11 +40,11 @@ func containsAccountIdentifier(
}

// containsCurrency returns a boolean indicating if a
// *models.Currency is contained within a slice of
// *models.Currency. The check for equality takes
// into account everything within the models.Currency
// *types.Currency is contained within a slice of
// *types.Currency. The check for equality takes
// into account everything within the types.Currency
// struct (including currency.Metadata).
func containsCurrency(currencies []*models.Currency, currency *models.Currency) bool {
func containsCurrency(currencies []*types.Currency, currency *types.Currency) bool {
for _, curr := range currencies {
if reflect.DeepEqual(curr, currency) {
return true
Expand All @@ -55,12 +55,12 @@ func containsCurrency(currencies []*models.Currency, currency *models.Currency)
}

// assertBalanceAmounts returns an error if a slice
// of models.Amount returned as an models.AccountIdentifier's
// of types.Amount returned as an types.AccountIdentifier's
// balance is invalid. It is considered invalid if the same
// currency is returned multiple times (these shoould be
// consolidated) or if a models.Amount is considered invalid.
func assertBalanceAmounts(amounts []*models.Amount) error {
currencies := make([]*models.Currency, 0)
// consolidated) or if a types.Amount is considered invalid.
func assertBalanceAmounts(amounts []*types.Amount) error {
currencies := make([]*types.Currency, 0)
for _, amount := range amounts {
// Ensure a currency is used at most once in balance.Amounts
if containsCurrency(currencies, amount.Currency) {
Expand All @@ -77,19 +77,19 @@ func assertBalanceAmounts(amounts []*models.Amount) error {
}

// AccountBalance returns an error if the provided
// models.BlockIdentifier is invalid, if the same
// models.AccountIdentifier appears in multiple
// models.Balance structs (should be consolidated),
// or if a models.Balance is considered invalid.
// types.BlockIdentifier is invalid, if the same
// types.AccountIdentifier appears in multiple
// types.Balance structs (should be consolidated),
// or if a types.Balance is considered invalid.
func AccountBalance(
block *models.BlockIdentifier,
balances []*models.Balance,
block *types.BlockIdentifier,
balances []*types.Balance,
) error {
if err := BlockIdentifier(block); err != nil {
return err
}

accounts := make([]*models.AccountIdentifier, 0)
accounts := make([]*types.AccountIdentifier, 0)
for _, balance := range balances {
if err := AccountIdentifier(balance.AccountIdentifier); err != nil {
return err
Expand Down
Loading

0 comments on commit 68ba2cd

Please sign in to comment.