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

Fix small code issues, simplify code #276

Merged
merged 1 commit into from
Dec 14, 2023
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: 2 additions & 2 deletions internal/blockchain/ethereum/besu/besu_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ func (p *BesuProvider) GetDockerServiceDefinitions() []*docker.ServiceDefinition
addresses := ""
for i, member := range p.stack.Members {
account := member.Account.(*ethereum.Account)
addresses = addresses + account.Address
addresses += account.Address
if i+1 < len(p.stack.Members) {
addresses = addresses + ","
addresses += ","
}
}
besuCommand := fmt.Sprintf(`--genesis-file=/data/genesis.json --network-id %d --rpc-http-enabled --rpc-http-api=ETH,NET,CLIQUE --host-allowlist="*" --rpc-http-cors-origins="all" --sync-mode=FULL --discovery-enabled=false --node-private-key-file=/data/nodeKey --min-gas-price=0`, p.stack.ChainID())
Expand Down
5 changes: 2 additions & 3 deletions internal/blockchain/ethereum/besu/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -64,7 +63,7 @@ type Alloc struct {

func (g *Genesis) WriteGenesisJson(filename string) error {
genesisJsonBytes, _ := json.MarshalIndent(g, "", " ")
if err := os.WriteFile(filepath.Join(filename), genesisJsonBytes, 0755); err != nil {
if err := os.WriteFile(filename, genesisJsonBytes, 0755); err != nil {
return err
}
return nil
Expand All @@ -80,7 +79,7 @@ func CreateGenesis(addresses []string, blockPeriod int, chainID int64) *Genesis
alloc[address] = &Alloc{
Balance: "0x200000000000000000000000000000000000000000000000000000000000000",
}
extraData = extraData + address
extraData += extraData
}
extraData = strings.ReplaceAll(fmt.Sprintf("%-236s", extraData), " ", "0")
return &Genesis{
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/ethereum/connector/ethconnect/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ethconnect
import (
"fmt"
"os"
"path/filepath"

"github.com/hyperledger/firefly-cli/internal/blockchain/ethereum/connector"
"github.com/hyperledger/firefly-cli/pkg/types"
Expand Down Expand Up @@ -59,7 +58,7 @@ type HTTP struct {

func (e *Config) WriteConfig(filename string, extraConnectorConfigPath string) error {
configYamlBytes, _ := yaml.Marshal(e)
if err := os.WriteFile(filepath.Join(filename), configYamlBytes, 0755); err != nil {
if err := os.WriteFile(filename, configYamlBytes, 0755); err != nil {
return err
}
if extraConnectorConfigPath != "" {
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/ethereum/connector/evmconnect/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package evmconnect
import (
"fmt"
"os"
"path/filepath"

"github.com/hyperledger/firefly-cli/internal/blockchain/ethereum/connector"
"github.com/hyperledger/firefly-cli/pkg/types"
Expand Down Expand Up @@ -76,7 +75,7 @@ type GasOracleConfig struct {

func (e *Config) WriteConfig(filename string, extraEvmconnectConfigPath string) error {
configYamlBytes, _ := yaml.Marshal(e)
if err := os.WriteFile(filepath.Join(filename), configYamlBytes, 0755); err != nil {
if err := os.WriteFile(filename, configYamlBytes, 0755); err != nil {
return err
}
if extraEvmconnectConfigPath != "" {
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/ethereum/ethsigner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ethsigner

import (
"os"
"path/filepath"

"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -65,7 +64,7 @@ type Config struct {

func (e *Config) WriteConfig(filename string) error {
configYamlBytes, _ := yaml.Marshal(e)
return os.WriteFile(filepath.Join(filename), configYamlBytes, 0755)
return os.WriteFile(filename, configYamlBytes, 0755)
}

func GenerateSignerConfig(chainID int64, rpcURL string) *Config {
Expand Down
5 changes: 2 additions & 3 deletions internal/blockchain/ethereum/geth/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -72,7 +71,7 @@ func CreateGenesis(addresses []string, blockPeriod int, chainID int64) *Genesis
alloc[address] = &Alloc{
Balance: "0x200000000000000000000000000000000000000000000000000000000000000",
}
extraData = extraData + address
extraData += address
}
extraData = strings.ReplaceAll(fmt.Sprintf("%-236s", extraData), " ", "0")

Expand Down Expand Up @@ -108,7 +107,7 @@ func CreateGenesis(addresses []string, blockPeriod int, chainID int64) *Genesis

func (g *Genesis) WriteGenesisJson(filename string) error {
genesisJsonBytes, _ := json.MarshalIndent(g, "", " ")
if err := os.WriteFile(filepath.Join(filename), genesisJsonBytes, 0755); err != nil {
if err := os.WriteFile(filename, genesisJsonBytes, 0755); err != nil {
return err
}
return nil
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/tezos/connector/tezosconnect/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tezosconnect
import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/hyperledger/firefly-cli/internal/blockchain/tezos/connector"
Expand Down Expand Up @@ -73,7 +72,7 @@ type ConfirmationsConfig struct {

func (c *Config) WriteConfig(filename string, extraTezosconnectConfigPath string) error {
configYamlBytes, _ := yaml.Marshal(c)
if err := os.WriteFile(filepath.Join(filename), configYamlBytes, 0755); err != nil {
if err := os.WriteFile(filename, configYamlBytes, 0755); err != nil {
return err
}
if extraTezosconnectConfigPath != "" {
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/tezos/tezossigner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package tezossigner

import (
"os"
"path/filepath"

"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -61,7 +60,7 @@ type AllowedTransactionsConfig struct {

func (c *Config) WriteConfig(filename string) error {
configYamlBytes, _ := yaml.Marshal(c)
return os.WriteFile(filepath.Join(filename), configYamlBytes, 0755)
return os.WriteFile(filename, configYamlBytes, 0755)
}

func GenerateSignerConfig(accountsAddresses []string) *Config {
Expand Down
36 changes: 18 additions & 18 deletions internal/core/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import (
"github.com/stretchr/testify/assert"
)

func TestGetFireFlyManifest(T *testing.T) {
func TestGetFireFlyManifest(t *testing.T) {
manifest, err := GetManifestForRelease("main")
assert.NoError(T, err)
assert.NotNil(T, manifest)
assert.NotNil(T, manifest.FireFly)
assert.NotNil(T, manifest.Ethconnect)
assert.NotNil(T, manifest.Fabconnect)
assert.NotNil(T, manifest.DataExchange)
assert.NotNil(T, manifest.TokensERC1155)
assert.NotNil(T, manifest.TokensERC20ERC721)
assert.NoError(t, err)
assert.NotNil(t, manifest)
assert.NotNil(t, manifest.FireFly)
assert.NotNil(t, manifest.Ethconnect)
assert.NotNil(t, manifest.Fabconnect)
assert.NotNil(t, manifest.DataExchange)
assert.NotNil(t, manifest.TokensERC1155)
assert.NotNil(t, manifest.TokensERC20ERC721)
}

func TestGetLatestReleaseManifest(T *testing.T) {
func TestGetLatestReleaseManifest(t *testing.T) {
manifest, err := GetManifestForChannel(types.ReleaseChannelStable)
assert.NoError(T, err)
assert.NotNil(T, manifest)
assert.NotNil(T, manifest.FireFly)
assert.NotNil(T, manifest.Ethconnect)
assert.NotNil(T, manifest.Fabconnect)
assert.NotNil(T, manifest.DataExchange)
assert.NotNil(T, manifest.TokensERC1155)
assert.NotNil(T, manifest.TokensERC20ERC721)
assert.NoError(t, err)
assert.NotNil(t, manifest)
assert.NotNil(t, manifest.FireFly)
assert.NotNil(t, manifest.Ethconnect)
assert.NotNil(t, manifest.Fabconnect)
assert.NotNil(t, manifest.DataExchange)
assert.NotNil(t, manifest.TokensERC1155)
assert.NotNil(t, manifest.TokensERC20ERC721)
}
2 changes: 1 addition & 1 deletion internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func RunDockerComposeCommand(ctx context.Context, workingDir string, command ...
_, err := runCommand(ctx, dockerCmd)
return err
default:
return fmt.Errorf("No version for docker-compose has been detected.")
return fmt.Errorf("no version for docker-compose has been detected")
}
}

Expand Down
21 changes: 10 additions & 11 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (s *StackManager) writeStackStateJSON(directory string) error {
func (s *StackManager) ensureInitDirectories() error {
configDir := filepath.Join(s.Stack.InitDir, "config")

if err := os.MkdirAll(filepath.Join(configDir), 0755); err != nil {
if err := os.MkdirAll(configDir, 0755); err != nil {
return err
}

Expand Down Expand Up @@ -566,7 +566,6 @@ func (s *StackManager) createMember(id string, index int, options *types.InitOpt

if options.SandboxEnabled {
member.ExposedSandboxPort = nextPort
nextPort++
}
return member, nil
}
Expand Down Expand Up @@ -1057,39 +1056,39 @@ func replaceVersions(oldManifest, newManifest *types.VersionManifest, filename s

old := oldManifest.FireFly.GetDockerImageString()
new := newManifest.FireFly.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.Ethconnect.GetDockerImageString()
new = newManifest.Ethconnect.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.Evmconnect.GetDockerImageString()
new = newManifest.Evmconnect.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.Tezosconnect.GetDockerImageString()
new = newManifest.Tezosconnect.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.Fabconnect.GetDockerImageString()
new = newManifest.Fabconnect.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.DataExchange.GetDockerImageString()
new = newManifest.DataExchange.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.TokensERC1155.GetDockerImageString()
new = newManifest.TokensERC1155.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.TokensERC20ERC721.GetDockerImageString()
new = newManifest.TokensERC20ERC721.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

old = oldManifest.Signer.GetDockerImageString()
new = newManifest.Signer.GetDockerImageString()
s = strings.Replace(s, old, new, -1)
s = strings.ReplaceAll(s, old, new)

return os.WriteFile(filename, []byte(s), 0755)
}
Expand Down