func DeployJob(deploy *definitions.Deploy, do *definitions.Do) (result string, err error) { // Preprocess variables deploy.Source, _ = util.PreProcess(deploy.Source, do) deploy.Contract, _ = util.PreProcess(deploy.Contract, do) deploy.Instance, _ = util.PreProcess(deploy.Instance, do) deploy.Libraries, _ = util.PreProcessLibs(deploy.Libraries, do) deploy.Amount, _ = util.PreProcess(deploy.Amount, do) deploy.Nonce, _ = util.PreProcess(deploy.Nonce, do) deploy.Fee, _ = util.PreProcess(deploy.Fee, do) deploy.Gas, _ = util.PreProcess(deploy.Gas, do) // trim the extension contractName := strings.TrimSuffix(deploy.Contract, filepath.Ext(deploy.Contract)) // Use defaults deploy.Source = useDefault(deploy.Source, do.Package.Account) deploy.Instance = useDefault(deploy.Instance, contractName) deploy.Amount = useDefault(deploy.Amount, do.DefaultAmount) deploy.Fee = useDefault(deploy.Fee, do.DefaultFee) deploy.Gas = useDefault(deploy.Gas, do.DefaultGas) // assemble contract var p string if _, err := os.Stat(deploy.Contract); err == nil { p = deploy.Contract } else { p = filepath.Join(do.ContractsPath, deploy.Contract) } log.WithField("=>", p).Info("Contract path") // use the proper compiler if do.Compiler != "" { log.WithField("=>", do.Compiler).Info("Setting compiler path") } // Don't use pubKey if account override var oldKey string if deploy.Source != do.Package.Account { oldKey = do.PublicKey do.PublicKey = "" } // compile if filepath.Ext(deploy.Contract) == ".bin" { log.Info("Binary file detected. Using binary deploy sequence.") // binary deploy sequence contractCode, err := ioutil.ReadFile(p) if err != nil { result := "could not read binary file" return result, err } tx, err := deployRaw(do, deploy, contractName, string(contractCode)) if err != nil { result := "could not deploy binary contract" return result, err } result, err := deployFinalize(do, tx, deploy.Wait) if err != nil { return "", fmt.Errorf("Error finalizing contract deploy %s: %v", p, err) } return result, err } else { // normal compilation/deploy sequence resp, err := compilers.BeginCompile(do.Compiler, p, false, deploy.Libraries) if err != nil { log.Errorln("Error compiling contracts: Compilers error:") return "", err } else if resp.Error != "" { log.Errorln("Error compiling contracts: Language error:") return "", fmt.Errorf("%v", resp.Error) } // loop through objects returned from compiler switch { case len(resp.Objects) == 1: log.WithField("path", p).Info("Deploying the only contract in file") r := resp.Objects[0] if r.Bytecode != "" { result, err = deployContract(deploy, do, r, p) if err != nil { return "", err } } case deploy.Instance == "all": log.WithField("path", p).Info("Deploying all contracts") var baseObj string for _, r := range resp.Objects { if r.Bytecode == "" { continue } result, err = deployContract(deploy, do, r, p) if err != nil { return "", err } if strings.ToLower(r.Objectname) == strings.ToLower(strings.TrimSuffix(filepath.Base(deploy.Contract), filepath.Ext(filepath.Base(deploy.Contract)))) { baseObj = result } } if baseObj != "" { result = baseObj } default: log.WithField("contract", deploy.Instance).Info("Deploying a single contract") for _, r := range resp.Objects { if r.Bytecode == "" { continue } if strings.ToLower(r.Objectname) == strings.ToLower(deploy.Instance) { result, err = deployContract(deploy, do, r, p) if err != nil { return "", err } } } } } // Don't use pubKey if account override if deploy.Source != do.Package.Account { do.PublicKey = oldKey } return result, nil }