wallet

package
v1.66.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2022 License: BSD-3-Clause Imports: 30 Imported by: 11

Documentation

Overview

Package wallet wallet chain33钱包功能实现

Index

Constants

View Source
const (
	// AddTx 添加交易操作
	AddTx int32 = 20001
	// DelTx 删除交易操作
	DelTx int32 = 20002
)
View Source
const BACKUPKEYINDEX = "backupkeyindex"

BACKUPKEYINDEX 备份索引Key值

Variables

View Source
var (
	// SeedLong 随机种子的长度
	SeedLong = 15
	// SaveSeedLong 保存的随机种子个数
	SaveSeedLong = 12

	// WalletSeed 钱包种子前缀
	WalletSeed = []byte("walletseed")

	// ChineseSeedCache 中文种子缓存映射
	ChineseSeedCache = make(map[string]string)
	// EnglishSeedCache 英文种子缓存映射
	EnglishSeedCache = make(map[string]string)
)
View Source
var (

	// MaxTxHashsPerTime 每次处理的最大交易哈希数量
	MaxTxHashsPerTime int64 = 100
)

Functions

func AesgcmDecrypter

func AesgcmDecrypter(password []byte, seed []byte) ([]byte, error)

AesgcmDecrypter 使用钱包的password对seed进行aesgcm解密,返回解密后的seed

func AesgcmEncrypter

func AesgcmEncrypter(password []byte, seed []byte) ([]byte, error)

AesgcmEncrypter 使用钱包的password对seed进行aesgcm加密,返回加密后的seed

func CalcWalletPassKey

func CalcWalletPassKey() []byte

CalcWalletPassKey 获取钱包密码的数据库字段Key值

func CreateSeed

func CreateSeed(folderpath string, lang int32) (string, error)

CreateSeed 通过指定语言类型生成seed种子,传入语言类型以及 lang = 0 通过英语单词生成种子 lang = 1 通过中文生成种子 bitsize=128 返回12个单词或者汉子,bitsize+32=160 返回15个单词或者汉子,bitszie=256 返回24个单词或者汉子

func DisableLog

func DisableLog()

DisableLog 禁用日志

func GetPrivkeyBySeed

func GetPrivkeyBySeed(db dbm.DB, seed string, specificIndex uint32, SignType int, coinType uint32) (string, error)

GetPrivkeyBySeed 通过seed生成子私钥十六进制字符串

func GetSeed

func GetSeed(db dbm.DB, password string) (string, error)

GetSeed 使用password解密seed上报给上层

func InitSeedLibrary

func InitSeedLibrary()

InitSeedLibrary 初始化seed标准库的单词到map中,方便seed单词的校验

func SaveSeedInBatch

func SaveSeedInBatch(db dbm.DB, seed string, password string, batch dbm.Batch) (bool, error)

SaveSeedInBatch 保存种子数据到数据库

func SetLogLevel

func SetLogLevel(level string)

SetLogLevel 设置日志登记

func VerifySeed

func VerifySeed(seed string, signType int, coinType uint32) (bool, error)

VerifySeed 校验输入的seed字符串数是否合法,通过助记词能否生成钱包来判断合法性

Types

type Wallet

type Wallet struct {
	Password    string
	FeeAmount   int64
	EncryptFlag int64

	SignType int    // SignType 签名类型 1;secp256k1,2:ed25519,3:sm2
	CoinType uint32 // CoinType 币种类型 bty:0x80003333,ycc:0x80003334
	// contains filtered or unexported fields
}

Wallet 钱包功能的实现类

func New

func New(cfg *types.Chain33Config) *Wallet

New 创建一个钱包对象

func (*Wallet) AddWaitGroup

func (wallet *Wallet) AddWaitGroup(delta int)

AddWaitGroup 添加一个分组等待事件

func (*Wallet) AddrInWallet

func (wallet *Wallet) AddrInWallet(addr string) bool

AddrInWallet 地址对应的账户是否属于本钱包

func (*Wallet) CheckWalletStatus

func (wallet *Wallet) CheckWalletStatus() (bool, error)

CheckWalletStatus 钱包状态检测函数,解锁状态,seed是否已保存

func (*Wallet) Close

func (wallet *Wallet) Close()

Close 关闭钱包

func (*Wallet) ExecWallet

func (wallet *Wallet) ExecWallet(msg *queue.Message) (types.Message, error)

ExecWallet 执行钱包的功能

func (*Wallet) GenSeed

func (wallet *Wallet) GenSeed(lang int32) (*types.ReplySeed, error)

GenSeed 获取随机种子

func (*Wallet) GetAPI

func (wallet *Wallet) GetAPI() client.QueueProtocolAPI

GetAPI 获取操作API

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

func (wallet *Wallet) GetAllPrivKeys() ([]crypto.PrivKey, error)

GetAllPrivKeys 获取所有私钥信息

func (*Wallet) GetBalance

func (wallet *Wallet) GetBalance(addr string, execer string) (*types.Account, error)

GetBalance 根据地址和执行器类型获取对应的金额

