forked from blocktree/tron-adapter
/
manager.go
107 lines (88 loc) · 3.25 KB
/
manager.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
/*
* 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 tron
import (
"github.com/blocktree/openwallet/v2/hdkeystore"
"github.com/blocktree/openwallet/v2/log"
"github.com/blocktree/openwallet/v2/openwallet"
"github.com/shopspring/decimal"
)
var (
//coinDecimal decimal.Decimal = decimal.NewFromFloat(1000000)
coinDecimal decimal.Decimal = decimal.NewFromFloat(1000000)
)
func init() {
// log.SetFlags(log.Lshortfile | log.LstdFlags)
}
// WalletManager struct
type WalletManager struct {
openwallet.AssetsAdapterBase
Config *WalletConfig //钱包管理配置
Storage *hdkeystore.HDKeystore //秘钥存取
FullnodeClient *Client // 全节点客户端
WalletClient *Client // 节点客户端
Log *log.OWLogger //日志工具
WalletsInSum map[string]*openwallet.Wallet //参与汇总的钱包
Blockscanner *TronBlockScanner //区块扫描器
AddrDecoder openwallet.AddressDecoder //地址编码器
TxDecoder openwallet.TransactionDecoder //交易单编码器
ContractDecoder openwallet.SmartContractDecoder //
}
// NewWalletManager create instance
func NewWalletManager() *WalletManager {
wm := WalletManager{}
wm.Config = NewConfig()
wm.Storage = hdkeystore.NewHDKeystore(wm.Config.keyDir, hdkeystore.StandardScryptN, hdkeystore.StandardScryptP)
wm.WalletsInSum = make(map[string]*openwallet.Wallet)
wm.Blockscanner = NewTronBlockScanner(&wm)
wm.AddrDecoder = NewAddressDecoder(&wm)
wm.TxDecoder = NewTransactionDecoder(&wm)
wm.Log = log.NewOWLogger(wm.Symbol())
wm.ContractDecoder = NewContractDecoder(&wm)
//wm.WalletClient = NewClient("http://192.168.27.124:18090", "", true)
return &wm
}
//------------------------------------------------------------------------------------------------
//CurveType 曲线类型
func (wm *WalletManager) CurveType() uint32 {
return wm.Config.CurveType
}
//FullName 币种全名
func (wm *WalletManager) FullName() string {
return "TRX"
}
//Symbol 币种标识
func (wm *WalletManager) Symbol() string {
return wm.Config.Symbol
}
//Decimal 小数位精度 *1000000
func (wm *WalletManager) Decimal() int32 {
return Decimals
}
//GetAddressDecode 地址解析器
func (wm *WalletManager) GetAddressDecode() openwallet.AddressDecoder {
return wm.AddrDecoder
}
//GetTransactionDecoder 交易单解析器
func (wm *WalletManager) GetTransactionDecoder() openwallet.TransactionDecoder {
return wm.TxDecoder
}
//GetBlockScanner 获取区块链
func (wm *WalletManager) GetBlockScanner() openwallet.BlockScanner {
return wm.Blockscanner
}
func (this *WalletManager) GetSmartContractDecoder() openwallet.SmartContractDecoder {
return this.ContractDecoder
}