accounts

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package accounts defines account-related helper methods and types. The accounts database, for example, is defined in this package.

Package accounts defines account-related helper methods and types. The accounts database, for example, is defined in this package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAccountAlreadyExists is an error definition describing an attempted duplicate put.
	ErrAccountAlreadyExists = errors.New("account already exists")

	// ErrAccountDoesNotExist is an error definition describing an account value of nil.
	ErrAccountDoesNotExist = errors.New("no account exists with the given username")

	// ErrPasswordInvalid is an error definition describing an invalid password value.
	ErrPasswordInvalid = errors.New("invalid password")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Name string `json:"name"` // Name

	PasswordHash []byte `json:"password_hash"` // Password hash

	Address common.Address `json:"address"` // Address

	LastFaucetClaimTime   time.Time  `json:"last_claim_time"`   // Last claim time
	LastFaucetClaimAmount *big.Float `json:"last_claim_amount"` // Last claim amount

	Tokens    []string `json:"tokens"`     // Account tokens
	FcmTokens []string `json:"fcm_tokens"` // Account Firebase Cloud Messaging tokens
}

Account represents a username-password keypair linking to a private key in the accounts database.

func AccountFromBytes

func AccountFromBytes(b []byte) (*Account, error)

AccountFromBytes deserializes an account from a given byte array.

func (*Account) Bytes

func (account *Account) Bytes() []byte

Bytes serializes a given account to a byte array.

func (*Account) String

func (account *Account) String() string

String serializes a given account to a JSON string.

type DB

type DB struct {
	DB *bolt.DB // DB represents the currently opened db.
}

DB is a data type representing a link to a working accounts boltdb instance.

func OpenDB

func OpenDB() (*DB, error)

OpenDB opens the local DB, and creates one if it doesn't already exist.

func (*DB) AddNewAccount

func (db *DB) AddNewAccount(name string, password string, address string) (*Account, error)

AddNewAccount adds a new account to the list of accounts in the working database.

func (*DB) Auth added in v0.5.2

func (db *DB) Auth(name string, password string) bool

Auth checks that a given user can be authenticated.

func (*DB) CloseDB

func (db *DB) CloseDB() error

CloseDB closes the db.

func (*DB) CreateAccountsBucketIfNotExist

func (db *DB) CreateAccountsBucketIfNotExist() error

CreateAccountsBucketIfNotExist creates the accounts bucket if it doesn't already exist.

func (*DB) CreateNewAccount

func (db *DB) CreateNewAccount(name string, password string) (*Account, error)

CreateNewAccount creates a new account with a given name and password. Returns the new account's address and an error (if applicable).

func (*DB) DeleteAccount added in v0.5.8

func (db *DB) DeleteAccount(name string, password string) error

DeleteAccount deletes an account from the working DB.

func (*DB) GetUserBalance

func (db *DB) GetUserBalance(username string) (*big.Float, error)

GetUserBalance calculates the balance of a particular account.

func (*DB) GetUserTransactions

func (db *DB) GetUserTransactions(username string) ([]*types.Transaction, error)

GetUserTransactions fetches the list of transactions for a particular account.

func (*DB) IssueAccountToken added in v0.5.9

func (db *DB) IssueAccountToken(username, password string) (string, error)

IssueAccountToken issues a new account token.

func (*DB) MakeFaucetClaim added in v0.5.8

func (db *DB) MakeFaucetClaim(account *Account, amount *big.Float) error

MakeFaucetClaim makes a faucet claim for a given account.

func (*DB) QueryAccountByAddress added in v0.5.8

func (db *DB) QueryAccountByAddress(address summercashCommon.Address) (*Account, error)

QueryAccountByAddress queries the database for an account with a given address.

func (*DB) QueryAccountByUsername

func (db *DB) QueryAccountByUsername(name string) (*Account, error)

QueryAccountByUsername queries the database for an account with a given username.

func (*DB) ResetAccountPassword

func (db *DB) ResetAccountPassword(name string, oldPassword string, newPassword string) error

ResetAccountPassword resets an accounts password.

func (*DB) ValidateAccountToken added in v0.5.9

func (db *DB) ValidateAccountToken(account *Account, token string) bool

ValidateAccountToken checks whether or not a given token is valid.

Jump to

Keyboard shortcuts

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