Skip to content

Commit

Permalink
Merge branch 'hyperledger:main' into tobytobias#271
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyweb3x authored Oct 6, 2023
2 parents 6529c63 + 5f7fbf7 commit a38c7fd
Show file tree
Hide file tree
Showing 32 changed files with 658 additions and 72 deletions.
65 changes: 65 additions & 0 deletions cmd/init_tezos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// 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"
"path/filepath"

"github.com/spf13/cobra"

"github.com/hyperledger/firefly-cli/internal/log"
"github.com/hyperledger/firefly-cli/internal/stacks"
"github.com/hyperledger/firefly-cli/pkg/types"
)

var initTezosCmd = &cobra.Command{
Use: "tezos [stack_name] [member_count]",
Short: "Create a new FireFly local dev stack using an Tezos blockchain",
Long: `Create a new FireFly local dev stack using an Tezos blockchain`,
Args: cobra.MaximumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := log.WithVerbosity(context.Background(), verbose)
ctx = log.WithLogger(ctx, logger)
stackManager := stacks.NewStackManager(ctx)
initOptions.BlockchainProvider = types.BlockchainProviderTezos.String()
initOptions.BlockchainConnector = types.BlockchainConnectorTezosconnect.String()
initOptions.BlockchainNodeProvider = types.BlockchainNodeProviderRemoteRPC.String()
// By default we turn off multiparty mode while it's not supported yet
initOptions.MultipartyEnabled = false
initOptions.TokenProviders = []string{}
if err := initCommon(args); err != nil {
return err
}
if err := stackManager.InitStack(&initOptions); err != nil {
stackManager.RemoveStack()
return err
}
fmt.Printf("Stack '%s' created!\nTo start your new stack run:\n\n%s start %s\n", initOptions.StackName, rootCmd.Use, initOptions.StackName)
fmt.Printf("\nYour docker compose file for this stack can be found at: %s\n\n", filepath.Join(stackManager.Stack.StackDir, "docker-compose.yml"))
return nil
},
}

