Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed May 6, 2020
1 parent 360392d commit 7c5d199
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 72 deletions.
7 changes: 6 additions & 1 deletion cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ func loadAccounts(filePath string) ([]*reconciler.AccountCurrency, error) {
return nil, err
}

log.Printf("Found %d accounts at %s: %s\n", len(accounts), filePath, types.PrettyPrintStruct(accounts))
log.Printf(
"Found %d accounts at %s: %s\n",
len(accounts),
filePath,
types.PrettyPrintStruct(accounts),
)

return accounts, nil
}
Expand Down
69 changes: 69 additions & 0 deletions cmd/create_configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 cmd

import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path"

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

const (
fileMode = 0600
)

var (
createConfigurationCmd = &cobra.Command{
Use: "create:configuration",
Short: "",
Long: ``,
Run: runCreateConfigurationCmd,
Args: cobra.ExactArgs(1),
}
)

func runCreateConfigurationCmd(cmd *cobra.Command, args []string) {
ctx := context.Background()

// Create a new fetcher
newFetcher := fetcher.New(
ServerURL,
)

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

configuration, err := newFetcher.Asserter.ClientConfiguration()
if err != nil {
log.Fatal(fmt.Errorf("%w: unable to generate spec", err))
}

specString := types.PrettyPrintStruct(configuration)
log.Printf("Spec File: %s\n", specString)

if err := ioutil.WriteFile(path.Clean(args[0]), []byte(specString), os.FileMode(fileMode)); err != nil {
log.Fatal(err)
}
}
51 changes: 0 additions & 51 deletions cmd/create_spec.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func init() {
rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(viewBlockCmd)
rootCmd.AddCommand(viewAccountCmd)
rootCmd.AddCommand(createSpecCmd)
rootCmd.AddCommand(createConfigurationCmd)
}
14 changes: 14 additions & 0 deletions cmd/view_account.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 cmd

import (
Expand Down
14 changes: 14 additions & 0 deletions cmd/view_block.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 cmd

import (
Expand Down
14 changes: 14 additions & 0 deletions internal/processor/reconciler_handler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
14 changes: 14 additions & 0 deletions internal/processor/reconciler_helper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
14 changes: 14 additions & 0 deletions internal/processor/storage_helper.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
30 changes: 21 additions & 9 deletions internal/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type BalanceChange struct {
Difference string `json:"difference,omitempty"`
}

type ReconcilerHelper interface {
type Helper interface {
BlockExists(
ctx context.Context,
block *types.BlockIdentifier,
Expand All @@ -118,7 +118,7 @@ type ReconcilerHelper interface {
) (*types.Amount, *types.BlockIdentifier, error)
}

type ReconcilerHandler interface {
type Handler interface {
ReconciliationFailed(
ctx context.Context,
reconciliationType string,
Expand All @@ -144,8 +144,8 @@ type ReconcilerHandler interface {
// by a Rosetta Server.
type Reconciler struct {
network *types.NetworkIdentifier
helper ReconcilerHelper
handler ReconcilerHandler
helper Helper
handler Handler
fetcher *fetcher.Fetcher
accountConcurrency uint64
lookupBalanceByBlock bool
Expand All @@ -169,8 +169,8 @@ type Reconciler struct {
// NewReconciler creates a new Reconciler.
func NewReconciler(
network *types.NetworkIdentifier,
helper ReconcilerHelper,
handler ReconcilerHandler,
helper Helper,
handler Handler,
fetcher *fetcher.Fetcher,
accountConcurrency uint64,
lookupBalanceByBlock bool,
Expand Down Expand Up @@ -277,7 +277,10 @@ func (r *Reconciler) CompareBalance(
// Head block should be set before we CompareBalance
head, err := r.helper.CurrentBlock(ctx)
if err != nil {
return zeroString, "", 0, fmt.Errorf("%w: unable to get current block for reconciliation", err)
return zeroString, "", 0, fmt.Errorf(
"%w: unable to get current block for reconciliation",
err,
)
}

// Check if live block is < head (or wait)
Expand All @@ -293,7 +296,11 @@ func (r *Reconciler) CompareBalance(
// Check if live block is in store (ensure not reorged)
exists, err := r.helper.BlockExists(ctx, liveBlock)
if err != nil {
return zeroString, "", 0, fmt.Errorf("%w: unable to check if block exists: %+v", err, liveBlock)
return zeroString, "", 0, fmt.Errorf(
"%w: unable to check if block exists: %+v",
err,
liveBlock,
)
}
if !exists {
return zeroString, "", head.Index, fmt.Errorf(
Expand All @@ -311,7 +318,12 @@ func (r *Reconciler) CompareBalance(
head,
)
if err != nil {
return zeroString, "", head.Index, fmt.Errorf("%w: unable to get cached balance for %+v:%+v", err, account, currency)
return zeroString, "", head.Index, fmt.Errorf(
"%w: unable to get cached balance for %+v:%+v",
err,
account,
currency,
)
}

if liveBlock.Index < balanceBlock.Index {
Expand Down
12 changes: 8 additions & 4 deletions internal/storage/block_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func GetBalanceKey(account *types.AccountIdentifier, currency *types.Currency) [
)
}

type BlockStorageHelper interface {
type Helper interface {
AccountBalance(
ctx context.Context,
account *types.AccountIdentifier,
Expand All @@ -142,14 +142,14 @@ type BlockStorageHelper interface {
// on top of a Database and DatabaseTransaction interface.
type BlockStorage struct {
db Database
helper BlockStorageHelper
helper Helper
}

// NewBlockStorage returns a new BlockStorage.
func NewBlockStorage(
ctx context.Context,
db Database,
helper BlockStorageHelper,
helper Helper,
) *BlockStorage {
return &BlockStorage{
db: db,
Expand Down Expand Up @@ -420,7 +420,11 @@ func (b *BlockStorage) SetNewStartIndex(
}

if head.Index < startIndex {
return fmt.Errorf("last processed block %d is less than start index %d", head.Index, startIndex)
return fmt.Errorf(
"last processed block %d is less than start index %d",
head.Index,
startIndex,
)
}

currBlock := head
Expand Down
Loading

0 comments on commit 7c5d199

Please sign in to comment.