spvwallet

package
v0.0.0-...-a6db85c Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: MIT Imports: 21 Imported by: 5

Documentation

Index

Constants

View Source
const (
	KeystoreFilename = "keystore.dat"
)
View Source
const (
	KeystoreVersion = "1.0"
)

Variables

View Source
var SystemAssetId = getSystemAssetId()

Functions

func InputFromUTXO

func InputFromUTXO(utxo *UTXO) *Input

func ToUTXO

func ToUTXO(txId Uint256, height uint32, index int, value Fixed64, lockTime uint32) *db.UTXO

Types

type Database

type Database interface {
	AddAddress(address *Uint168, script []byte, addrType int) error
	GetAddress(address *Uint168) (*Addr, error)
	GetAddrs() ([]*Addr, error)
	DeleteAddress(address *Uint168) error
	GetAddressUTXOs(address *Uint168) ([]*UTXO, error)
	GetAddressSTXOs(address *Uint168) ([]*STXO, error)
	ChainHeight() uint32
	Reset() error
}

func GetDatabase

func GetDatabase() (Database, error)

type DatabaseImpl

type DatabaseImpl struct {
	DataStore
	// contains filtered or unexported fields
}

func (*DatabaseImpl) AddAddress

func (db *DatabaseImpl) AddAddress(address *Uint168, script []byte, addrType int) error

func (*DatabaseImpl) ChainHeight

func (db *DatabaseImpl) ChainHeight() uint32

func (*DatabaseImpl) DeleteAddress

func (db *DatabaseImpl) DeleteAddress(address *Uint168) error

func (*DatabaseImpl) GetAddress

func (db *DatabaseImpl) GetAddress(address *Uint168) (*Addr, error)

func (*DatabaseImpl) GetAddressSTXOs

func (db *DatabaseImpl) GetAddressSTXOs(address *Uint168) ([]*STXO, error)

func (*DatabaseImpl) GetAddressUTXOs

func (db *DatabaseImpl) GetAddressUTXOs(address *Uint168) ([]*UTXO, error)

func (*DatabaseImpl) GetAddrs

func (db *DatabaseImpl) GetAddrs() ([]*Addr, error)

func (*DatabaseImpl) Reset

func (db *DatabaseImpl) Reset() error

type Keystore

type Keystore interface {
	ChangePassword(old, new []byte) error

	MainAccount() *Account
	NewAccount() *Account
	GetAccounts() []*Account
	GetAccountByIndex(index int) *Account
	GetAccountByProgramHash(programHash *Uint168) *Account

	Json() (string, error)
	FromJson(json string, password string) error
}

func CreateKeystore

func CreateKeystore(password []byte) (Keystore, error)

func OpenKeystore

func OpenKeystore(password []byte) (Keystore, error)

type KeystoreFile

type KeystoreFile struct {
	sync.Mutex

	Version string

	IV                  string
	PasswordHash        string
	MasterKeyEncrypted  string
	PrivateKeyEncrypted string

	SubAccountsCount int
}

func CreateKeystoreFile

func CreateKeystoreFile() (*KeystoreFile, error)

func OpenKeystoreFile

func OpenKeystoreFile() (*KeystoreFile, error)

func (*KeystoreFile) FromJson

func (store *KeystoreFile) FromJson(str string) error

func (*KeystoreFile) GetIV

func (store *KeystoreFile) GetIV() ([]byte, error)

func (*KeystoreFile) GetMasterKeyEncrypted

func (store *KeystoreFile) GetMasterKeyEncrypted() ([]byte, error)

func (*KeystoreFile) GetPasswordHash

func (store *KeystoreFile) GetPasswordHash() ([]byte, error)

func (*KeystoreFile) GetPrivetKeyEncrypted

func (store *KeystoreFile) GetPrivetKeyEncrypted() ([]byte, error)

func (*KeystoreFile) Json

func (store *KeystoreFile) Json() (string, error)

func (*KeystoreFile) LoadFromFile

func (store *KeystoreFile) LoadFromFile() error

func (*KeystoreFile) SaveToFile

func (store *KeystoreFile) SaveToFile() error

func (*KeystoreFile) SetIV

func (store *KeystoreFile) SetIV(iv []byte)

func (*KeystoreFile) SetMasterKeyEncrypted

func (store *KeystoreFile) SetMasterKeyEncrypted(masterKeyEncrypted []byte)

func (*KeystoreFile) SetPasswordHash

func (store *KeystoreFile) SetPasswordHash(passwordHash []byte)

func (*KeystoreFile) SetPrivateKeyEncrypted

func (store *KeystoreFile) SetPrivateKeyEncrypted(privateKeyEncrypted []byte)

type KeystoreImpl

type KeystoreImpl struct {
	sync.Mutex

	*KeystoreFile
	// contains filtered or unexported fields
}

func (*KeystoreImpl) ChangePassword

func (store *KeystoreImpl) ChangePassword(oldPassword, newPassword []byte) error

func (*KeystoreImpl) FromJson

func (store *KeystoreImpl) FromJson(str string, password string) error

func (*KeystoreImpl) GetAccountByIndex

func (store *KeystoreImpl) GetAccountByIndex(index int) *Account

func (*KeystoreImpl) GetAccountByProgramHash

func (store *KeystoreImpl) GetAccountByProgramHash(programHash *Uint168) *Account

func (*KeystoreImpl) GetAccounts

