forked from sasaxie/go-client-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
71 lines (62 loc) · 1.74 KB
/
account.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
package controllers
import (
"github.com/sasaxie/go-client-api/models"
"encoding/json"
"github.com/astaxie/beego"
"github.com/sasaxie/go-client-api/models/contract"
)
// Operations about Account
type AccountController struct {
beego.Controller
}
// @Title Get account
// @Description get account by address
// @Param address path string true "The key for staticblock"
// @Success 200 {account} models.Account
// @Failure 403 :address is empty
// @router /address/:address [get]
func (a *AccountController) Get() {
address := a.GetString(":address")
if address != "" {
account, err := models.GetAccountByAddress(address)
if err != nil {
a.Data["json"] = err.Error()
} else {
a.Data["json"] = account
}
}
a.ServeJSON()
}
// @Title Get account net message
// @Description get account net message by address
// @Param address path string true
// @Success 200 {accountnetmessage} models.AccountNetMessage
// @Failure 403 :address is empty
// @router /net-message/address/:address [get]
func (a *AccountController) NetMessage() {
address := a.GetString(":address")
if address != "" {
accountNetMessage := models.GetAccountNet(address)
a.Data["json"] = accountNetMessage
}
a.ServeJSON()
}
// @Title Create account
// @Param owneraddress body string true
// @Param accountaddress body string true
// @router /create [post]
func (a *AccountController) CreateAccount() {
var accountCreateContract contract.AccountCreateContract
err := json.Unmarshal(a.Ctx.Input.RequestBody, &accountCreateContract)
if err != nil {
a.Data["json"] = err.Error()
} else {
transaction, err := contract.CreateAccount(accountCreateContract)
if err != nil {
a.Data["json"] = err.Error()
} else {
a.Data["json"] = transaction
}
}
a.ServeJSON()
}