From 3d48b69a5f77207dd5291b1e2f593cbf26c4d5cd Mon Sep 17 00:00:00 2001 From: Vladislav Dmitriyev Date: Fri, 11 May 2018 15:24:19 +0300 Subject: [PATCH 1/5] Removed hashing of fields in conversion and transition --- state/conversion.go | 20 +------------------- state/state.go | 12 ------------ state/transition.go | 17 +---------------- 3 files changed, 2 insertions(+), 47 deletions(-) diff --git a/state/conversion.go b/state/conversion.go index d0e39b6..4cb60ef 100644 --- a/state/conversion.go +++ b/state/conversion.go @@ -51,8 +51,7 @@ func (s *State) AddConversion(conversion *Conversion) error { } func (s *State) SetConversion(conversion *Conversion) error { - return s.DB.C(conversionsCollection).Insert( - s.encryptConversion(conversion)) + return s.DB.C(conversionsCollection).Insert(conversion) } func (s *State) HasConversion(id string) bool { @@ -74,20 +73,3 @@ func (s *State) ListConversions() (result []*Conversion, err error) { func (s *State) SearchConversions(query interface{}, limit, offset int) (result []*Conversion, err error) { return result, s.DB.C(conversionsCollection).Find(query).Skip(offset).Limit(limit).All(&result) } - -func (s *State) encryptConversion(conversion *Conversion) *Conversion { - // Encrypt fields with BLAKE2B 256-bit algorithm - return &Conversion{ - ID: conversion.ID, - AdvertiserAccountID: conversion.AdvertiserAccountID, - AffiliateAccountID: conversion.AffiliateAccountID, - ClickID: s.hash(conversion.ClickID), - OfferID: s.hash(conversion.OfferID), - ClientID: s.hash(conversion.ClientID), - GoalID: s.hash(conversion.GoalID), - StreamID: s.hash(conversion.StreamID), - CreatedAt: conversion.CreatedAt, - Comment: conversion.Comment, - Status: conversion.Status, - } -} diff --git a/state/state.go b/state/state.go index 3a806a6..535eed4 100644 --- a/state/state.go +++ b/state/state.go @@ -22,10 +22,7 @@ package state import ( - "encoding/base64" - "github.com/globalsign/mgo" - "golang.org/x/crypto/blake2b" ) type State struct { @@ -36,12 +33,3 @@ type State struct { func NewStateFromDB(db *mgo.Database) *State { return &State{db} } - -func (s *State) hash(data string) string { - hash, err := blake2b.New256(nil) - hash.Write([]byte(data)) - if err != nil { - return "" - } - return base64.StdEncoding.EncodeToString(hash.Sum(nil)) -} diff --git a/state/transition.go b/state/transition.go index 87d4563..f0910e7 100644 --- a/state/transition.go +++ b/state/transition.go @@ -49,8 +49,7 @@ func (s *State) AddTransition(transition *Transition) error { func (s *State) SetTransition(transition *Transition) error { - return s.DB.C(transitionsCollection).Insert( - s.encryptTransition(transition)) + return s.DB.C(transitionsCollection).Insert(transition) } func (s *State) HasTransition(id string) bool { @@ -72,17 +71,3 @@ func (s *State) ListTransitions() (result []*Transition, err error) { func (s *State) SearchTransitions(query interface{}, limit, offset int) (result []*Transition, err error) { return result, s.DB.C(transitionsCollection).Find(query).Skip(offset).Limit(limit).All(&result) } - -func (s *State) encryptTransition(transition *Transition) *Transition { - // Encrypt fields with BLAKE2B 256-bit algorithm - return &Transition{ - ID: transition.ID, - AdvertiserAccountID: transition.AdvertiserAccountID, - AffiliateAccountID: transition.AffiliateAccountID, - ClickID: s.hash(transition.ClickID), - OfferID: s.hash(transition.OfferID), - StreamID: s.hash(transition.StreamID), - CreatedAt: transition.CreatedAt, - ExpiresIn: transition.ExpiresIn, - } -} From 634a3baa28aeae625d40f0dc6a219285dc1ea151 Mon Sep 17 00:00:00 2001 From: Vladislav Dmitriyev Date: Fri, 11 May 2018 15:38:49 +0300 Subject: [PATCH 2/5] Commented account and state files --- state/account.go | 12 ++++++++---- state/state.go | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/state/account.go b/state/account.go index 7794cca..38070a4 100644 --- a/state/account.go +++ b/state/account.go @@ -29,6 +29,7 @@ import ( //go:generate msgp +// Account struct keeps account related fields. type Account struct { ID string `msg:"_id" json:"_id" mapstructure:"_id" bson:"_id"` PubKey string `msg:"pubkey" json:"pubkey" mapstructure:"pubkey" bson:"pubkey"` @@ -36,6 +37,7 @@ type Account struct { const accountsCollection = "accounts" +// AddAccount method adds new account if all checks was passed. func (s *State) AddAccount(account *Account) error { if s.HasAccount(account.ID) { return errors.New("Account exists") @@ -43,10 +45,12 @@ func (s *State) AddAccount(account *Account) error { return s.SetAccount(account) } +// SetAccount method adds account in the state. func (s *State) SetAccount(account *Account) error { return s.DB.C(accountsCollection).Insert(account) } +// HasAccount method checks account existence in the state. func (s *State) HasAccount(id string) bool { if res, _ := s.GetAccount(id); res != nil { return true @@ -54,15 +58,13 @@ func (s *State) HasAccount(id string) bool { return false } +// GetAccount method returns account from accounts collection in the state. func (s *State) GetAccount(id string) (*Account, error) { var result *Account return result, s.DB.C(accountsCollection).FindId(id).One(&result) } -func (s *State) DeleteAccount(id string) error { - return s.DB.C(accountsCollection).RemoveId(id) -} - +// GetAccountPubKey method returns public key by given account id. func (s *State) GetAccountPubKey(id string) (*crypto.Key, error) { acc, err := s.GetAccount(id) if err != nil { @@ -71,10 +73,12 @@ func (s *State) GetAccountPubKey(id string) (*crypto.Key, error) { return crypto.NewFromStrings(acc.PubKey, "") } +// ListAccounts method returns all accounts from the state. func (s *State) ListAccounts() (result []*Account, err error) { return result, s.DB.C(accountsCollection).Find(nil).All(&result) } +// SearchAccounts method returns accounts by given search query, limit and offset parameters. func (s *State) SearchAccounts(query interface{}, limit, offset int) (result []*Account, err error) { return result, s.DB.C(accountsCollection).Find(query).Skip(offset).Limit(limit).All(&result) } diff --git a/state/state.go b/state/state.go index 535eed4..5ce78a6 100644 --- a/state/state.go +++ b/state/state.go @@ -25,11 +25,12 @@ import ( "github.com/globalsign/mgo" ) +// State struct contains pointer to MongoDB instance. type State struct { DB *mgo.Database } -// NewStateFromDB method constructs MongoDB state +// NewStateFromDB method constructs MongoDB state. func NewStateFromDB(db *mgo.Database) *State { return &State{db} } From daf4ca7890061cff7448b58dc92f0a4344a95dd6 Mon Sep 17 00:00:00 2001 From: Vladislav Dmitriyev Date: Fri, 11 May 2018 17:00:45 +0300 Subject: [PATCH 3/5] Removed build context in docker develop yml files --- deploy/DOCKER/leadschain-develop.yaml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/deploy/DOCKER/leadschain-develop.yaml b/deploy/DOCKER/leadschain-develop.yaml index 3d09ea7..c2de0f3 100644 --- a/deploy/DOCKER/leadschain-develop.yaml +++ b/deploy/DOCKER/leadschain-develop.yaml @@ -44,9 +44,6 @@ services: leadschain-abci-develop: image: leadschain/abci:develop - build: - context: . - dockerfile: dockerfiles/develop/leadschain-abci-develop.Dockerfile container_name: leadschain-abci-develop logging: driver: "json-file" @@ -62,13 +59,10 @@ services: - ${ABCI_PORT}:${ABCI_PORT} depends_on: - leadschain-mongodb - entrypoint: tmlc-abci --dbhost=mongodb://172.16.238.02:${DB_PORT} --addr=tcp://172.16.238.03:${ABCI_PORT} --loglevel=*:error + entrypoint: tmlc-abci --dbhost=mongodb://172.16.238.02:${DB_PORT} --addr=tcp://172.16.238.03:${ABCI_PORT} --loglevel=*:info leadschain-node-develop: image: leadschain/node:develop - build: - context: . - dockerfile: dockerfiles/develop/leadschain-node-develop.Dockerfile container_name: leadschain-node-develop logging: driver: "json-file" @@ -95,9 +89,6 @@ services: leadschain-rest-api-develop: image: leadschain/api:develop - build: - context: . - dockerfile: dockerfiles/develop/leadschain-rest-api-develop.Dockerfile container_name: leadschain-rest-api-develop logging: driver: "json-file" @@ -111,7 +102,7 @@ services: - ${REST_PORT}:${REST_PORT} depends_on: - leadschain-abci-develop - entrypoint: tmlc-api --endpoint=http://${NODE_IP}:${GRPC_PORT} --ip=${NODE_IP} --port=${REST_PORT} --loglevel=*:error + entrypoint: tmlc-api --endpoint=http://${NODE_IP}:${GRPC_PORT} --ip=${NODE_IP} --port=${REST_PORT} --loglevel=*:info networks: back: From cf6d1c7e5083235bd2b3dce24569d373f25de927 Mon Sep 17 00:00:00 2001 From: Vladislav Dmitriyev Date: Tue, 15 May 2018 11:24:25 +0300 Subject: [PATCH 4/5] Added comments to account, conversion, transition related methods --- state/account.go | 8 ++++---- state/conversion.go | 7 +++++++ state/transition.go | 8 +++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/state/account.go b/state/account.go index 38070a4..8184ca1 100644 --- a/state/account.go +++ b/state/account.go @@ -37,7 +37,7 @@ type Account struct { const accountsCollection = "accounts" -// AddAccount method adds new account if all checks was passed. +// AddAccount method adds new account if all checks were passed. func (s *State) AddAccount(account *Account) error { if s.HasAccount(account.ID) { return errors.New("Account exists") @@ -45,12 +45,12 @@ func (s *State) AddAccount(account *Account) error { return s.SetAccount(account) } -// SetAccount method adds account in the state. +// SetAccount method adds account in state. func (s *State) SetAccount(account *Account) error { return s.DB.C(accountsCollection).Insert(account) } -// HasAccount method checks account existence in the state. +// HasAccount method checks if account exists in state or not exists. func (s *State) HasAccount(id string) bool { if res, _ := s.GetAccount(id); res != nil { return true @@ -58,7 +58,7 @@ func (s *State) HasAccount(id string) bool { return false } -// GetAccount method returns account from accounts collection in the state. +// GetAccount method returns account from accounts collection by given accoutn id. func (s *State) GetAccount(id string) (*Account, error) { var result *Account return result, s.DB.C(accountsCollection).FindId(id).One(&result) diff --git a/state/conversion.go b/state/conversion.go index 4cb60ef..eecd284 100644 --- a/state/conversion.go +++ b/state/conversion.go @@ -27,6 +27,7 @@ import ( //go:generate msgp +// Conversion struct keep conversion related fields. type Conversion struct { ID string `msg:"_id" json:"_id" mapstructure:"_id" bson:"_id"` AdvertiserAccountID string `msg:"advertiser_account_id" json:"advertiser_account_id" mapstructure:"advertiser_account_id" bson:"advertiser_account_id"` @@ -43,6 +44,7 @@ type Conversion struct { const conversionsCollection = "conversions" +// AddConversion method adds new conversion to the state if it not exists. func (s *State) AddConversion(conversion *Conversion) error { if s.HasConversion(conversion.ID) { return errors.New("Conversion exists") @@ -50,10 +52,12 @@ func (s *State) AddConversion(conversion *Conversion) error { return s.SetConversion(conversion) } +// SetConversion inserts new conversion to state without any checks. func (s *State) SetConversion(conversion *Conversion) error { return s.DB.C(conversionsCollection).Insert(conversion) } +// HasConversion method checks exists conversion in state ot not. func (s *State) HasConversion(id string) bool { if res, _ := s.GetConversion(id); res != nil { return true @@ -61,15 +65,18 @@ func (s *State) HasConversion(id string) bool { return false } +// GetConversion method gets conversion from state by it identifier. func (s *State) GetConversion(id string) (*Conversion, error) { var result *Conversion return result, s.DB.C(conversionsCollection).FindId(id).One(&result) } +// ListConversions method returns list of all conversions in state. func (s *State) ListConversions() (result []*Conversion, err error) { return result, s.DB.C(conversionsCollection).Find(nil).All(&result) } +// SearchConversions method finds conversions using mongodb query language. func (s *State) SearchConversions(query interface{}, limit, offset int) (result []*Conversion, err error) { return result, s.DB.C(conversionsCollection).Find(query).Skip(offset).Limit(limit).All(&result) } diff --git a/state/transition.go b/state/transition.go index f0910e7..62a816d 100644 --- a/state/transition.go +++ b/state/transition.go @@ -27,6 +27,7 @@ import ( //go:generate msgp +// Transition struct keeps transition related fields. type Transition struct { ID string `msg:"_id" json:"_id" mapstructure:"_id" bson:"_id"` AdvertiserAccountID string `msg:"advertiser_account_id" json:"advertiser_account_id" mapstructure:"advertiser_account_id" bson:"advertiser_account_id"` @@ -40,6 +41,7 @@ type Transition struct { const transitionsCollection = "transitions" +// AddTransition method adds new transition to state if it not exists. func (s *State) AddTransition(transition *Transition) error { if s.HasTransition(transition.ID) { return errors.New("Transition exists") @@ -47,11 +49,12 @@ func (s *State) AddTransition(transition *Transition) error { return s.SetTransition(transition) } +// SetTransition method inserts new transition in state without any checks. func (s *State) SetTransition(transition *Transition) error { - return s.DB.C(transitionsCollection).Insert(transition) } +// HasTransition method checks exists conversion in state or not exists. func (s *State) HasTransition(id string) bool { if res, _ := s.GetTransition(id); res != nil { return true @@ -59,15 +62,18 @@ func (s *State) HasTransition(id string) bool { return false } +// GetTransition method gets transition from state by given id. func (s *State) GetTransition(id string) (*Transition, error) { var result *Transition return result, s.DB.C(transitionsCollection).FindId(id).One(&result) } +// ListTransitions method returns list of all transitions from state. func (s *State) ListTransitions() (result []*Transition, err error) { return result, s.DB.C(transitionsCollection).Find(nil).All(&result) } +// SearchTransitions method finds conversions in state using mongodb query language. func (s *State) SearchTransitions(query interface{}, limit, offset int) (result []*Transition, err error) { return result, s.DB.C(transitionsCollection).Find(query).Skip(offset).Limit(limit).All(&result) } From a4cc2ba8d85fe267efd997dad9a8b1c45a3106b7 Mon Sep 17 00:00:00 2001 From: Vladislav Dmitriyev Date: Tue, 15 May 2018 11:25:35 +0300 Subject: [PATCH 5/5] Bumped version to 1.2.2 --- version/version.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version/version.go b/version/version.go index 5835753..b5ffb81 100644 --- a/version/version.go +++ b/version/version.go @@ -2,11 +2,11 @@ package version const Major = "1" const Minor = "2" -const Fix = "1" +const Fix = "2" var ( // Version is the current version of Leadschain platform - Version = "1.2.1" + Version = "1.2.2" // GitCommit is the current HEAD set using ldflags. GitCommit string