-
Notifications
You must be signed in to change notification settings - Fork 0
/
CIL.go
57 lines (53 loc) · 1.06 KB
/
CIL.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
package main
import (
"fmt"
"os"
"strconv"
)
var useinfo string = `
list 打印链
search --address ADDRESS 查询address余额
send FROM to TO PRICE SOMEONE Data 发送货币从地址1到地址2, 其中最后指定矿工打包交易
wallet 生成一个钱包
show address 显示全部地址
`
type CIL struct {
bc *BlockChain
}
func (cil *CIL) Run() error {
args := os.Args
if len(args) < 2 {
fmt.Println(useinfo)
return nil
}
cmd := args[1]
switch cmd {
case "list":
cil.ShowChain()
case "search":
if len(args) == 4 && args[2] == "--address" {
cil.GetBlance(args[3])
}
case "send":
if len(args) == 8 && args[3] == "to" {
//send FROM to TO PRICE SOMEONE
from := args[2]
to := args[4]
amount, _ := strconv.ParseFloat(args[5], 64)
miner := args[6]
data := args[7]
fmt.Println(amount)
cil.Send(from, to, amount, miner, data)
}
case "wallet":
cil.NewWallet()
case "show":
if len(args) == 3 && args[2] == "address" {
cil.ListAddresses()
}
default:
fmt.Println("参数错误")
fmt.Println(useinfo)
}
return nil
}