wallet

package
v0.0.0-...-d9e9b57 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotExistsWalletFile = errors.New("not exists wallet file!")
)

Functions

func GetPubKeyHashFromAddress

func GetPubKeyHashFromAddress(address []byte) []byte

GetPubKeyHashFromAddress get PublicKeyHash from address 1.base58 decode 2.remove version & checksum

func HashPublicKey

func HashPublicKey(pubKey []byte) []byte

HashPublicKey hashes public key 1.sha256 publick key 2.ripemd160(sha256(public key)) 疑惑: RIPEMD160已被sha-256和SHA 512和它们的派生算法取代。 SHA256和SHA512提供更好的安全和性能比RIPEMD160。 使用RIPEMD160仅为与旧的应用程序和数据的兼容性。 一种看法:在SAH256基础上进行RIPEMD160,一方面双重hash保护,一方面将生成的散列码由256位缩短为160位

func ValidateAddress

func ValidateAddress(address string) bool

ValidateAddress check if address if valid 1.base58 decode 2.get checksum(4 byte) 3.get version 4.get pubKeyHash 5.get checksum,use first 4 bytes

Types

type Wallet

type Wallet struct {
	PrivateKey ecdsa.PrivateKey
	PublicKey  []byte
}

Wallet stores private and public keys

func (Wallet) GetAddress

func (w Wallet) GetAddress() []byte

GetAddress returns wallet address 1.hashes public key - ripemd160(sha256(public key)) 2.connect version to the PubKeyHash header. 3.get checksum,use first 4 bytes 4.connect checksum to the end of the hash data 5.base58 data

func (Wallet) GetStringAddress

func (w Wallet) GetStringAddress() string

GetStringAddress returns wallet address string format

type WalletSet

type WalletSet struct {
	NodeID       string
	MinerAddress string
	Wallets      map[string]*Wallet
	// contains filtered or unexported fields
}

WalletMap stores a collection of wallets

func LoadWallets

func LoadWallets(nodeID string) (*WalletSet, error)

LoadWallets load Wallets and fills it from a file if not exists file, auto create it

func (*WalletSet) CreateWallet

func (ws *WalletSet) CreateWallet() *Wallet

CreateWallet adds a Wallet to Wallets

func (*WalletSet) GetAddresses

func (ws *WalletSet) GetAddresses() []string

GetAddresses returns an array of addresses stored in the wallet file

func (*WalletSet) GetMinerAddress

func (ws *WalletSet) GetMinerAddress() string

GetMinerWallet get miner address from current WalletSet

func (*WalletSet) GetWallet

func (ws *WalletSet) GetWallet(address string) *Wallet

GetWallet returns a Wallet by its address if not exists, return nil

func (*WalletSet) LoadFromFile

func (ws *WalletSet) LoadFromFile(nodeID string) error

LoadFromFile loads wallets from the file

func (*WalletSet) SaveToFile

func (ws *WalletSet) SaveToFile()

SaveToFile saves wallets to a file

func (*WalletSet) SetMinerAddress

func (ws *WalletSet) SetMinerAddress(addr string) error

SetMinerWallet set miner address into current WalletSet

Jump to

Keyboard shortcuts

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