func (store *KeystoreImpl) GetAccounts() []*Account

func (*KeystoreImpl) Json

func (store *KeystoreImpl) Json() (string, error)

func (*KeystoreImpl) MainAccount

func (store *KeystoreImpl) MainAccount() *Account

func (*KeystoreImpl) NewAccount

func (store *KeystoreImpl) NewAccount() *Account

type SPVWallet

type SPVWallet struct {
	sync.Mutex
	sdk.SPVService
	// contains filtered or unexported fields
}

func Init

func Init(clientId uint64, seeds []string) (*SPVWallet, error)

func (*SPVWallet) Close

func (wallet *SPVWallet) Close()

Close the database

func (*SPVWallet) CommitTx

func (wallet *SPVWallet) CommitTx(storeTx *StoreTx) (bool, error)

Commit a transaction return if this is a false positive and error

func (*SPVWallet) DataStore

func (wallet *SPVWallet) DataStore() db.DataStore

func (*SPVWallet) GetChainHeight

func (wallet *SPVWallet) GetChainHeight() uint32

Get chain height from database

func (*SPVWallet) GetChainTip

func (wallet *SPVWallet) GetChainTip() (*StoreHeader, error)

Get the header on chain tip

func (*SPVWallet) GetHeader

func (wallet *SPVWallet) GetHeader(hash Uint256) (*StoreHeader, error)

Get full header with it's hash

func (*SPVWallet) GetPrevious

func (wallet *SPVWallet) GetPrevious(header *StoreHeader) (*StoreHeader, error)

Get previous block of the given header

func (*SPVWallet) Headers

func (wallet *SPVWallet) Headers() db.Headers

func (*SPVWallet) NotifyNewAddress

func (wallet *SPVWallet) NotifyNewAddress(hash []byte) error

func (*SPVWallet) PutChainHeight

func (wallet *SPVWallet) PutChainHeight(height uint32)

Save chain height to database

func (*SPVWallet) PutHeader

func (wallet *SPVWallet) PutHeader(header *StoreHeader, newTip bool) error

Save a header to database

func (*SPVWallet) Reset

func (wallet *SPVWallet) Reset() error

Reset database, clear all data

func (*SPVWallet) Rollback

func (wallet *SPVWallet) Rollback(height uint32) error

Rollback chain data on the given height

func (*SPVWallet) SendTransaction

func (wallet *SPVWallet) SendTransaction(tx Transaction) error

func (*SPVWallet) Start

func (wallet *SPVWallet) Start()

func (*SPVWallet) Stop

func (wallet *SPVWallet) Stop()

type Transfer

type Transfer struct {
	Address string
	Value   *Fixed64
}

type Wallet

type Wallet interface {
	Database

	VerifyPassword(password []byte) error
	ChangePassword(oldPassword, newPassword []byte) error

	NewSubAccount(password []byte) (*Uint168, error)
	AddMultiSignAccount(M uint, publicKey ...*crypto.PublicKey) (*Uint168, error)

	CreateTransaction(fromAddress, toAddress string, amount, fee *Fixed64) (*Transaction, error)
	CreateLockedTransaction(fromAddress, toAddress string, amount, fee *Fixed64, lockedUntil uint32) (*Transaction, error)
	CreateMultiOutputTransaction(fromAddress string, fee *Fixed64, output ...*Transfer) (*Transaction, error)
	CreateLockedMultiOutputTransaction(fromAddress string, fee *Fixed64, lockedUntil uint32, output ...*Transfer) (*Transaction, error)
	Sign(password []byte, transaction *Transaction) (*Transaction, error)
	SendTransaction(txn *Transaction) error
}

func Create

func Create(password []byte) (Wallet, error)

func Open

func Open() (Wallet, error)

type WalletImpl

type WalletImpl struct {
	Database
	Keystore
}

func (*WalletImpl) AddMultiSignAccount

func (wallet *WalletImpl) AddMultiSignAccount(M uint, publicKeys ...*crypto.PublicKey) (*Uint168, error)

func (*WalletImpl) CreateLockedMultiOutputTransaction

func (wallet *WalletImpl) CreateLockedMultiOutputTransaction(fromAddress string, fee *Fixed64, lockedUntil uint32, outputs ...*Transfer) (*Transaction, error)

func (*WalletImpl) CreateLockedTransaction

func (wallet *WalletImpl) CreateLockedTransaction(fromAddress, toAddress string, amount, fee *Fixed64, lockedUntil uint32) (*Transaction, error)

func (*WalletImpl) CreateMultiOutputTransaction

func (wallet *WalletImpl) CreateMultiOutputTransaction(fromAddress string, fee *Fixed64, outputs ...*Transfer) (*Transaction, error)

func (*WalletImpl) CreateTransaction

func (wallet *WalletImpl) CreateTransaction(fromAddress, toAddress string, amount, fee *Fixed64) (*Transaction, error)

func (*WalletImpl) NewSubAccount

func (wallet *WalletImpl) NewSubAccount(password []byte) (*Uint168, error)

func (*WalletImpl) SendTransaction

func (wallet *WalletImpl) SendTransaction(txn *Transaction) error

func (*WalletImpl) Sign

func (wallet *WalletImpl) Sign(password []byte, txn *Transaction) (*Transaction, error)

func (*WalletImpl) VerifyPassword

func (wallet *WalletImpl) VerifyPassword(password []byte) error

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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