Skip to content

Commit

Permalink
Old truffle config support for pushing multiple contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanHabic committed Jun 5, 2019
1 parent c483571 commit 3c62ca3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
30 changes: 24 additions & 6 deletions commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
"github.com/tenderly/tenderly-cli/userError"
)

const (
newTruffleConfigFile = "truffle-config.js"
oldTruffleConfigFile = "truffle.js"
)

func init() {
rootCmd.AddCommand(pushCmd)
}
Expand Down Expand Up @@ -66,9 +71,12 @@ func uploadContracts(rest *rest.Rest) error {
}

logrus.Info("Analyzing Truffle configuration...")
truffleConfig, err := getTruffleConfig("truffle-config.js", projectDir)
truffleConfigFile := newTruffleConfigFile

truffleConfig, err := getTruffleConfig(truffleConfigFile, projectDir)
if err != nil {
truffleConfig, err = getTruffleConfig("truffle.js", projectDir)
truffleConfigFile = oldTruffleConfigFile
truffleConfig, err = getTruffleConfig(truffleConfigFile, projectDir)
}

if err != nil {
Expand Down Expand Up @@ -112,12 +120,22 @@ func uploadContracts(rest *rest.Rest) error {

s.Start()

response, err := rest.Contract.UploadContracts(payloads.UploadContractsRequest{
Contracts: contracts,
Config: payloads.Config{
var configPayload *payloads.Config
if truffleConfigFile == newTruffleConfigFile && truffleConfig.Compilers != nil {
configPayload = &payloads.Config{
OptimizationsUsed: truffleConfig.Compilers["solc"].Optimizer.Enabled,
OptimizationsCount: truffleConfig.Compilers["solc"].Optimizer.Runs,
},
}
} else if truffleConfigFile == oldTruffleConfigFile && truffleConfig.Solc != nil {
configPayload = &payloads.Config{
OptimizationsUsed: truffleConfig.Solc["optimizer"].Enabled,
OptimizationsCount: truffleConfig.Solc["optimizer"].Runs,
}
}

response, err := rest.Contract.UploadContracts(payloads.UploadContractsRequest{
Contracts: contracts,
Config: configPayload,
})

s.Stop()
Expand Down
2 changes: 1 addition & 1 deletion rest/payloads/contractPayloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/tenderly/tenderly-cli/truffle"

type UploadContractsRequest struct {
Contracts []truffle.Contract `json:"contracts"`
Config Config `json:"config"`
Config *Config `json:"config,omitempty"`
}

type UploadContractsResponse struct {
Expand Down
1 change: 1 addition & 0 deletions truffle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
ProjectDirectory string `json:"project_directory"`
BuildDirectory string `json:"contracts_build_directory"`
Networks map[string]NetworkConfig `json:"networks"`
Solc map[string]Optimizer `json:"solc"`
Compilers map[string]Compiler `json:"compilers"`
}

Expand Down

0 comments on commit 3c62ca3

Please sign in to comment.