Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
95789c60
Unverified
Commit
95789c60
authored
4 years ago
by
jonastheis
Browse files
Options
Downloads
Patches
Plain Diff
Add accessor and convenience methods for parents
parent
70b0cb87
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/tangle/message.go
+54
-11
54 additions, 11 deletions
packages/tangle/message.go
with
54 additions
and
11 deletions
packages/tangle/message.go
+
54
−
11
View file @
95789c60
...
...
@@ -32,7 +32,7 @@ const (
// WeakParent identifies a weak parent in the bitmask.
WeakParent
uint8
=
0
MinParentsCount
=
2
MinParentsCount
=
1
MaxParentsCount
=
8
MinStrongParentsCount
=
1
)
...
...
@@ -180,8 +180,8 @@ func MessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Messa
return
}
parentsCount
,
err
:=
marshalUtil
.
ReadByte
()
if
err
!=
nil
{
var
parentsCount
uint8
if
parentsCount
,
err
=
marshalUtil
.
ReadByte
();
err
!=
nil
{
err
=
xerrors
.
Errorf
(
"failed to parse parents count from MarshalUtil: %w"
,
err
)
return
}
...
...
@@ -190,8 +190,8 @@ func MessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Messa
return
}
parentTypes
,
err
:=
marshalUtil
.
ReadByte
()
if
err
!=
nil
{
var
parentTypes
uint8
if
parentTypes
,
err
=
marshalUtil
.
ReadByte
();
err
!=
nil
{
err
=
xerrors
.
Errorf
(
"failed to parse parent types from MarshalUtil: %w"
,
err
)
return
}
...
...
@@ -199,8 +199,8 @@ func MessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Messa
var
previousParent
MessageID
for
i
:=
0
;
i
<
int
(
parentsCount
);
i
++
{
parentID
,
err
:=
MessageID
FromMarshalUtil
(
marshalUtil
)
if
err
!=
nil
{
var
parentID
MessageID
if
parentID
,
err
=
MessageIDFromMarshalUtil
(
marshalUtil
);
err
!=
nil
{
err
=
xerrors
.
Errorf
(
"failed to parse parent %d from MarshalUtil: %w"
,
i
,
err
)
return
}
...
...
@@ -210,8 +210,7 @@ func MessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Messa
result
.
weakParents
=
append
(
result
.
weakParents
,
parentID
)
}
// verify that parents are sorted lexicographically ASC
// TODO: do we allow duplicate parents?
// verify that parents are sorted lexicographically ASC and unique
if
bytes
.
Compare
(
previousParent
.
Bytes
(),
parentID
.
Bytes
())
>
-
1
{
err
=
xerrors
.
Errorf
(
"parents not sorted lexicographically ascending: %w"
,
cerrors
.
ErrParseBytesFailed
)
return
...
...
@@ -319,8 +318,52 @@ func (m *Message) ID() (result MessageID) {
return
}
// TODO: accessor/convenience methods to access strong/weak parents
// Version returns the message version.
func
(
m
*
Message
)
Version
()
uint8
{
return
m
.
version
}
// StrongParents returns a slice of all strong parents of the message.
func
(
m
*
Message
)
StrongParents
()
[]
MessageID
{
return
m
.
strongParents
}
// StrongParents returns a slice of all strong parents of the message.
func
(
m
*
Message
)
WeakParents
()
[]
MessageID
{
return
m
.
weakParents
}
// ForEachParent executes a consumer func for each parent.
func
(
m
*
Message
)
ForEachParent
(
consumer
func
(
parent
Parent
))
{
for
_
,
parentID
:=
range
m
.
strongParents
{
consumer
(
Parent
{
ID
:
parentID
,
Type
:
StrongParent
,
})
}
for
_
,
parentID
:=
range
m
.
weakParents
{
consumer
(
Parent
{
ID
:
parentID
,
Type
:
WeakParent
,
})
}
}
// ForEachStrongParent executes a consumer func for each strong parent.
func
(
m
*
Message
)
ForEachStrongParent
(
consumer
func
(
parent
MessageID
))
{
for
_
,
parentID
:=
range
m
.
strongParents
{
consumer
(
parentID
)
}
}
// ForEachWeakParent executes a consumer func for each weak parent.
func
(
m
*
Message
)
ForEachWeakParent
(
consumer
func
(
parent
MessageID
))
{
for
_
,
parentID
:=
range
m
.
weakParents
{
consumer
(
parentID
)
}
}
// ParentsCount returns the total parents count of this message.
func
(
m
*
Message
)
ParentsCount
()
uint8
{
return
uint8
(
len
(
m
.
strongParents
)
+
len
(
m
.
weakParents
))
}
...
...
@@ -355,7 +398,7 @@ func (m *Message) Signature() ed25519.Signature {
return
m
.
signature
}
// calculates the message
id
.
// calculates the message
's MessageID
.
func
(
m
*
Message
)
calculateID
()
MessageID
{
return
blake2b
.
Sum256
(
m
.
Bytes
())
}
...
...
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