Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Leveraging blockchain usage to enhance slag exchange
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HyperCOG public
Leveraging blockchain usage to enhance slag exchange
Commits
429e7dd3
Commit
429e7dd3
authored
3 years ago
by
Gomez Goiri, Aitor
Browse files
Options
Downloads
Patches
Plain Diff
Adding some debug messages and restricting access to functions
parent
fa8a40a2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
chaincode/controller/stats/stub.go
+30
-2
30 additions, 2 deletions
chaincode/controller/stats/stub.go
with
30 additions
and
2 deletions
chaincode/controller/stats/stub.go
+
30
−
2
View file @
429e7dd3
...
...
@@ -8,8 +8,10 @@ package stats
import
(
"encoding/json"
"fmt"
"git.code.tecnalia.com/blockchain/hypercog/model"
"git.code.tecnalia.com/ledgerbuilder/sdk/core/util/logging"
"git.code.tecnalia.com/ledgerbuilder/sdk/shared"
)
...
...
@@ -18,6 +20,7 @@ const ORG_LIST_KEY = "org_list"
type
OrgList
[]
string
var
log
=
logging
.
NewGoLogger
(
"stats"
)
func
getStats
(
stub
shared
.
LedgerBuildrStubInterface
,
key
string
)
(
st
*
model
.
RawStats
,
err
error
)
{
value
,
err
:=
stub
.
GetState
(
key
)
...
...
@@ -61,6 +64,26 @@ func getOrgList(stub shared.LedgerBuildrStubInterface) (st *OrgList, err error)
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
)
{
for
_
,
o
:=
range
orgs
{
if
o
==
org
{
...
...
@@ -70,7 +93,7 @@ func (orgs OrgList) contains(org string) (bool) {
return
false
}
func
A
ddOrgIfNotExist
(
stub
shared
.
LedgerBuildrStubInterface
,
org
string
)
(
err
error
)
{
func
a
ddOrgIfNotExist
(
stub
shared
.
LedgerBuildrStubInterface
,
org
string
)
(
err
error
)
{
orgs
,
err
:=
getOrgList
(
stub
)
if
err
!=
nil
{
return
err
...
...
@@ -88,6 +111,8 @@ func AddOrgIfNotExist(stub shared.LedgerBuildrStubInterface, org string) (err er
if
err
!=
nil
{
return
err
}
log
.
Debug
(
"Added stat for new org"
)
}
return
nil
...
...
@@ -129,11 +154,12 @@ func upgradeStats(stub shared.LedgerBuildrStubInterface, globalStats *model.RawS
return
err
}
err
=
A
ddOrgIfNotExist
(
stub
,
org
)
err
=
a
ddOrgIfNotExist
(
stub
,
org
)
if
err
!=
nil
{
return
err
}
log
.
Debug
(
"Upgrading stats"
)
return
nil
}
...
...
@@ -164,6 +190,8 @@ func RegisterSale(stub shared.LedgerBuildrStubInterface, quantity uint32, price
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
)
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment