-
Notifications
You must be signed in to change notification settings - Fork 50
/
model.go
110 lines (88 loc) · 2.94 KB
/
model.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
/*
* Copyright 2018 The openwallet Authors
* This file is part of the openwallet library.
*
* The openwallet library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The openwallet library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
package sia
import (
"github.com/asdine/storm"
"github.com/blocktree/openwallet/common/file"
"github.com/tidwall/gjson"
"path/filepath"
)
//Wallet 钱包模型
type Wallet struct {
WalletID string `json:"rootid"`
Alias string `json:"alias"`
Balance string `json:"balance"`
Password string `json:"password"`
RootPub string `json:"rootpub"`
KeyFile string
ConfirmBalance string `json:"confirmedsiacoinbalance"`
OutgoingSC string `json:"unconfirmedoutgoingsiacoins"`
IncomingSC string `json:"unconfirmedincomingsiacoins"`
SiaFundBalance string `json:"siafundbalance"`
SiaCoinClaimBalance string `json:"siacoinclaimbalance"`
Rescanning bool `json:"rescanning"`
Unlocked bool `json:"unlocked"`
Encrypted bool `json:"encrypted"`
}
//NewWallet 创建钱包
func NewWallet(json gjson.Result) *Wallet {
w := &Wallet{}
//解析json
w.ConfirmBalance = gjson.Get(json.Raw, "confirmedsiacoinbalance").String()
w.OutgoingSC = gjson.Get(json.Raw, "unconfirmedoutgoingsiacoins").String()
w.IncomingSC = gjson.Get(json.Raw, "unconfirmedincomingsiacoins").String()
w.SiaFundBalance = gjson.Get(json.Raw, "siafundbalance").String()
w.SiaCoinClaimBalance = gjson.Get(json.Raw, "siacoinclaimbalance").String()
w.Rescanning = gjson.Get(json.Raw, "rescanning").Bool()
w.Unlocked = gjson.Get(json.Raw, "unlocked").Bool()
w.Encrypted = gjson.Get(json.Raw, "encrypted").Bool()
return w
}
//HDKey 获取钱包密钥,需要密码
//func (w *Wallet) HDKey(password string) (*keystore.HDKey, error) {
// key, err := storage.GetKey(w.WalletID, w.KeyFile, password)
// if err != nil {
// return nil, err
// }
// return key, err
//}
//openDB 打开钱包数据库
func (w *Wallet) OpenDB() (*storm.DB, error) {
file.MkdirAll(dbPath)
file := filepath.Join(dbPath, w.FileName()+".db")
return storm.Open(file)
}
//FileName 该钱包定义的文件名规则
func (w *Wallet)FileName() string {
return w.Alias+"-"+w.WalletID
}
type Account struct {
Alias string `json:"alias"`
ID string `json:"id"`
KeyIndex int64 `json:"key_index"`
Quorum int64 `json:"quorum"`
XPubs []string `json:"xpubs"`
}
type Address struct {
//Alias string
//AccountId string
Address string
}
func NewAddress(json gjson.Result) *Address {
a := &Address{}
//解析json
a.Address = gjson.Get(json.Raw, "address").String()
return a
}