data

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JobUser           = "user"
	JobBillingChecker = "billing_checker"
	JobBCMonitor      = "bc_monitor"
	JobTask           = "task"
	JobServiceAdapter = "service_adapter"
	JobSessionServer  = "session_server"
)

Job creators.

View Source
const (
	JobActive   = "active"
	JobDone     = "done"
	JobFailed   = "failed"
	JobCanceled = "canceled"
)

Job statuses.

View Source
const (
	JobOffering = "offering"
	JobChannel  = "channel"
	JobEndpoint = "endpoint"
	JobAccount  = "account"
)

Job related object types.

View Source
const (
	JobClientPreChannelCreate               = "clientPreChannelCreate"
	JobClientAfterChannelCreate             = "clientAfterChannelCreate"
	JobClientPreChannelTopUp                = "clientPreChannelTopUp"
	JobClientAfterChannelTopUp              = "clientAfterChannelTopUp"
	JobClientPreUncooperativeCloseRequest   = "clientPreUncooperativeCloseRequest"
	JobClientAfterUncooperativeCloseRequest = "clientAfterUncooperativeCloseRequest"
	JobClientPreUncooperativeClose          = "clientPreUncooperativeClose"
	JobClientAfterUncooperativeClose        = "clientAfterUncooperativeClose"
	JobClientAfterCooperativeClose          = "clientAfterCooperativeClose"
	JobClientPreServiceSuspend              = "clientPreServiceSuspend"
	JobClientPreServiceUnsuspend            = "clientPreServiceUnsuspend"
	JobClientPreServiceTerminate            = "clientPreServiceTerminate"
	JobClientEndpointRestore                = "clientEndpointRestore"
	JobClientAfterOfferingMsgBCPublish      = "clientAfterOfferingMsgBCPublish"
	JobClientAfterOfferingPopUp             = "clientAfterOfferingPopUp"
	JobClientAfterOfferingDelete            = "clientAfterOfferingDelete"
	JobClientCompleteServiceTransition      = "completeServiceTransition"
	JobAgentAfterChannelCreate              = "agentAfterChannelCreate"
	JobAgentAfterChannelTopUp               = "agentAfterChannelTopUp"
	JobAgentAfterUncooperativeCloseRequest  = "agentAfterUncooperativeCloseRequest"
	JobAgentAfterUncooperativeClose         = "agentAfterUncooperativeClose"
	JobAgentAfterCooperativeClose           = "agentAfterCooperativeClose"
	JobAgentPreServiceSuspend               = "agentPreServiceSuspend"
	JobAgentPreServiceUnsuspend             = "agentPreServiceUnsuspend"
	JobAgentPreServiceTerminate             = "agentPreServiceTerminate"
	JobAgentPreEndpointMsgCreate            = "agentPreEndpointMsgCreate"
	JobAgentPreOfferingMsgBCPublish         = "agentPreOfferingMsgBCPublish"
	JobAgentAfterOfferingMsgBCPublish       = "agentAfterOfferingMsgBCPublish"
	JobAgentPreOfferingDelete               = "agentPreOfferingDelete"
	JobAgentPreOfferingPopUp                = "agentPreOfferingPopUp"
	JobAgentAfterOfferingPopUp              = "agentAfterOfferingPopUp"
	JobAgentAfterOfferingDelete             = "agentAfterOfferingDelete"
	JobPreAccountAddBalanceApprove          = "preAccountAddBalanceApprove"
	JobPreAccountAddBalance                 = "preAccountAddBalance"
	JobAfterAccountAddBalance               = "afterAccountAddBalance"
	JobPreAccountReturnBalance              = "preAccountReturnBalance"
	JobAfterAccountReturnBalance            = "afterAccountReturnBalance"
	JobAccountUpdateBalances                = "accountUpdateBalances"
	JobDecrementCurrentSupply               = "decrementCurrentSupply"
	JobIncrementCurrentSupply               = "incrementCurrentSupply"
)

Job types.

View Source
const (
	RoleAgent  = "agent"
	RoleClient = "client"
)

Possible user roles.

View Source
const (
	TemplateOffer  = "offer"
	TemplateAccess = "access"
)

Templates kinds.

View Source
const (
	ProductUsageIncremental = "incremental"
	ProductUsageTotal       = "total"
)

Product usage reporting types.

View Source
const (
	UnitScalar  = "units"
	UnitSeconds = "seconds"
)

Unit used for billing calculation.

View Source
const (
	BillingPrepaid  = "prepaid"
	BillingPostpaid = "postpaid"
)

Billing types.

View Source
const (
	OfferEmpty       = "empty"
	OfferPoppingUp   = "popping_up"
	OfferPoppedUp    = "popped_up"
	OfferRegistering = "registering"
	OfferRegistered  = "registered"
	OfferRemoving    = "removing"
	OfferRemoved     = "removed"
)

Offering statuses.

View Source
const (
	ChannelPending       = "pending"
	ChannelActive        = "active"
	ChannelWaitCoop      = "wait_coop"
	ChannelClosedCoop    = "closed_coop"
	ChannelWaitChallenge = "wait_challenge"
	ChannelInChallenge   = "in_challenge"
	ChannelWaitUncoop    = "wait_uncoop"
	ChannelClosedUncoop  = "closed_uncoop"
)

State channel statuses.

View Source
const (
	ServicePending     = "pending"
	ServiceActivating  = "activating"
	ServiceActive      = "active"
	ServiceSuspending  = "suspending"
	ServiceSuspended   = "suspended"
	ServiceTerminating = "terminating"
	ServiceTerminated  = "terminated"
)

Service operational statuses.

View Source
const (
	ContractPTC = "ptc"
	ContractPSC = "psc"
)

Contract types.

View Source
const (
	AccessDenied = iota
	ReadOnly
	ReadWrite
)

Permissions for settings.

View Source
const (
	CountryStatusUnknown = "unknown"
	CountryStatusValid   = "valid"
	CountryStatusInvalid = "invalid"
)

Country statuses.

View Source
const (
	TxUnsent = "unsent"
	TxSent   = "sent"
	TxMined  = "mined"
	TxUncle  = "uncle"
)

Transaction statuses.

View Source
const (
	SettingAppVersion         = "system.version.app"
	SettingBlockLimit         = "eth.event.blocklimit"
	SettingDefaultGasPrice    = "eth.default.gasprice"
	SettingFreshBlocks        = "eth.event.freshblocks"
	SettingOfferingAutoPopUp  = "offering.autopopup"
	SettingLastProcessedBlock = "eth.event.lastProcessedBlock"
	SettingMinConfirmations   = "eth.min.confirmations"
	SettingPasswordHash       = "system.password"
	SettingPasswordSalt       = "system.salt"
	SettingsPeriodChallange   = "psc.periods.challenge"
	SettingsPeriodPopUp       = "psc.periods.popup"
	SettingsPeriodRemove      = "psc.periods.remove"
	SettingGUI                = "system.gui"
)

Setting keys.

View Source
const (
	TestPassword     = "secret"
	TestPasswordHash = "JDJhJDEwJHNVbWNtTkVwQk5DMkwuOC5OL1BXU08uYkJMMkxjcmthTW1BZklOTUNjNWZDdWNUOU54Tzlp"
	TestSalt         = 6012867121110302348
)

Test authentication constants.

View Source
const (
	ClientIdentByChannelID = "by_channel_id"
)

Product authentication types.

View Source
const (
	OfferingSOMCTor uint8 = 1 + iota
)

Comminication types.

View Source
const (
	TestServiceEndpointAddress = "localhost"
)

Test service addresses.

Variables

This section is empty.

Functions

func BeginTestTX

func BeginTestTX(t *testing.T, db *reform.DB) *reform.TX

BeginTestTX begins a test transaction.

func BytesToUint32

func BytesToUint32(b []byte) (uint32, error)

BytesToUint32 using big endian.

func ChannelKey

func ChannelKey(client, agent HexString, block uint32,
	offeringHash HexString) ([]byte, error)

