func (c *Controller) VotesExchange() (string, error) { txType := "VotesExchange" txTypeId := utils.TypeInt(txType) timeNow := time.Now().Unix() eOwner := utils.StrToInt64(c.Parameters["e_owner_id"]) result := utils.StrToInt64(c.Parameters["result"]) signData := fmt.Sprintf("%d,%d,%d,%d,%d", txTypeId, timeNow, c.SessUserId, eOwner, result) if eOwner == 0 { signData = "" } TemplateStr, err := makeTemplate("votes_exchange", "votesExchange", &VotesExchangePage{ Alert: c.Alert, Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, UserId: c.SessUserId, TimeNow: timeNow, TxType: txType, TxTypeId: txTypeId, EOwner: eOwner, Result: result, SignData: signData}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) CfCatalog() (string, error) { var err error log.Debug("CfCatalog") categoryId := utils.Int64ToStr(int64(utils.StrToFloat64(c.Parameters["category_id"]))) log.Debug("categoryId", categoryId) var curCategory string addSql := "" if categoryId != "0" { addSql = `AND category_id = ` + categoryId curCategory = c.Lang["cf_category_"+categoryId] } cfUrl := "" projects := make(map[string]map[string]string) cfProjects, err := c.GetAll(` SELECT cf_projects.id, lang_id, blurb_img, country, city, currency_id, end_time, amount FROM cf_projects LEFT JOIN cf_projects_data ON cf_projects_data.project_id = cf_projects.id WHERE del_block_id = 0 AND end_time > ? AND lang_id = ? `+addSql+` ORDER BY funders DESC LIMIT 100 `, 100, utils.Time(), c.LangInt) if err != nil { return "", utils.ErrInfo(err) } for _, data := range cfProjects { CfProjectData, err := c.GetCfProjectData(utils.StrToInt64(data["id"]), utils.StrToInt64(data["end_time"]), c.LangInt, utils.StrToFloat64(data["amount"]), cfUrl) if err != nil { return "", utils.ErrInfo(err) } for k, v := range CfProjectData { data[k] = v } projects[data["id"]] = data } cfCategory := utils.MakeCfCategories(c.Lang) TemplateStr, err := makeTemplate("cf_catalog", "cfCatalog", &cfCatalogPage{ Lang: c.Lang, CfCategory: cfCategory, CurrencyList: c.CurrencyList, CurCategory: curCategory, Projects: projects, UserId: c.SessUserId, CategoryId: categoryId, CfUrl: cfUrl}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) ESaveOrder() (string, error) { if c.SessUserId == 0 { return "", errors.New(c.Lang["sign_up_please"]) } c.r.ParseForm() sellCurrencyId := utils.StrToInt64(c.r.FormValue("sell_currency_id")) buyCurrencyId := utils.StrToInt64(c.r.FormValue("buy_currency_id")) amount := utils.StrToFloat64(c.r.FormValue("amount")) sellRate := utils.StrToFloat64(c.r.FormValue("sell_rate")) orderType := c.r.FormValue("type") // можно ли торговать такими валютами checkCurrency, err := c.Single("SELECT count(id) FROM e_currency WHERE id IN (?, ?)", sellCurrencyId, buyCurrencyId).Int64() if err != nil { return "", utils.ErrInfo(err) } if checkCurrency != 2 { return "", errors.New("Currency error") } if orderType != "sell" && orderType != "buy" { return "", errors.New("Type error") } if amount == 0 { return "", errors.New(c.Lang["amount_error"]) } if amount < 0.001 && sellCurrencyId < 1000 { return "", errors.New(strings.Replace(c.Lang["save_order_min_amount"], "[amount]", "0.001", -1)) } if sellRate < 0.0001 { return "", errors.New(strings.Replace(c.Lang["save_order_min_price"], "[price]", "0.0001", -1)) } reductionLock, err := utils.EGetReductionLock() if err != nil { return "", utils.ErrInfo(err) } if reductionLock > 0 { return "", errors.New(strings.Replace(c.Lang["creating_orders_unavailable"], "[minutes]", "30", -1)) } // нужно проверить, есть ли нужная сумма на счету юзера userAmountAndProfit := utils.EUserAmountAndProfit(c.SessUserId, sellCurrencyId) if userAmountAndProfit < amount { return "", errors.New(c.Lang["not_enough_money"] + " (" + utils.Float64ToStr(userAmountAndProfit) + "<" + utils.Float64ToStr(amount) + ")" + strings.Replace(c.Lang["add_funds_link"], "[currency]", "USD", -1)) } err = NewForexOrder(c.SessUserId, amount, sellRate, sellCurrencyId, buyCurrencyId, orderType, utils.StrToMoney(c.EConfig["commission"])) if err != nil { return "", utils.ErrInfo(err) } else { return utils.JsonAnswer(c.Lang["order_created"], "success").String(), nil } return ``, nil }
func (c *Controller) MyCfProjects() (string, error) { var err error txType := "NewCfProject" txTypeId := utils.TypeInt(txType) timeNow := utils.Time() projectsLang := make(map[string]map[string]string) projects := make(map[string]map[string]string) cfProjects, err := c.GetAll(` SELECT id, category_id, project_currency_name, country, city, currency_id, end_time, amount FROM cf_projects WHERE user_id = ? AND del_block_id = 0 `, -1, c.SessUserId) if err != nil { return "", utils.ErrInfo(err) } for _, data := range cfProjects { CfProjectData, err := c.GetCfProjectData(utils.StrToInt64(data["id"]), utils.StrToInt64(data["end_time"]), c.LangInt, utils.StrToFloat64(data["amount"]), "") if err != nil { return "", utils.ErrInfo(err) } for k, v := range CfProjectData { data[k] = v } projects[data["id"]] = data lang, err := c.GetMap(`SELECT id, lang_id FROM cf_projects_data WHERE project_id = ?`, "id", "lang_id", data["id"]) projectsLang[data["id"]] = lang } cfLng, err := c.GetAllCfLng() TemplateStr, err := makeTemplate("my_cf_projects", "myCfProjects", &MyCfProjectsPage{ Alert: c.Alert, Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, UserId: c.SessUserId, TimeNow: timeNow, TxType: txType, TxTypeId: txTypeId, CfLng: cfLng, CurrencyList: c.CurrencyList, Projects: projects, ProjectsLang: projectsLang}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (c *Controller) EDelOrder() (string, error) { c.r.ParseForm() orderId := utils.StrToInt64(c.r.FormValue("order_id")) // возвращаем сумму ордера на кошелек + возращаем комиссию. order, err := utils.DB.OneRow("SELECT amount, sell_currency_id FROM e_orders WHERE id = ? AND user_id = ? AND del_time = 0 AND empty_time = 0", orderId, c.SessUserId).String() if err != nil { return "", utils.ErrInfo(err) } if len(order) == 0 { return "", utils.ErrInfo("order_id error") } sellCurrencyId := utils.StrToInt64(order["sell_currency_id"]) amount := utils.StrToFloat64(order["amount"]) amountAndCommission := utils.StrToFloat64(order["amount"]) / (1 - c.ECommission/100) // косиссия биржи commission := amountAndCommission - amount err = userLock(c.SessUserId) if err != nil { return "", err } // отмечаем, что ордер удален err = utils.DB.ExecSql("UPDATE e_orders SET del_time = ? WHERE id = ? AND user_id = ?", utils.Time(), orderId, c.SessUserId) if err != nil { return "", utils.ErrInfo(err) } // возвращаем остаток ордера на кошель userAmount := utils.EUserAmountAndProfit(c.SessUserId, sellCurrencyId) err = utils.DB.ExecSql("UPDATE e_wallets SET amount = ?, last_update = ? WHERE user_id = ? AND currency_id = ?", userAmount+amountAndCommission, utils.Time(), c.SessUserId, sellCurrencyId) if err != nil { return "", utils.ErrInfo(err) } // вычитаем комиссию биржи userAmount = utils.EUserAmountAndProfit(1, sellCurrencyId) err = utils.DB.ExecSql("UPDATE e_wallets SET amount = ?, last_update = ? WHERE user_id = 1 AND currency_id = ?", userAmount-commission, utils.Time(), sellCurrencyId) if err != nil { return "", utils.ErrInfo(err) } userUnlock(c.SessUserId) return ``, nil }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "DelPromisedAmount" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("1")) // promised_amount_id txSlice = append(txSlice, []byte("4")) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "ChangeArbitrationDaysRefund" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("91573")) // arbitration_days_refund txSlice = append(txSlice, []byte("150")) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "NewPct" txTime := "1599278817" userId := []byte("2") var blockId int64 = 140015 //data:=`{"currency":{"1":{"miner_pct":"0.0000000617044","user_pct":"0.0000000439591"},"72":{"miner_pct":"0.0000000617044","user_pct":"0.0000000439591"}},"referral":{"first":10,"second":0,"third":0}}` data := `{"currency":{"1":{"miner_pct":"0.0000000617044","user_pct":"0.0000000435602"},"72":{"miner_pct":"0.0000000760368","user_pct":"0.0000000562834"}},"referral":{"first":30,"second":20,"third":5}}` var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, userId) // promised_amount_id txSlice = append(txSlice, []byte(data)) dataForSign := fmt.Sprintf("%v,%v,%s,%s", utils.TypeInt(txType), txTime, userId, data) err := tests_utils.MakeFrontTest(txSlice, utils.StrToInt64(txTime), dataForSign, txType, utils.BytesToInt64(userId), "", blockId) if err != nil { fmt.Println(err) } }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "Abuses" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("1")) // message txSlice = append(txSlice, []byte(`{"1":"fdfdsfdd", "2":"fsdfkj43 43 34"}`)) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func (c *Controller) ERedirect() (string, error) { c.r.ParseForm() token := c.r.FormValue("FormToken") amount := c.r.FormValue("FormExAmount") buyCurrencyId := utils.StrToInt64(c.r.FormValue("FormDC")) if !utils.CheckInputData(token, "string") { return "", errors.New("incorrect data") } // order_id занесем когда поуступят деньги в платежной системе err := c.ExecSql(`UPDATE e_tokens SET buy_currency_id = ?, amount_fiat = ? WHERE token = ?`, buyCurrencyId, utils.StrToFloat64(c.r.FormValue("FormExAmount")), token) if err != nil { return "", utils.ErrInfo(err) } tokenId, err := c.Single(`SELECT id FROM e_tokens WHERE token = ?`, token).String() if err != nil { return "", utils.ErrInfo(err) } TemplateStr, err := makeTemplate("e_redirect", "eRedirect", &ERedirectPage{ Lang: c.Lang, EConfig: c.EConfig, TokenId: tokenId, EURL: c.EURL, MDesc: base64.StdEncoding.EncodeToString([]byte("token-" + tokenId)), Amount: amount}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "NewUser" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("1")) // public_key txSlice = append(txSlice, utils.HexToBin([]byte("30820122300d06092a864886f70d01010105000382010f003082010a0282010100ae7797b5c16358862f083bb26cde86b233ba97c48087df44eaaf88efccfe554bf51df8dc7e99072cbe433933f1b87aa9ef62bd5d49dc40e75fe398426c727b0773ea9e4d88184d64c1aa561b1cdf78abe07ca5d23711c403f58abf30d41f4b96161649a91a95818d9d482e8fa3f91829abce3d80f6fc3708ce23f6841bb4a8bae301b23745fce5134420fec0519a081f162d16e4dd0da2e8869b5b67122a1fb7e9bcdb8b2512d1edabdb271bee190563b36a66f5498f50d2fc7202ad2f43b90f860428d5ecd67973900d9997475d4e1a1e4c56b44411cc4b5e9c660fe23fdcd5ab956a834fa05a4ecac9d815143d84993c9424d86379b6f76e3be9aeaaff48fb0203010001)"))) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "ChangeHost" txTime := "1399278817" userId := []byte("2") var blockId int64 = 1415 host := "http://fdfdfd.ru/" var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, userId) // promised_amount_id txSlice = append(txSlice, []byte(host)) dataForSign := fmt.Sprintf("%v,%v,%s,%s", utils.TypeInt(txType), txTime, userId, host) err := tests_utils.MakeFrontTest(txSlice, utils.StrToInt64(txTime), dataForSign, txType, utils.BytesToInt64(userId), "", blockId) if err != nil { fmt.Println(err) } }
func (c *Controller) EData() (string, error) { c.w.Header().Set("Access-Control-Allow-Origin", "*") // сколько всего продается DC eOrders, err := c.GetAll(`SELECT sell_currency_id, sum(amount) as amount FROM e_orders WHERE sell_currency_id < 1000 AND empty_time = 0 GROUP BY sell_currency_id`, 100) if err != nil { return "", utils.ErrInfo(err) } values := "" for _, data := range eOrders { values += utils.ClearNull(data["amount"], 0) + ` d` + c.CurrencyList[utils.StrToInt64(data["sell_currency_id"])] + `, ` } if len(values) > 0 { values = values[:len(values)-2] } ps, err := c.Single(`SELECT value FROM e_config WHERE name = 'ps'`).String() if err != nil { return "", utils.ErrInfo(err) } jsonData, err := json.Marshal(map[string]string{"values": values, "ps": ps}) if err != nil { return "", utils.ErrInfo(err) } return string(jsonData), nil }
func makeVcomplex(json_data []byte) (*vComplex, error) { vComplex := new(vComplex) err := json.Unmarshal(json_data, &vComplex) if err != nil { vComplex_ := new(vComplex_) err = json.Unmarshal(json_data, &vComplex_) if err != nil { vComplex__ := new(vComplex__) err = json.Unmarshal(json_data, &vComplex__) if err != nil { return vComplex, err } vComplex.Referral = vComplex__.Referral vComplex.Currency = vComplex__.Currency vComplex.Admin = utils.StrToInt64(vComplex__.Admin) } else { vComplex.Referral = make(map[string]string) for k, v := range vComplex_.Referral { vComplex.Referral[k] = utils.Int64ToStr(v) } vComplex.Currency = vComplex_.Currency vComplex.Admin = vComplex_.Admin } } return vComplex, nil }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "ChangeKeyActive" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("91573")) // secret txSlice = append(txSlice, []byte("156516546572676276827")) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "NewMaxOtherCurrencies" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("1")) // json data txSlice = append(txSlice, []byte(`{"1":"1000", "72":500}`)) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func checkHosts(hosts []map[string]string, countOk *int) []map[string]string { ch := make(chan *answerType) for _, host := range hosts { userId := utils.StrToInt64(host["user_id"]) go func(userId int64, host string) { ch_ := make(chan *answerType, 1) go func() { log.Debug("host: %v / userId: %v", host, userId) ch_ <- check(host, userId) }() select { case reachable := <-ch_: ch <- reachable case <-time.After(consts.WAIT_CONFIRMED_NODES * time.Second): ch <- &answerType{userId: userId, answer: 0} } }(userId, host["host"]) } log.Debug("%v", "hosts", hosts) var newHosts []map[string]string // если нода не отвечает, то удалем её из таблы nodes_connection for i := 0; i < len(hosts); i++ { result := <-ch if result.answer == 0 { log.Info("delete %v", result.userId) err = utils.DB.ExecSql("DELETE FROM nodes_connection WHERE user_id = ?", result.userId) if err != nil { log.Error("%v", err) } /*for _, data := range hosts { if utils.StrToInt64(data["user_id"]) != result.userId { newHosts = append(newHosts, data) } }*/ } else { for _, data := range hosts { if utils.StrToInt64(data["user_id"]) == result.userId { newHosts = append(newHosts, data) } } *countOk++ } log.Info("answer: %v", result) } return newHosts }
func (c *Controller) Interface() (string, error) { if c.SessRestricted != 0 { return "", utils.ErrInfo(errors.New("Permission denied")) } var err error name := "" if len(c.Parameters["show_map"]) > 0 { name = "show_map" } else if len(c.Parameters["show_sign_data"]) > 0 { name = "show_sign_data" } else if len(c.Parameters["show_progress_bar"]) > 0 { name = "show_progress_bar" } alert := "" if len(name) > 0 { err = c.ExecSql("UPDATE "+c.MyPrefix+"my_table SET "+name+" = ?", utils.StrToInt64(c.Parameters[name])) if err != nil { return "", utils.ErrInfo(err) } alert = c.Lang["done"] } data, err := c.OneRow("SELECT * FROM " + c.MyPrefix + "my_table").Int64() if err != nil { return "", utils.ErrInfo(err) } show_sign_data := data["show_sign_data"] show_map := data["show_map"] show_progress_bar := data["show_progress_bar"] param_show_progress_bar := utils.StrToInt64(c.Parameters["show_progress_bar"]) TemplateStr, err := makeTemplate("interface", "interface", &InterfacePage{ Lang: c.Lang, Show_sign_data: show_sign_data, Show_map: show_map, Show_progress_bar: show_progress_bar, Param_show_progress_bar: param_show_progress_bar, Alert: alert}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "NewMiner." txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("91573")) //race txSlice = append(txSlice, []byte("1")) //country txSlice = append(txSlice, []byte("1")) //latitude txSlice = append(txSlice, []byte("55")) //longitude txSlice = append(txSlice, []byte("55")) //host txSlice = append(txSlice, []byte("http://55.55.55.55/")) //face_coords txSlice = append(txSlice, []byte("[[118,275],[241,274],[39,274],[316,276],[180,364],[182,430],[181,490],[93,441],[259,433]]")) //profile_coords txSlice = append(txSlice, []byte("[[289,224],[148,216],[172,304],[123,239],[328,261],[305,349]]")) //face_hash txSlice = append(txSlice, []byte("face_hash")) //profile_hash txSlice = append(txSlice, []byte("profile_hash")) //video_type txSlice = append(txSlice, []byte("youtube")) //video_url_id txSlice = append(txSlice, []byte("video_url_id")) //node_public_key txSlice = append(txSlice, []byte("node_public_key")) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func (c *Controller) EWithdraw() (string, error) { if c.SessUserId == 0 { return "", errors.New(c.Lang["sign_up_please"]) } c.r.ParseForm() currencyId := utils.StrToInt64(c.r.FormValue("currency_id")) if !utils.CheckInputData(c.r.FormValue("amount"), "amount") { return "", fmt.Errorf("incorrect amount") } method := c.r.FormValue("method") if !utils.CheckInputData(method, "method") { return "", fmt.Errorf("incorrect method") } account := c.r.FormValue("account") if !utils.CheckInputData(account, "account") { return "", fmt.Errorf("incorrect account") } amount := utils.StrToFloat64(c.r.FormValue("amount")) curTime := utils.Time() // нужно проверить, есть ли нужная сумма на счету юзера userAmount := utils.EUserAmountAndProfit(c.SessUserId, currencyId) if userAmount < amount { return "", fmt.Errorf("%s (%f<%f)", c.Lang["not_enough_money"], userAmount, amount) } if method != "Dcoin" && currencyId < 1000 { return "", fmt.Errorf("incorrect method") } err := userLock(c.SessUserId) if err != nil { return "", utils.ErrInfo(err) } err = c.ExecSql(`UPDATE e_wallets SET amount = ?, last_update = ? WHERE user_id = ? AND currency_id = ?`, userAmount-amount, curTime, c.SessUserId, currencyId) if err != nil { return "", utils.ErrInfo(err) } var commission float64 if method == "Dcoin" { commission = utils.StrToFloat64(c.EConfig["dc_commission"]) } else if method == "Perfect-money" { commission = utils.StrToFloat64(c.EConfig["pm_commission"]) } wdAmount := utils.ClearNull(utils.Float64ToStr(amount*(1-commission/100)), 2) err = c.ExecSql(`INSERT INTO e_withdraw (open_time, user_id, currency_id, account, amount, wd_amount, method) VALUES (?, ?, ?, ?, ?, ?, ?)`, curTime, c.SessUserId, currencyId, account, amount, wdAmount, method) if err != nil { return "", utils.ErrInfo(err) } userUnlock(c.SessUserId) return utils.JsonAnswer(c.Lang["request_is_created"], "success").String(), nil }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "CfProjectData" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("1111111111")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, []byte("4")) //project_id txSlice = append(txSlice, []byte("1")) //lang_id txSlice = append(txSlice, []byte("45")) //blurb_img txSlice = append(txSlice, []byte("http://i.imgur.com/YRCoVnc.jpg")) //head_img txSlice = append(txSlice, []byte("http://i.imgur.com/YRCoVnc.jpg")) //description_img txSlice = append(txSlice, []byte("http://i.imgur.com/YRCoVnc.jpg")) //picture txSlice = append(txSlice, []byte("http://i.imgur.com/YRCoVnc.jpg")) //video_type txSlice = append(txSlice, []byte("youtube")) //video_url_id txSlice = append(txSlice, []byte("X-_fg47G5yf-_f")) //news_img txSlice = append(txSlice, []byte("http://i.imgur.com/YRCoVnc.jpg")) //links txSlice = append(txSlice, []byte(`[["http:\/\/goo.gl\/fnfh1Dg",1,532,234,0],["http:\/\/goo.gl\/28Fh4h",1355,1344,2222,66]]`)) //hide txSlice = append(txSlice, []byte("1")) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func (c *Controller) EGateIk() (string, error) { c.r.ParseForm() fmt.Println(c.r.Form) var ikNames []string for name, _ := range c.r.Form { if name[:2] == "ik" && name != "ik_sign" { ikNames = append(ikNames, name) } } sort.Strings(ikNames) fmt.Println(ikNames) var ikValues []string for _, names := range ikNames { ikValues = append(ikValues, c.r.FormValue(names)) } ikValues = append(ikValues, c.EConfig["ik_s_key"]) fmt.Println(ikValues) sign := strings.Join(ikValues, ":") fmt.Println(sign) sign = base64.StdEncoding.EncodeToString(utils.HexToBin(utils.Md5(sign))) fmt.Println(sign) if sign != c.r.FormValue("ik_sign") { return "", errors.New("Incorrect signature") } currencyId := int64(0) if c.r.FormValue("ik_cur") == "USD" { currencyId = 1001 } if currencyId == 0 { return "", errors.New("Incorrect currencyId") } amount := utils.StrToFloat64(c.r.FormValue("ik_am")) pmId := utils.StrToInt64(c.r.FormValue("ik_inv_id")) // проверим, не зачисляли ли мы уже это платеж existsId, err := c.Single(`SELECT id FROM e_adding_funds_ik WHERE id = ?`, pmId).Int64() if err != nil { return "", utils.ErrInfo(err) } if existsId != 0 { return "", errors.New("Incorrect ik_inv_id") } paymentInfo := c.r.FormValue("ik_desc") txTime := utils.Time() err = EPayment(paymentInfo, currencyId, txTime, amount, pmId, "ik", c.ECommission) if err != nil { return "", utils.ErrInfo(err) } return ``, nil }
func main() { f, err := os.OpenFile("dclog.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777) defer f.Close() //log.SetOutput(f) log.SetOutput(io.MultiWriter(f, os.Stdout)) log.SetFlags(log.LstdFlags | log.Lshortfile) txType := "Mining" txTime := "1406545938" userId := []byte("105") var blockId int64 = 123925 promised_amount_id := "24" amount := "5.69" var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, userId) // promised_amount_id txSlice = append(txSlice, []byte(promised_amount_id)) // amount txSlice = append(txSlice, []byte(amount)) dataForSign := fmt.Sprintf("%v,%v,%s,%s,%s", utils.TypeInt(txType), txTime, userId, promised_amount_id, amount) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err = tests_utils.MakeFrontTest(txSlice, utils.StrToInt64(txTime), dataForSign, txType, utils.BytesToInt64(userId), "", blockId) if err != nil { fmt.Println(err) } }
func (c *Controller) EGatePm() (string, error) { c.r.ParseForm() fmt.Println(c.r.Form) sign := strings.ToUpper(string(utils.Md5(c.r.FormValue("PAYMENT_ID") + ":" + c.r.FormValue("PAYEE_ACCOUNT") + ":" + c.r.FormValue("PAYMENT_AMOUNT") + ":" + c.r.FormValue("PAYMENT_UNITS") + ":" + c.r.FormValue("PAYMENT_BATCH_NUM") + ":" + c.r.FormValue("PAYER_ACCOUNT") + ":" + strings.ToUpper(string(utils.Md5(c.EConfig["pm_s_key"]))) + ":" + c.r.FormValue("TIMESTAMPGMT")))) txTime := utils.StrToInt64(c.r.FormValue("TIMESTAMPGMT")) if sign != c.r.FormValue("V2_HASH") { return "", errors.New("Incorrect signature") } currencyId := int64(0) if c.r.FormValue("PAYMENT_UNITS") == "USD" { currencyId = 1001 } if currencyId == 0 { return "", errors.New("Incorrect currencyId") } amount := utils.StrToFloat64(c.r.FormValue("PAYMENT_AMOUNT")) pmId := utils.StrToInt64(c.r.FormValue("PAYMENT_BATCH_NUM")) // проверим, не зачисляли ли мы уже это платеж existsId, err := c.Single(`SELECT id FROM e_adding_funds_pm WHERE id = ?`, pmId).Int64() if err != nil { return "", utils.ErrInfo(err) } if existsId != 0 { return "", errors.New("Incorrect PAYMENT_BATCH_NUM") } paymentInfo := c.r.FormValue("PAYMENT_ID") err = EPayment(paymentInfo, currencyId, txTime, amount, pmId, "pm", c.ECommission) if err != nil { return "", utils.ErrInfo(err) } return ``, nil }
func main() { f, err := os.OpenFile("dclog.txt", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777) defer f.Close() //log.SetOutput(f) log.SetOutput(io.MultiWriter(f, os.Stdout)) log.SetFlags(log.LstdFlags | log.Lshortfile) txType := "Mining" txTime := "1406545931" userId := []byte("2") var blockId int64 = 123924 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, userId) // promised_amount_id txSlice = append(txSlice, []byte(`26`)) // amount txSlice = append(txSlice, []byte(`6`)) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) dir, err := utils.GetCurrentDir() if err != nil { fmt.Println(err) } configIni_, err := config.NewConfig("ini", dir+"/config.ini") if err != nil { fmt.Println(err) } configIni, err := configIni_.GetSection("default") db := utils.DbConnect(configIni) // делаем снимок БД в виде хэшей до начала тестов hashesStart, err := tests_utils.AllHashes(db) err = tests_utils.MakeTest(txSlice, blockData, txType, hashesStart, db, "work") if err != nil { fmt.Println(err) } }
func main() { /* Currency map[string][]float64 `json:"currency"` Referral map[string]int64 `json:"referral"` Admin int64 `json:"admin"` */ f := tests_utils.InitLog() defer f.Close() txType := "VotesComplex" txTime := "1427383713" userId := []byte("2") var blockId int64 = 128008 newPct := new(vComplex) newPct.Currency = make(map[string][]float64) newPct.Referral = make(map[string]int64) newPct.Currency["1"] = []float64{0.0000000760368, 0.0000000497405, 1000, 55, 10} newPct.Currency["33"] = []float64{0.0000000760368, 0.0000000497405, 1000, 55, 10} newPct.Currency["2"] = []float64{0.0000000760368, 0.0000000497405, 1000, 55, 10} newPct.Referral["first"] = 30 newPct.Referral["second"] = 0 newPct.Referral["third"] = 30 newPct.Admin = 100 newPctJson, _ := json.Marshal(newPct) //newPct1:=new(vComplex) //err := json.Unmarshal([]byte(`{"currency":{"1":[7.60368e-08,4.97405e-08,1000,55,10],"2":[7.60368e-08,4.97405e-08,1000,55,10],"33":[7.60368e-08,4.97405e-08,1000,55,10]},"referral":{"first":30,"second":0,"third":30},"admin":100}`), &newPct1) //fmt.Println(newPct1) //fmt.Println(err) var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, userId) // newPctJson txSlice = append(txSlice, []byte(newPctJson)) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func (c *Controller) CurrencyExchangeDelete() (string, error) { txType := "DelForexOrder" txTypeId := utils.TypeInt(txType) timeNow := time.Now().Unix() delId := utils.StrToInt64(c.Parameters["del_id"]) signData := fmt.Sprintf("%d,%d,%d,%d", txTypeId, timeNow, c.SessUserId, delId) /*data, err := static.Asset("static/templates/currency_exchange_delete.html") if err != nil { return "", utils.ErrInfo(err) } signatures, err := static.Asset("static/templates/signatures.html") if err != nil { return "", utils.ErrInfo(err) } alert_success, err := static.Asset("static/templates/alert_success.html") if err != nil { return "", utils.ErrInfo(err) } t := template.Must(template.New("template").Parse(string(data))) t = template.Must(t.Parse(string(alert_success))) t = template.Must(t.Parse(string(signatures))) b := new(bytes.Buffer) t.ExecuteTemplate(b, "currencyExchangeDelete", ¤cyExchangeDeletePage{ Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, UserId: c.SessUserId, TimeNow: timeNow, TxType: txType, TxTypeId: txTypeId, DelId: delId, SignData: signData}) return b.String(), nil*/ TemplateStr, err := makeTemplate("currency_exchange_delete", "currencyExchangeDelete", ¤cyExchangeDeletePage{ Lang: c.Lang, CountSignArr: c.CountSignArr, ShowSignData: c.ShowSignData, UserId: c.SessUserId, TimeNow: timeNow, TxType: txType, TxTypeId: txTypeId, DelId: delId, SignData: signData}) if err != nil { return "", utils.ErrInfo(err) } return TemplateStr, nil }
func (p *Parser) AdminBanUnbanChat() error { users_ids := strings.Split(p.TxMaps.String["users_ids"], ",") for i := 0; i < len(users_ids); i++ { userId := utils.StrToInt64(users_ids[i]) err := p.selectiveLoggingAndUpd([]string{"chat_ban"}, []interface{}{1}, "users", []string{"user_id"}, []string{utils.Int64ToStr(userId)}) if err != nil { return p.ErrInfo(err) } } return nil }
func main() { f := tests_utils.InitLog() defer f.Close() txType := "SendDc" txTime := "1409288580" userId := []byte("2") var blockId int64 = 10000 var txSlice [][]byte // hash txSlice = append(txSlice, []byte("22cb812e53e22ee539af4a1d39b4596d")) // type txSlice = append(txSlice, utils.Int64ToByte(utils.TypeInt(txType))) // time txSlice = append(txSlice, []byte(txTime)) // user_id txSlice = append(txSlice, userId) // to_user_id txSlice = append(txSlice, []byte("2")) // currency_id txSlice = append(txSlice, []byte("72")) // amount txSlice = append(txSlice, []byte("8")) // commission txSlice = append(txSlice, []byte("0.1")) /* for i:=0; i<5; i++ { txSlice = append(txSlice, []byte("0")) } for i:=0; i<5; i++ { txSlice = append(txSlice, []byte("0")) }*/ // comment txSlice = append(txSlice, []byte("1111111111111111111111111111111111")) // sign txSlice = append(txSlice, []byte("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")) blockData := new(utils.BlockData) blockData.BlockId = blockId blockData.Time = utils.StrToInt64(txTime) blockData.UserId = utils.BytesToInt64(userId) err := tests_utils.MakeTest(txSlice, blockData, txType, "work_and_rollback") if err != nil { fmt.Println(err) } }
func GetSessUserId(sess session.SessionStore) int64 { sessUserId := sess.Get("user_id") log.Debug("sessUserId: %v", sessUserId) switch sessUserId.(type) { case int64: return sessUserId.(int64) case int: return int64(sessUserId.(int)) case string: return utils.StrToInt64(sessUserId.(string)) default: return 0 } return 0 }