Skip to content

Commit

Permalink
Merge pull request #14 from leadschain/develop
Browse files Browse the repository at this point in the history
Removed hashing of conversions, transitions related fields in state
  • Loading branch information
eeonevision committed May 15, 2018
2 parents f6054d9 + a4cc2ba commit 4a05888
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 66 deletions.
13 changes: 2 additions & 11 deletions deploy/DOCKER/leadschain-develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions state/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,42 @@ 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"`
}

const accountsCollection = "accounts"

// 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")
}
return s.SetAccount(account)
}

// SetAccount method adds account in state.
func (s *State) SetAccount(account *Account) error {
return s.DB.C(accountsCollection).Insert(account)
}

// 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
}
return false
}

// 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)
}

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 {
Expand All @@ -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)
}
27 changes: 8 additions & 19 deletions state/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -43,51 +44,39 @@ 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")
}
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(
s.encryptConversion(conversion))
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
}
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)
}

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,
}
}
15 changes: 2 additions & 13 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@
package state

import (
"encoding/base64"

"github.com/globalsign/mgo"
"golang.org/x/crypto/blake2b"
)

// 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}
}

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))
}
25 changes: 8 additions & 17 deletions state/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -40,49 +41,39 @@ 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")
}
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(
s.encryptTransition(transition))
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
}
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)
}

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,
}
}
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a05888

Please sign in to comment.