-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwallet_check.go
154 lines (134 loc) · 4.26 KB
/
wallet_check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"fmt"
"net/http"
"strconv"
"github.com/go-macaron/session"
"gopkg.in/macaron.v1"
ms "github.com/ValidatorCenter/minter-go-sdk"
)
// Функция создания чека
func CreateCheck(sess session.Store, coin string, value float32, pswrd string, nonce uint64) (string, error) {
sdk.AccAddress = sess.Get("login").(string)
sdk.AccPrivateKey = sess.Get("priv_k").(string)
chDt := ms.TxCreateCkeckData{
Coin: coin,
Stake: value,
Password: pswrd,
Nonce: nonce,
}
resCheck, err := sdk.TxCreateCheck(&chDt)
if err != nil {
return "", err
}
return resCheck, nil
}
// Функция обналичивания чека
func RedeemCheck(sess session.Store, check string, pswrd string) (string, error) {
sdk.AccAddress = sess.Get("login").(string)
sdk.AccPrivateKey = sess.Get("priv_k").(string)
rchDt := ms.TxRedeemCheckData{
Check: check,
Password: pswrd,
GasCoin: ms.GetBaseCoin(),
GasPrice: 1,
}
resHash, err := sdk.TxRedeemCheck(&rchDt)
if err != nil {
return "", err
}
return resHash, nil
}
// СТРАНИЦА: управления Чеками
func hndWalletTxChecks(ctx *macaron.Context, sess session.Store) {
var alertMsg, alertType, alertAct string
var auth bool = false
var usrName, idUsr string
if sess.Get("login") != nil {
auth = true
idUsr = sess.Get("login").(string)
usrName = fmt.Sprintf("%s...%s", idUsr[:6], idUsr[len(idUsr)-4:len(idUsr)])
} else {
// Редирект на главную или страницу авторизации
ctx.Redirect("/coins")
return
}
//...............................................................
newCheckData := ""
// если был POST!
ctx.Req.ParseForm()
ctx.Resp.WriteHeader(http.StatusOK)
typeAct := ctx.Req.PostFormValue("typeAct")
if typeAct == "REDEEM" {
inputCheck := ctx.Req.PostFormValue("inputCheck")
inputPswrd := ctx.Req.PostFormValue("inputPswrd")
resHash, err := RedeemCheck(sess, inputCheck, inputPswrd)
if err != nil {
alertAct = "Redeem check"
alertMsg = fmt.Sprintf("%s-%s", err, resHash)
alertType = "danger" //danger warning
} else {
alertAct = "Redeem check"
alertMsg = resHash
alertType = "success" //danger warning
}
} else if typeAct == "NEWCHECK" {
inputNonce := ctx.Req.PostFormValue("inputNonce")
inputAmnt := ctx.Req.PostFormValue("inputAmnt")
inputCoin := ctx.Req.PostFormValue("inputCoin")
inputPswrd := ctx.Req.PostFormValue("inputPswrd")
// TODO: в SDK реализовать!
//inputLiveBlock := ctx.Req.PostFormValue("inputLiveBlock")
inputAmnt_f32, err := strconv.ParseFloat(inputAmnt, 32)
if err != nil {
alertAct = "New check(a)"
alertMsg = fmt.Sprintf("%s", err)
alertType = "danger" //danger warning
} else {
inputNonce_i, err := strconv.Atoi(inputNonce)
if err != nil {
alertAct = "New check(i)"
alertMsg = fmt.Sprintf("%s", err)
alertType = "danger" //danger warning
} else {
fmt.Println(inputNonce_i)
resCheck, err := CreateCheck(sess, inputCoin, float32(inputAmnt_f32), inputPswrd, uint64(inputNonce_i))
if err != nil {
alertAct = "New check"
alertMsg = fmt.Sprintf("%s-%s", err, resCheck)
alertType = "danger" //danger warning
} else {
alertAct = "New check"
alertMsg = resCheck
alertType = "success" //danger warning
newCheckData = resCheck
}
}
}
}
//...............................................................
// Последний синхронизированный блок
ResultNetwork, _ := sdk.GetStatus()
statusMDB := srchSysSql(dbSys)
// Инф. о синхронизации БД с БлокЧейном:
ctx.Data["LastSync"] = statusMDB.LatestBlockSave
ctx.Data["Current"] = ResultNetwork.LatestBlockHeight
if sdk.ChainMainnet {
ctx.Data["ChainNet"] = "mainnet"
} else {
ctx.Data["ChainNet"] = "testnet"
}
// получаем список
coinsAddrs, totalAmnt, _ := sdk.GetAddress(idUsr)
ctx.Data["AllCoins"] = coinsAddrs
ctx.Data["TotalAmntInBaseCoin"] = totalAmnt
ctx.Data["NewCheckData"] = newCheckData
ctx.Data["Title"] = "Checks"
ctx.Data["UsrAuth"] = auth
ctx.Data["UsrName"] = usrName
ctx.Data["UsrAddress"] = idUsr
ctx.Data["AlertAct"] = alertAct
ctx.Data["AlertMsg"] = alertMsg
ctx.Data["AlertType"] = alertType
ctx.HTML(200, "tx_checks")
}