wallet

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BalanceFor added in v0.3.0

func BalanceFor(addr string, tid *types.TokenID, db storage.Table) (uint64, error)

BalanceFor returns balance amount of an address using balance index

func FetchUtxosOf added in v0.3.0

func FetchUtxosOf(
	addr string, tid *types.TokenID, total uint64, forBalance bool, db storage.Table,
) ([]*rpcpb.Utxo, error)

FetchUtxosOf fetches utxos from db NOTE: if total is 0, fetch all utxos NOTE: if tokenID is nil, fetch box utxos

func ReadPassphraseStdin

func ReadPassphraseStdin() (string, error)

ReadPassphraseStdin reads passphrase from stdin without echo passphrase into terminal

Types

type Config added in v0.3.0

type Config struct {
	Enable        bool `mapstructure:"enable"`
	CacheSize     int  `mapstructure:"cache_size"`
	UtxoCacheTime int  `mapstructure:"utxo_cache_time"`
}

Config contains config information for wallet server

type LiveUtxoCache added in v0.3.0

type LiveUtxoCache struct {
	sync.RWMutex

	Op2ts map[types.OutPoint]int64
	// contains filtered or unexported fields
}

LiveUtxoCache defines a cache in that utxos keep alive

func NewLiveUtxoCache added in v0.3.0

func NewLiveUtxoCache() *LiveUtxoCache

NewLiveUtxoCache new a LiveUtxoCache instance with expired seconds

func (*LiveUtxoCache) Add added in v0.3.0

func (cache *LiveUtxoCache) Add(op *types.OutPoint)

Add adds a OutPoint to cache

func (*LiveUtxoCache) Contains added in v0.3.0

func (cache *LiveUtxoCache) Contains(op *types.OutPoint) bool

Contains return whether OutPoint is in cache

func (*LiveUtxoCache) Count added in v0.3.0

func (cache *LiveUtxoCache) Count() int

Count returns OutPoint count

func (*LiveUtxoCache) Del added in v0.3.0

func (cache *LiveUtxoCache) Del(op ...*types.OutPoint)

Del deletes a OutPoint in cache

func (*LiveUtxoCache) SetLiveDuration added in v0.3.0

func (cache *LiveUtxoCache) SetLiveDuration(expired int)

SetLiveDuration sets live duration

func (*LiveUtxoCache) Shrink added in v0.3.0

func (cache *LiveUtxoCache) Shrink()

Shrink shrinks phase out OutPoints

type Manager

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

Manager is a directory based type to manipulate account Operation add/delete/query, import/export and sign are supported

func NewWalletManager

func NewWalletManager(path string) (*Manager, error)

NewWalletManager creates a wallet manager from files in the path

func (*Manager) DumpPrivKey

func (wlt *Manager) DumpPrivKey(address, passphrase string) (string, error)

DumpPrivKey returns an account's private key bytes in hex string format

func (*Manager) GetAccount

func (wlt *Manager) GetAccount(pubKeyHash string) (account *acc.Account, exist bool)

GetAccount checks if this Manager contains this public key and returns the related account if it exists

func (*Manager) ListAccounts

func (wlt *Manager) ListAccounts() []*acc.Account

ListAccounts returns all the addresses of keystore files in directory

func (*Manager) NewAccount

func (wlt *Manager) NewAccount(passphrase string) (string, error)

NewAccount creates a ecdsa key pair and store them in a file encrypted by the passphrase user entered returns a hexstring format public key hash, address and error

func (*Manager) NewAccountWithPrivKey

func (wlt *Manager) NewAccountWithPrivKey(privKey *crypto.PrivateKey, passphrase string) (string, error)

NewAccountWithPrivKey store the give private key in a file encrypted by the passphrase user entered returns a hexstring format public key hash, address and error

func (*Manager) Sign

func (wlt *Manager) Sign(msg []byte, pubKeyHash, passphrase string) ([]byte, error)

Sign create signature of message bytes using private key related to input public key

type Server added in v0.3.0

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

Server is the struct type of an wallet service

func NewServer added in v0.3.0

func NewServer(parent goprocess.Process, config *Config, s storage.Storage,
	bus eventbus.Bus) (*Server, error)

NewServer creates an Server instance using config and storage

func (*Server) Balance added in v0.3.0

func (w *Server) Balance(addr string, tokenID *types.TokenID) (uint64, error)

Balance returns the total balance of an address

func (*Server) Proc added in v0.3.0

func (w *Server) Proc() goprocess.Process

Proc returns then go process of the wallet server

func (*Server) Run added in v0.3.0

func (w *Server) Run() error

Run starts Server main loop

func (*Server) Stop added in v0.3.0

func (w *Server) Stop()

Stop terminate the Server process

func (*Server) Utxos added in v0.3.0

func (w *Server) Utxos(addr string, tokenID *types.TokenID, amount uint64) (
	[]*rpcpb.Utxo, error)

Utxos returns all utxos of an address NOTE: return all utxos of addr if amount is equal to 0

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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