func (*Wallet) GetBlockHeight

func (wallet *Wallet) GetBlockHeight() int64

GetBlockHeight 获取区块高度

func (*Wallet) GetCoinType added in v1.65.0

func (wallet *Wallet) GetCoinType() uint32

GetCoinType 获取币种类型

func (*Wallet) GetConfig

func (wallet *Wallet) GetConfig() *types.Wallet

GetConfig 获取钱包配置

func (*Wallet) GetDBStore

func (wallet *Wallet) GetDBStore() dbm.DB

GetDBStore 获取数据库存储对象操作接口

func (*Wallet) GetHeight

func (wallet *Wallet) GetHeight() int64

GetHeight 获取当前区块最新高度

func (*Wallet) GetLastHeader

func (wallet *Wallet) GetLastHeader() *types.Header

GetLastHeader 获取最新高度信息

func (*Wallet) GetPassword

func (wallet *Wallet) GetPassword() string

GetPassword 获取密码

func (*Wallet) GetPrivKeyByAddr

func (wallet *Wallet) GetPrivKeyByAddr(addr string) (crypto.PrivKey, error)

GetPrivKeyByAddr 根据地址获取私钥

func (*Wallet) GetRandom

func (wallet *Wallet) GetRandom() *rand.Rand

GetRandom 获取随机值

func (*Wallet) GetSeed

func (wallet *Wallet) GetSeed(password string) (string, error)

GetSeed 获取seed种子, 通过钱包密码

func (*Wallet) GetSignType

func (wallet *Wallet) GetSignType() int

GetSignType 获取签名类型

func (*Wallet) GetTxDetailByHashs

func (wallet *Wallet) GetTxDetailByHashs(ReqHashes *types.ReqHashes)

GetTxDetailByHashs 根据交易哈希获取对应的交易详情

func (*Wallet) GetWaitGroup

func (wallet *Wallet) GetWaitGroup() *sync.WaitGroup

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) IsCaughtUp

func (wallet *Wallet) IsCaughtUp() bool

IsCaughtUp 检测当前区块是否已经同步完成

func (*Wallet) IsClose

func (wallet *Wallet) IsClose() bool

IsClose 检查是否处于关闭状态

func (*Wallet) IsRescanUtxosFlagScaning

func (wallet *Wallet) IsRescanUtxosFlagScaning() (bool, error)

IsRescanUtxosFlagScaning 是否处于扫描UTXO状态

func (*Wallet) IsTransfer

func (wallet *Wallet) IsTransfer(addr string) (bool, error)

IsTransfer 检测钱包是否允许转账到指定地址,判断钱包锁和是否有seed以及挖矿锁

func (*Wallet) IsWalletLocked

func (wallet *Wallet) IsWalletLocked() bool

IsWalletLocked 返回钱包锁的状态

func (*Wallet) Nonce

func (wallet *Wallet) Nonce() int64

Nonce 获取随机值

func (*Wallet) On_AddBlock

func (wallet *Wallet) On_AddBlock(block *types.BlockDetail) (types.Message, error)

On_AddBlock 处理新增区块

func (*Wallet) On_DelBlock

func (wallet *Wallet) On_DelBlock(block *types.BlockDetail) (types.Message, error)

On_DelBlock 处理删除区块

func (*Wallet) On_DumpPrivkey

func (wallet *Wallet) On_DumpPrivkey(req *types.ReqString) (types.Message, error)

On_DumpPrivkey 处理到处私钥

func (*Wallet) On_DumpPrivkeysFile

func (wallet *Wallet) On_DumpPrivkeysFile(req *types.ReqPrivkeysFile) (types.Message, error)

On_DumpPrivkeysFile 处理到处私钥

func (*Wallet) On_ErrToFront

func (wallet *Wallet) On_ErrToFront(req *types.ReportErrEvent) (types.Message, error)

On_ErrToFront 错误通知

func (*Wallet) On_FatalFailure

func (wallet *Wallet) On_FatalFailure(req *types.ReqNil) (types.Message, error)

On_FatalFailure 定时查询是否有致命性故障产生

func (*Wallet) On_GenSeed

func (wallet *Wallet) On_GenSeed(req *types.GenSeedLang) (types.Message, error)

On_GenSeed 处理创建SEED

func (*Wallet) On_GetSeed

func (wallet *Wallet) On_GetSeed(req *types.GetSeedByPw) (types.Message, error)

On_GetSeed 处理获取Seed

func (*Wallet) On_GetWalletStatus

func (wallet *Wallet) On_GetWalletStatus(req *types.ReqNil) (types.Message, error)

On_GetWalletStatus 处理获取钱包状态

func (*Wallet) On_ImportPrivkeysFile

func (wallet *Wallet) On_ImportPrivkeysFile(req *types.ReqPrivkeysFile) (types.Message, error)

On_ImportPrivkeysFile 响应导入多个私钥

func (*Wallet) On_NewAccount

func (wallet *Wallet) On_NewAccount(req *types.ReqNewAccount) (types.Message, error)

