Documentation ¶
Overview ¶
Package wallet wallet turingchain钱包功能实现
Index ¶
- Constants
- Variables
- func AesgcmDecrypter(password []byte, seed []byte) ([]byte, error)
- func AesgcmEncrypter(password []byte, seed []byte) ([]byte, error)
- func CalcWalletPassKey() []byte
- func CreateSeed(folderpath string, lang int32) (string, error)
- func DisableLog()
- func GetPrivkeyBySeed(db dbm.DB, seed string, specificIndex uint32, SignType int, coinType uint32) (string, error)
- func GetSeed(db dbm.DB, password string) (string, error)
- func InitSeedLibrary()
- func SaveSeedInBatch(db dbm.DB, seed string, password string, batch dbm.Batch) (bool, error)
- func SetLogLevel(level string)
- func VerifySeed(seed string, signType int, coinType uint32) (bool, error)
- type Wallet
- func (wallet *Wallet) AddWaitGroup(delta int)
- func (wallet *Wallet) AddrInWallet(addr string) bool
- func (wallet *Wallet) CheckWalletStatus() (bool, error)
- func (wallet *Wallet) Close()
- func (wallet *Wallet) ExecWallet(msg *queue.Message) (types.Message, error)
- func (wallet *Wallet) GenSeed(lang int32) (*types.ReplySeed, error)
- func (wallet *Wallet) GetAPI() client.QueueProtocolAPI
- func (wallet *Wallet) GetAccountByAddr(addr string) (*types.WalletAccountStore, error)
- func (wallet *Wallet) GetAccountByLabel(label string) (*types.WalletAccountStore, error)
- func (wallet *Wallet) GetAllPrivKeys() ([]crypto.PrivKey, error)
- func (wallet *Wallet) GetBalance(addr string, execer string) (*types.Account, error)
- func (wallet *Wallet) GetBlockHeight() int64
- func (wallet *Wallet) GetCoinType() uint32
- func (wallet *Wallet) GetConfig() *types.Wallet
- func (wallet *Wallet) GetDBStore() dbm.DB
- func (wallet *Wallet) GetHeight() int64
- func (wallet *Wallet) GetLastHeader() *types.Header
- func (wallet *Wallet) GetPassword() string
- func (wallet *Wallet) GetPrivKeyByAddr(addr string) (crypto.PrivKey, error)
- func (wallet *Wallet) GetRandom() *rand.Rand
- func (wallet *Wallet) GetSeed(password string) (string, error)
- func (wallet *Wallet) GetSignType() int
- func (wallet *Wallet) GetTxDetailByHashs(ReqHashes *types.ReqHashes)
- func (wallet *Wallet) GetWaitGroup() *sync.WaitGroup
- func (wallet *Wallet) GetWalletAccounts() ([]*types.WalletAccountStore, error)
- func (wallet *Wallet) GetWalletDone() chan struct{}
- func (wallet *Wallet) GetWalletStatus() *types.WalletStatus
- func (wallet *Wallet) IsCaughtUp() bool
- func (wallet *Wallet) IsClose() bool
- func (wallet *Wallet) IsRescanUtxosFlagScaning() (bool, error)
- func (wallet *Wallet) IsTransfer(addr string) (bool, error)
- func (wallet *Wallet) IsWalletLocked() bool
- func (wallet *Wallet) Nonce() int64
- func (wallet *Wallet) On_AddBlock(block *types.BlockDetail) (types.Message, error)
- func (wallet *Wallet) On_DelBlock(block *types.BlockDetail) (types.Message, error)
- func (wallet *Wallet) On_DumpPrivkey(req *types.ReqString) (types.Message, error)
- func (wallet *Wallet) On_DumpPrivkeysFile(req *types.ReqPrivkeysFile) (types.Message, error)
- func (wallet *Wallet) On_ErrToFront(req *types.ReportErrEvent) (types.Message, error)
- func (wallet *Wallet) On_FatalFailure(req *types.ReqNil) (types.Message, error)
- func (wallet *Wallet) On_GenSeed(req *types.GenSeedLang) (types.Message, error)
- func (wallet *Wallet) On_GetSeed(req *types.GetSeedByPw) (types.Message, error)
- func (wallet *Wallet) On_GetWalletStatus(req *types.ReqNil) (types.Message, error)
- func (wallet *Wallet) On_ImportPrivkeysFile(req *types.ReqPrivkeysFile) (types.Message, error)
- func (wallet *Wallet) On_NewAccount(req *types.ReqNewAccount) (types.Message, error)
- func (wallet *Wallet) On_NewAccountByIndex(req *types.Int32) (types.Message, error)
- func (wallet *Wallet) On_SaveSeed(req *types.SaveSeedByPw) (types.Message, error)
- func (wallet *Wallet) On_SignRawTx(req *types.ReqSignRawTx) (types.Message, error)
- func (wallet *Wallet) On_WalletGetAccount(req *types.ReqGetAccount) (types.Message, error)
- func (wallet *Wallet) On_WalletGetAccountList(req *types.ReqAccountList) (types.Message, error)
- func (wallet *Wallet) On_WalletImportPrivkey(req *types.ReqWalletImportPrivkey) (types.Message, error)
- func (wallet *Wallet) On_WalletLock(req *types.ReqNil) (types.Message, error)
- func (wallet *Wallet) On_WalletMergeBalance(req *types.ReqWalletMergeBalance) (types.Message, error)
- func (wallet *Wallet) On_WalletSendToAddress(req *types.ReqWalletSendToAddress) (types.Message, error)
- func (wallet *Wallet) On_WalletSetFee(req *types.ReqWalletSetFee) (types.Message, error)
- func (wallet *Wallet) On_WalletSetLabel(req *types.ReqWalletSetLabel) (types.Message, error)
- func (wallet *Wallet) On_WalletSetPasswd(req *types.ReqWalletSetPasswd) (types.Message, error)
- func (wallet *Wallet) On_WalletTransactionList(req *types.ReqWalletTransactionList) (types.Message, error)
- func (wallet *Wallet) On_WalletUnLock(req *types.WalletUnLock) (types.Message, error)
- func (wallet *Wallet) ProcCreateNewAccount(Label *types.ReqNewAccount) (*types.WalletAccount, error)
- func (wallet *Wallet) ProcDumpPrivkey(addr string) (string, error)
- func (wallet *Wallet) ProcDumpPrivkeysFile(fileName, passwd string) error
- func (wallet *Wallet) ProcGetAccount(req *types.ReqGetAccount) (*types.WalletAccount, error)
- func (wallet *Wallet) ProcGetAccountList(req *types.ReqAccountList) (*types.WalletAccounts, error)
- func (wallet *Wallet) ProcImportPrivKey(PrivKey *types.ReqWalletImportPrivkey) (*types.WalletAccount, error)
- func (wallet *Wallet) ProcImportPrivkeysFile(fileName, passwd string) error
- func (wallet *Wallet) ProcMergeBalance(MergeBalance *types.ReqWalletMergeBalance) (*types.ReplyHashes, error)
- func (wallet *Wallet) ProcRecvMsg()
- func (wallet *Wallet) ProcSendToAddress(SendToAddress *types.ReqWalletSendToAddress) (*types.ReplyHash, error)
- func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error)
- func (wallet *Wallet) ProcWalletAddBlock(block *types.BlockDetail)
- func (wallet *Wallet) ProcWalletDelBlock(block *types.BlockDetail)
- func (wallet *Wallet) ProcWalletLock() error
- func (wallet *Wallet) ProcWalletSetFee(WalletSetFee *types.ReqWalletSetFee) error
- func (wallet *Wallet) ProcWalletSetLabel(SetLabel *types.ReqWalletSetLabel) (*types.WalletAccount, error)
- func (wallet *Wallet) ProcWalletSetPasswd(Passwd *types.ReqWalletSetPasswd) error
- func (wallet *Wallet) ProcWalletTxList(TxList *types.ReqWalletTransactionList) (*types.WalletTxDetails, error)
- func (wallet *Wallet) ProcWalletUnLock(WalletUnLock *types.WalletUnLock) error
- func (wallet *Wallet) RegisterMineStatusReporter(reporter wcom.MineStatusReport) error
- func (wallet *Wallet) SaveSeed(password string, seed string) (bool, error)
- func (wallet *Wallet) SendToAddress(priv crypto.PrivKey, addrto string, amount int64, note string, Istoken bool, ...) (*types.ReplyHash, error)
- func (wallet *Wallet) SendTransaction(payload types.Message, execer []byte, priv crypto.PrivKey, to string) (hash []byte, err error)
- func (wallet *Wallet) SetQueueClient(cli queue.Client)
- func (wallet *Wallet) SetWalletAccount(update bool, addr string, account *types.WalletAccountStore) error
- func (wallet *Wallet) Wait()
- func (wallet *Wallet) WaitGroupDone()
- func (wallet *Wallet) WaitTx(hash []byte) *types.TransactionDetail
- func (wallet *Wallet) WaitTxs(hashes [][]byte) (ret []*types.TransactionDetail)
Constants ¶
const ( // AddTx 添加交易操作 AddTx int32 = 20001 // DelTx 删除交易操作 DelTx int32 = 20002 )
const BACKUPKEYINDEX = "backupkeyindex"
BACKUPKEYINDEX 备份索引Key值
Variables ¶
var ( // SeedLong 随机种子的长度 SeedLong = 15 // SaveSeedLong 保存的随机种子个数 SaveSeedLong = 12 // WalletSeed 钱包种子前缀 WalletSeed = []byte("walletseed") // ChineseSeedCache 中文种子缓存映射 ChineseSeedCache = make(map[string]string) // EnglishSeedCache 英文种子缓存映射 EnglishSeedCache = make(map[string]string) )
var ( // MaxTxHashsPerTime 每次处理的最大交易哈希数量 MaxTxHashsPerTime int64 = 100 )
Functions ¶
func AesgcmDecrypter ¶
AesgcmDecrypter 使用钱包的password对seed进行aesgcm解密,返回解密后的seed
func AesgcmEncrypter ¶
AesgcmEncrypter 使用钱包的password对seed进行aesgcm加密,返回加密后的seed
func CreateSeed ¶
CreateSeed 通过指定语言类型生成seed种子,传入语言类型以及 lang = 0 通过英语单词生成种子 lang = 1 通过中文生成种子 bitsize=128 返回12个单词或者汉子,bitsize+32=160 返回15个单词或者汉子,bitszie=256 返回24个单词或者汉子
func GetPrivkeyBySeed ¶
func GetPrivkeyBySeed(db dbm.DB, seed string, specificIndex uint32, SignType int, coinType uint32) (string, error)
GetPrivkeyBySeed 通过seed生成子私钥十六进制字符串
func SaveSeedInBatch ¶
SaveSeedInBatch 保存种子数据到数据库
Types ¶
type Wallet ¶
type Wallet struct { Password string FeeAmount int64 EncryptFlag int64 SignType int // SignType 签名类型 1;secp256k1,2:ed25519,3:sm2 CoinType uint32 // CoinType 币种类型 trc:0x80003333,ycc:0x80003334 // contains filtered or unexported fields }
Wallet 钱包功能的实现类
func (*Wallet) AddrInWallet ¶
AddrInWallet 地址对应的账户是否属于本钱包
func (*Wallet) CheckWalletStatus ¶
CheckWalletStatus 钱包状态检测函数,解锁状态,seed是否已保存
func (*Wallet) ExecWallet ¶
ExecWallet 执行钱包的功能
func (*Wallet) GetAccountByAddr ¶
func (wallet *Wallet) GetAccountByAddr(addr string) (*types.WalletAccountStore, error)
GetAccountByAddr 根据地址获取账户
func (*Wallet) GetAccountByLabel ¶
func (wallet *Wallet) GetAccountByLabel(label string) (*types.WalletAccountStore, error)
GetAccountByLabel 根据标签获取账号
func (*Wallet) GetAllPrivKeys ¶
GetAllPrivKeys 获取所有私钥信息
func (*Wallet) GetBalance ¶
GetBalance 根据地址和执行器类型获取对应的金额
func (*Wallet) GetLastHeader ¶
GetLastHeader 获取最新高度信息
func (*Wallet) GetPrivKeyByAddr ¶
GetPrivKeyByAddr 根据地址获取私钥
func (*Wallet) GetTxDetailByHashs ¶
GetTxDetailByHashs 根据交易哈希获取对应的交易详情
func (*Wallet) GetWaitGroup ¶
GetWaitGroup 获取等待互斥量
func (*Wallet) GetWalletAccounts ¶
func (wallet *Wallet) GetWalletAccounts() ([]*types.WalletAccountStore, error)
GetWalletAccounts 获取账号列表
func (*Wallet) GetWalletDone ¶
func (wallet *Wallet) GetWalletDone() chan struct{}
GetWalletDone 是否结束的通道
func (*Wallet) GetWalletStatus ¶
func (wallet *Wallet) GetWalletStatus() *types.WalletStatus
GetWalletStatus 获取钱包状态
func (*Wallet) IsRescanUtxosFlagScaning ¶
IsRescanUtxosFlagScaning 是否处于扫描UTXO状态
func (*Wallet) IsTransfer ¶
IsTransfer 检测钱包是否允许转账到指定地址,判断钱包锁和是否有seed以及挖矿锁
func (*Wallet) On_AddBlock ¶
On_AddBlock 处理新增区块
func (*Wallet) On_DelBlock ¶
On_DelBlock 处理删除区块
func (*Wallet) On_DumpPrivkey ¶
On_DumpPrivkey 处理到处私钥
func (*Wallet) On_DumpPrivkeysFile ¶
On_DumpPrivkeysFile 处理到处私钥
func (*Wallet) On_ErrToFront ¶
On_ErrToFront 错误通知
func (*Wallet) On_FatalFailure ¶
On_FatalFailure 定时查询是否有致命性故障产生
func (*Wallet) On_GenSeed ¶
On_GenSeed 处理创建SEED
func (*Wallet) On_GetSeed ¶
On_GetSeed 处理获取Seed
func (*Wallet) On_GetWalletStatus ¶
On_GetWalletStatus 处理获取钱包状态
func (*Wallet) On_ImportPrivkeysFile ¶
On_ImportPrivkeysFile 响应导入多个私钥
func (*Wallet) On_NewAccount ¶
On_NewAccount 响应新建账号
func (*Wallet) On_NewAccountByIndex ¶
On_NewAccountByIndex 获取指定index的私钥,返回私钥的hex字符串ReqString
func (*Wallet) On_SaveSeed ¶
On_SaveSeed 处理保存SEED
func (*Wallet) On_SignRawTx ¶
On_SignRawTx 处理交易签名
func (*Wallet) On_WalletGetAccount ¶
On_WalletGetAccount 通过账户标签获取账户地址
func (*Wallet) On_WalletGetAccountList ¶
On_WalletGetAccountList 响应获取账户列表
func (*Wallet) On_WalletImportPrivkey ¶
func (wallet *Wallet) On_WalletImportPrivkey(req *types.ReqWalletImportPrivkey) (types.Message, error)
On_WalletImportPrivkey 响应导入私钥
func (*Wallet) On_WalletLock ¶
On_WalletLock 处理钱包加锁
func (*Wallet) On_WalletMergeBalance ¶
func (wallet *Wallet) On_WalletMergeBalance(req *types.ReqWalletMergeBalance) (types.Message, error)
On_WalletMergeBalance 响应钱包合并金额
func (*Wallet) On_WalletSendToAddress ¶
func (wallet *Wallet) On_WalletSendToAddress(req *types.ReqWalletSendToAddress) (types.Message, error)
On_WalletSendToAddress 响应钱包想地址转账
func (*Wallet) On_WalletSetFee ¶
On_WalletSetFee 响应设置钱包手续费
func (*Wallet) On_WalletSetLabel ¶
On_WalletSetLabel 处理钱包设置标签
func (*Wallet) On_WalletSetPasswd ¶
On_WalletSetPasswd 处理钱包设置密码
func (*Wallet) On_WalletTransactionList ¶
func (wallet *Wallet) On_WalletTransactionList(req *types.ReqWalletTransactionList) (types.Message, error)
On_WalletTransactionList 响应获取钱包交易列表
func (*Wallet) On_WalletUnLock ¶
On_WalletUnLock 处理钱包解锁
func (*Wallet) ProcCreateNewAccount ¶
func (wallet *Wallet) ProcCreateNewAccount(Label *types.ReqNewAccount) (*types.WalletAccount, error)
ProcCreateNewAccount 处理创建新账号 input:
type ReqNewAccount struct { Label string
output:
type WalletAccount struct { Acc *Account Label string
type Account struct { Currency int32 Balance int64 Frozen int64 Addr string
创建一个新的账户
func (*Wallet) ProcDumpPrivkey ¶
ProcDumpPrivkey 获取地址对应的私钥
func (*Wallet) ProcDumpPrivkeysFile ¶
ProcDumpPrivkeysFile 获取全部私钥保存到文件
func (*Wallet) ProcGetAccount ¶
func (wallet *Wallet) ProcGetAccount(req *types.ReqGetAccount) (*types.WalletAccount, error)
ProcGetAccount 通过地址标签获取账户地址
func (*Wallet) ProcGetAccountList ¶
func (wallet *Wallet) ProcGetAccountList(req *types.ReqAccountList) (*types.WalletAccounts, error)
ProcGetAccountList 获取钱包账号列表 output:
type WalletAccounts struct { Wallets []*WalletAccount
type WalletAccount struct { Acc *Account Label string
获取钱包的地址列表
func (*Wallet) ProcImportPrivKey ¶
func (wallet *Wallet) ProcImportPrivKey(PrivKey *types.ReqWalletImportPrivkey) (*types.WalletAccount, error)
ProcImportPrivKey 处理导入私钥 input:
type ReqWalletImportPrivKey struct { Privkey string Label string
output:
type WalletAccount struct { Acc *Account Label string
导入私钥,并且同时会导入交易
func (*Wallet) ProcImportPrivkeysFile ¶
ProcImportPrivkeysFile 处理导入私钥 input:
type struct { fileName string passwd string
导入私钥,并且同时会导入交易
func (*Wallet) ProcMergeBalance ¶
func (wallet *Wallet) ProcMergeBalance(MergeBalance *types.ReqWalletMergeBalance) (*types.ReplyHashes, error)
ProcMergeBalance 处理 input:
type ReqWalletMergeBalance struct { To string
output:
type ReplyHashes struct { Hashes [][]byte
合并所有的balance 到一个地址
func (*Wallet) ProcSendToAddress ¶
func (wallet *Wallet) ProcSendToAddress(SendToAddress *types.ReqWalletSendToAddress) (*types.ReplyHash, error)
ProcSendToAddress 响应发送到地址 input:
type ReqWalletSendToAddress struct { From string To string Amount int64 Note string
output:
type ReplyHash struct { Hashe []byte
发送一笔交易给对方地址,返回交易hash
func (*Wallet) ProcSignRawTx ¶
func (wallet *Wallet) ProcSignRawTx(unsigned *types.ReqSignRawTx) (string, error)
ProcSignRawTx 用钱包对交易进行签名 input:
type ReqSignRawTx struct { Addr string Privkey string TxHex string Expire string }
output: string 签名交易
func (*Wallet) ProcWalletAddBlock ¶
func (wallet *Wallet) ProcWalletAddBlock(block *types.BlockDetail)
ProcWalletAddBlock wallet模块收到blockchain广播的addblock消息,需要解析钱包相关的tx并存储到db中
func (*Wallet) ProcWalletDelBlock ¶
func (wallet *Wallet) ProcWalletDelBlock(block *types.BlockDetail)
ProcWalletDelBlock wallet模块收到blockchain广播的delblock消息,需要解析钱包相关的tx并存db中删除
func (*Wallet) ProcWalletSetFee ¶
func (wallet *Wallet) ProcWalletSetFee(WalletSetFee *types.ReqWalletSetFee) error
ProcWalletSetFee 处理设置手续费
type ReqWalletSetFee struct { Amount int64
设置钱包默认的手续费
func (*Wallet) ProcWalletSetLabel ¶
func (wallet *Wallet) ProcWalletSetLabel(SetLabel *types.ReqWalletSetLabel) (*types.WalletAccount, error)
ProcWalletSetLabel 处理设置账号标签 input:
type ReqWalletSetLabel struct { Addr string Label string
output:
type WalletAccount struct { Acc *Account Label string
设置某个账户的标签
func (*Wallet) ProcWalletSetPasswd ¶
func (wallet *Wallet) ProcWalletSetPasswd(Passwd *types.ReqWalletSetPasswd) error
ProcWalletSetPasswd 处理钱包的保存密码 input:
type ReqWalletSetPasswd struct { Oldpass string Newpass string
设置或者修改密码
func (*Wallet) ProcWalletTxList ¶
func (wallet *Wallet) ProcWalletTxList(TxList *types.ReqWalletTransactionList) (*types.WalletTxDetails, error)
ProcWalletTxList 处理获取钱包交易列表 input:
type ReqWalletTransactionList struct { FromTx []byte Count int32
output:
type WalletTxDetails struct { TxDetails []*WalletTxDetail
type WalletTxDetail struct { Tx *Transaction Receipt *ReceiptData Height int64 Index int64
获取所有钱包的交易记录
func (*Wallet) ProcWalletUnLock ¶
func (wallet *Wallet) ProcWalletUnLock(WalletUnLock *types.WalletUnLock) error
ProcWalletUnLock 处理钱包解锁 input:
type WalletUnLock struct { Passwd string Timeout int64
解锁钱包Timeout时间,超时后继续锁住
func (*Wallet) RegisterMineStatusReporter ¶
func (wallet *Wallet) RegisterMineStatusReporter(reporter wcom.MineStatusReport) error
RegisterMineStatusReporter 向钱包注册状态回报
func (*Wallet) SendToAddress ¶
func (wallet *Wallet) SendToAddress(priv crypto.PrivKey, addrto string, amount int64, note string, Istoken bool, tokenSymbol string) (*types.ReplyHash, error)
SendToAddress 想合约地址转账
func (*Wallet) SendTransaction ¶
func (wallet *Wallet) SendTransaction(payload types.Message, execer []byte, priv crypto.PrivKey, to string) (hash []byte, err error)
SendTransaction 发送一笔交易
func (*Wallet) SetQueueClient ¶
SetQueueClient 初始化客户端消息队列
func (*Wallet) SetWalletAccount ¶
func (wallet *Wallet) SetWalletAccount(update bool, addr string, account *types.WalletAccountStore) error
SetWalletAccount 设置钱包账户
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bipwallet 比特币改进协议钱包相关定义
|
Package bipwallet 比特币改进协议钱包相关定义 |
basen
Package basen basen (base-N) is a simple Go encoding package for representing bytes as big integers in arbitrary base-N encoding.
|
Package basen basen (base-N) is a simple Go encoding package for representing bytes as big integers in arbitrary base-N encoding. |
btcutilecc
Package btcutil Utility functions for Bitcoin elliptic curve cryptography.
|
Package btcutil Utility functions for Bitcoin elliptic curve cryptography. |
go-bip32
Package bip32 A fully compliant implementation of the BIP0032 spec for Hierarchical Deterministic Bitcoin addresses
|
Package bip32 A fully compliant implementation of the BIP0032 spec for Hierarchical Deterministic Bitcoin addresses |
go-bip39
Package bip39 A golang implementation of the BIP0039 spec for mnemonic seeds
|
Package bip39 A golang implementation of the BIP0039 spec for mnemonic seeds |
go-bip44
Package bip44 基于 BIP32 的系统,赋予树状结构中的各层特殊的意义。
|
Package bip44 基于 BIP32 的系统,赋予树状结构中的各层特殊的意义。 |
transformer
Package transformer 通过私钥生成所选币种的公钥和地址
|
Package transformer 通过私钥生成所选币种的公钥和地址 |
transformer/btcbase
Package btcbase 转换基于比特币地址规则的币种 使用此规则的币种有:BTC、BCH、LTC、ZEC、USDT、 TRC
|
Package btcbase 转换基于比特币地址规则的币种 使用此规则的币种有:BTC、BCH、LTC、ZEC、USDT、 TRC |
Package common 实现钱包基础功能包
|
Package common 实现钱包基础功能包 |