state

package
v2.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID     string `msg:"_id" json:"_id" mapstructure:"_id" bson:"_id"`
	PubKey string `msg:"public_key" json:"public_key" mapstructure:"public_key" bson:"public_key"`
}

Account struct keeps account related fields.

type Payload

type Payload struct {
	ID              string         `msg:"_id" json:"_id" mapstructure:"_id" bson:"_id"`
	SenderAccountID string         `msg:"sender_account_id" json:"sender_account_id" mapstructure:"sender_account_id" bson:"sender_account_id"`
	PublicData      interface{}    `msg:"public_data" json:"public_data" mapstructure:"public_data" bson:"public_data"`
	PrivateData     []*PrivateData `msg:"private_data" json:"private_data" mapstructure:"private_data" bson:"private_data"`
	CreatedAt       float64        `msg:"created_at" json:"created_at" mapstructure:"created_at" bson:"created_at"`
}

Payload struct keeps transaction data related fields.

  • PublicData keeps open data of any structure;
  • PrivateData keeps encrypted data set by receiver's public key with ECDH algorithm and represented as base64 string;
  • CreatedAt is date of object creation in UNIX time (milliseconds).

type PrivateData

type PrivateData struct {
	ReceiverAccountID string      `msg:"receiver_account_id" json:"receiver_account_id" mapstructure:"receiver_account_id" bson:"receiver_account_id"`
	Data              interface{} `msg:"data" json:"data" mapstructure:"data" bson:"data"`
}

PrivateData keeps information about receiver and data, encrypted by receiver's public key

type State

type State struct {
	DB *mgo.Database
}

State struct contains pointer to MongoDB instance.

func NewStateFromDB

func NewStateFromDB(db *mgo.Database) *State

NewStateFromDB method constructs MongoDB state.

func (*State) AddAccount

func (s *State) AddAccount(account *Account) error

AddAccount method adds new account if all checks were passed.

func (*State) AddPayload

func (s *State) AddPayload(data *Payload) error

AddPayload method adds new payload to the state if it not exists.

func (*State) GetAccount

func (s *State) GetAccount(id string) (*Account, error)

GetAccount method returns account from accounts collection by given accoutn id.

func (*State) GetAccountPubKey

func (s *State) GetAccountPubKey(id string) (*crypto.Key, error)

GetAccountPubKey method returns public key by given account id.

func (*State) GetPayload

func (s *State) GetPayload(id string) (*Payload, error)

GetPayload method gets data from state by it identifier.

func (*State) HasAccount

func (s *State) HasAccount(id string) bool

HasAccount method checks if account exists in state or not exists.

func (*State) HasPayload

func (s *State) HasPayload(id string) bool

HasPayload method checks exists payload in state ot not.

func (*State) ListAccounts

func (s *State) ListAccounts() (result []*Account, err error)

ListAccounts method returns all accounts from the state.

func (*State) SearchAccounts added in v1.2.0

func (s *State) SearchAccounts(query interface{}, limit, offset int) (result []*Account, err error)

SearchAccounts method returns accounts by given search query, limit and offset parameters.

func (*State) SearchPayloads

func (s *State) SearchPayloads(query interface{}, limit, offset int) (result []*Payload, err error)

SearchPayloads method finds payloads using mongodb query language.

func (*State) SetAccount

func (s *State) SetAccount(account *Account) error

SetAccount method adds account in state.

func (*State) SetPayload

func (s *State) SetPayload(data *Payload) error

SetPayload inserts new payload to state without any checks.

Jump to

Keyboard shortcuts

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