Skip to content
Snippets Groups Projects
Commit 429e7dd3 authored by Gomez Goiri, Aitor's avatar Gomez Goiri, Aitor
Browse files

Adding some debug messages and restricting access to functions

parent fa8a40a2
No related branches found
No related tags found
No related merge requests found
...@@ -8,8 +8,10 @@ package stats ...@@ -8,8 +8,10 @@ package stats
import ( import (
"encoding/json" "encoding/json"
"fmt"
"git.code.tecnalia.com/blockchain/hypercog/model" "git.code.tecnalia.com/blockchain/hypercog/model"
"git.code.tecnalia.com/ledgerbuilder/sdk/core/util/logging"
"git.code.tecnalia.com/ledgerbuilder/sdk/shared" "git.code.tecnalia.com/ledgerbuilder/sdk/shared"
) )
...@@ -18,6 +20,7 @@ const ORG_LIST_KEY = "org_list" ...@@ -18,6 +20,7 @@ const ORG_LIST_KEY = "org_list"
type OrgList []string type OrgList []string
var log = logging.NewGoLogger("stats")
func getStats(stub shared.LedgerBuildrStubInterface, key string) (st *model.RawStats, err error) { func getStats(stub shared.LedgerBuildrStubInterface, key string) (st *model.RawStats, err error) {
value, err := stub.GetState(key) value, err := stub.GetState(key)
...@@ -61,6 +64,26 @@ func getOrgList(stub shared.LedgerBuildrStubInterface) (st *OrgList, err error) ...@@ -61,6 +64,26 @@ func getOrgList(stub shared.LedgerBuildrStubInterface) (st *OrgList, err error)
return st, nil return st, nil
} }
func resetStats(stub shared.LedgerBuildrStubInterface) (error) {
err := stub.DelState(GLOBAL_KEY)
if err != nil {
return err
}
orgs, err := getOrgList(stub)
if len(*orgs) > 0 {
for _, org := range *orgs {
err = stub.DelState(org)
if err != nil {
return err
}
}
}
err = stub.DelState(ORG_LIST_KEY)
return err
}
func (orgs OrgList) contains(org string) (bool) { func (orgs OrgList) contains(org string) (bool) {
for _, o := range orgs { for _, o := range orgs {
if o == org { if o == org {
...@@ -70,7 +93,7 @@ func (orgs OrgList) contains(org string) (bool) { ...@@ -70,7 +93,7 @@ func (orgs OrgList) contains(org string) (bool) {
return false return false
} }
func AddOrgIfNotExist(stub shared.LedgerBuildrStubInterface, org string) (err error) { func addOrgIfNotExist(stub shared.LedgerBuildrStubInterface, org string) (err error) {
orgs, err := getOrgList(stub) orgs, err := getOrgList(stub)
if err != nil { if err != nil {
return err return err
...@@ -88,6 +111,8 @@ func AddOrgIfNotExist(stub shared.LedgerBuildrStubInterface, org string) (err er ...@@ -88,6 +111,8 @@ func AddOrgIfNotExist(stub shared.LedgerBuildrStubInterface, org string) (err er
if err != nil { if err != nil {
return err return err
} }
log.Debug("Added stat for new org")
} }
return nil return nil
...@@ -129,11 +154,12 @@ func upgradeStats(stub shared.LedgerBuildrStubInterface, globalStats *model.RawS ...@@ -129,11 +154,12 @@ func upgradeStats(stub shared.LedgerBuildrStubInterface, globalStats *model.RawS
return err return err
} }
err = AddOrgIfNotExist(stub, org) err = addOrgIfNotExist(stub, org)
if err != nil { if err != nil {
return err return err
} }
log.Debug("Upgrading stats")
return nil return nil
} }
...@@ -164,6 +190,8 @@ func RegisterSale(stub shared.LedgerBuildrStubInterface, quantity uint32, price ...@@ -164,6 +190,8 @@ func RegisterSale(stub shared.LedgerBuildrStubInterface, quantity uint32, price
orgStats.UpgradeSell(quantity, price, units) orgStats.UpgradeSell(quantity, price, units)
orgStats.UpgradeSell(quantity, price, units) orgStats.UpgradeSell(quantity, price, units)
log.Debug(fmt.Sprintf("Sale registered in stats (quantity: %s, price: %s, units: %s)", quantity, price, units))
err = upgradeStats(stub, globalStats, orgStats) err = upgradeStats(stub, globalStats, orgStats)
if err != nil { if err != nil {
return err return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment