github.com/turingchain2020/turingchain@v1.1.21/wallet/common/walletoperate.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package common 实现钱包基础功能包 6 package common 7 8 import ( 9 "math/rand" 10 "reflect" 11 "sync" 12 13 "github.com/turingchain2020/turingchain/client" 14 "github.com/turingchain2020/turingchain/common/crypto" 15 "github.com/turingchain2020/turingchain/common/db" 16 "github.com/turingchain2020/turingchain/types" 17 ) 18 19 var ( 20 // QueryData 查询接口数据全局对象 21 QueryData = types.NewQueryData("On_") 22 // PolicyContainer 钱包业务容器 23 PolicyContainer = make(map[string]WalletBizPolicy) 24 ) 25 26 // Init 初始化所有已经注册的钱包业务 27 func Init(wallet WalletOperate, sub map[string][]byte) { 28 for k, v := range PolicyContainer { 29 v.Init(wallet, sub[k]) 30 } 31 } 32 33 // RegisterPolicy 注册钱包业务策略接口 34 func RegisterPolicy(key string, policy WalletBizPolicy) { 35 if _, existed := PolicyContainer[key]; existed { 36 panic("RegisterPolicy dup") 37 } 38 PolicyContainer[key] = policy 39 QueryData.Register(key, policy) 40 QueryData.SetThis(key, reflect.ValueOf(policy)) 41 } 42 43 // WalletOperate 钱包对业务插件提供服务的操作接口 44 type WalletOperate interface { 45 RegisterMineStatusReporter(reporter MineStatusReport) error 46 47 GetAPI() client.QueueProtocolAPI 48 GetDBStore() db.DB 49 GetSignType() int 50 GetCoinType() uint32 51 GetPassword() string 52 GetBlockHeight() int64 53 GetRandom() *rand.Rand 54 GetWalletDone() chan struct{} 55 GetLastHeader() *types.Header 56 GetTxDetailByHashs(ReqHashes *types.ReqHashes) 57 GetWaitGroup() *sync.WaitGroup 58 GetAllPrivKeys() ([]crypto.PrivKey, error) 59 GetWalletAccounts() ([]*types.WalletAccountStore, error) 60 GetPrivKeyByAddr(addr string) (crypto.PrivKey, error) 61 GetConfig() *types.Wallet 62 GetBalance(addr string, execer string) (*types.Account, error) 63 64 IsWalletLocked() bool 65 IsClose() bool 66 IsCaughtUp() bool 67 AddrInWallet(addr string) bool 68 69 CheckWalletStatus() (bool, error) 70 Nonce() int64 71 72 WaitTx(hash []byte) *types.TransactionDetail 73 WaitTxs(hashes [][]byte) (ret []*types.TransactionDetail) 74 SendTransaction(payload types.Message, execer []byte, priv crypto.PrivKey, to string) (hash []byte, err error) 75 SendToAddress(priv crypto.PrivKey, addrto string, amount int64, note string, Istoken bool, tokenSymbol string) (*types.ReplyHash, error) 76 }