Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MainNet commitments
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
archives
MainNet commitments
Commits
7a150ed2
Commit
7a150ed2
authored
Jul 12, 2022
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Mapimpl should properly upsert to match db
parent
1c58c9bd
Branches
Branches containing commit
No related tags found
1 merge request
!12
Add new columns to db, info call to api
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
storage/database.go
+2
-2
2 additions, 2 deletions
storage/database.go
storage/mapImpl.go
+13
-6
13 additions, 6 deletions
storage/mapImpl.go
with
15 additions
and
8 deletions
storage/database.go
+
2
−
2
View file @
7a150ed2
...
...
@@ -85,8 +85,8 @@ func newDatabase(username, password, dbName, address,
defer
jww
.
INFO
.
Println
(
"Map backend initialized successfully!"
)
mapImpl
:=
&
MapImpl
{
members
:
map
[
string
]
Member
{},
commitments
:
map
[
string
]
Commitment
{},
members
:
map
[
string
]
*
Member
{},
commitments
:
map
[
string
]
*
Commitment
{},
}
return
database
(
mapImpl
),
nil
...
...
This diff is collapsed.
Click to expand it.
storage/mapImpl.go
+
13
−
6
View file @
7a150ed2
...
...
@@ -16,8 +16,8 @@ import (
// MapImpl struct implements the database interface with an underlying Map
type
MapImpl
struct
{
members
map
[
string
]
Member
commitments
map
[
string
]
Commitment
members
map
[
string
]
*
Member
commitments
map
[
string
]
*
Commitment
sync
.
RWMutex
}
...
...
@@ -25,7 +25,7 @@ func (db *MapImpl) InsertMembers(members []Member) error {
db
.
Lock
()
defer
db
.
Unlock
()
for
_
,
m
:=
range
members
{
db
.
members
[
base64
.
StdEncoding
.
EncodeToString
(
m
.
Id
)]
=
m
db
.
members
[
base64
.
StdEncoding
.
EncodeToString
(
m
.
Id
)]
=
&
m
}
return
nil
}
...
...
@@ -33,7 +33,14 @@ func (db *MapImpl) InsertMembers(members []Member) error {
func
(
db
*
MapImpl
)
InsertCommitment
(
commitment
Commitment
)
error
{
db
.
Lock
()
defer
db
.
Unlock
()
db
.
commitments
[
string
(
commitment
.
Id
)]
=
commitment
if
_
,
ok
:=
db
.
commitments
[
string
(
commitment
.
Id
)];
ok
{
db
.
commitments
[
string
(
commitment
.
Id
)]
.
NominatorWallet
=
commitment
.
NominatorWallet
db
.
commitments
[
string
(
commitment
.
Id
)]
.
SelectedStake
=
commitment
.
SelectedStake
db
.
commitments
[
string
(
commitment
.
Id
)]
.
Email
=
commitment
.
Email
db
.
commitments
[
string
(
commitment
.
Id
)]
.
Wallet
=
commitment
.
Wallet
}
else
{
db
.
commitments
[
string
(
commitment
.
Id
)]
=
&
commitment
}
return
nil
}
...
...
@@ -51,7 +58,7 @@ func (db *MapImpl) GetMember(id string) (*Member, error) {
if
!
ok
{
return
nil
,
errors
.
Errorf
(
"No member in MapImpl with id %+v"
,
id
)
}
return
&
m
,
nil
return
m
,
nil
}
func
(
db
*
MapImpl
)
GetCommitment
(
id
string
)
(
*
Commitment
,
error
)
{
...
...
@@ -67,5 +74,5 @@ func (db *MapImpl) GetCommitment(id string) (*Commitment, error) {
if
!
ok
{
return
nil
,
errors
.
Errorf
(
"No commitment in MapImpl with id %+v"
,
id
)
}
return
&
c
,
nil
return
c
,
nil
}
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