Documentation
¶
Index ¶
- Constants
- func BeginTestTX(t *testing.T, db *reform.DB) *reform.TX
- func BytesToUint32(b []byte) (uint32, error)
- func CleanTestDB(t *testing.T, db *reform.DB)
- func CleanTestTable(t *testing.T, db *reform.DB, tbl reform.Table)
- func CloseDB(db *reform.DB)
- func CommitTestTX(t *testing.T, tx *reform.TX)
- func DeleteFromTestDB(t *testing.T, db *reform.DB, recs ...reform.Record)
- func EncryptedKey(pkey *ecdsa.PrivateKey, auth string) (string, error)
- func FindInTestDB(t *testing.T, db *reform.DB, str reform.Struct, column string, arg interface{})
- func FromBytes(src []byte) string
- func GetUint64Setting(db *reform.DB, key string) (uint64, error)
- func HashPassword(password, salt string) (string, error)
- func InsertToTestDB(t *testing.T, db *reform.DB, rows ...reform.Struct)
- func NewDB(conf *DBConfig, logger *util.Logger) (*reform.DB, error)
- func NewDBFromConnStr(connStr string, logger *util.Logger) (*reform.DB, error)
- func NewTestDB(conf *DBConfig, logger *util.Logger) *reform.DB
- func ReloadFromTestDB(t *testing.T, db *reform.DB, recs ...reform.Record)
- func RollbackTestTX(t *testing.T, tx *reform.TX)
- func SaveToTestDB(t *testing.T, db *reform.DB, recs ...reform.Record)
- func TestEncryptedKey(pkey *ecdsa.PrivateKey, auth string) (string, error)
- func TestToAddress(t *testing.T, addr string) common.Address
- func TestToBytes(t *testing.T, s string) []byte
- func TestToHash(t *testing.T, h string) common.Hash
- func TestToPrivateKey(keyB64, auth string) (*ecdsa.PrivateKey, error)
- func ToAddress(addr string) (common.Address, error)
- func ToBytes(s string) ([]byte, error)
- func ToHash(h string) (common.Hash, error)
- func ToPrivateKey(keyB64, auth string) (*ecdsa.PrivateKey, error)
- func Uint32ToBytes(x uint32) [4]byte
- func ValidatePassword(hash, password, salt string) error
- type Account
- type B64BigInt
- type Channel
- type Contract
- type DBConfig
- type EncryptedKeyFunc
- type Endpoint
- type EndpointUI
- type EthLog
- type EthTx
- type Job
- type JobBalanceData
- type JobPublishData
- type LogTopics
- type Offering
- type PWDGetSetter
- type PWDGetter
- type PWDSetter
- type PWDStorage
- type Product
- type Session
- type Setting
- type StaticPWDStorage
- type Template
- type TestData
- type TestFixture
- type ToPrivateKeyFunc
- type User
Constants ¶
const ( TemplateOffer = "offer" TemplateAccess = "access" )
Templates kinds.
const ( ProductUsageIncremental = "incremental" ProductUsageTotal = "total" )
Product usage reporting types.
const ( UnitScalar = "units" UnitSeconds = "seconds" )
Unit used for billing calculation.
const ( BillingPrepaid = "prepaid" BillingPostpaid = "postpaid" )
Billing types.
const ( MsgUnpublished = "unpublished" // Saved but not published. MsgBChainPublishing = "bchain_publishing" // To blockchain. MsgBChainPublished = "bchain_published" // To blockchain. MsgChPublished = "msg_channel_published" // Published in messaging channel. )
Message statuses.
const ( OfferEmpty = "empty" OfferRegister = "register" OfferRemove = "remove" )
Offering statuses.
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.
const ( ServicePending = "pending" ServiceActive = "active" ServiceSuspended = "suspended" ServiceTerminated = "terminated" )
Service operational statuses.
const ( ContractPTC = "ptc" ContractPSC = "psc" )
Contract types.
const ( JobUser = "user" JobBillingChecker = "billing_checker" JobBCMonitor = "bc_monitor" JobTask = "task" )
Job creators.
const ( JobActive = "active" JobDone = "done" JobFailed = "failed" JobCanceled = "canceled" )
Job statuses.
const ( JobOfferring = "offering" JobChannel = "channel" JobEndpoint = "endpoint" JobAccount = "account" )
Job related object types.
const ( TxUnsent = "unsent" TxSent = "sent" TxMined = "mined" TxUncle = "uncle" )
Transaction statuses.
const ( JobClientPreChannelCreate = "clientPreChannelCreate" JobClientAfterChannelCreate = "clientAfterChannelCreate" JobClientPreChannelTopUp = "clientPreChannelTopUp" JobClientAfterChannelTopUp = "clientAfterChannelTopUp" JobClientPreUncooperativeCloseRequest = "clientPreUncooperativeCloseRequest" JobClientAfterUncooperativeCloseRequest = "clientAfterUncooperativeCloseRequest" JobClientPreUncooperativeClose = "clientPreUncooperativeClose" JobClientAfterUncooperativeClose = "clientAfterUncooperativeClose" JobClientAfterCooperativeClose = "clientAfterCooperativeClose" JobClientPreServiceTerminate = "clientPreServiceTerminate" JobClientAfterServiceTerminate = "clientAfterServiceTerminate" JobClientPreEndpointMsgSOMCGet = "clientPreEndpointMsgSOMCGet" JobClientAfterOfferingMsgBCPublish = "clientAfterOfferingMsgBCPublish" JobClientPreOfferingMsgSOMCGet = "clientPreOfferingMsgSOMCGet" JobAgentAfterChannelCreate = "agentAfterChannelCreate" JobAgentAfterChannelTopUp = "agentAfterChannelTopUp" JobAgentAfterUncooperativeCloseRequest = "agentAfterUncooperativeCloseRequest" JobAgentAfterUncooperativeClose = "agentAfterUncooperativeClose" JobAgentPreCooperativeClose = "agentPreCooperativeClose" JobAgentAfterCooperativeClose = "agentAfterCooperativeClose" JobAgentPreServiceSuspend = "agentPreServiceSuspend" JobAgentPreServiceUnsuspend = "agentPreServiceUnsuspend" JobAgentPreServiceTerminate = "agentPreServiceTerminate" JobAgentPreEndpointMsgCreate = "agentPreEndpointMsgCreate" JobAgentPreEndpointMsgSOMCPublish = "agentPreEndpointMsgSOMCPublish" JobAgentAfterEndpointMsgSOMCPublish = "agentAfterEndpointMsgSOMCPublish" JobAgentPreOfferingMsgBCPublish = "agentPreOfferingMsgBCPublish" JobAgentAfterOfferingMsgBCPublish = "agentAfterOfferingMsgBCPublish" JobAgentPreOfferingMsgSOMCPublish = "agentPreOfferingMsgSOMCPublish" JobPreAccountAddBalanceApprove = "preAccountAddBalanceApprove" JobPreAccountAddBalance = "preAccountAddBalance" JobAfterAccountAddBalance = "afterAccountAddBalance" JobPreAccountReturnBalance = "preAccountReturnBalance" JobAfterAccountReturnBalance = "afterAccountReturnBalance" JobAccountAddCheckBalance = "addCheckBalance" )
Job types.
const ( TestPassword = "secret" TestPasswordHash = "JDJhJDEwJHNVbWNtTkVwQk5DMkwuOC5OL1BXU08uYkJMMkxjcmthTW1BZklOTUNjNWZDdWNUOU54Tzlp" TestSalt = 6012867121110302348 )
Test authentication constants.
const (
ClientIdentByChannelID = "by_channel_id"
)
Product authentication types.
Variables ¶
This section is empty.
Functions ¶
func BeginTestTX ¶
BeginTestTX begins a test transaction.
func CleanTestDB ¶
CleanTestDB deletes all records from all test DB tables.
func CleanTestTable ¶
CleanTestTable deletes all records from a given DB table.
func CommitTestTX ¶
CommitTestTX commits a test transaction.
func DeleteFromTestDB ¶
DeleteFromTestDB deletes records from test DB.
func EncryptedKey ¶
func EncryptedKey(pkey *ecdsa.PrivateKey, auth string) (string, error)
EncryptedKey returns encrypted keystore.Key in base64.
func FindInTestDB ¶
FindInTestDB selects a record from test db
func GetUint64Setting ¶
GetUint64Setting finds the key value in table Setting. Checks that the value in the format of uint64
func HashPassword ¶
HashPassword computes encoded hash of the password.
func InsertToTestDB ¶
InsertToTestDB inserts rows to test DB.
func NewDBFromConnStr ¶
NewDBFromConnStr creates a new data connection handle from a given connection string.
func ReloadFromTestDB ¶
ReloadFromTestDB reloads records from test DB.
func RollbackTestTX ¶
RollbackTestTX rollbacks a test transaction.
func SaveToTestDB ¶
SaveToTestDB saves records to test DB.
func TestEncryptedKey ¶
func TestEncryptedKey(pkey *ecdsa.PrivateKey, auth string) (string, error)
TestEncryptedKey is a key encryption simplified for tests performance.
func TestToAddress ¶
TestToAddress decodes to address or fails.
func TestToBytes ¶
TestToBytes returns binary representation of base64 encoded string or fails.
func TestToHash ¶
TestToHash decodes to hash or fails.
func TestToPrivateKey ¶
func TestToPrivateKey(keyB64, auth string) (*ecdsa.PrivateKey, error)
TestToPrivateKey is a key decryption simplified for tests performance.
func ToPrivateKey ¶
func ToPrivateKey(keyB64, auth string) (*ecdsa.PrivateKey, error)
ToPrivateKey returns decrypted *ecdsa.PrivateKey from base64 of encrypted keystore.Key.
func ValidatePassword ¶
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 string `json:"ethAddr" reform:"eth_addr"`
PublicKey string `json:"-" reform:"public_key"`
PrivateKey string `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:"psc_balance" reform:"psc_balance"`
EthBalance B64BigInt `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.
type B64BigInt ¶
type B64BigInt string
B64BigInt is a base64 of big.Int that implements json.Marshaler.
func (B64BigInt) MarshalJSON ¶
MarshalJSON marshals itself.
type Channel ¶
type Channel struct {
ID string `json:"id" reform:"id,pk"`
Agent string `json:"agent" reform:"agent"`
Client string `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"`
TotalDeposit uint64 `json:"totalDeposit" reform:"total_deposit"`
Salt uint64 `json:"-" reform:"salt"`
Username *string `json:"-" reform:"username"`
Password string `json:"-" reform:"password"`
ReceiptBalance uint64 `json:"-" reform:"receipt_balance"` // Last payment.
ReceiptSignature *string `json:"-" reform:"receipt_signature"` // Last payment's signature.
}
Channel is a state channel.
type Contract ¶
type Contract struct {
ID string `json:"id" reform:"id,pk"`
Address string `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 EncryptedKeyFunc ¶
type EncryptedKeyFunc func(*ecdsa.PrivateKey, string) (string, 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 string `json:"hash" reform:"hash"`
RawMsg string `reform:"raw_msg"`
Status string `json:"status" reform:"status"`
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"`
}
Endpoint messages is info about service access.
func NewTestEndpoint ¶
NewTestEndpoint returns new endpoint.
type EndpointUI ¶
type EndpointUI struct {
ID string `json:"id" reform:"id,pk"`
AdditionalParams []byte `json:"additionalParams" reform:"additional_params"`
}
EndpointUI contains only certain fields of endpoints table.
type EthLog ¶
type EthLog struct {
ID string `reform:"id,pk"`
TxHash string `reform:"tx_hash"`
TxStatus string `reform:"status"`
JobID *string `reform:"job"`
BlockNumber uint64 `reform:"block_number"`
Addr string `reform:"addr"`
Data string `reform:"data"`
Topics LogTopics `reform:"topics"`
Failures uint64 `reform:"failures"`
Ignore bool `reform:"ignore"`
}
EthLog is an ethereum log entry.
type EthTx ¶
type EthTx struct {
ID string `reform:"id,pk" json:"id"`
Hash string `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 string `reform:"addr_from" json:"addrFrom"`
AddrTo string `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 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 ¶
NewTestJob returns a default test job.
type JobBalanceData ¶
JobBalanceData is a data required for transfer jobs.
type JobPublishData ¶
type JobPublishData struct {
GasPrice uint64
}
JobPublishData is a data required for blockchain publish jobs.
type LogTopics ¶
LogTopics is a database/sql compatible type for ethereum log topics.
type Offering ¶
type Offering struct {
ID string `json:"id" reform:"id,pk"`
IsLocal bool `json:"is_local" 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 string `json:"hash" reform:"hash"` // Offering's hash.
Status string `json:"status" reform:"status"`
OfferStatus string `json:"offerStatus" reform:"offer_status"`
BlockNumberUpdated uint64 `json:"blockNumberUpdated" reform:"block_number_updated"`
Agent string `json:"agent" reform:"agent" validate:"required"`
RawMsg string `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"`
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 []byte `json:"additionalParams" reform:"additional_params" validate:"required"`
}
Offering is a service offering.
func NewTestOffering ¶
NewTestOffering returns new offering.
type PWDGetSetter ¶
PWDGetSetter can get and set password to storage.
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 string `json:"-" reform:"password"`
ClientIdent string `json:"clientIdent" reform:"client_ident"`
Config []byte `json:"config" reform:"config"`
ServiceEndpointAddress *string `json:"serviceEndpointAddress" reform:"service_endpoint_address"`
}
Product stores billing and action related settings.
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 ¶
NewTestSession returns new session.
type Setting ¶
type Setting struct {
Key string `json:"key" reform:"key,pk"`
Value string `json:"value" reform:"value"`
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.
type Template ¶
type Template struct {
ID string `json:"id" reform:"id,pk"`
Hash string `json:"hash" reform:"hash"`
Raw []byte `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 ¶
NewTestTemplate returns new tempalte.
type TestFixture ¶
type TestFixture struct {
T *testing.T
DB *reform.DB
Product *Product
Account *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
func NewTestFixture ¶
func NewTestFixture(t *testing.T, db *reform.DB) *TestFixture
NewTestFixture creates a new test fixture.
type ToPrivateKeyFunc ¶
type ToPrivateKeyFunc func(string, string) (*ecdsa.PrivateKey, error)
ToPrivateKeyFunc is a func that returns decrypted *ecdsa.PrivateKey from base64 of encrypted keystore.Key.