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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
bea5c328
Commit
bea5c328
authored
4 years ago
by
Acha Bill
Browse files
Options
Downloads
Patches
Plain Diff
review comments
parent
e343331f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
packages/tangle/attachment.go
+19
-20
19 additions, 20 deletions
packages/tangle/attachment.go
packages/tangle/messagebooker.go
+1
-5
1 addition, 5 deletions
packages/tangle/messagebooker.go
packages/tangle/messagestore.go
+8
-0
8 additions, 0 deletions
packages/tangle/messagestore.go
with
28 additions
and
25 deletions
packages/tangle/attachment.go
+
19
−
20
View file @
bea5c328
package
tangle
import
(
"fmt"
"github.com/iotaledger/goshimmer/packages/ledgerstate"
"github.com/iotaledger/hive.go/byteutils"
"github.com/iotaledger/hive.go/marshalutil"
"github.com/iotaledger/hive.go/objectstorage"
"github.com/iotaledger/hive.go/stringify"
"golang.org/x/xerrors"
)
// Attachment stores the information which transaction was attached by which message. We need this to be able to perform
...
...
@@ -41,11 +40,11 @@ func AttachmentFromBytes(bytes []byte) (result *Attachment, consumedBytes int, e
func
ParseAttachment
(
marshalUtil
*
marshalutil
.
MarshalUtil
)
(
result
*
Attachment
,
err
error
)
{
result
=
&
Attachment
{}
if
result
.
transactionID
,
err
=
ledgerstate
.
TransactionIDFromMarshalUtil
(
marshalUtil
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to parse transaction ID in attachment: %w"
,
err
)
err
=
xerrors
.
Errorf
(
"failed to parse transaction ID in attachment: %w"
,
err
)
return
}
if
result
.
messageID
,
err
=
MessageIDFromMarshalUtil
(
marshalUtil
);
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to parse message ID in attachment: %w"
,
err
)
err
=
xerrors
.
Errorf
(
"failed to parse message ID in attachment: %w"
,
err
)
return
}
...
...
@@ -54,51 +53,51 @@ func ParseAttachment(marshalUtil *marshalutil.MarshalUtil) (result *Attachment,
// AttachmentFromObjectStorage gets called when we restore an Attachment from the storage - it parses the key bytes and
// returns the new object.
func
AttachmentFromObjectStorage
(
key
[]
byte
,
data
[]
byte
)
(
result
objectstorage
.
StorableObject
,
err
error
)
{
result
,
_
,
err
=
AttachmentFromBytes
(
byteutils
.
ConcatBytes
(
key
,
data
)
)
func
AttachmentFromObjectStorage
(
key
[]
byte
,
_
[]
byte
)
(
result
objectstorage
.
StorableObject
,
err
error
)
{
result
,
_
,
err
=
AttachmentFromBytes
(
key
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to parse attachment from object storage: %w"
,
err
)
err
=
xerrors
.
Errorf
(
"failed to parse attachment from object storage: %w"
,
err
)
}
return
}
// TransactionID returns the transactionID of this Attachment.
func
(
a
ttachment
*
Attachment
)
TransactionID
()
ledgerstate
.
TransactionID
{
return
a
ttachment
.
transactionID
func
(
a
*
Attachment
)
TransactionID
()
ledgerstate
.
TransactionID
{
return
a
.
transactionID
}
// MessageID returns the messageID of this Attachment.
func
(
a
ttachment
*
Attachment
)
MessageID
()
MessageID
{
return
a
ttachment
.
messageID
func
(
a
*
Attachment
)
MessageID
()
MessageID
{
return
a
.
messageID
}
// Bytes marshals the Attachment into a sequence of bytes.
func
(
a
ttachment
*
Attachment
)
Bytes
()
[]
byte
{
return
a
ttachment
.
ObjectStorageKey
()
func
(
a
*
Attachment
)
Bytes
()
[]
byte
{
return
a
.
ObjectStorageKey
()
}
// String returns a human readable version of the Attachment.
func
(
a
ttachment
*
Attachment
)
String
()
string
{
func
(
a
*
Attachment
)
String
()
string
{
return
stringify
.
Struct
(
"Attachment"
,
stringify
.
StructField
(
"transactionId"
,
a
ttachment
.
TransactionID
()),
stringify
.
StructField
(
"messageID"
,
a
ttachment
.
MessageID
()),
stringify
.
StructField
(
"transactionId"
,
a
.
TransactionID
()),
stringify
.
StructField
(
"messageID"
,
a
.
MessageID
()),
)
}
// ObjectStorageKey returns the key that is used to store the object in the database.
func
(
a
ttachment
*
Attachment
)
ObjectStorageKey
()
[]
byte
{
return
byteutils
.
ConcatBytes
(
a
ttachment
.
transactionID
.
Bytes
(),
a
ttachment
.
MessageID
()
.
Bytes
())
func
(
a
*
Attachment
)
ObjectStorageKey
()
[]
byte
{
return
byteutils
.
ConcatBytes
(
a
.
transactionID
.
Bytes
(),
a
.
MessageID
()
.
Bytes
())
}
// ObjectStorageValue marshals the "content part" of an Attachment to a sequence of bytes. Since all of the information
// for this object are stored in its key, this method does nothing and is only required to conform with the interface.
func
(
a
ttachment
*
Attachment
)
ObjectStorageValue
()
(
data
[]
byte
)
{
func
(
a
*
Attachment
)
ObjectStorageValue
()
(
data
[]
byte
)
{
return
}
// Update is disabled - updates are supposed to happen through the setters (if existing).
func
(
a
ttachment
*
Attachment
)
Update
(
other
objectstorage
.
StorableObject
)
{
func
(
a
*
Attachment
)
Update
(
other
objectstorage
.
StorableObject
)
{
panic
(
"update forbidden"
)
}
...
...
This diff is collapsed.
Click to expand it.
packages/tangle/messagebooker.go
+
1
−
5
View file @
bea5c328
...
...
@@ -187,11 +187,7 @@ func (m *MessageBooker) referencedTransactionIDs(transaction *ledgerstate.Transa
// Attachments retrieves the attachments of a transaction.
func
(
m
*
MessageBooker
)
Attachments
(
transactionID
ledgerstate
.
TransactionID
)
(
attachments
MessageIDs
)
{
cachedAttachments
:=
m
.
messageStore
.
Attachments
(
transactionID
)
cachedAttachments
.
Consume
(
func
(
attachment
*
Attachment
)
{
attachments
=
append
(
attachments
,
attachment
.
MessageID
())
})
return
return
m
.
messageStore
.
AttachmentMessageIDs
(
transactionID
)
}
func
(
m
*
MessageBooker
)
determineTargetBranch
(
branchIDsOfStrongParents
ledgerstate
.
BranchIDs
)
(
targetBranch
ledgerstate
.
BranchID
,
err
error
)
{
...
...
This diff is collapsed.
Click to expand it.
packages/tangle/messagestore.go
+
8
−
0
View file @
bea5c328
...
...
@@ -180,6 +180,14 @@ func (m *MessageStore) Attachments(transactionID ledgerstate.TransactionID) (cac
return
}
// AttachmentMessageIDs returns the messageIDs of the transaction in attachmentStorage.
func
(
m
*
MessageStore
)
AttachmentMessageIDs
(
transactionID
ledgerstate
.
TransactionID
)
(
messageIDs
MessageIDs
)
{
m
.
Attachments
(
transactionID
)
.
Consume
(
func
(
attachment
*
Attachment
)
{
messageIDs
=
append
(
messageIDs
,
attachment
.
MessageID
())
})
return
}
// DeleteMessage deletes a message and its association to approvees by un-marking the given
// message as an approver.
func
(
m
*
MessageStore
)
DeleteMessage
(
messageID
MessageID
)
{
...
...
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