func init() {
initTezosCmd.Flags().IntVar(&initOptions.BlockPeriod, "block-period", -1, "Block period in seconds. Default is variable based on selected blockchain provider.")
initTezosCmd.Flags().StringVar(&initOptions.ContractAddress, "contract-address", "", "Do not automatically deploy a contract, instead use a pre-configured address")
initTezosCmd.Flags().StringVar(&initOptions.RemoteNodeURL, "remote-node-url", "", "For cases where the node is pre-existing and running remotely")

initCmd.AddCommand(initTezosCmd)
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ module github.com/hyperledger/firefly-cli
go 1.16

require (
blockwatch.cc/tzgo v1.17.1
github.com/briandowns/spinner v1.12.0
github.com/btcsuite/btcd v0.22.1
github.com/google/go-containerregistry v0.8.0
github.com/hyperledger/firefly-common v1.1.2
github.com/hyperledger/firefly-signer v0.9.6
github.com/mattn/go-isatty v0.0.14
github.com/mattn/go-isatty v0.0.19
github.com/miracl/conflate v1.2.1
github.com/mitchellh/go-homedir v1.1.0
github.com/otiai10/copy v1.7.0
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.12.1-0.20220712161005-5247643f0235
github.com/stretchr/testify v1.8.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/crypto v0.10.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)
61 changes: 51 additions & 10 deletions go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions internal/blockchain/ethereum/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ethereum
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -45,7 +44,7 @@ func CreateWalletFile(outputDirectory, prefix, password string) (*secp256k1.KeyP
} else {
filename = filepath.Join(outputDirectory, keyPair.Address.String()[2:])
}
err = ioutil.WriteFile(filename, wallet.JSON(), 0755)
err = os.WriteFile(filename, wallet.JSON(), 0755)
if err != nil {
return nil, "", err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/ethereum/besu/besu_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package besu
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (p *BesuProvider) WriteConfig(options *types.InitOptions) error {
// Generate node key
nodeAddress, nodeKey := ethereum.GenerateAddressAndPrivateKey()
// Write the node key to disk
if err := ioutil.WriteFile(filepath.Join(initDir, "blockchain", "nodeKey"), []byte(nodeKey), 0755); err != nil {
if err := os.WriteFile(filepath.Join(initDir, "blockchain", "nodeKey"), []byte(nodeKey), 0755); err != nil {
return err
}
// Drop the 0x on the front of the address here because that's what is expected in the genesis.json
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/besu/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package besu
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -64,7 +64,7 @@ type Alloc struct {

func (g *Genesis) WriteGenesisJson(filename string) error {
genesisJsonBytes, _ := json.MarshalIndent(g, "", " ")
if err := ioutil.WriteFile(filepath.Join(filename), genesisJsonBytes, 0755); err != nil {
if err := os.WriteFile(filepath.Join(filename), genesisJsonBytes, 0755); err != nil {
return err
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/blockchain/ethereum/connector/ethconnect/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package ethconnect

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

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

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

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

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

func (e *Config) WriteConfig(filename string, extraEvmconnectConfigPath string) error {
configYamlBytes, _ := yaml.Marshal(e)
if err := ioutil.WriteFile(filepath.Join(filename), configYamlBytes, 0755); err != nil {
if err := os.WriteFile(filepath.Join(filename), configYamlBytes, 0755); err != nil {
return err
}
if extraEvmconnectConfigPath != "" {
Expand All @@ -88,7 +88,7 @@ func (e *Config) WriteConfig(filename string, extraEvmconnectConfigPath string)
if err != nil {
return err
}
if err := ioutil.WriteFile(filename, bytes, 0755); err != nil {
if err := os.WriteFile(filename, bytes, 0755); err != nil {
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/blockchain/ethereum/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package ethereum
import (
"context"
"encoding/json"
"io/ioutil"
"os"

"github.com/hyperledger/firefly-cli/internal/blockchain/ethereum/ethtypes"
"github.com/hyperledger/firefly-cli/internal/docker"
Expand All @@ -32,7 +32,7 @@ type truffleCompiledContract struct {
}

func ReadTruffleCompiledContract(filePath string) (*ethtypes.CompiledContracts, error) {
d, _ := ioutil.ReadFile(filePath)
d, _ := os.ReadFile(filePath)
var truffleCompiledContract *truffleCompiledContract
err := json.Unmarshal(d, &truffleCompiledContract)
if err != nil {
Expand All @@ -51,7 +51,7 @@ func ReadTruffleCompiledContract(filePath string) (*ethtypes.CompiledContracts,
}

func ReadSolcCompiledContract(filePath string) (*ethtypes.CompiledContracts, error) {
d, _ := ioutil.ReadFile(filePath)
d, _ := os.ReadFile(filePath)
var contracts *ethtypes.CompiledContracts
err := json.Unmarshal(d, &contracts)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/ethsigner/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package ethsigner
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/hyperledger/firefly-cli/internal/docker"
Expand All @@ -38,7 +38,7 @@ key-file = "/data/keystore/%s"
password-file = "/data/password"
`, keyFile)
filename := filepath.Join(outputDirectory, fmt.Sprintf("%s.toml", keyFile))
return filename, ioutil.WriteFile(filename, []byte(toml), 0755)
return filename, os.WriteFile(filename, []byte(toml), 0755)
}

func (p *EthSignerProvider) copyTomlFileToVolume(ctx context.Context, tomlFilePath, volumeName string) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/ethsigner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package ethsigner

import (
"io/ioutil"
"os"
"path/filepath"

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

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

func GenerateSignerConfig(chainID int64, rpcURL string) *Config {
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/ethereum/ethsigner/ethsigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"encoding/hex"
"fmt"
"io/ioutil"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (p *EthSignerProvider) WriteConfig(options *types.InitOptions, rpcURL strin
if err := os.MkdirAll(blockchainDirectory, 0755); err != nil {
return err
}
if err := ioutil.WriteFile(filepath.Join(initDir, "blockchain", "password"), []byte(keyPassword), 0755); err != nil {
if err := os.WriteFile(filepath.Join(initDir, "blockchain", "password"), []byte(keyPassword), 0755); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/geth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func (g *GethClient) UnlockAccount(address string, password string) error {
return err
}
defer resp.Body.Close()
responseBody, err := ioutil.ReadAll(resp.Body)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/ethereum/geth/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package geth
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -108,7 +108,7 @@ func CreateGenesis(addresses []string, blockPeriod int, chainID int64) *Genesis

func (g *Genesis) WriteGenesisJson(filename string) error {
genesisJsonBytes, _ := json.MarshalIndent(g, "", " ")
if err := ioutil.WriteFile(filepath.Join(filename), genesisJsonBytes, 0755); err != nil {
if err := os.WriteFile(filepath.Join(filename), genesisJsonBytes, 0755); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/fabric/cryptogen_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package fabric

import (
"io/ioutil"
"os"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -94,5 +94,5 @@ func WriteCryptogenConfig(memberCount int, path string) error {
}

cryptogenConfigBytes, _ := yaml.Marshal(cryptogenConfig)
return ioutil.WriteFile(path, cryptogenConfigBytes, 0755)
return os.WriteFile(path, cryptogenConfigBytes, 0755)
}
6 changes: 3 additions & 3 deletions internal/blockchain/fabric/fabconnect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -73,7 +73,7 @@ func CreateIdentity(fabconnectUrl string, signer string) (*CreateIdentityRespons
return nil, err
}
defer resp.Body.Close()
responseBody, err := ioutil.ReadAll(resp.Body)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func EnrollIdentity(fabconnectUrl, signer, secret string) (*EnrollIdentityRespon
return nil, err
}
defer resp.Body.Close()
responseBody, err := ioutil.ReadAll(resp.Body)
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/fabric/fabconnect/fabconnect_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package fabconnect

import (
"io/ioutil"
"os"

"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -86,5 +86,5 @@ func WriteFabconnectConfig(filePath string) error {
}

fabconnectConfigBytes, _ := yaml.Marshal(fabconnectConfig)
return ioutil.WriteFile(filePath, fabconnectConfigBytes, 0755)
return os.WriteFile(filePath, fabconnectConfigBytes, 0755)
}
3 changes: 1 addition & 2 deletions internal/blockchain/fabric/fabric_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -321,7 +320,7 @@ func (p *FabricProvider) getFabconnectServiceDefinitions(members []*types.Organi
func (p *FabricProvider) writeConfigtxYaml() error {
if !p.stack.RemoteFabricNetwork {
filePath := path.Join(p.stack.InitDir, "blockchain", "configtx.yaml")
return ioutil.WriteFile(filePath, []byte(configtxYaml), 0755)
return os.WriteFile(filePath, []byte(configtxYaml), 0755)
}
return nil
}
Expand Down
Loading

0 comments on commit a38c7fd

Please sign in to comment.