wallet

package
v0.0.0-...-9259d71 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: BSD-2-Clause Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 交易操作的方向
	AddTx int32 = 20001
	DelTx int32 = 20002
)
View Source
const BACKUPKEYINDEX = "backupkeyindex"

Variables

View Source
var (
	SeedLong     = 15
	SaveSeedLong = 12

	WalletSeed = []byte("walletseed")

	ChineseSeedCache = make(map[string]string)
	EnglishSeedCache = make(map[string]string)
)
View Source
var (
	MaxTxHashsPerTime int64 = 100

	// 1;secp256k1,2:ed25519,3:sm2
	SignType = 1
)

Functions

func AesgcmDecrypter

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

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

func AesgcmEncrypter

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

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

func CalcWalletPassKey

func CalcWalletPassKey() []byte

func CreateSeed

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

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

func DisableLog

func DisableLog()

func GetPrivkeyBySeed

func GetPrivkeyBySeed(db dbm.DB, seed string) (string, error)

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

func GetSeed

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

使用password解密seed上报给上层

func InitSeedLibrary

func InitSeedLibrary()

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

func NewStore

func NewStore(db db.DB) *walletStore

func SaveSeed

func SaveSeed(db dbm.DB, seed string, password string) (bool, error)

使用password加密seed存储到db中

func SaveSeedInBatch

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

func SetLogLevel

func SetLogLevel(level string)

func VerifySeed

func VerifySeed(seed string) (bool, error)

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

Types

type Wallet

type Wallet struct {
	Password    string
	FeeAmount   int64
	EncryptFlag int64
	// contains filtered or unexported fields
}

func New

func New(cfg *types.Wallet, sub map[string][]byte) *Wallet

func (*Wallet) AddWaitGroup

func (wallet *Wallet) AddWaitGroup(delta int)

func (*Wallet) AddrInWallet

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

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

func (*Wallet) CheckWalletStatus

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

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

func (*Wallet) Close

func (wallet *Wallet) Close()

func (*Wallet) ExecWallet

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

func (*Wallet) GenSeed

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

func (*Wallet) GetAPI

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

func (*Wallet) GetAccountByAddr

func (wallet *Wallet) GetAccountByAddr(addr string) (*types.WalletAccountStore, error)

func (*Wallet) GetAccountByLabel

func (ws *Wallet) GetAccountByLabel(label string) (*types.WalletAccountStore, error)

func (*Wallet) GetAllPrivKeys

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

func (*Wallet) GetBalance

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

func (*Wallet) GetBlockHeight

func (wallet *Wallet) GetBlockHeight() int64

func (*Wallet) GetConfig

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

func (*Wallet) GetDBStore

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

func (*Wallet) GetHeight

func (wallet *Wallet) GetHeight() int64

func (*Wallet) GetLastHeader

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

func (*Wallet) GetMutex

func (wallet *Wallet) GetMutex() *sync.Mutex

func (*Wallet) GetPassword

func (wallet *Wallet) GetPassword() string

func (*Wallet) GetPrivKeyByAddr

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

func (*Wallet) GetRandom

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

func (*Wallet) GetSignType

func (wallet *Wallet) GetSignType() int

func (*Wallet) GetTxDetailByHashs

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

func (*Wallet) GetWaitGroup

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

func (*Wallet) GetWalletAccounts

func (wallet *Wallet) GetWalletAccounts() ([]*types.WalletAccountStore, error)

output:

type WalletAccountStore struct {
	Privkey   string  //加密后的私钥hex值
	Label     string
	Addr      string
	TimeStamp string

获取钱包的所有账户地址列表,

func (*Wallet) GetWalletDone

func (wallet *Wallet) GetWalletDone() chan struct{}

func (*Wallet) GetWalletStatus

func (wallet *Wallet) GetWalletStatus() *types.WalletStatus

func (*Wallet) IsCaughtUp

func (wallet *Wallet) IsCaughtUp() bool

func (*Wallet) IsClose

func (wallet *Wallet) IsClose() bool

func (*Wallet) IsRescanUtxosFlagScaning

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

func (*Wallet) IsTransfer

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

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

func (*Wallet) IsWalletLocked

func (wallet *Wallet) IsWalletLocked() bool

返回钱包锁的状态

func (*Wallet) Nonce

func (wallet *Wallet) Nonce() int64

func (*Wallet) On_AddBlock

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

func (*Wallet) On_DelBlock

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

func (*Wallet) On_DumpPrivkey

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

func (*Wallet) On_ErrToFront

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

func (*Wallet) On_FatalFailure

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

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

func (*Wallet) On_GenSeed

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

func (*Wallet) On_GetSeed

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

func (*Wallet) On_GetWalletStatus

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

func (*Wallet) On_NewAccount

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

func (*Wallet) On_SaveSeed

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

func (*Wallet) On_SignRawTx

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

func (*Wallet) On_WalletGetAccountList

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

func (*Wallet) On_WalletImportPrivkey

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

func (*Wallet) On_WalletLock

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

func (*Wallet) On_WalletMergeBalance

func (wallet *Wallet) On_WalletMergeBalance(req *types.ReqWalletMergeBalance) (types.Message, error)

func (*Wallet) On_WalletSendToAddress

func (wallet *Wallet) On_WalletSendToAddress(req *types.ReqWalletSendToAddress) (types.Message, error)

func (*Wallet) On_WalletSetFee

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

func (*Wallet) On_WalletSetLabel

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

func (*Wallet) On_WalletSetPasswd

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

func (*Wallet) On_WalletTransactionList

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

func (*Wallet) On_WalletUnLock

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

func (*Wallet) ProcCreateNewAccount

func (wallet *Wallet) ProcCreateNewAccount(Label *types.ReqNewAccount) (*types.WalletAccount, error)

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)

