func makeWizard(do *definitions.Do) error { proceed, err := common.GetBoolResponse(ChainsMakeWelcome(), true, os.Stdin) log.WithField("=>", proceed).Debug("What the marmots heard") if err != nil { return err } if !proceed { log.Warn("The marmots will not proceed without your authorization. Exiting.") return nil } prelims := make(map[string]bool) for e, q := range ChainsMakePrelimQuestions() { prelims[e], err = common.GetBoolResponse(q, false, os.Stdin) log.WithField("=>", prelims[e]).Debug("What the marmots heard") if err != nil { return err } } accountTypes, err := LoadAccountTypes() if err != nil { return err } for _, accountT := range accountTypes { if err := assembleTypesWizard(accountT, prelims["tokens"]); err != nil { return err } } if prelims["dryrun"] { // todo check if procede or return.... } if prelims["manual"] { var err error accountTypes, err = addManualAccountType(accountTypes, 0) if err != nil { return err } } return maker(do, "mint", accountTypes) }
func PreProcessInputData(function string, data interface{}, do *definitions.Do, constructor bool) (string, []string, error) { var callDataArray []string var callArray []string if function == "" && !constructor { if reflect.TypeOf(data).Kind() == reflect.Slice { return "", []string{""}, fmt.Errorf("Incorrect formatting of epm run file. Please update your epm run file to include a function field.") } log.Warn("Deprecation Warning: The use of the 'data' field to specify the name of the contract function has been deprecated. Please update your epm jobs file to utilize a combination of 'function' and 'data' fields instead. See documentation for further details.") function = strings.Split(data.(string), " ")[0] callArray = strings.Split(data.(string), " ")[1:] for _, val := range callArray { output, _ := PreProcess(val, do) callDataArray = append(callDataArray, output) } } else if data != nil { if reflect.TypeOf(data).Kind() != reflect.Slice { if constructor { log.Warn("Deprecation Warning: Your deploy job is currently using a soon to be deprecated way of declaring constructor values. Please remember to update your run file to store them as a array rather than a string. See documentation for further details.") callArray = strings.Split(data.(string), " ") for _, val := range callArray { output, _ := PreProcess(val, do) callDataArray = append(callDataArray, output) } return function, callDataArray, nil } else { return "", make([]string, 0), fmt.Errorf("Incorrect formatting of epm run file. Please update your epm run file to include a function field.") } } val := reflect.ValueOf(data) for i := 0; i < val.Len(); i++ { s := val.Index(i) var newString string switch s.Interface().(type) { case bool: newString = strconv.FormatBool(s.Interface().(bool)) case int, int32, int64: newString = strconv.FormatInt(int64(s.Interface().(int)), 10) case []interface{}: var args []string for _, index := range s.Interface().([]interface{}) { value := reflect.ValueOf(index) var stringified string switch value.Kind() { case reflect.Int: stringified = strconv.FormatInt(value.Int(), 10) case reflect.String: stringified = value.String() } index, _ = PreProcess(stringified, do) args = append(args, stringified) } newString = "[" + strings.Join(args, ",") + "]" log.Debug(newString) default: newString = s.Interface().(string) } newString, _ = PreProcess(newString, do) callDataArray = append(callDataArray, newString) } } return function, callDataArray, nil }
func CallJob(call *definitions.Call, do *definitions.Do) (string, []*definitions.Variable, error) { var err error var callData string var callDataArray []string // Preprocess variables call.Source, _ = util.PreProcess(call.Source, do) call.Destination, _ = util.PreProcess(call.Destination, do) //todo: find a way to call the fallback function here call.Function, callDataArray, err = util.PreProcessInputData(call.Function, call.Data, do, false) if err != nil { return "", make([]*definitions.Variable, 0), err } call.Function, _ = util.PreProcess(call.Function, do) call.Amount, _ = util.PreProcess(call.Amount, do) call.Nonce, _ = util.PreProcess(call.Nonce, do) call.Fee, _ = util.PreProcess(call.Fee, do) call.Gas, _ = util.PreProcess(call.Gas, do) call.ABI, _ = util.PreProcess(call.ABI, do) // Use default call.Source = useDefault(call.Source, do.Package.Account) call.Amount = useDefault(call.Amount, do.DefaultAmount) call.Fee = useDefault(call.Fee, do.DefaultFee) call.Gas = useDefault(call.Gas, do.DefaultGas) // formulate call var packedBytes []byte if call.ABI == "" { packedBytes, err = util.ReadAbiFormulateCall(call.Destination, call.Function, callDataArray, do) callData = hex.EncodeToString(packedBytes) } else { packedBytes, err = util.ReadAbiFormulateCall(call.ABI, call.Function, callDataArray, do) callData = hex.EncodeToString(packedBytes) } if err != nil { if call.Function == "()" { log.Warn("Calling the fallback function") } else { var str, err = util.ABIErrorHandler(do, err, call, nil) return str, make([]*definitions.Variable, 0), err } } // Don't use pubKey if account override var oldKey string if call.Source != do.Package.Account { oldKey = do.PublicKey do.PublicKey = "" } log.WithFields(log.Fields{ "destination": call.Destination, "function": call.Function, "data": callData, }).Info("Calling") erisNodeClient := client.NewErisNodeClient(do.Chain) erisKeyClient := keys.NewErisKeyClient(do.Signer) tx, err := core.Call(erisNodeClient, erisKeyClient, do.PublicKey, call.Source, call.Destination, call.Amount, call.Nonce, call.Gas, call.Fee, callData) if err != nil { return "", make([]*definitions.Variable, 0), err } // Don't use pubKey if account override if call.Source != do.Package.Account { do.PublicKey = oldKey } // Sign, broadcast, display res, err := core.SignAndBroadcast(do.ChainID, erisNodeClient, erisKeyClient, tx, true, true, call.Wait) if err != nil { var str, err = util.MintChainErrorHandler(do, err) return str, make([]*definitions.Variable, 0), err } txResult := res.Return var result string log.Debug(txResult) // Formally process the return if txResult != nil { log.WithField("=>", result).Debug("Decoding Raw Result") if call.ABI == "" { call.Variables, err = util.ReadAndDecodeContractReturn(call.Destination, call.Function, txResult, do) } else { call.Variables, err = util.ReadAndDecodeContractReturn(call.ABI, call.Function, txResult, do) } if err != nil { return "", make([]*definitions.Variable, 0), err } log.WithField("=>", call.Variables).Debug("call variables:") result = util.GetReturnValue(call.Variables) if result != "" { log.WithField("=>", result).Warn("Return Value") } else { log.Debug("No return.") } } else { log.Debug("No return from contract.") } if call.Save == "tx" { log.Info("Saving tx hash instead of contract return") result = fmt.Sprintf("%X", res.Hash) } return result, call.Variables, nil }