common

package
v1.68.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: BSD-3-Clause Imports: 16 Imported by: 47

Documentation

Overview

Package common 实现钱包基础功能包

Index

Constants

This section is empty.

Variables

View Source
var (
	// QueryData 查询接口数据全局对象
	QueryData = types.NewQueryData("On_")
	// PolicyContainer 钱包业务容器
	PolicyContainer = make(map[string]WalletBizPolicy)
)

Functions

func CBCDecrypterPrivkey

func CBCDecrypterPrivkey(password []byte, privkey []byte) []byte

CBCDecrypterPrivkey 使用钱包的password对私钥进行aes cbc解密,返回解密后的privkey

func CBCEncrypterPrivkey

func CBCEncrypterPrivkey(password []byte, privkey []byte) []byte

CBCEncrypterPrivkey 使用钱包的password对私钥进行aes cbc加密,返回加密后的privkey

func CalcAccountKey

func CalcAccountKey(timestamp string, addr string) []byte

CalcAccountKey 用于所有Account账户的输出list,需要安装时间排序

func CalcAddrKey

func CalcAddrKey(addr string) []byte

CalcAddrKey 通过addr地址查询Account账户信息

func CalcAirDropIndex

func CalcAirDropIndex() []byte

CalcAirDropIndex 通过钱包Seed指定index生成的空投地址

func CalcEncryptionFlag

func CalcEncryptionFlag() []byte

CalcEncryptionFlag 加密标志Key

func CalcLabelKey

func CalcLabelKey(label string) []byte

CalcLabelKey 通过label查询Account账户信息

func CalcPasswordHash

func CalcPasswordHash() []byte

CalcPasswordHash 密码hash的Key

func CalcTxKey

func CalcTxKey(key string) []byte

CalcTxKey 通过height*100000+index 查询Tx交易信息 key:Tx:height*100000+index

func CalcWalletSeed

func CalcWalletSeed() []byte

CalcWalletSeed 钱包Seed的Key

func CalckeyEncryptionCompFlag

func CalckeyEncryptionCompFlag() []byte

CalckeyEncryptionCompFlag 加密比较标志Key

func Init

func Init(wallet WalletOperate, sub map[string][]byte)

Init 初始化所有已经注册的钱包业务

func RegisterPolicy

func RegisterPolicy(key string, policy WalletBizPolicy)

RegisterPolicy 注册钱包业务策略接口

Types

type AddrInfo

type AddrInfo struct {
	Index  uint32 `json:"index,omitempty"`
	Addr   string `json:"addr,omitempty"`
	Pubkey string `json:"pubkey,omitempty"`
}

AddrInfo 通过seed指定index创建的账户信息,目前主要用于空投地址

type MineStatusReport

type MineStatusReport interface {
	IsAutoMining() bool
	// 返回挖矿买票锁的状态
	IsTicketLocked() bool
	PolicyName() string
}

MineStatusReport 挖矿操作状态

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 钱包通用数据库存储类,实现对钱包账户数据库操作的基本实现

func NewStore

func NewStore(db db.DB) *Store

NewStore 新建存储对象

func (*Store) Close

func (store *Store) Close()

Close 关闭数据库

func (*Store) DelAccountByLabel

func (store *Store) DelAccountByLabel(label string)

DelAccountByLabel 根据标签名称,删除对应的账号信息

func (*Store) FreeBlockBatch added in v1.65.0

func (store *Store) FreeBlockBatch()

FreeBlockBatch free

func (*Store) Get

func (store *Store) Get(key []byte) ([]byte, error)

Get 取值

func (*Store) GetAccountByAddr

func (store *Store) GetAccountByAddr(addr string) (*types.WalletAccountStore, error)

GetAccountByAddr 根据地址获取账号信息

func (*Store) GetAccountByLabel

func (store *Store) GetAccountByLabel(label string) (*types.WalletAccountStore, error)

GetAccountByLabel 根据标签获取账号信息

func (*Store) GetAccountByPrefix

func (store *Store) GetAccountByPrefix(addr string) ([]*types.WalletAccountStore, error)

GetAccountByPrefix 根据前缀获取账号信息列表

func (*Store) GetAccountByte

func (store *Store) GetAccountByte(update bool, addr string, account *types.WalletAccountStore) ([]byte, error)

GetAccountByte 获取账号byte类型

func (*Store) GetAirDropIndex

func (store *Store) GetAirDropIndex() (string, error)

GetAirDropIndex 获取指定index的空投地址

func (*Store) GetBlockBatch added in v1.65.0

func (store *Store) GetBlockBatch(sync bool) db.Batch

GetBlockBatch 新建批处理操作对象接口

func (*Store) GetDB

func (store *Store) GetDB() db.DB

GetDB 获取数据库操作接口

func (*Store) GetEncryptionFlag

func (store *Store) GetEncryptionFlag() int64

GetEncryptionFlag 获取加密方式

func (*Store) GetTxDetailByIter

func (store *Store) GetTxDetailByIter(TxList *types.ReqWalletTransactionList) (*types.WalletTxDetails, error)

GetTxDetailByIter 迭代获取从指定key:height*100000+index 开始向前或者向后查找指定count的交易

func (*Store) GetWalletVersion

func (store *Store) GetWalletVersion() int64

GetWalletVersion 获取wallet数据库的版本号

func (*Store) HasSeed

func (store *Store) HasSeed() (bool, error)

HasSeed 判断钱包是否已经保存seed

func (*Store) NewBatch

func (store *Store) NewBatch(sync bool) db.Batch

