common

package
v0.0.0-...-b8899bb Latest Latest
Warning

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

Go to latest
Published: May 29, 2017 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MessageIDKey is a key for message ID
	// This ID is required to track from which chat a given send transaction request is coming.
	MessageIDKey = contextKey("message_id")
)

Variables

View Source
var (
	ErrDeprecatedMethod = errors.New("Method is depricated and will be removed in future release")
)

errors

View Source
var (
	ErrInvalidAccountAddressOrKey = errors.New("cannot parse address or key to valid account address")
)

errors

Functions

func Fatalf

func Fatalf(reason interface{}, args ...interface{})

Fatalf is used to halt the execution. When called the function prints stack end exits. Failure is logged into both StdErr and StdOut.

func FromAddress

func FromAddress(accountAddress string) common.Address

FromAddress converts account address from string to common.Address. The function is useful to format "From" field of send transaction struct.

func ImportTestAccount

func ImportTestAccount(keystoreDir, accountFile string) error

ImportTestAccount checks if test account exists in keystore, and if not tries to import it (from static resources, see "static/keys" folder)

func MessageIDFromContext

func MessageIDFromContext(ctx context.Context) string

MessageIDFromContext returns message id from context (if exists)

func NameOf

func NameOf(f interface{}) string

NameOf returns name of caller, at runtime

func PanicAfter

func PanicAfter(waitSeconds time.Duration, abort chan struct{}, desc string)

PanicAfter throws panic() after waitSeconds, unless abort channel receives notification

func ParseAccountString

func ParseAccountString(account string) (accounts.Account, error)

ParseAccountString parses hex encoded string and returns is as accounts.Account.

func ParseJSONArray

func ParseJSONArray(items string) ([]string, error)

ParseJSONArray parses JSON array into Go array of string

func ToAddress

func ToAddress(accountAddress string) *common.Address

ToAddress converts account address from string to *common.Address. The function is useful to format "To" field of send transaction struct.

Types

type APIResponse

type APIResponse struct {
	Error string `json:"error"`
}

APIResponse generic response from API

type AccountInfo

type AccountInfo struct {
	Address  string `json:"address"`
	PubKey   string `json:"pubkey"`
	Mnemonic string `json:"mnemonic"`
	Error    string `json:"error"`
}

AccountInfo represents account's info

type AccountManager

type AccountManager interface {
	// CreateAccount creates an internal geth account
	// BIP44-compatible keys are generated: CKD#1 is stored as account key, CKD#2 stored as sub-account root
	// Public key of CKD#1 is returned, with CKD#2 securely encoded into account key file (to be used for
	// sub-account derivations)
	CreateAccount(password string) (address, pubKey, mnemonic string, err error)

	// CreateChildAccount creates sub-account for an account identified by parent address.
	// CKD#2 is used as root for master accounts (when parentAddress is "").
	// Otherwise (when parentAddress != ""), child is derived directly from parent.
	CreateChildAccount(parentAddress, password string) (address, pubKey string, err error)

	// RecoverAccount re-creates master key using given details.
	// Once master key is re-generated, it is inserted into keystore (if not already there).
	RecoverAccount(password, mnemonic string) (address, pubKey string, err error)

	// VerifyAccountPassword tries to decrypt a given account key file, with a provided password.
	// If no error is returned, then account is considered verified.
	VerifyAccountPassword(keyStoreDir, address, password string) (*keystore.Key, error)

	// SelectAccount selects current account, by verifying that address has corresponding account which can be decrypted
	// using provided password. Once verification is done, decrypted key is injected into Whisper (as a single identity,
	// all previous identities are removed).
	SelectAccount(address, password string) error

	// ReSelectAccount selects previously selected account, often, after node restart.
	ReSelectAccount() error

	// SelectedAccount returns currently selected account
	SelectedAccount() (*SelectedExtKey, error)

	// Logout clears whisper identities
	Logout() error

	// AccountsListRequestHandler returns handler to process account list request
	AccountsListRequestHandler() func(entities []common.Address) []common.Address

	// AddressToDecryptedAccount tries to load decrypted key for a given account.
	// The running node, has a keystore directory which is loaded on start. Key file
	// for a given address is expected to be in that directory prior to node start.
	AddressToDecryptedAccount(address, password string) (accounts.Account, *keystore.Key, error)
}

AccountManager defines expected methods for managing Status accounts

type CompleteTransactionResult

type CompleteTransactionResult struct {
	ID    string `json:"id"`
	Hash  string `json:"hash"`
	Error string `json:"error"`
}

CompleteTransactionResult is a JSON returned from transaction complete function (used in exposed method)

type CompleteTransactionsResult

type CompleteTransactionsResult struct {
	Results map[string]CompleteTransactionResult `json:"results"`
}

CompleteTransactionsResult is list of results from CompleteTransactions() (used in exposed method)

type DiscardTransactionResult

type DiscardTransactionResult struct {
	ID    string `json:"id"`
	Error string `json:"error"`
}

DiscardTransactionResult is a JSON returned from transaction discard function

type DiscardTransactionsResult

type DiscardTransactionsResult struct {
	Results map[string]DiscardTransactionResult `json:"results"`
}

DiscardTransactionsResult is a list of results from DiscardTransactions()

type JailCell

type JailCell interface {
	CellVM() *otto.Otto
}

JailCell represents single jail cell, which is basically a JavaScript VM.