ChannelKey returns the unique channel identifier used in a Privatix Service Contract.

func CleanTestDB

func CleanTestDB(t *testing.T, db *reform.DB)

CleanTestDB deletes all records from all test DB tables.

func CleanTestTable

func CleanTestTable(t *testing.T, db *reform.DB, tbl reform.View)

CleanTestTable deletes all records from a given DB table.

func CloseDB

func CloseDB(db *reform.DB)

CloseDB closes database connection.

func CommitTestTX

func CommitTestTX(t *testing.T, tx *reform.TX)

CommitTestTX commits a test transaction.

func DeleteFromTestDB

func DeleteFromTestDB(t *testing.T, db *reform.DB, recs ...reform.Record)

DeleteFromTestDB deletes records from test DB.

func ExecuteCommand

func ExecuteCommand(args []string) error

ExecuteCommand executes commands to manage database db-create - command to create database db-migrate - command to execute migration scripts db-init-data - command to initialize database by default values db-version - command to print the version of the database schema.

func FindByPrimaryKeyTo

func FindByPrimaryKeyTo(db *reform.Querier,
	rec reform.Record, key interface{}) error

FindByPrimaryKeyTo calls db.FindByPrimaryKeyTo() returning more descriptive error.

func FindInTestDB

func FindInTestDB(t *testing.T, db *reform.DB,
	str reform.Struct, column string, arg interface{})

FindInTestDB selects a record from test DB.

func FindOneTo

func FindOneTo(db *reform.Querier,
	str reform.Struct, column string, arg interface{}) error

FindOneTo calls db.FindOneTo() returning more descriptive error.

func FromBase64ToHex

func FromBase64ToHex(s Base64String) (string, error)

FromBase64ToHex return hex of base 64 encoded.

func GetUint64Setting

func GetUint64Setting(db *reform.DB, key string) (uint64, error)

GetUint64Setting finds the key value in table Setting. Checks that the value in the format of uint64

func HexToAddress

func HexToAddress(addr HexString) (common.Address, error)

HexToAddress returns ethereum's address from base 64 encoded string.

func HexToBytes

func HexToBytes(s HexString) ([]byte, error)

HexToBytes reutrns the bytes represented by the hex of string s.

func HexToHash

func HexToHash(h HexString) (common.Hash, error)

HexToHash returns the ethereum's hash represented by the hex of string s.

func Insert

func Insert(db *reform.Querier, str reform.Struct) error

Insert calls db.Insert() returning more descriptive error.

func InsertToTestDB

func InsertToTestDB(t *testing.T, db *reform.DB, rows ...reform.Struct)

InsertToTestDB inserts rows to test DB.

func MinDeposit

func MinDeposit(offering *Offering) uint64

MinDeposit calculates minimal deposit required to accept the offering.

func NewDB

func NewDB(conf *DBConfig) (*reform.DB, error)

NewDB creates a new data connection handle.

func NewDBFromConnStr

func NewDBFromConnStr(connStr string) (*reform.DB, error)

NewDBFromConnStr connects to db and returns db instance.

func NewTestDB

func NewTestDB(conf *DBConfig) *reform.DB

NewTestDB creates a new database connection.

func ReadBoolSetting

func ReadBoolSetting(db *reform.Querier, key string) (bool, error)

ReadBoolSetting reads value of a given bool setting.

func ReadSetting

func ReadSetting(db *reform.Querier, key string) (string, error)

ReadSetting reads value of a given setting.

func ReadUintSetting

func ReadUintSetting(db *reform.Querier, key string) (uint, error)

ReadUintSetting reads value of a given uint setting.

func Recover

func Recover(db *reform.DB) error

Recover ensures data consistency after unexpected controller's exit.

func ReloadFromTestDB

func ReloadFromTestDB(t *testing.T, db *reform.DB, recs ...reform.Record)

ReloadFromTestDB reloads records from test DB.

func RollbackTestTX

func RollbackTestTX(t *testing.T, tx *reform.TX)

RollbackTestTX rollbacks a test transaction.

func Save

func Save(db *reform.Querier, rec reform.Record) error

Save calls db.Save() returning more descriptive error.

func SaveToTestDB

func SaveToTestDB(t *testing.T, db *reform.DB, recs ...reform.Record)

SaveToTestDB saves records to test DB.

func SelectOneFromTestDBTo

func SelectOneFromTestDBTo(t *testing.T, db *reform.DB,
	str reform.Struct, tail string, args ...interface{})

SelectOneFromTestDBTo selects a record from test DB using a given query tail.

func TestToAddress

func TestToAddress(t *testing.T, addr HexString) common.Address

TestToAddress decodes to address or fails.

func TestToBytes

func TestToBytes(t *testing.T, s Base64String) []byte

TestToBytes returns binary representation of base64 encoded string or fails.

func TestToHash

func TestToHash(t *testing.T, h HexString) common.Hash

TestToHash decodes to hash or fails.

func TestToPrivateKey

func TestToPrivateKey(
	keyB64 Base64String, _ string) (*ecdsa.PrivateKey, error)

TestToPrivateKey is a key decryption simplified for tests performance.

func ToBytes

func ToBytes(s Base64String) ([]byte, error)

ToBytes returns the bytes represented by the base64 string s.

func ToHash

func ToHash(h Base64String) (common.Hash, error)

ToHash returns the ethereum's hash represented by the base64 string s.

func ToPrivateKey

func ToPrivateKey(keyB64 Base64String, auth string) (*ecdsa.PrivateKey, error)

ToPrivateKey returns decrypted *ecdsa.PrivateKey from base64 of encrypted keystore.Key.

func Uint192ToBytes

func Uint192ToBytes(x *big.Int) [24]byte

Uint192ToBytes using big endian with leading zeros.

func Uint32ToBytes

func Uint32ToBytes(x uint32) [4]byte

Uint32ToBytes using big endian.

func Uint64ToBytes

func Uint64ToBytes(x uint64) [8]byte

Uint64ToBytes using big endian.

func ValidatePassword

func ValidatePassword(hash Base64String, password, salt string) error

ValidatePassword checks if a given password, hash and salt are matching.

Types

type Account

type Account struct {
	ID               string       `json:"id" reform:"id,pk"`
	EthAddr          HexString    `json:"ethAddr" reform:"eth_addr"`
	PublicKey        Base64String `json:"-" reform:"public_key"`
	PrivateKey       Base64String `json:"-" reform:"private_key"`
	IsDefault        bool         `json:"isDefault" reform:"is_default"`
	InUse            bool         `json:"inUse" reform:"in_use"`
	Name             string       `json:"name" reform:"name"`
	PTCBalance       uint64       `json:"ptcBalance" reform:"ptc_balance"`
	PSCBalance       uint64       `json:"pscBalance" reform:"psc_balance"`
	EthBalance       Base64BigInt `json:"ethBalance" reform:"eth_balance"`
	LastBalanceCheck *time.Time   `json:"lastBalanceCheck" reform:"last_balance_check"`
}

Account is an ethereum account.

func NewEthTestAccount

func NewEthTestAccount(auth string, acc *truffle.TestAccount) *Account

NewEthTestAccount returns new account based on truffle.TestAccount.

func NewTestAccount

func NewTestAccount(auth string) *Account

NewTestAccount returns new account.

type Base64BigInt

type Base64BigInt string

Base64BigInt is a base64 of big.Int that implements json.Marshaler.

func (Base64BigInt) MarshalJSON

func (n Base64BigInt) MarshalJSON() ([]byte, error)

MarshalJSON marshals itself.

type Base64String

type Base64String string

Base64String is a base64-encoded binary data.

func EncryptedKey

func EncryptedKey(pkey *ecdsa.PrivateKey, auth string) (Base64String, error)

EncryptedKey returns encrypted keystore.Key in base64.

func FromBytes

func FromBytes(src []byte) Base64String

FromBytes returns the base64 encoding of src.

func HashPassword

func HashPassword(password, salt string) (Base64String, error)