NewBatch 新建批处理操作对象接口

func (*Store) NewListHelper

func (store *Store) NewListHelper() *db.ListHelper

NewListHelper 新建列表复制操作对象

func (*Store) Set

func (store *Store) Set(key []byte, value []byte) (err error)

Set 设置值

func (*Store) SetAirDropIndex

func (store *Store) SetAirDropIndex(airDropIndex *AddrInfo) error

SetAirDropIndex 存储指定index的空投地址信息

func (*Store) SetEncryptionFlag

func (store *Store) SetEncryptionFlag(batch db.Batch) error

SetEncryptionFlag 设置加密方式标志

func (*Store) SetPasswordHash

func (store *Store) SetPasswordHash(password string, batch db.Batch) error

SetPasswordHash 保存密码哈希

func (*Store) SetWalletAccount

func (store *Store) SetWalletAccount(update bool, addr string, account *types.WalletAccountStore) error

SetWalletAccount 保存钱包账户信息

func (*Store) SetWalletAccountInBatch

func (store *Store) SetWalletAccountInBatch(update bool, addr string, account *types.WalletAccountStore, newbatch db.Batch) error

SetWalletAccountInBatch 保存钱包账号信息

func (*Store) SetWalletVersion

func (store *Store) SetWalletVersion(ver int64) error

SetWalletVersion 升级数据库的版本号

func (*Store) VerifyPasswordHash

func (store *Store) VerifyPasswordHash(password string) bool

VerifyPasswordHash 检查密码有效性

type WalletBizPolicy

type WalletBizPolicy interface {
	// Init 初始化钱包业务策略,在使用前调用
	Init(walletBiz WalletOperate, sub []byte)
	// OnAddBlockTx 当区块被增加确认时调用本函数
	// block: 被增加的区块详细信息
	// tx: 区块增加的交易信息
	// index: 交易信息在区块上的索引为止,从0开始计数
	// dbbatch: 数据库批量操作接口
	// 返回值为提供给外部快速检索的钱包详细信息,如果内部已经处理,不需要外部处理的情况下,可以返回nil
	OnAddBlockTx(block *types.BlockDetail, tx *types.Transaction, index int32, dbbatch db.Batch) *types.WalletTxDetail
	// OnDeleteBlockTx 当区块被回退删除时调用本函数
	// block: 被回退的区块详细信息
	// tx: 区块回退的交易信息
	// index: 交易信息在区块上的索引为止,从0开始计数
	// dbbatch: 数据库批量操作接口
	// 返回值为提供给外部快速检索的钱包详细信息,如果内部已经处理,不需要外部处理的情况下,可以返回nil
	OnDeleteBlockTx(block *types.BlockDetail, tx *types.Transaction, index int32, dbbatch db.Batch) *types.WalletTxDetail
	// SignTransaction 针对特殊的交易,按照新的签名方式签名
	// key 签名的私钥信息
	// req 需要签名交易流信息
	// needSysSign 表示是否需要继续走系统流程的签名,true表示继续,false表示已经完成签名,不需要系统处理
	// signtx 签名成功后,保存签名成功的交易字符串
	// err 错误信息
	SignTransaction(key crypto.PrivKey, req *types.ReqSignRawTx) (needSysSign bool, signtx string, err error)
	// OnCreateNewAccount 当用户在钱包中新建账户时,将调用本接口函数
	OnCreateNewAccount(acc *types.Account)
	// OnImportPrivateKey 当用户导入私钥时,将调用本函数
	OnImportPrivateKey(acc *types.Account)
	OnWalletLocked()
	OnWalletUnlocked(WalletUnLock *types.WalletUnLock)
	OnAddBlockFinish(block *types.BlockDetail)
	OnDeleteBlockFinish(block *types.BlockDetail)
	OnClose()
	OnSetQueueClient()
	Call(funName string, in types.Message) (ret types.Message, err error)
}

WalletBizPolicy 细分钱包业务逻辑的街口

type WalletOperate

type WalletOperate interface {
	RegisterMineStatusReporter(reporter MineStatusReport) error

	GetAPI() client.QueueProtocolAPI
	GetDBStore() db.DB
	GetSignType() int
	GetCoinType() uint32
	GetPassword() string
	GetBlockHeight() int64
	GetRandom() *rand.Rand
	GetWalletDone() chan struct{}
	GetLastHeader() *types.Header
	GetTxDetailByHashs(ReqHashes *types.ReqHashes)
	GetWaitGroup() *sync.WaitGroup
	GetAllPrivKeys() ([]crypto.PrivKey, error)
	GetWalletAccounts() ([]*types.WalletAccountStore, error)
	GetPrivKeyByAddr(addr string) (crypto.PrivKey, error)
	GetConfig() *types.Wallet
	GetBalance(addr string, execer string) (*types.Account, error)

	IsWalletLocked() bool
	IsClose() bool
	IsCaughtUp() bool
	AddrInWallet(addr string) bool

	CheckWalletStatus() (bool, error)
	Nonce() int64

	WaitTx(hash []byte) *types.TransactionDetail
	WaitTxs(hashes [][]byte) (ret []*types.TransactionDetail)
	SendTransaction(payload types.Message, execer []byte, priv crypto.PrivKey, addressID int32, to string) (hash []byte, err error)
	SendToAddress(priv crypto.PrivKey, addressID int32, addrto string, amount int64, note string, Istoken bool, tokenSymbol string) (*types.ReplyHash, error)
}

WalletOperate 钱包对业务插件提供服务的操作接口

Jump to

Keyboard shortcuts

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