-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (51 loc) · 1.09 KB
/
main.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
package main
import (
"strconv"
"github.com/gin-gonic/gin"
"github.com/jackxu/dApp/logic"
)
func main() {
//step1: init logic imp
err, imp := logic.NewDAppLogic()
if err != nil {
panic(any(err))
}
//step2: create event consume thread
imp.HandleEvent()
//step3: init gin framework
r := gin.Default()
r.GET("/mint", func(c *gin.Context) {
addr := c.Query("addr")
title := c.Query("title")
image := c.Query("image")
amount, _ := strconv.ParseInt(c.Query("amount"), 10, 64)
err, token := imp.Mint(addr, title, image, amount)
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
c.JSON(200, gin.H{
"message": "OK",
"token": token,
})
})
r.GET("/transfer", func(c *gin.Context) {
from := c.Query("from")
to := c.Query("to")
token, _ := strconv.ParseInt(c.Query("token"), 10, 64)
amount, _ := strconv.ParseInt(c.Query("amount"), 10, 64)
err = imp.Transfer(from, to, token, amount)
if err != nil {
c.JSON(200, gin.H{
"message": err.Error(),
})
return
}
c.JSON(200, gin.H{
"message": "OK",
})
})
_ = r.Run()
}