當前位置: 首頁>>代碼示例>>Golang>>正文


Golang RedisLogger.Transaction方法代碼示例

本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.Transaction方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.Transaction方法的具體用法?Golang RedisLogger.Transaction怎麽用?Golang RedisLogger.Transaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ginuerzh/sports/models.RedisLogger的用法示例。


在下文中一共展示了RedisLogger.Transaction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: txHandler

func txHandler(r *http.Request, w http.ResponseWriter,
	client *ApnClient, redis *models.RedisLogger, user *models.Account, p Parameter) {
	form := p.(txForm)

	if form.FromAddr == form.ToAddr {
		writeResponse(r.RequestURI, w, map[string]string{"txid": ""}, nil)
		return
	}

	if form.Value <= 0 {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError, "無效的金額"))
		return
	}

	receiver := &models.Account{}
	if find, err := receiver.FindByWalletAddr(form.ToAddr); !find {
		e := errors.NewError(errors.NotFoundError, "無效的收款地址")
		if err != nil {
			e = errors.NewError(errors.DbError, "無效的錢包地址")
		}
		writeResponse(r.RequestURI, w, nil, e)
		return
	}

	if redis.Relationship(receiver.Id, user.Id) == models.RelBlacklist {
		writeResponse(r.RequestURI, w, nil,
			errors.NewError(errors.AccessError, "對方屏蔽了你!"))
		return
	}

	wal, err := getWallet(user.Wallet.Id, user.Wallet.Key)
	if err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, "獲取錢包失敗"))
		return
	}

	outputs, amount, err := getUnspent(form.FromAddr, wal.Keys, form.Value)
	if err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError, "獲取賬戶信息失敗"))
		return
	}
	//log.Println("amount:", amount, "value:", form.Value)

	if form.Value > amount {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.AccessError, "餘額不足"))
		return
	}

	article := &models.Article{}
	if strings.ToLower(form.Type) == "reward" && len(form.Id) > 0 {
		if b, e := article.FindById(form.Id); !b {
			err := errors.NewError(errors.NotExistsError, "文章不存在!")
			if e != nil {
				err = errors.NewError(errors.DbError)
			}
			writeResponse(r.RequestURI, w, nil, err)
			return
		}
	}

	changeAddr := form.FromAddr
	if len(changeAddr) == 0 {
		changeAddr = wal.Keys[0].PubKey
	}
	rawtx, err := CreateRawTx2(outputs, amount, form.Value, form.ToAddr, changeAddr)
	if err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError))
		return
	}

	txid, err := sendRawTx(rawtx)
	if err != nil {
		writeResponse(r.RequestURI, w, nil, errors.NewError(errors.DbError))
		return
	}

	redis.Transaction(user.Id, receiver.Id, form.Value)
	// ws push
	event := &models.Event{
		Type: models.EventWallet,
		Time: time.Now().Unix(),
	}

	//log.Println("tx type:", strings.ToLower(form.Type))

	switch strings.ToLower(form.Type) {
	case "reward":

		article.Reward(user.Id, form.Value)

		event.Data = models.EventData{
			Type: models.EventReward,
			Id:   article.Id.Hex(),
			From: user.Id,
			To:   receiver.Id,
			Body: []models.MsgBody{
				{Type: "nikename", Content: user.Nickname},
				{Type: "image", Content: article.Image},
				{Type: "total_count", Content: strconv.FormatInt(article.TotalReward, 10)},
				//{Type: "new_count", Content: strconv.Itoa(models.EventCount(models.EventReward, article.Id.Hex()) + 1)},
//.........這裏部分代碼省略.........
開發者ID:shevilangle,項目名稱:sports,代碼行數:101,代碼來源:wallet.go


注:本文中的github.com/ginuerzh/sports/models.RedisLogger.Transaction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。