Skip to content
Snippets Groups Projects
Commit bea5c328 authored by Acha Bill's avatar Acha Bill
Browse files

review comments

parent e343331f
No related branches found
No related tags found
No related merge requests found
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 (attachment *Attachment) TransactionID() ledgerstate.TransactionID {
return attachment.transactionID
func (a *Attachment) TransactionID() ledgerstate.TransactionID {
return a.transactionID
}
// MessageID returns the messageID of this Attachment.
func (attachment *Attachment) MessageID() MessageID {
return attachment.messageID
func (a *Attachment) MessageID() MessageID {
return a.messageID
}
// Bytes marshals the Attachment into a sequence of bytes.
func (attachment *Attachment) Bytes() []byte {
return attachment.ObjectStorageKey()
func (a *Attachment) Bytes() []byte {
return a.ObjectStorageKey()
}
// String returns a human readable version of the Attachment.
func (attachment *Attachment) String() string {
func (a *Attachment) String() string {
return stringify.Struct("Attachment",
stringify.StructField("transactionId", attachment.TransactionID()),
stringify.StructField("messageID", attachment.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 (attachment *Attachment) ObjectStorageKey() []byte {
return byteutils.ConcatBytes(attachment.transactionID.Bytes(), attachment.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 (attachment *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 (attachment *Attachment) Update(other objectstorage.StorableObject) {
func (a *Attachment) Update(other objectstorage.StorableObject) {
panic("update forbidden")
}
......
......@@ -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) {
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment