Skip to content

Commit

Permalink
Adds missing fields in getTransactionReceipt rpc response.
Browse files Browse the repository at this point in the history
  • Loading branch information
nebojsa94 committed Jun 5, 2019
1 parent 568003c commit c483571
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
21 changes: 13 additions & 8 deletions commands/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ package commands
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/briandowns/spinner"
"github.com/logrusorgru/aurora"
"github.com/sirupsen/logrus"
Expand All @@ -12,12 +19,6 @@ import (
"github.com/tenderly/tenderly-cli/rest/payloads"
"github.com/tenderly/tenderly-cli/truffle"
"github.com/tenderly/tenderly-cli/userError"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)

func init() {
Expand Down Expand Up @@ -65,9 +66,9 @@ func uploadContracts(rest *rest.Rest) error {
}

logrus.Info("Analyzing Truffle configuration...")
truffleConfig, err := getTruffleConfig("truffle.js", projectDir)
truffleConfig, err := getTruffleConfig("truffle-config.js", projectDir)
if err != nil {
truffleConfig, err = getTruffleConfig("truffle-config.js", projectDir)
truffleConfig, err = getTruffleConfig("truffle.js", projectDir)
}

if err != nil {
Expand Down Expand Up @@ -113,6 +114,10 @@ func uploadContracts(rest *rest.Rest) error {

response, err := rest.Contract.UploadContracts(payloads.UploadContractsRequest{
Contracts: contracts,
Config: payloads.Config{
OptimizationsUsed: truffleConfig.Compilers["solc"].Optimizer.Enabled,
OptimizationsCount: truffleConfig.Compilers["solc"].Optimizer.Runs,
},
})

s.Stop()
Expand Down
4 changes: 2 additions & 2 deletions rest/call/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewContractCalls() *ContractCalls {
}

func (rest *ContractCalls) UploadContracts(request payloads.UploadContractsRequest) (*payloads.UploadContractsResponse, error) {
contractsJson, err := json.Marshal(request)
uploadJson, err := json.Marshal(request)
if err != nil {
return nil, err
}
Expand All @@ -26,7 +26,7 @@ func (rest *ContractCalls) UploadContracts(request payloads.UploadContractsReque
response := client.Request(
"POST",
"api/v1/account/"+config.GetString(config.AccountID)+"/project/"+config.GetString(config.ProjectSlug)+"/contracts",
contractsJson,
uploadJson,
)

err = json.NewDecoder(response).Decode(&contracts)
Expand Down
6 changes: 6 additions & 0 deletions rest/payloads/contractPayloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import "github.com/tenderly/tenderly-cli/truffle"

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

type UploadContractsResponse struct {
Contracts []truffle.ApiContract `json:"contracts"`
Error *ApiError `json:"error"`
}

type Config struct {
OptimizationsUsed bool `json:"optimizations_used"`
OptimizationsCount int `json:"optimizations_count"`
}
10 changes: 10 additions & 0 deletions truffle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@ type NetworkConfig struct {
NetworkID interface{} `json:"network_id"`
}

type Compiler struct {
Version string `json:"version"`
Optimizer Optimizer `json:"optimizer"`
}

type Optimizer struct {
Enabled bool `json:"enabled"`
Runs int `json:"runs"`
}
type Config struct {
ProjectDirectory string `json:"project_directory"`
BuildDirectory string `json:"contracts_build_directory"`
Networks map[string]NetworkConfig `json:"networks"`
Compilers map[string]Compiler `json:"compilers"`
}

func (c *Config) AbsoluteBuildDirectoryPath() string {
Expand Down

0 comments on commit c483571

Please sign in to comment.