type JailManager

type JailManager interface {
	// Parse creates a new jail cell context, with the given chatID as identifier.
	// New context executes provided JavaScript code, right after the initialization.
	Parse(chatID string, js string) string

	// Call executes given JavaScript function w/i a jail cell context identified by the chatID.
	// Jail cell is clonned before call is executed i.e. all calls execute w/i their own contexts.
	Call(chatID string, path string, args string) string

	// NewJailCell initializes and returns jail cell
	NewJailCell(id string) JailCell

	// JailCellVM returns instance of Otto VM (which is persisted w/i jail cell) by chatID
	JailCellVM(chatID string) (*otto.Otto, error)

	// BaseJS allows to setup initial JavaScript to be loaded on each jail.Parse()
	BaseJS(js string)
}

JailManager defines methods for managing jailed environments

type Logger

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

Logger is wrapper for custom logging

func SetupLogger

func SetupLogger(config *params.NodeConfig) (*Logger, error)

SetupLogger configs logger using parameters in config

func (*Logger) SetV

func (l *Logger) SetV(logLevel string)

SetV allows to dynamically change log level of messages being written

func (*Logger) Start

func (l *Logger) Start() error

Start installs logger handler

func (*Logger) Stop

func (l *Logger) Stop() error

Stop replaces our handler back to the original log handler

type NodeManager

type NodeManager interface {
	// StartNode start Status node, fails if node is already started
	StartNode(config *params.NodeConfig) (<-chan struct{}, error)

	// StopNode stop the running Status node.
	// Stopped node cannot be resumed, one starts a new node instead.
	StopNode() (<-chan struct{}, error)

	// RestartNode restart running Status node, fails if node is not running
	RestartNode() (<-chan struct{}, error)

	// ResetChainData remove chain data from data directory.
	// Node is stopped, and new node is started, with clean data directory.
	ResetChainData() (<-chan struct{}, error)

	// IsNodeRunning confirm that node is running
	IsNodeRunning() bool

	// NodeConfig returns reference to running node's configuration
	NodeConfig() (*params.NodeConfig, error)

	// Node returns underlying Status node
	Node() (*node.Node, error)

	// PopulateStaticPeers populates node's list of static bootstrap peers
	PopulateStaticPeers() error

	// AddPeer adds URL of static peer
	AddPeer(url string) error

	// LightEthereumService exposes reference to LES service running on top of the node
	LightEthereumService() (*les.LightEthereum, error)

	// WhisperService returns reference to running Whisper service
	WhisperService() (*whisper.Whisper, error)

	// AccountManager returns reference to node's account manager
	AccountManager() (*accounts.Manager, error)

	// AccountKeyStore returns reference to account manager's keystore
	AccountKeyStore() (*keystore.KeyStore, error)

	// RPCClient exposes reference to RPC client connected to the running node
	RPCClient() (*rpc.Client, error)

	// RPCServer exposes reference to running node's in-proc RPC server/handler
	RPCServer() (*rpc.Server, error)
}

NodeManager defines expected methods for managing Status node

type RPCManager

type RPCManager interface {
	// Call executes RPC request on node's in-proc RPC server
	Call(inputJSON string) string
}

RPCManager defines expected methods for managing RPC client/server

type RawCompleteTransactionResult

type RawCompleteTransactionResult struct {
	Hash  common.Hash
	Error error
}

RawCompleteTransactionResult is a JSON returned from transaction complete function (used internally)

type RawDiscardTransactionResult

type RawDiscardTransactionResult struct {
	Error error
}

RawDiscardTransactionResult is list of results from CompleteTransactions() (used internally)

type SelectedExtKey

type SelectedExtKey struct {
	Address     common.Address
	AccountKey  *keystore.Key
	SubAccounts []accounts.Account
}

SelectedExtKey is a container for currently selected (logged in) account

func (*SelectedExtKey) Hex

func (k *SelectedExtKey) Hex() string

Hex dumps address of a given extended key as hex string

type TestConfig

type TestConfig struct {
	Node struct {
		SyncSeconds time.Duration
		HTTPPort    int
		WSPort      int
	}
	Account1 struct {
		Address  string
		Password string
	}
	Account2 struct {
		Address  string
		Password string
	}
}

TestConfig contains shared (among different test packages) parameters

func LoadTestConfig

func LoadTestConfig() (*TestConfig, error)

LoadTestConfig loads test configuration values from disk

type TxQueueManager

type TxQueueManager interface {
	// TransactionQueueHandler returns handler that processes incoming tx queue requests
	TransactionQueueHandler() func(queuedTx status.QueuedTx)

	// TransactionReturnHandler returns handler that processes responses from internal tx manager
	TransactionReturnHandler() func(queuedTx *status.QueuedTx, err error)

	// CompleteTransaction instructs backend to complete sending of a given transaction
	CompleteTransaction(id, password string) (common.Hash, error)

	// CompleteTransactions instructs backend to complete sending of multiple transactions
	CompleteTransactions(ids, password string) map[string]RawCompleteTransactionResult

	// DiscardTransaction discards a given transaction from transaction queue
	DiscardTransaction(id string) error

	// DiscardTransactions discards given multiple transactions from transaction queue
	DiscardTransactions(ids string) map[string]RawDiscardTransactionResult
}

TxQueueManager defines expected methods for managing transaction queue

Jump to

Keyboard shortcuts

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