获取地址对应的私钥

func (*Wallet) ProcGetAccountList

func (wallet *Wallet) ProcGetAccountList(req *types.ReqAccountList) (*types.WalletAccounts, error)

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)

input:

type ReqWalletImportPrivKey struct {
	Privkey string
	Label   string

output:

type WalletAccount struct {
	Acc   *Account
	Label string

导入私钥,并且同时会导入交易

func (*Wallet) ProcMergeBalance

func (wallet *Wallet) ProcMergeBalance(MergeBalance *types.ReqWalletMergeBalance) (*types.ReplyHashes, error)

input:

type ReqWalletMergeBalance struct {
	To string

output:

type ReplyHashes struct {
	Hashes [][]byte

合并所有的balance 到一个地址

func (*Wallet) ProcRecvMsg

func (wallet *Wallet) ProcRecvMsg()

func (*Wallet) ProcSendToAddress

func (wallet *Wallet) ProcSendToAddress(SendToAddress *types.ReqWalletSendToAddress) (*types.ReplyHash, error)

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)

input:

type ReqSignRawTx struct {
	Addr    string
	Privkey string
	TxHex   string
	Expire  string
}

output: string 签名交易

func (*Wallet) ProcWalletAddBlock

func (wallet *Wallet) ProcWalletAddBlock(block *types.BlockDetail)

wallet模块收到blockchain广播的addblock消息,需要解析钱包相关的tx并存储到db中

func (*Wallet) ProcWalletDelBlock

func (wallet *Wallet) ProcWalletDelBlock(block *types.BlockDetail)

wallet模块收到blockchain广播的delblock消息,需要解析钱包相关的tx并存db中删除

func (*Wallet) ProcWalletLock

func (wallet *Wallet) ProcWalletLock() error

锁定钱包

func (*Wallet) ProcWalletSetFee

func (wallet *Wallet) ProcWalletSetFee(WalletSetFee *types.ReqWalletSetFee) error
type ReqWalletSetFee struct {
	Amount int64

设置钱包默认的手续费

func (*Wallet) ProcWalletSetLabel

func (wallet *Wallet) ProcWalletSetLabel(SetLabel *types.ReqWalletSetLabel) (*types.WalletAccount, error)

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

input:

type ReqWalletSetPasswd struct {
	Oldpass string
	Newpass string

设置或者修改密码

func (*Wallet) ProcWalletTxList

func (wallet *Wallet) ProcWalletTxList(TxList *types.ReqWalletTransactionList) (*types.WalletTxDetails, error)

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

input:

type WalletUnLock struct {
	Passwd  string
	Timeout int64

解锁钱包Timeout时间,超时后继续锁住

func (*Wallet) RegisterMineStatusReporter

func (wallet *Wallet) RegisterMineStatusReporter(reporter wcom.MineStatusReport) error

func (*Wallet) SaveSeed

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

func (*Wallet) SendToAddress

func (wallet *Wallet) SendToAddress(priv crypto.PrivKey, addrto string, amount int64, note string, Istoken bool, tokenSymbol string) (*types.ReplyHash, error)

func (*Wallet) SendTransaction

func (wallet *Wallet) SendTransaction(payload types.Message, execer []byte, priv crypto.PrivKey, to string) (hash []byte, err error)

func (*Wallet) SetQueueClient

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

func (*Wallet) SetWalletAccount

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

func (*Wallet) WaitGroupDone

func (wallet *Wallet) WaitGroupDone()

func (*Wallet) WaitTx

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

func (*Wallet) WaitTxs

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

Directories

Path Synopsis
transformer/btcbase
转换基于比特币地址规则的币种 使用此规则的币种有:BTC、BCH、LTC、ZEC、USDT、 BTY 对各个币种进行注册
转换基于比特币地址规则的币种 使用此规则的币种有:BTC、BCH、LTC、ZEC、USDT、 BTY 对各个币种进行注册

Jump to

Keyboard shortcuts

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