On_NewAccount 响应新建账号

func (*Wallet) On_NewAccountByIndex

func (wallet *Wallet) On_NewAccountByIndex(req *types.Int32) (types.Message, error)

On_NewAccountByIndex 获取指定index的私钥,返回私钥的hex字符串ReqString

func (*Wallet) On_NewRandAccount added in v1.65.3

func (wallet *Wallet) On_NewRandAccount(req *types.GenSeedLang) (types.Message, error)

On_NewRandAccount 响应新建随机账号

func (*Wallet) On_SaveSeed

func (wallet *Wallet) On_SaveSeed(req *types.SaveSeedByPw) (types.Message, error)

On_SaveSeed 处理保存SEED

func (*Wallet) On_SignRawTx

func (wallet *Wallet) On_SignRawTx(req *types.ReqSignRawTx) (types.Message, error)

On_SignRawTx 处理交易签名

func (*Wallet) On_WalletGetAccount added in v1.65.0

func (wallet *Wallet) On_WalletGetAccount(req *types.ReqGetAccount) (types.Message, error)

On_WalletGetAccount 通过账户标签获取账户地址

func (*Wallet) On_WalletGetAccountList

func (wallet *Wallet) On_WalletGetAccountList(req *types.ReqAccountList) (types.Message, error)

On_WalletGetAccountList 响应获取账户列表

func (*Wallet) On_WalletImportPrivkey

func (wallet *Wallet) On_WalletImportPrivkey(req *types.ReqWalletImportPrivkey) (types.Message, error)

On_WalletImportPrivkey 响应导入私钥

func (*Wallet) On_WalletLock

func (wallet *Wallet) On_WalletLock(req *types.ReqNil) (types.Message, error)

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

func (wallet *Wallet) On_WalletSetFee(req *types.ReqWalletSetFee) (types.Message, error)

On_WalletSetFee 响应设置钱包手续费

func (*Wallet) On_WalletSetLabel

func (wallet *Wallet) On_WalletSetLabel(req *types.ReqWalletSetLabel) (types.Message, error)

On_WalletSetLabel 处理钱包设置标签

func (*Wallet) On_WalletSetPasswd

func (wallet *Wallet) On_WalletSetPasswd(req *types.ReqWalletSetPasswd) (types.Message, error)

On_WalletSetPasswd 处理钱包设置密码

func (*Wallet) On_WalletTransactionList

func (wallet *Wallet) On_WalletTransactionList(req *types.ReqWalletTransactionList) (types.Message, error)

On_WalletTransactionList 响应获取钱包交易列表

func (*Wallet) On_WalletUnLock

func (wallet *Wallet) On_WalletUnLock(req *types.WalletUnLock) (types.Message, error)

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

func (wallet *Wallet) ProcDumpPrivkey(addr string) (string, error)

ProcDumpPrivkey 获取地址对应的私钥

func (*Wallet) ProcDumpPrivkeysFile

func (wallet *Wallet) ProcDumpPrivkeysFile(fileName, passwd string) error

ProcDumpPrivkeysFile 获取全部私钥保存到文件

func (*Wallet) ProcGetAccount added in v1.65.0

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

func (wallet *Wallet) ProcImportPrivkeysFile(fileName, passwd string) error

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) ProcNewRandAccount added in v1.65.3

func (wallet *Wallet) ProcNewRandAccount(req *types.GenSeedLang) (*types.AccountInfo, error)

ProcNewRandAccount 随机创建新账号

func (*Wallet) ProcRecvMsg

func (wallet *Wallet) ProcRecvMsg()

ProcRecvMsg 处理消息循环

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) ProcWalletLock

func (wallet *Wallet) ProcWalletLock() error

ProcWalletLock 锁定钱包

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) SaveSeed

func (wallet *Wallet) SaveSeed(password string, seed string) (bool, error)

SaveSeed 保存种子

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

func (wallet *Wallet) SetQueueClient(cli queue.Client)

SetQueueClient 初始化客户端消息队列

func (*Wallet) SetWalletAccount

func (wallet *Wallet) SetWalletAccount(update bool, addr string, account *types.WalletAccountStore) error

SetWalletAccount 设置钱包账户

func (*Wallet) Wait

func (wallet *Wallet) Wait()

Wait for wallet ready

func (*Wallet) WaitGroupDone

func (wallet *Wallet) WaitGroupDone()

WaitGroupDone 完成分组事件

func (*Wallet) WaitTx

func (wallet *Wallet) WaitTx(hash []byte) *types.TransactionDetail

WaitTx 等待交易确认

func (*Wallet) WaitTxs

func (wallet *Wallet) WaitTxs(hashes [][]byte) (ret []*types.TransactionDetail)

WaitTxs 等待多个交易确认

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、 BTY
Package btcbase 转换基于比特币地址规则的币种 使用此规则的币种有:BTC、BCH、LTC、ZEC、USDT、 BTY
Package common 实现钱包基础功能包
Package common 实现钱包基础功能包

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL