Skip to content

Commit

Permalink
Merge pull request #53 from ElrondNetwork/lint-grammar-fixes
Browse files Browse the repository at this point in the history
linter and grammar fixes
  • Loading branch information
bogdan-rosianu authored Oct 11, 2022
2 parents 6e6122e + 1906689 commit 6b92c67
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 68 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In order to set up Rosetta using Docker, use [ElrondNetwork/rosetta-docker](http

### Setup an Observer

Follow the official documentation to setup an observer:
Follow the official documentation to set up an observer:
- [mainnet](https://docs.elrond.com/validators/mainnet/config-scripts/)
- [devnet](https://docs.elrond.com/validators/elrond-go-scripts/config-scripts/)

Expand Down Expand Up @@ -49,7 +49,7 @@ Furthermore, adjust `config/config.toml`, as follows:

### Setup Observer's database

In order to set up a database supporting historical balances lookup, please follow the instructions in section [Setup a database](#setup-a-database).
In order to set up a database supporting historical balances lookup, please follow the instructions in section [Set up a database](#setup-a-database).

### Setup Rosetta

Expand Down Expand Up @@ -85,7 +85,7 @@ Or, in order to start using the `offline` mode:

## Setup a database

In order to support historical balances lookup, Rosetta has to connect to an Observer whose database contains _non-pruned accounts tries_. Such databases can be re-built locally or downloaded from the Elrond public archive - the URL being available [on request](https://t.me/ElrondDevelopers).
In order to support historical balances' lookup, Rosetta has to connect to an Observer whose database contains _non-pruned accounts tries_. Such databases can be re-built locally or downloaded from the Elrond public archive - the URL being available [on request](https://t.me/ElrondDevelopers).

### Build archives

Expand Down
4 changes: 2 additions & 2 deletions server/factory/components/disabledExternalConnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ type DisabledExternalStorageConnector struct {
}

// GetTransactionsByAddress returns nothing
func (connector *DisabledExternalStorageConnector) GetTransactionsByAddress(address string) ([]data.DatabaseTransaction, error) {
func (connector *DisabledExternalStorageConnector) GetTransactionsByAddress(_ string) ([]data.DatabaseTransaction, error) {
return make([]data.DatabaseTransaction, 0), nil
}

// GetAtlasBlockByShardIDAndNonce returns nothing
func (connector *DisabledExternalStorageConnector) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) {
func (connector *DisabledExternalStorageConnector) GetAtlasBlockByShardIDAndNonce(_ uint32, _ uint64) (data.AtlasBlock, error) {
return data.AtlasBlock{}, nil
}

Expand Down
28 changes: 13 additions & 15 deletions server/factory/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ func CreateControllers(networkProvider services.NetworkProvider) ([]server.Route
func createOfflineControllers(networkProvider services.NetworkProvider) ([]server.Router, error) {
log.Info("createOfflineControllers()")

asserter, err := createAsserter(networkProvider)
asserterInstance, err := createAsserter(networkProvider)
if err != nil {
return nil, err
}

offlineService := services.NewOfflineService()

networkService := services.NewNetworkService(networkProvider)
networkController := server.NewNetworkAPIController(networkService, asserter)
networkController := server.NewNetworkAPIController(networkService, asserterInstance)

accountController := server.NewAccountAPIController(offlineService, asserter)
blockController := server.NewBlockAPIController(offlineService, asserter)
mempoolController := server.NewMempoolAPIController(offlineService, asserter)
accountController := server.NewAccountAPIController(offlineService, asserterInstance)
blockController := server.NewBlockAPIController(offlineService, asserterInstance)
mempoolController := server.NewMempoolAPIController(offlineService, asserterInstance)

constructionService := services.NewConstructionService(networkProvider)
constructionController := server.NewConstructionAPIController(constructionService, asserter)
constructionController := server.NewConstructionAPIController(constructionService, asserterInstance)

return []server.Router{
networkController,
Expand All @@ -47,25 +47,25 @@ func createOfflineControllers(networkProvider services.NetworkProvider) ([]serve
func createOnlineControllers(networkProvider services.NetworkProvider) ([]server.Router, error) {
log.Info("createOnlineControllers()")

asserter, err := createAsserter(networkProvider)
asserterInstance, err := createAsserter(networkProvider)
if err != nil {
return nil, err
}

networkService := services.NewNetworkService(networkProvider)
networkController := server.NewNetworkAPIController(networkService, asserter)
networkController := server.NewNetworkAPIController(networkService, asserterInstance)

accountService := services.NewAccountService(networkProvider)
accountController := server.NewAccountAPIController(accountService, asserter)
accountController := server.NewAccountAPIController(accountService, asserterInstance)

blockService := services.NewBlockService(networkProvider)
blockController := server.NewBlockAPIController(blockService, asserter)
blockController := server.NewBlockAPIController(blockService, asserterInstance)

mempoolService := services.NewMempoolService(networkProvider)
mempoolController := server.NewMempoolAPIController(mempoolService, asserter)
mempoolController := server.NewMempoolAPIController(mempoolService, asserterInstance)

constructionService := services.NewConstructionService(networkProvider)
constructionController := server.NewConstructionAPIController(constructionService, asserter)
constructionController := server.NewConstructionAPIController(constructionService, asserterInstance)

return []server.Router{
networkController,
Expand All @@ -77,12 +77,10 @@ func createOnlineControllers(networkProvider services.NetworkProvider) ([]server
}

func createAsserter(networkProvider services.NetworkProvider) (*asserter.Asserter, error) {
isHistoricalBalancesLookupEnabled := true

// The asserter automatically rejects incorrectly formatted requests.
asserterServer, err := asserter.NewServer(
services.SupportedOperationTypes,
isHistoricalBalancesLookupEnabled,
true, // isHistoricalBalancesLookupEnabled := true
[]*types.NetworkIdentifier{
{
Blockchain: networkProvider.GetBlockchainName(),
Expand Down
3 changes: 2 additions & 1 deletion server/factory/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/ElrondNetwork/rosetta/server/resources"
)

type networkProvider interface {
// NetworkProvider defines the actions that need to be performed by the component that handles network data fetching
type NetworkProvider interface {
IsOffline() bool
GetBlockchainName() string
GetNativeCurrency() resources.NativeCurrency
Expand Down
2 changes: 1 addition & 1 deletion server/factory/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ArgsCreateNetworkProvider struct {
}

// CreateNetworkProvider creates a network provider
func CreateNetworkProvider(args ArgsCreateNetworkProvider) (networkProvider, error) {
func CreateNetworkProvider(args ArgsCreateNetworkProvider) (NetworkProvider, error) {
shardCoordinator, err := sharding.NewMultiShardCoordinator(args.NumShards, args.ObservedActualShard)
if err != nil {
return nil, err
Expand Down
8 changes: 0 additions & 8 deletions server/provider/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,3 @@ var (
genesisBlockNonce = 0
blocksCacheCapacity = 256
)

type MiniblockProcessingType string

const (
Normal MiniblockProcessingType = "Normal"
Scheduled MiniblockProcessingType = "Scheduled"
Processed MiniblockProcessingType = "Processed"
)
2 changes: 1 addition & 1 deletion server/provider/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func newErrCannotGetTransaction(hash string, innerError error) error {
}

// In elrond-proxy-go, the function CallGetRestEndPoint() returns an error message as the JSON content of the erroneous HTTP response.
// Here, we attept to decode that JSON and create an error with a "flat" error message.
// Here, we attempt to decode that JSON and create an error with a "flat" error message.
func convertStructuredApiErrToFlatErr(apiErr error) error {
structuredApiErr := &structuredApiError{}
err := json.Unmarshal([]byte(apiErr.Error()), structuredApiErr)
Expand Down
6 changes: 3 additions & 3 deletions server/provider/networkProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type networkProvider struct {

func NewNetworkProvider(args ArgsNewNetworkProvider) (*networkProvider, error) {
// Since for each block N we also have to fetch block N-1 and block N+1 (see "simplifyBlockWithScheduledTransactions"),
// it makes sense to cache the block response (using a LRU cache).
// it makes sense to cache the block response (using an LRU cache).
blocksCache, err := lrucache.NewCache(blocksCacheCapacity)
if err != nil {
return nil, err
Expand Down Expand Up @@ -350,14 +350,14 @@ func (provider *networkProvider) ComputeReceiptHash(apiReceipt *transaction.ApiR
return "", err
}

receipt := &receipt.Receipt{
receiptObj := &receipt.Receipt{
TxHash: txHash,
SndAddr: senderPubkey,
Value: apiReceipt.Value,
Data: []byte(apiReceipt.Data),
}

receiptHash, err := core.CalculateHash(provider.marshalizerForHashing, provider.hasher, receipt)
receiptHash, err := core.CalculateHash(provider.marshalizerForHashing, provider.hasher, receiptObj)
if err != nil {
return "", err
}
Expand Down
8 changes: 4 additions & 4 deletions server/services/networkProviderExtension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ func TestNetworkProviderExtension_ValueToNativeAmount(t *testing.T) {
extension := newNetworkProviderExtension(networkProvider)

amount := extension.valueToNativeAmount("1")
expecteAmount := &types.Amount{
expectedAmount := &types.Amount{
Value: "1",
Currency: &types.Currency{
Symbol: "EGLD",
Decimals: 18,
},
}

require.Equal(t, expecteAmount, amount)
require.Equal(t, expectedAmount, amount)
}

func TestNetworkProviderExtension_ValueToCustomAmount(t *testing.T) {
networkProvider := testscommon.NewNetworkProviderMock()
extension := newNetworkProviderExtension(networkProvider)

amount := extension.valueToCustomAmount("1", "ABC-abcdef")
expecteAmount := &types.Amount{
expectedAmount := &types.Amount{
Value: "1",
Currency: &types.Currency{
Symbol: "ABC-abcdef",
},
}

require.Equal(t, expecteAmount, amount)
require.Equal(t, expectedAmount, amount)
}
2 changes: 1 addition & 1 deletion server/services/offline_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (service *offlineService) Block(
}

// BlockTransaction - not implemented
// We dont need this method because all transactions are returned by method Block
// We don't need this method because all transactions are returned by method Block
func (service *offlineService) BlockTransaction(
_ context.Context,
_ *types.BlockTransactionRequest,
Expand Down
2 changes: 1 addition & 1 deletion server/services/transactionsTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (transformer *transactionsTransformer) mempoolMoveBalanceTxToRosettaTx(tx *
}
}

func (transformer *transactionsTransformer) addOperationsGivenTransactionEvents(tx *transaction.ApiTransactionResult, rosettaTx *types.Transaction) error {
func (transformer *transactionsTransformer) addOperationsGivenTransactionEvents(_ *transaction.ApiTransactionResult, _ *types.Transaction) error {
// TBD: uncomment when applicable ("transferValueOnly" events duplicate the information of SCRs in most contexts)
// err := transformer.addOperationsGivenEventTransferValueOnly(tx, rosettaTx)
// if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/services/transactionsTransformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func TestTransactionsTransformer_UnsignedTxToRosettaTx(t *testing.T) {

txsInBlock := []*transaction.ApiTransactionResult{refundTx, moveBalanceTx}

rosettaFefundTx := transformer.unsignedTxToRosettaTx(refundTx, txsInBlock)
rosettaRefundTx := transformer.unsignedTxToRosettaTx(refundTx, txsInBlock)
rosettaMoveBalanceTx := transformer.unsignedTxToRosettaTx(moveBalanceTx, txsInBlock)
require.Equal(t, expectedRefundTx, rosettaFefundTx)
require.Equal(t, expectedRefundTx, rosettaRefundTx)
require.Equal(t, expectedMoveBalanceTx, rosettaMoveBalanceTx)
}

Expand Down
14 changes: 0 additions & 14 deletions testscommon/addresses.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
package testscommon

import (
"encoding/hex"
)

var (
// TestAddressAlice is a test address
TestAddressAlice = "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
// TestPubKeyAlice is a test pubkey
TestPubKeyAlice, _ = RealWorldBech32PubkeyConverter.Decode(TestAddressAlice)
// TestPubKeyHexAlice is a test pubkey
TestPubKeyHexAlice = hex.EncodeToString(TestPubKeyAlice)

// TestAddressBob is a test address
TestAddressBob = "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx"
// TestPubKeyBob is a test pubkey
TestPubKeyBob, _ = RealWorldBech32PubkeyConverter.Decode(TestAddressBob)
// TestPubKeyHexBob is a test pubkey
TestPubKeyHexBob = hex.EncodeToString(TestPubKeyBob)

// TestAddressOfContract is a test address
TestAddressOfContract = "erd1qqqqqqqqqqqqqpgqfejaxfh4ktp8mh8s77pl90dq0uzvh2vk396qlcwepw"
// TestPubkeyOfContract is a test pubkey
TestPubkeyOfContract, _ = RealWorldBech32PubkeyConverter.Decode(TestAddressOfContract)
// TestPubkeyHexOfContract is a test pubkey
TestPubkeyHexOfContract = hex.EncodeToString(TestPubkeyOfContract)
)
12 changes: 6 additions & 6 deletions testscommon/networkProviderMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (mock *networkProviderMock) GetAccount(address string) (*resources.AccountO
return nil, fmt.Errorf("account %s not found", address)
}

func (mock *networkProviderMock) GetAccountNativeBalance(address string, options resources.AccountQueryOptions) (*resources.AccountNativeBalance, error) {
func (mock *networkProviderMock) GetAccountNativeBalance(address string, _ resources.AccountQueryOptions) (*resources.AccountNativeBalance, error) {
if mock.MockNextError != nil {
return nil, mock.MockNextError
}
Expand All @@ -223,7 +223,7 @@ func (mock *networkProviderMock) GetAccountNativeBalance(address string, options
return nil, fmt.Errorf("account %s not found", address)
}

func (mock *networkProviderMock) GetAccountESDTBalance(address string, tokenIdentifier string, options resources.AccountQueryOptions) (*resources.AccountESDTBalance, error) {
func (mock *networkProviderMock) GetAccountESDTBalance(address string, tokenIdentifier string, _ resources.AccountQueryOptions) (*resources.AccountESDTBalance, error) {
if mock.MockNextError != nil {
return nil, mock.MockNextError
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func (mock *networkProviderMock) ConvertAddressToPubKey(address string) ([]byte,
}

// ComputeTransactionHash -
func (mock *networkProviderMock) ComputeTransactionHash(tx *data.Transaction) (string, error) {
func (mock *networkProviderMock) ComputeTransactionHash(_ *data.Transaction) (string, error) {
if mock.MockNextError != nil {
return "", mock.MockNextError
}
Expand All @@ -288,7 +288,7 @@ func (mock *networkProviderMock) ComputeTransactionHash(tx *data.Transaction) (s
}

// ComputeReceiptHash -
func (mock *networkProviderMock) ComputeReceiptHash(apiReceipt *transaction.ApiReceipt) (string, error) {
func (mock *networkProviderMock) ComputeReceiptHash(_ *transaction.ApiReceipt) (string, error) {
if mock.MockNextError != nil {
return "", mock.MockNextError
}
Expand Down Expand Up @@ -325,9 +325,9 @@ func (mock *networkProviderMock) GetMempoolTransactionByHash(hash string) (*tran
return nil, mock.MockNextError
}

transaction, ok := mock.MockMempoolTransactionsByHash[hash]
transactionObj, ok := mock.MockMempoolTransactionsByHash[hash]
if ok {
return transaction, nil
return transactionObj, nil
}

return nil, nil
Expand Down
12 changes: 6 additions & 6 deletions testscommon/observerFacadeMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func (mock *observerFacadeMock) CallGetRestEndPoint(baseUrl string, path string,
return 0, mock.MockNextError
}

data, err := json.Marshal(mock.MockGetResponse)
marshalledData, err := json.Marshal(mock.MockGetResponse)
if err != nil {
return 500, err
}

err = json.Unmarshal(data, value)
err = json.Unmarshal(marshalledData, value)
if err != nil {
return 500, err
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (mock *observerFacadeMock) SendTransaction(tx *data.Transaction) (int, stri
}

// ComputeTransactionHash -
func (mock *observerFacadeMock) ComputeTransactionHash(tx *data.Transaction) (string, error) {
func (mock *observerFacadeMock) ComputeTransactionHash(_ *data.Transaction) (string, error) {
if mock.MockNextError != nil {
return "", mock.MockNextError
}
Expand All @@ -115,14 +115,14 @@ func (mock *observerFacadeMock) ComputeTransactionHash(tx *data.Transaction) (st
}

// GetTransactionByHashAndSenderAddress -
func (mock *observerFacadeMock) GetTransactionByHashAndSenderAddress(hash string, sender string, withEvents bool) (*transaction.ApiTransactionResult, int, error) {
func (mock *observerFacadeMock) GetTransactionByHashAndSenderAddress(hash string, _ string, _ bool) (*transaction.ApiTransactionResult, int, error) {
if mock.MockNextError != nil {
return nil, 0, mock.MockNextError
}

transaction, ok := mock.MockTransactionsByHash[hash]
transactionObj, ok := mock.MockTransactionsByHash[hash]
if ok {
return transaction, 0, mock.MockNextError
return transactionObj, 0, mock.MockNextError
}

return nil, 0, fmt.Errorf("transaction %s not found", hash)
Expand Down

0 comments on commit 6b92c67

Please sign in to comment.