forked from ChainStack-Official/simple_blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (29 loc) · 827 Bytes
/
Copy pathmain.go
File metadata and controls
34 lines (29 loc) · 827 Bytes
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
package main
import (
"os"
"github.com/ChainStack-Official/simple_blockchain/handler"
"github.com/ethereum/go-ethereum/log"
"github.com/gin-gonic/gin"
)
func init() {
// 初始化全局日志
log.Root().SetHandler(log.StreamHandler(os.Stdout, log.TerminalFormat(true)))
}
func main() {
log.Info("启动程序")
// http服务
router := gin.Default()
// 提交一个msg(交易)
router.POST("/msg", handler.NewMsgHandler)
// 新建区块
router.POST("/block", handler.NewBlockHandler)
// 查看当前链上的所有块
router.GET("/block", handler.GetBlocksHandler)
// 修改难度值
router.GET("/mine_conf", handler.ChangeDifficultyHandler)
// 启动挖矿
router.GET("/start_mine", handler.StartMineHandler)
// 停止挖矿
router.GET("/stop_mine", handler.StopMineHandler)
router.Run(":3000")
}