HashPassword computes encoded hash of the password.

func TestEncryptedKey

func TestEncryptedKey(pkey *ecdsa.PrivateKey, _ string) (Base64String, error)

TestEncryptedKey is a key encryption simplified for tests performance.

type Channel

type Channel struct {
	ID                 string        `json:"id" reform:"id,pk"`
	Agent              HexString     `json:"agent" reform:"agent"`
	Client             HexString     `json:"client" reform:"client"`
	Offering           string        `json:"offering" reform:"offering"`
	Block              uint32        `json:"block" reform:"block"`                  // When state channel created.
	ChannelStatus      string        `json:"channelStatus" reform:"channel_status"` // Status related to blockchain.
	ServiceStatus      string        `json:"serviceStatus" reform:"service_status"`
	ServiceChangedTime *time.Time    `json:"serviceChangedTime" reform:"service_changed_time"`
	PreparedAt         time.Time     `json:"preparedAt" reform:"prepared_at"`
	TotalDeposit       uint64        `json:"totalDeposit" reform:"total_deposit"`
	Salt               uint64        `json:"-" reform:"salt"`
	Username           *string       `json:"-" reform:"username"`
	Password           Base64String  `json:"-" reform:"password"`
	ReceiptBalance     uint64        `json:"receiptBalance" reform:"receipt_balance"` // Last payment.
	ReceiptSignature   *Base64String `json:"-" reform:"receipt_signature"`            // Last payment's signature.
}

Channel is a state channel.

func NewTestChannel

func NewTestChannel(agent, client HexString, offering string,
	balance, deposit uint64, status string) *Channel

NewTestChannel returns new channel.

type Contract

type Contract struct {
	ID      string    `json:"id" reform:"id,pk"`
	Address HexString `json:"address" reform:"address"` // Ethereum address
	Type    string    `json:"type" reform:"type"`
	Version *uint8    `json:"version" reform:"version"`
	Enabled bool      `json:"enabled" reform:"enabled"`
}

Contract is a smart contract.

type DBConfig

type DBConfig struct {
	Conn     map[string]string
	MaxOpen  int
	MaxIddle int
}

DBConfig is a DB configuration.

func NewDBConfig

func NewDBConfig() *DBConfig

NewDBConfig creates a default DB configuration.

func (DBConfig) ConnStr

func (c DBConfig) ConnStr() string

ConnStr composes a data connection string.

type EncryptedKeyFunc

type EncryptedKeyFunc func(*ecdsa.PrivateKey, string) (Base64String, error)

EncryptedKeyFunc is a func that returns encrypted keystore.Key in base64.

type Endpoint

type Endpoint struct {
	ID                     string       `json:"id" reform:"id,pk"`
	Template               string       `json:"template" reform:"template"`
	Channel                string       `json:"channel" reform:"channel"`
	Hash                   HexString    `json:"hash" reform:"hash"`
	RawMsg                 Base64String `reform:"raw_msg"`
	PaymentReceiverAddress *string      `json:"paymentReceiverAddress" reform:"payment_receiver_address"`
	ServiceEndpointAddress *string      `json:"serviceEndpointAddress" reform:"service_endpoint_address"`
	Username               *string      `json:"username" reform:"username"`
	Password               *string      `json:"password" reform:"password"`
	AdditionalParams       []byte       `json:"additionalParams" reform:"additional_params"`
	CountryStatus          *string      `json:"countryStatus" reform:"country_status"`
}

Endpoint messages is info about service access.

func NewTestEndpoint

func NewTestEndpoint(chanID, tplID string) *Endpoint

NewTestEndpoint returns new endpoint.

type EndpointUI

type EndpointUI struct {
	ID                     string  `json:"id" reform:"id,pk"`
	PaymentReceiverAddress *string `json:"paymentReceiverAddress" reform:"payment_receiver_address"`
	ServiceEndpointAddress *string `json:"serviceEndpointAddress" reform:"service_endpoint_address"`
	CountryStatus          *string `json:"countryStatus" reform:"country_status"`
}

EndpointUI contains only certain fields of endpoints table.

type EthTx

type EthTx struct {
	ID          string    `reform:"id,pk" json:"id"`
	Hash        HexString `reform:"hash" json:"hash"`
	Method      string    `reform:"method" json:"method"`
	Status      string    `reform:"status" json:"status"`
	JobID       *string   `reform:"job" json:"jobID"`
	Issued      time.Time `reform:"issued" json:"issued"`
	AddrFrom    HexString `reform:"addr_from" json:"addrFrom"`
	AddrTo      HexString `reform:"addr_to" json:"addrTo"`
	Nonce       *string   `reform:"nonce" json:"nonce"`
	GasPrice    uint64    `reform:"gas_price" json:"gasPrice"`
	Gas         uint64    `reform:"gas" json:"gas"`
	TxRaw       []byte    `reform:"tx_raw" json:"txRaw"`
	RelatedType string    `reform:"related_type" json:"relatedType"`
	RelatedID   string    `reform:"related_id" json:"relatedID"`
}

EthTx is an ethereum transaction

type HexString

type HexString string

HexString is a hex-encoded binary data.

func HexFromBytes

func HexFromBytes(src []byte) HexString

HexFromBytes returns the hex encoding of src.

type Job

type Job struct {
	ID          string    `reform:"id,pk"`
	Type        string    `reform:"type"`
	Status      string    `reform:"status"`
	RelatedType string    `reform:"related_type"`
	RelatedID   string    `reform:"related_id"`
	CreatedAt   time.Time `reform:"created_at"`
	NotBefore   time.Time `reform:"not_before"`
	CreatedBy   string    `reform:"created_by"`
	TryCount    uint8     `reform:"try_count"`
	Data        []byte    `reform:"data"`
}

Job is a task within persistent queue.

func NewTestJob

func NewTestJob(jobType, createdBy, relType string) *Job

NewTestJob returns a default test job.

type JobBalanceData

type JobBalanceData struct {
	GasPrice uint64
	Amount   uint64
}

JobBalanceData is a data required for transfer jobs.

type JobCreateChannelData

type JobCreateChannelData struct {
	GasPrice uint64
	Deposit  uint
}

JobCreateChannelData is a data required by client to accept an offering.

type JobData

type JobData struct {
	EthLog *JobEthLog `json:"ethereumLog"`
}

JobData data set by blockchain monitor for log derived jobs.

type JobEndpointCreateData

type JobEndpointCreateData struct {
	EndpointSealed []byte
}

JobEndpointCreateData is a data for client endpoint create job.

type JobEthLog

type JobEthLog struct {
	Block  uint64    `json:"block"`
	Data   []byte    `json:"data"`
	Topics LogTopics `json:"topics"`
	TxHash HexString `json:"transactionHash"`
}

JobEthLog is log data a job derived from.

type JobPublishData

type JobPublishData struct {
	GasPrice uint64
}

JobPublishData is a data required for blockchain publish jobs.

type JobTopUpChannelData

type JobTopUpChannelData struct {
	GasPrice uint64
	Deposit  uint64
}

JobTopUpChannelData is a data for top up channel job.

type LogEvent

type LogEvent struct {
	Time    time.Time       `json:"time" reform:"time"`
	Level   log.Level       `json:"level" reform:"level"`
	Message string          `json:"message" reform:"message"`
	Context json.RawMessage `json:"context" reform:"context"`
	Stack   *string         `json:"stack" reform:"stack"`
}

LogEvent is a log event.

type LogTopics

type LogTopics []common.Hash

LogTopics is a database/sql compatible type for ethereum log topics.

func (*LogTopics) Scan

func (t *LogTopics) Scan(src interface{}) error

Scan deserializes the log topics.

func (LogTopics) Value

func (t LogTopics) Value() (driver.Value, error)

Value serializes the log topics.

type Offering

type Offering struct {
	ID                 string          `json:"id" reform:"id,pk"`
	IsLocal            bool            `json:"isLocal" reform:"is_local"`
	Template           string          `json:"template" reform:"tpl" validate:"required"`    // Offering's.
	Product            string          `json:"product" reform:"product" validate:"required"` // Specific billing and actions.
	Hash               HexString       `json:"hash" reform:"hash"`                           // Offering's hash.
	Status             string          `json:"status" reform:"status"`
	BlockNumberUpdated uint64          `json:"blockNumberUpdated" reform:"block_number_updated"`
	Agent              HexString       `json:"agent" reform:"agent" validate:"required"`
	RawMsg             Base64String    `json:"rawMsg" reform:"raw_msg"`
	ServiceName        string          `json:"serviceName" reform:"service_name" validate:"required"`
	Description        *string         `json:"description" reform:"description"`
	Country            string          `json:"country" reform:"country" validate:"required"` // ISO 3166-1 alpha-2.
	Supply             uint16          `json:"supply" reform:"supply" validate:"required"`
	CurrentSupply      uint16          `json:"currentSupply" reform:"current_supply"`
	UnitName           string          `json:"unitName" reform:"unit_name" validate:"required"` // Like megabytes, minutes, etc.
	UnitType           string          `json:"unitType" reform:"unit_type" validate:"required"`
	BillingType        string          `json:"billingType" reform:"billing_type" validate:"required"`
	SetupPrice         uint64          `json:"setupPrice" reform:"setup_price"` // Setup fee.
	UnitPrice          uint64          `json:"unitPrice" reform:"unit_price"`
	MinUnits           uint64          `json:"minUnits" reform:"min_units" validate:"required"`
	MaxUnit            *uint64         `json:"maxUnit" reform:"max_unit"`
	BillingInterval    uint            `json:"billingInterval" reform:"billing_interval" validate:"required"` // Every unit number to be paid.
	MaxBillingUnitLag  uint            `json:"maxBillingUnitLag" reform:"max_billing_unit_lag"`               // Max maximum tolerance for payment lag.
	MaxSuspendTime     uint            `json:"maxSuspendTime" reform:"max_suspended_time"`                    // In seconds.
	MaxInactiveTimeSec uint64          `json:"maxInactiveTimeSec" reform:"max_inactive_time_sec"`
	FreeUnits          uint8           `json:"freeUnits" reform:"free_units"`
	AdditionalParams   json.RawMessage `json:"additionalParams" reform:"additional_params" validate:"required"`
	AutoPopUp          *bool           `json:"autoPopUp" reform:"auto_pop_up"`
	SOMCType           uint8           `json:"somcType" reform:"somc_type"`
	SOMCData           Base64String    `json:"somcData" reform:"somc_data"`
	SOMCSuccessPing    *time.Time      `json:"somcSuccessPing" reform:"somc_success_ping"`
}

Offering is a service offering.

func NewTestOffering

func NewTestOffering(agent HexString, product, tpl string) *Offering

NewTestOffering returns new offering.

type PWDGetSetter

type PWDGetSetter interface {
	PWDGetter
	PWDSetter
}

PWDGetSetter can get and set password to storage.

type PWDGetter

type PWDGetter interface {
	Get() string
}

PWDGetter can retrieve stored password.

type PWDSetter

type PWDSetter interface {
	Set(string)
}

PWDSetter can set new password.

type PWDStorage

type PWDStorage string

PWDStorage stores password in memory.

func (*PWDStorage) Get

func (p *PWDStorage) Get() string

Get returns stored password.

func (*PWDStorage) Set

func (p *PWDStorage) Set(pwd string)

Set sets stored password.

type Product

type Product struct {
	ID                     string          `json:"id" reform:"id,pk"`
	Name                   string          `json:"name" reform:"name"`
	OfferTplID             *string         `json:"offerTplID" reform:"offer_tpl_id"`
	OfferAccessID          *string         `json:"offerAccessID" reform:"offer_access_id"`
	UsageRepType           string          `json:"usageRepType" reform:"usage_rep_type"`
	IsServer               bool            `json:"isServer" reform:"is_server"`
	Salt                   uint64          `json:"-" reform:"salt"`
	Password               Base64String    `json:"-" reform:"password"`
	ClientIdent            string          `json:"clientIdent" reform:"client_ident"`
	Config                 json.RawMessage `json:"config" reform:"config"`
	ServiceEndpointAddress *string         `json:"serviceEndpointAddress" reform:"service_endpoint_address"`
	Country                *string         `json:"country" reform:"country"`
}

Product stores billing and action related settings.

func NewTestProduct

func NewTestProduct() *Product

NewTestProduct returns new product.

type Session

type Session struct {
	ID              string     `json:"id" reform:"id,pk"`
	Channel         string     `json:"channel" reform:"channel"`
	Started         time.Time  `json:"started" reform:"started"`
	Stopped         *time.Time `json:"stopped" reform:"stopped"`
	UnitsUsed       uint64     `json:"unitsUsed" reform:"units_used"`
	SecondsConsumed uint64     `json:"secondsConsumed" reform:"seconds_consumed"`
	LastUsageTime   time.Time  `json:"lastUsageTime" reform:"last_usage_time"`
	ClientIP        *string    `json:"clientIP" reform:"client_ip"`
	ClientPort      *uint16    `json:"clientPort" reform:"client_port"`
}

Session is a client session.

func NewTestSession

func NewTestSession(chanID string) *Session

NewTestSession returns new session.

type Setting

type Setting struct {
	Key         string  `json:"key" reform:"key,pk"`
	Value       string  `json:"value" reform:"value"`
	Permissions int     `json:"permissions" reform:"permissions"`
	Description *string `json:"description" reform:"description"`
	Name        string  `json:"name" reform:"name"`
}

Setting is a user setting.

type StaticPWDStorage

type StaticPWDStorage string

StaticPWDStorage returns static static password, can't be rewritten.

func (*StaticPWDStorage) Get

func (s *StaticPWDStorage) Get() string

Get returns stored static password.

func (*StaticPWDStorage) Set

func (s *StaticPWDStorage) Set(_ string)

Set does nothing.

type Template

type Template struct {
	ID   string          `json:"id" reform:"id,pk"`
	Hash HexString       `json:"hash" reform:"hash"`
	Raw  json.RawMessage `json:"raw" reform:"raw"`
	Kind string          `json:"kind" reform:"kind"`
}

Template is a user defined structures. It can be an offer or access template.

func NewTestTemplate

func NewTestTemplate(kind string) *Template

NewTestTemplate returns new tempalte.

type TestData

type TestData struct {
	Channel  string
	Password string
}

TestData is a container for testing data items.

type TestFixture

type TestFixture struct {
	T              *testing.T
	DB             *reform.DB
	Product        *Product
	Account        *Account
	UserAcc        *Account
	User           *User
	TemplateOffer  *Template
	TemplateAccess *Template
	Offering       *Offering
	Channel        *Channel
	Endpoint       *Endpoint
}

TestFixture encapsulates a typical set of DB objects useful for testing.

func NewEthTestFixture

func NewEthTestFixture(t *testing.T, db *reform.DB,
	account *truffle.TestAccount) *TestFixture

NewEthTestFixture creates a new ethereum test fixture.

func NewTestFixture

func NewTestFixture(t *testing.T, db *reform.DB) *TestFixture

NewTestFixture creates a new test fixture.

func (*TestFixture) Close

func (f *TestFixture) Close()

Close closes a given test fixture.

type ToPrivateKeyFunc

type ToPrivateKeyFunc func(Base64String, string) (*ecdsa.PrivateKey, error)

ToPrivateKeyFunc is a func that returns decrypted *ecdsa.PrivateKey from base64 of encrypted keystore.Key.

type User

type User struct {
	ID        string       `json:"id" reform:"id,pk"`
	EthAddr   HexString    `json:"ethAddr" reform:"eth_addr"`
	PublicKey Base64String `json:"publicKey" reform:"public_key"`
}

User is party in distributed trade. It can play an agent role, a client role, or both of them.

func NewTestUser

func NewTestUser() *User

NewTestUser returns new subject.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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