tangle

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2021 License: Apache-2.0, BSD-2-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const AttachmentLength = transaction.IDLength + payload.IDLength

AttachmentLength holds the length of a marshaled Attachment in bytes.

ConsumerLength holds the length of a marshaled Consumer in bytes.

Variables

View Source
var (
	// ErrFatal represents an error that is not "expected".
	ErrFatal = errors.New("fatal error")

	// ErrTransactionInvalid represents an error type that is triggered when an invalid transaction is detected.
	ErrTransactionInvalid = errors.New("transaction invalid")

	// ErrPayloadInvalid represents an error type that is triggered when an invalid payload is detected.
	ErrPayloadInvalid = errors.New("payload invalid")

	// ErrDoubleSpendForbidden represents an error that is triggered when a user tries to issue a double spend.
	ErrDoubleSpendForbidden = errors.New("it is not allowed to issue a double spend")

	// ErrTransactionDoesNotSpendAllFunds is returned if a transaction does not spend all of its inputs.
	ErrTransactionDoesNotSpendAllFunds = errors.New("transaction does not spend all funds from inputs")
	// ErrInvalidTransactionSignature is returned if the signature of a transaction is invalid.
	ErrInvalidTransactionSignature = errors.New("missing or invalid transaction signature")
	// ErrMaxTransactionInputCountExceeded is returned if the max number of inputs of the transaction is exceeded.
	ErrMaxTransactionInputCountExceeded = errors.New("maximum transaction input count exceeded")
)

ConsumerPartitionKeys defines the "layout" of the key. This enables prefix iterations in the objectstorage.

View Source
var MissingOutputKeyPartitions = objectstorage.PartitionKey([]int{address.Length, transaction.IDLength}...)

MissingOutputKeyPartitions defines the "layout" of the key. This enables prefix iterations in the objectstorage.

OutputKeyPartitions defines the "layout" of the key. This enables prefix iterations in the objectstorage.

Functions

func AttachmentFromObjectStorage added in v0.3.0

func AttachmentFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

AttachmentFromObjectStorage gets called when we restore an Attachment from the storage - it parses the key bytes and returns the new object.

func ConsumerFromObjectStorage added in v0.3.0

func ConsumerFromObjectStorage(key []byte, _ []byte) (result objectstorage.StorableObject, err error)

ConsumerFromObjectStorage is a factory method that creates a new Consumer instance from a storage key of the objectstorage. It is used by the objectstorage, to create new instances of this entity.

func MissingPayloadFromObjectStorage added in v0.3.0

func MissingPayloadFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

MissingPayloadFromObjectStorage gets called when we restore an entry for a missing value transfer payload from the storage. The bytes and the content will be unmarshaled by an external caller using the binary.ObjectStorageValue interface.

func OutputFromObjectStorage added in v0.3.0

func OutputFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

OutputFromObjectStorage get's called when we restore a Output from the storage. In contrast to other database models, it unmarshals some information from the key so we simply store the key before it gets handed over to UnmarshalObjectStorageValue (by the ObjectStorage).

func PayloadApproverFromObjectStorage added in v0.3.0

func PayloadApproverFromObjectStorage(key []byte, _ []byte) (result objectstorage.StorableObject, err error)

PayloadApproverFromObjectStorage get's called when we restore transaction metadata from the storage. In contrast to other database models, it unmarshals the information from the key and does not use the UnmarshalObjectStorageValue method.

func PayloadMetadataFromObjectStorage added in v0.3.0

func PayloadMetadataFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

PayloadMetadataFromObjectStorage gets called when we restore transaction metadata from the storage. The bytes and the content will be unmarshaled by an external caller using the binary.ObjectStorageValue interface.

func TransactionMetadataFromObjectStorage added in v0.3.0

func TransactionMetadataFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

TransactionMetadataFromObjectStorage get's called when we restore TransactionMetadata from the storage. In contrast to other database models, it unmarshals some information from the key so we simply store the key before it gets handed over to UnmarshalObjectStorageValue (by the ObjectStorage).

Types

type Attachment

type Attachment struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Attachment stores the information which transaction was attached by which payload. We need this to be able to perform reverse lookups from transactions to their corresponding payloads, that attach them.

func AttachmentFromBytes

func AttachmentFromBytes(bytes []byte) (result *Attachment, consumedBytes int, err error)

AttachmentFromBytes unmarshals an Attachment from a sequence of bytes - it either creates a new object or fills the optionally provided one with the parsed information.

func NewAttachment

func NewAttachment(transactionID transaction.ID, payloadID payload.ID) *Attachment

NewAttachment creates an attachment object with the given information.

func ParseAttachment

func ParseAttachment(marshalUtil *marshalutil.MarshalUtil) (result *Attachment, err error)

ParseAttachment is a wrapper for simplified unmarshaling of Attachments from a byte stream using the marshalUtil package.

func (*Attachment) Bytes

func (attachment *Attachment) Bytes() []byte

Bytes marshals the Attachment into a sequence of bytes.

func (*Attachment) ObjectStorageKey

func (attachment *Attachment) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database.

func (*Attachment) ObjectStorageValue

func (attachment *Attachment) ObjectStorageValue() (data []byte)

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) PayloadID

func (attachment *Attachment) PayloadID() payload.ID

PayloadID returns the payload id of this Attachment.

func (*Attachment) String

func (attachment *Attachment) String() string

String returns a human readable version of the Attachment.

func (*Attachment) TransactionID

func (attachment *Attachment) TransactionID() transaction.ID

TransactionID returns the transaction id of this Attachment.

func (*Attachment) Update

func (attachment *Attachment) Update(other objectstorage.StorableObject)

Update is disabled - updates are supposed to happen through the setters (if existing).

type CachedApprovers

type CachedApprovers []*CachedPayloadApprover

CachedApprovers represents a collection of CachedPayloadApprover.

func (CachedApprovers) Consume

func (cachedApprovers CachedApprovers) Consume(consumer func(approver *PayloadApprover)) (consumed bool)

Consume iterates over the CachedObjects, unwraps them and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes. It returns true, if at least one object was consumed.

type CachedAttachment

type CachedAttachment struct {
	objectstorage.CachedObject
}

CachedAttachment is a wrapper for the generic CachedObject returned by the objectstorage, that overrides the accessor methods, with a type-casted one.

func (*CachedAttachment) Consume

func (cachedAttachment *CachedAttachment) Consume(consumer func(attachment *Attachment)) (consumed bool)

Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes.

func (*CachedAttachment) Retain

func (cachedAttachment *CachedAttachment) Retain() *CachedAttachment

Retain marks this CachedObject to still be in use by the program.

func (*CachedAttachment) Unwrap

func (cachedAttachment *CachedAttachment) Unwrap() *Attachment

Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.

type CachedAttachments

type CachedAttachments []*CachedAttachment

CachedAttachments represents a collection of CachedAttachments.

func (CachedAttachments) Consume

func (cachedAttachments CachedAttachments) Consume(consumer func(attachment *Attachment)) (consumed bool)

Consume iterates over the CachedObjects, unwraps them and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes. It returns true, if at least one object was consumed.

type CachedAttachmentsEvent added in v0.3.0

type CachedAttachmentsEvent struct {
	Transaction         *transaction.CachedTransaction
	TransactionMetadata *CachedTransactionMetadata
	Attachments         *CachedAttachment
}

CachedAttachmentsEvent represents the parameters of cachedTransactionAttachmentEvent

type CachedConsumer

type CachedConsumer struct {
	objectstorage.CachedObject
}

CachedConsumer is a wrapper for the generic CachedObject returned by the objectstorage, that overrides the accessor methods, with a type-casted one.

func (*CachedConsumer) Consume

func (cachedConsumer *CachedConsumer) Consume(consumer func(consumer *Consumer)) (consumed bool)

Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes.

func (*CachedConsumer) Unwrap

func (cachedConsumer *CachedConsumer) Unwrap() *Consumer

Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.

type CachedConsumers

type CachedConsumers []*CachedConsumer

CachedConsumers represents a collection of CachedConsumers.

func (CachedConsumers) Consume

func (cachedConsumers CachedConsumers) Consume(consumer func(consumer *Consumer)) (consumed bool)

Consume iterates over the CachedObjects, unwraps them and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes. It returns true, if at least one object was consumed.

type CachedOutput

type CachedOutput struct {
	objectstorage.CachedObject
}

CachedOutput is a wrapper for the generic CachedObject returned by the objectstorage, that overrides the accessor methods, with a type-casted one.

func (*CachedOutput) Consume

func (cachedOutput *CachedOutput) Consume(consumer func(output *Output)) (consumed bool)

Consume unwraps the CachedObject and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes.

func (*CachedOutput) Unwrap

func (cachedOutput *CachedOutput) Unwrap() *Output

Unwrap is the type-casted equivalent of Get. It returns nil if the object does not exist.

type CachedOutputs

type CachedOutputs map[transaction.OutputID]*CachedOutput

CachedOutputs represents a collection of CachedOutputs.

func (CachedOutputs) Consume

func (cachedOutputs CachedOutputs) Consume(consumer func(output *Output)) (consumed bool)

Consume iterates over the CachedObjects, unwraps them and passes a type-casted version to the consumer (if the object is not empty - it exists). It automatically releases the object when the consumer finishes. It returns true, if at least one object was consumed.

func (CachedOutputs) Release

func (cachedOutputs CachedOutputs) Release(force ...bool)

Release is a utility function, that allows us to release all CachedObjects in the collection.

type CachedPayloadApprover

type CachedPayloadApprover struct {
	objectstorage.CachedObject
}

CachedPayloadApprover is a wrapper for the object storage, that takes care of type casting the managed objects. Since go does not have generics (yet), the object storage works based on the generic "interface{}" type, which means that we have to regularly type cast the returned objects, to match the expected type. To reduce the burden of manually managing these type, we create a wrapper that does this for us. This way, we can consistently handle the specialized types of CachedApprovers, without having to manually type cast over and over again.

func (*CachedPayloadApprover) Consume

func (cachedPayloadApprover *CachedPayloadApprover) Consume(consumer func(payload *PayloadApprover)) bool

Consume wraps the underlying method to return the correctly typed objects in the callback.

func (*CachedPayloadApprover) Retain

func (cachedPayloadApprover *CachedPayloadApprover) Retain() *CachedPayloadApprover

Retain wraps the underlying method to return a new "wrapped object".

func (*CachedPayloadApprover) Unwrap

func (cachedPayloadApprover *CachedPayloadApprover) Unwrap() *PayloadApprover

Unwrap provides a way to "Get" a type casted version of the underlying object.

type CachedPayloadEvent added in v0.3.0

type CachedPayloadEvent struct {
	Payload         *payload.CachedPayload
	PayloadMetadata *CachedPayloadMetadata
}

CachedPayloadEvent represents the parameters of cachedPayloadEvent

type CachedPayloadMetadata

type CachedPayloadMetadata struct {
	objectstorage.CachedObject
}

CachedPayloadMetadata is a wrapper for the object storage, that takes care of type casting the managed objects. Since go does not have generics (yet), the object storage works based on the generic "interface{}" type, which means that we have to regularly type cast the returned objects, to match the expected type. To reduce the burden of manually managing these type, we create a wrapper that does this for us. This way, we can consistently handle the specialized types of CachedObjects, without having to manually type cast over and over again.

func (*CachedPayloadMetadata) Consume

func (cachedPayloadMetadata *CachedPayloadMetadata) Consume(consumer func(payloadMetadata *PayloadMetadata)) bool

Consume wraps the underlying method to return the correctly typed objects in the callback.

func (*CachedPayloadMetadata) Retain

func (cachedPayloadMetadata *CachedPayloadMetadata) Retain() *CachedPayloadMetadata

Retain wraps the underlying method to return a new "wrapped object".

func (*CachedPayloadMetadata) Unwrap

func (cachedPayloadMetadata *CachedPayloadMetadata) Unwrap() *PayloadMetadata

Unwrap provides a way to "Get" a type casted version of the underlying object.

type CachedTransactionBookEvent added in v0.3.0

type CachedTransactionBookEvent struct {
	Transaction         *transaction.CachedTransaction
	TransactionMetadata *CachedTransactionMetadata
	Pending             bool
}

CachedTransactionBookEvent represents the parameters of transactionBookedEvent

type CachedTransactionEvent added in v0.3.0

type CachedTransactionEvent struct {
	Transaction         *transaction.CachedTransaction
	TransactionMetadata *CachedTransactionMetadata
}

CachedTransactionEvent represents the parameters of cachedTransactionEvent

type CachedTransactionMetadata

type CachedTransactionMetadata struct {
	objectstorage.CachedObject
}

CachedTransactionMetadata is a wrapper for the object storage, that takes care of type casting the TransactionMetadata objects. Since go does not have generics (yet), the object storage works based on the generic "interface{}" type, which means that we have to regularly type cast the returned objects, to match the expected type. To reduce the burden of manually managing these type, we create a wrapper that does this for us. This way, we can consistently handle the specialized types of TransactionMetadata, without having to manually type cast over and over again.

func (*CachedTransactionMetadata) Consume

func (cachedTransactionMetadata *CachedTransactionMetadata) Consume(consumer func(metadata *TransactionMetadata)) bool

Consume overrides the underlying method to use a CachedTransactionMetadata object instead of a generic CachedObject in the consumer).

func (*CachedTransactionMetadata) Retain

func (cachedTransactionMetadata *CachedTransactionMetadata) Retain() *CachedTransactionMetadata

Retain overrides the underlying method to return a new CachedTransactionMetadata instead of a generic CachedObject.

func (*CachedTransactionMetadata) Unwrap

func (cachedTransactionMetadata *CachedTransactionMetadata) Unwrap() *TransactionMetadata

Unwrap provides a way to retrieve a type casted version of the underlying object.

type Consumer

type Consumer struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Consumer stores the information which transaction output was consumed by which transaction. We need this to be able to perform reverse lookups from transaction outputs to their corresponding consuming transactions.

func ConsumerFromBytes

func ConsumerFromBytes(bytes []byte) (result *Consumer, consumedBytes int, err error)

ConsumerFromBytes unmarshals a Consumer from a sequence of bytes - it either creates a new object or fills the optionally provided one with the parsed information.

func NewConsumer

func NewConsumer(consumedInput transaction.OutputID, transactionID transaction.ID) *Consumer

NewConsumer creates a Consumer object with the given information.

func ParseConsumer

func ParseConsumer(marshalUtil *marshalutil.MarshalUtil) (result *Consumer, err error)

ParseConsumer unmarshals a Consumer using the given marshalUtil (for easier marshaling/unmarshaling).

func (*Consumer) Bytes

func (consumer *Consumer) Bytes() []byte

Bytes marshals the Consumer into a sequence of bytes.

func (*Consumer) ConsumedInput

func (consumer *Consumer) ConsumedInput() transaction.OutputID

ConsumedInput returns the OutputID of the Consumer.

func (*Consumer) ObjectStorageKey

func (consumer *Consumer) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database.

func (*Consumer) ObjectStorageValue

func (consumer *Consumer) ObjectStorageValue() (data []byte)

ObjectStorageValue marshals the "content part" of an Consumer 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 (*Consumer) String

func (consumer *Consumer) String() string

String returns a human readable version of the Consumer.

func (*Consumer) TransactionID

func (consumer *Consumer) TransactionID() transaction.ID

TransactionID returns the transaction ID of this Consumer.

func (*Consumer) Update

func (consumer *Consumer) Update(other objectstorage.StorableObject)

Update is disabled - updates are supposed to happen through the setters (if existing).

type Debugger

type Debugger struct {
	// contains filtered or unexported fields
}

Debugger represents a utility that allows us to print debug messages and function calls.

func NewDebugger

func NewDebugger() *Debugger

NewDebugger is the constructor of a debugger instance.

func (*Debugger) Disable

func (debugger *Debugger) Disable()

Disable sets the debugger to not print any debug information.

func (*Debugger) Enable

func (debugger *Debugger) Enable()

Enable sets the debugger to print the debug information.

func (*Debugger) FunctionCall

func (debugger *Debugger) FunctionCall(identifier string, params ...interface{}) *Debugger

FunctionCall prints debug information about a function call. It automatically indents all following debug outputs until Return() is called. The best way to use this is by starting a function call with a construct like:

defer debugger.FunctionCall("myFunction", param1, param2).Return()

func (*Debugger) Print

func (debugger *Debugger) Print(identifier string, params ...interface{})

Print prints an arbitrary debug message that can for example be used to print an information when a certain part of the code is executed.

func (*Debugger) RegisterAlias

func (debugger *Debugger) RegisterAlias(element interface{}, alias string)

RegisterAlias registers a string representation for the given element. This can be used to create a string representation for things like ids in the form of byte slices.

func (*Debugger) ResetAliases

func (debugger *Debugger) ResetAliases() *Debugger

ResetAliases removes any previously registered aliases. This can be useful if the same debugger instance is for example used in different tests or test cases.

func (*Debugger) Return

func (debugger *Debugger) Return() *Debugger

Return prints debug information about a FunctionCall() the was finished. It reduces the indentation for consecutive debug outputs.

type EventSource

type EventSource int

EventSource is a type that contains information from where a specific change was triggered (the branch manager or the tangle).

const (
	// EventSourceTangle indicates that a change was issued by the Tangle.
	EventSourceTangle EventSource = iota

	// EventSourceBranchManager indicates that a change was issued by the BranchManager.
	EventSourceBranchManager
)

func (EventSource) String

func (eventSource EventSource) String() string

type Events

type Events struct {
	// Get's called whenever a transaction
	PayloadAttached        *events.Event
	PayloadSolid           *events.Event
	PayloadLiked           *events.Event
	PayloadConfirmed       *events.Event
	PayloadRejected        *events.Event
	PayloadDisliked        *events.Event
	MissingPayloadReceived *events.Event
	PayloadMissing         *events.Event
	PayloadInvalid         *events.Event

	// TransactionReceived gets triggered whenever a transaction was received for the first time (not solid yet).
	TransactionReceived *events.Event

	// TransactionInvalid gets triggered whenever we receive an invalid transaction.
	TransactionInvalid *events.Event

	// TransactionSolid gets triggered whenever a transaction becomes solid for the first time.
	TransactionSolid *events.Event

	// TransactionBooked gets triggered whenever a transactions becomes solid and gets booked into a particular branch.
	TransactionBooked *events.Event

	TransactionPreferred *events.Event

	TransactionUnpreferred *events.Event

	TransactionLiked *events.Event

	TransactionDisliked *events.Event

	TransactionConfirmed *events.Event

	TransactionRejected *events.Event

	TransactionFinalized *events.Event

	// Fork gets triggered when a previously un-conflicting transaction get's some of its inputs double spend, so that a
	// new Branch is created.
	Fork *events.Event

	Error *events.Event
}

Events is a container for the different kind of events of the Tangle.

type ForkEvent added in v0.3.0

type ForkEvent struct {
	Transaction         *transaction.CachedTransaction
	TransactionMetadata *CachedTransactionMetadata
	Branch              *branchmanager.CachedBranch
	InputIDs            []transaction.OutputID
}

ForkEvent represents the parameters of forkEvent

type LedgerState

type LedgerState struct {
	// contains filtered or unexported fields
}

LedgerState represents a struct, that allows us to read the balances from the UTXODAG by filtering the existing unspent Outputs depending on the liked branches.

func NewLedgerState

func NewLedgerState(tangle *Tangle) *LedgerState

NewLedgerState is the constructor of the LedgerState. It creates a new instance with the given UTXODAG.

func (*LedgerState) Balances

func (ledgerState *LedgerState) Balances(address address.Address) (coloredBalances map[balance.Color]int64)

Balances returns a map containing the balances of the different colors that are unspent on a certain address.

type MissingOutput

type MissingOutput struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

MissingOutput represents an Output that was referenced by a Transaction, but that is missing in our object storage.

func MissingOutputFromBytes

func MissingOutputFromBytes(bytes []byte, optionalTargetObject ...*MissingOutput) (result *MissingOutput, consumedBytes int, err error)

MissingOutputFromBytes unmarshals a MissingOutput from a sequence of bytes - it either creates a new object or fills the optionally provided one with the parsed information.

func MissingOutputFromStorageKey

func MissingOutputFromStorageKey(key []byte, optionalTargetObject ...*MissingOutput) (result *MissingOutput, consumedBytes int, err error)

MissingOutputFromStorageKey gets called when we restore a MissingOutput from the storage. The content will be unmarshaled by an external caller using the binary.ObjectStorageValue interface.

func NewMissingOutput

func NewMissingOutput(outputID transaction.OutputID) *MissingOutput

NewMissingOutput creates a new MissingOutput object, that .

func ParseMissingOutput

func ParseMissingOutput(marshalUtil *marshalutil.MarshalUtil, optionalTargetObject ...*MissingOutput) (result *MissingOutput, err error)

ParseMissingOutput unmarshals a MissingOutput using the given marshalUtil (for easier marshaling/unmarshaling).

func (*MissingOutput) Bytes

func (missingOutput *MissingOutput) Bytes() []byte

Bytes marshals the MissingOutput into a sequence of bytes.

func (*MissingOutput) ID

func (missingOutput *MissingOutput) ID() transaction.OutputID

ID returns the id of the Output that is missing.

func (*MissingOutput) MissingSince

func (missingOutput *MissingOutput) MissingSince() time.Time

MissingSince returns the Time since the transaction was first reported as being missing.

func (*MissingOutput) ObjectStorageKey

func (missingOutput *MissingOutput) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the object storage.

func (*MissingOutput) ObjectStorageValue

func (missingOutput *MissingOutput) ObjectStorageValue() []byte

ObjectStorageValue returns a bytes representation of the Transaction by implementing the encoding.BinaryMarshaler interface.

func (*MissingOutput) UnmarshalObjectStorageValue

func (missingOutput *MissingOutput) UnmarshalObjectStorageValue(data []byte) (consumedBytes int, err error)

UnmarshalObjectStorageValue restores the values of a MissingOutput from a sequence of bytes using the encoding.BinaryUnmarshaler interface.

func (*MissingOutput) Update

func (missingOutput *MissingOutput) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - updates are supposed to happen through the setters.

type MissingPayload

type MissingPayload struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

MissingPayload represents a payload that was referenced through parent2 or parent1 but that is missing in our object storage.

func MissingPayloadFromBytes

func MissingPayloadFromBytes(bytes []byte) (result *MissingPayload, consumedBytes int, err error)

MissingPayloadFromBytes unmarshals an entry for a missing value transfer payload from a sequence of bytes. It either creates a new entry or fills the optionally provided one with the parsed information.

func NewMissingPayload

func NewMissingPayload(payloadID payload.ID) *MissingPayload

NewMissingPayload creates an entry for a missing value transfer payload.

func ParseMissingPayload

func ParseMissingPayload(marshalUtil *marshalutil.MarshalUtil) (result *MissingPayload, err error)

ParseMissingPayload unmarshals a MissingPayload using the given marshalUtil (for easier marshaling/unmarshaling).

func (*MissingPayload) Bytes

func (missingPayload *MissingPayload) Bytes() []byte

Bytes marshals the missing payload into a sequence of bytes.

func (*MissingPayload) ID

func (missingPayload *MissingPayload) ID() payload.ID

ID returns the payload id, that is missing.

func (*MissingPayload) MissingSince

func (missingPayload *MissingPayload) MissingSince() time.Time

MissingSince returns the time.Time since the transaction was first reported as being missing.

func (*MissingPayload) ObjectStorageKey

func (missingPayload *MissingPayload) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match StorableObject interface.

func (*MissingPayload) ObjectStorageValue

func (missingPayload *MissingPayload) ObjectStorageValue() (data []byte)

ObjectStorageValue is required to match the encoding.BinaryMarshaler interface.

func (*MissingPayload) Update

func (missingPayload *MissingPayload) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - updates are supposed to happen through the setters. It is required to match StorableObject interface.

type Output

type Output struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Output represents the output of a Transaction and contains the balances and the identifiers for this output.

func NewOutput

func NewOutput(address address.Address, transactionID transaction.ID, branchID branchmanager.BranchID, balances []*balance.Balance) *Output

NewOutput creates an Output that contains the balances and identifiers of a Transaction.

func OutputFromBytes

func OutputFromBytes(bytes []byte) (result *Output, consumedBytes int, err error)

OutputFromBytes unmarshals an Output object from a sequence of bytes. It either creates a new object or fills the optionally provided object with the parsed information.

func ParseOutput

func ParseOutput(marshalUtil *marshalutil.MarshalUtil) (result *Output, err error)

ParseOutput unmarshals an Output using the given marshalUtil (for easier marshaling/unmarshaling).

func (*Output) Address

func (output *Output) Address() address.Address

Address returns the address that this output belongs to.

func (*Output) Balances

func (output *Output) Balances() []*balance.Balance

Balances returns the colored balances (color + balance) that this output contains.

func (*Output) BranchID

func (output *Output) BranchID() branchmanager.BranchID

BranchID returns the id of the ledger state branch, that this output was booked in.

func (*Output) Bytes

func (output *Output) Bytes() []byte

Bytes marshals the object into a sequence of bytes.

func (*Output) Confirmed

func (output *Output) Confirmed() bool

Confirmed returns true if the Output was marked as confirmed.

func (*Output) ConsumerCount

func (output *Output) ConsumerCount() int

ConsumerCount returns the number of transactions that have spent this Output.

func (*Output) Finalized

func (output *Output) Finalized() bool

Finalized returns true, if the decision if this output is preferred or not has been finalized by consensus already.

func (*Output) ID

func (output *Output) ID() transaction.OutputID

ID returns the identifier of this Output.

func (*Output) Liked

func (output *Output) Liked() bool

Liked returns true if the Output was marked as liked.

func (*Output) ObjectStorageKey

func (output *Output) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match StorableObject interface.

func (*Output) ObjectStorageValue

func (output *Output) ObjectStorageValue() []byte

ObjectStorageValue marshals the balances into a sequence of bytes - the address and transaction id are stored inside the key and are ignored here.

func (*Output) Preferred

func (output *Output) Preferred() (result bool)

Preferred returns true if the output belongs to a preferred transaction.

func (*Output) RegisterConsumer

func (output *Output) RegisterConsumer(consumer transaction.ID) (consumerCount int, firstConsumerID transaction.ID)

RegisterConsumer keeps track of the first transaction, that consumed an Output and consequently keeps track of the amount of other transactions spending the same Output.

func (*Output) Rejected

func (output *Output) Rejected() bool

Rejected returns true if the Output was marked as confirmed.

func (*Output) Solid

func (output *Output) Solid() bool

Solid returns true if the output has been marked as solid.

func (*Output) SolidificationTime

func (output *Output) SolidificationTime() time.Time

SolidificationTime returns the time when this Output was marked to be solid.

func (*Output) String

func (output *Output) String() string

func (*Output) TransactionID

func (output *Output) TransactionID() transaction.ID

TransactionID returns the id of the Transaction, that created this output.

func (*Output) Update

func (output *Output) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - it is required to match StorableObject interface.

type PayloadApprover

type PayloadApprover struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

PayloadApprover is a database entity, that allows us to keep track of the "tangle structure" by encoding which payload approves which other payload. It allows us to traverse the tangle in the opposite direction of the referenced parent1 and parent2 payloads.

func NewPayloadApprover

func NewPayloadApprover(referencedPayload payload.ID, approvingPayload payload.ID) *PayloadApprover

NewPayloadApprover creates an approver object that encodes a single relation between an approved and an approving payload.

func ParsePayloadApprover

func ParsePayloadApprover(marshalUtil *marshalutil.MarshalUtil) (result *PayloadApprover, err error)

ParsePayloadApprover unmarshals a PayloadApprover using the given marshalUtil (for easier marshaling/unmarshaling).

func PayloadApproverFromBytes

func PayloadApproverFromBytes(bytes []byte) (result *PayloadApprover, consumedBytes int, err error)

PayloadApproverFromBytes unmarshals a PayloadApprover from a sequence of bytes.

func (*PayloadApprover) ApprovingPayloadID

func (payloadApprover *PayloadApprover) ApprovingPayloadID() payload.ID

ApprovingPayloadID returns the identifier of the approving payload.

func (*PayloadApprover) ObjectStorageKey

func (payloadApprover *PayloadApprover) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match StorableObject interface.

func (*PayloadApprover) ObjectStorageValue

func (payloadApprover *PayloadApprover) ObjectStorageValue() (data []byte)

ObjectStorageValue is implemented to conform with the StorableObject interface, but it does not really do anything, since all of the information about an approver are stored in the "key".

func (*PayloadApprover) Update

func (payloadApprover *PayloadApprover) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - updates are supposed to happen through the setters. It is required to match StorableObject interface.

type PayloadMetadata

type PayloadMetadata struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

PayloadMetadata is a container for the metadata of a value transfer payload. It is used to store the information in the database.

func NewPayloadMetadata

func NewPayloadMetadata(payloadID payload.ID) *PayloadMetadata

NewPayloadMetadata creates an empty container for the metadata of a value transfer payload.

func ParsePayloadMetadata

func ParsePayloadMetadata(marshalUtil *marshalutil.MarshalUtil) (result *PayloadMetadata, err error)

ParsePayloadMetadata is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.

func PayloadMetadataFromBytes

func PayloadMetadataFromBytes(bytes []byte) (result *PayloadMetadata, consumedBytes int, err error)

PayloadMetadataFromBytes unmarshals a container with the metadata of a value transfer payload from a sequence of bytes. It either creates a new container or fills the optionally provided container with the parsed information.

func (*PayloadMetadata) BranchID

func (payloadMetadata *PayloadMetadata) BranchID() branchmanager.BranchID

BranchID returns the identifier of the Branch that this Payload was booked into.

func (*PayloadMetadata) Bytes

func (payloadMetadata *PayloadMetadata) Bytes() []byte

Bytes marshals the metadata into a sequence of bytes.

func (*PayloadMetadata) Confirmed

func (payloadMetadata *PayloadMetadata) Confirmed() bool

Confirmed returns true if the Payload was marked as confirmed.

func (*PayloadMetadata) IsSolid

func (payloadMetadata *PayloadMetadata) IsSolid() (result bool)

IsSolid returns true if the payload has been marked as solid.

func (*PayloadMetadata) Liked

func (payloadMetadata *PayloadMetadata) Liked() bool

Liked returns true if the Payload was marked as liked.

func (*PayloadMetadata) ObjectStorageKey

func (payloadMetadata *PayloadMetadata) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to store the object in the database. It is required to match StorableObject interface.

func (*PayloadMetadata) ObjectStorageValue

func (payloadMetadata *PayloadMetadata) ObjectStorageValue() []byte

ObjectStorageValue is required to match the encoding.BinaryMarshaler interface.

func (*PayloadMetadata) PayloadID

func (payloadMetadata *PayloadMetadata) PayloadID() payload.ID

PayloadID return the id of the payload that this metadata is associated to.

func (*PayloadMetadata) Rejected

func (payloadMetadata *PayloadMetadata) Rejected() bool

Rejected returns true if the Payload was marked as confirmed.

func (*PayloadMetadata) SolidificationTime

func (payloadMetadata *PayloadMetadata) SolidificationTime() time.Time

SolidificationTime returns the time when the payload was marked to be solid.

func (*PayloadMetadata) String

func (payloadMetadata *PayloadMetadata) String() string

String creates a human readable version of the metadata (for debug purposes).

func (*PayloadMetadata) Update

func (payloadMetadata *PayloadMetadata) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - updates are supposed to happen through the setters. It is required to match StorableObject interface.

type SignatureFilter

type SignatureFilter struct {
	// contains filtered or unexported fields
}

SignatureFilter represents a filter for the Parser that filters out transactions with an invalid signature.

func NewSignatureFilter

func NewSignatureFilter() *SignatureFilter

NewSignatureFilter is the constructor of the MessageFilter.

func (*SignatureFilter) Filter

func (filter *SignatureFilter) Filter(message *tangle.Message, peer *peer.Peer)

Filter get's called whenever a new message is received. It rejects the message, if the message is not a valid value message.

func (*SignatureFilter) OnAccept

func (filter *SignatureFilter) OnAccept(callback func(message *tangle.Message, peer *peer.Peer))

OnAccept registers the given callback as the acceptance function of the filter.

func (*SignatureFilter) OnReject

func (filter *SignatureFilter) OnReject(callback func(message *tangle.Message, err error, peer *peer.Peer))

OnReject registers the given callback as the rejection function of the filter.

type Snapshot

type Snapshot map[transaction.ID]map[address.Address][]*balance.Balance

Snapshot defines a snapshot of the ledger state.

func (Snapshot) ReadFrom

func (s Snapshot) ReadFrom(reader io.Reader) (int64, error)

ReadFrom reads the snapshot bytes from the given reader. This function overrides existing content of the snapshot.

func (Snapshot) WriteTo

func (s Snapshot) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the snapshot data to the given writer in the following format:

transaction_count(int64)
-> transaction_count * transaction_id(32byte)
	->address_count(int64)
		->address_count * address(33byte)
			->balance_count(int64)
				->balance_count * value(int64)+color(32byte)

type Tangle

type Tangle struct {
	Events *Events
	// contains filtered or unexported fields
}

Tangle represents the value tangle that consists out of value payloads. It is an independent ontology, that lives inside the tangle.

func New

func New(store kvstore.KVStore) (tangle *Tangle)

New is the constructor of a Tangle and creates a new Tangle object from the given details.

func (*Tangle) Approvers

func (tangle *Tangle) Approvers(payloadID payload.ID) CachedApprovers

Approvers retrieves the approvers of a payload from the object storage.

func (*Tangle) AttachPayload

func (tangle *Tangle) AttachPayload(payload *payload.Payload)

AttachPayload adds a new payload to the value tangle.

func (*Tangle) AttachPayloadSync

func (tangle *Tangle) AttachPayloadSync(payloadToStore *payload.Payload)

AttachPayloadSync is the worker function that stores the payload and calls the corresponding storage events.

func (*Tangle) Attachments

func (tangle *Tangle) Attachments(transactionID transaction.ID) CachedAttachments

Attachments retrieves the attachment of a payload from the object storage.

func (*Tangle) BranchManager

func (tangle *Tangle) BranchManager() *branchmanager.BranchManager

BranchManager is the getter for the manager that takes care of creating and updating branches.

func (*Tangle) Consumers

func (tangle *Tangle) Consumers(outputID transaction.OutputID) CachedConsumers

Consumers retrieves the approvers of a payload from the object storage.

func (*Tangle) ForEachConsumers

func (tangle *Tangle) ForEachConsumers(currentTransaction *transaction.Transaction, consume func(payload *payload.CachedPayload, payloadMetadata *CachedPayloadMetadata, transaction *transaction.CachedTransaction, transactionMetadata *CachedTransactionMetadata))

ForEachConsumers iterates through the transactions that are consuming outputs of the given transactions

func (*Tangle) ForEachConsumersAndApprovers

func (tangle *Tangle) ForEachConsumersAndApprovers(currentPayload *payload.Payload, consume func(payload *payload.CachedPayload, payloadMetadata *CachedPayloadMetadata, transaction *transaction.CachedTransaction, transactionMetadata *CachedTransactionMetadata))

ForEachConsumersAndApprovers calls the passed in consumer for all payloads that either approve the given payload or that attach a transaction that spends outputs from the transaction inside the given payload.

func (*Tangle) ForeachApprovers

func (tangle *Tangle) ForeachApprovers(payloadID payload.ID, consume func(payload *payload.CachedPayload, payloadMetadata *CachedPayloadMetadata, transaction *transaction.CachedTransaction, transactionMetadata *CachedTransactionMetadata))

ForeachApprovers iterates through the approvers of a payload and calls the passed in consumer function.

func (*Tangle) Fork

func (tangle *Tangle) Fork(transactionID transaction.ID, conflictingInputs []transaction.OutputID) (forked bool, finalized bool, err error)

Fork creates a new branch from an existing transaction.

func (*Tangle) LoadSnapshot

func (tangle *Tangle) LoadSnapshot(snapshot map[transaction.ID]map[address.Address][]*balance.Balance)

LoadSnapshot creates a set of outputs in the value tangle, that are forming the genesis for future transactions.

func (*Tangle) OutputsOnAddress

func (tangle *Tangle) OutputsOnAddress(address address.Address) (result CachedOutputs)

OutputsOnAddress retrieves all the Outputs that are associated with an address.

func (*Tangle) Payload

func (tangle *Tangle) Payload(payloadID payload.ID) *payload.CachedPayload

Payload retrieves a payload from the object storage.

func (*Tangle) PayloadMetadata

func (tangle *Tangle) PayloadMetadata(payloadID payload.ID) *CachedPayloadMetadata

PayloadMetadata retrieves the metadata of a value payload from the object storage.

func (*Tangle) Prune

func (tangle *Tangle) Prune() (err error)

Prune resets the database and deletes all objects (for testing or "node resets").

func (*Tangle) SetTransactionFinalized

func (tangle *Tangle) SetTransactionFinalized(transactionID transaction.ID) (modified bool, err error)

SetTransactionFinalized modifies the finalized flag of a transaction. It updates the transactions metadata and propagates the changes to the BranchManager if the flag was updated.

func (*Tangle) SetTransactionPreferred

func (tangle *Tangle) SetTransactionPreferred(transactionID transaction.ID, preferred bool) (modified bool, err error)

SetTransactionPreferred modifies the preferred flag of a transaction. It updates the transactions metadata, propagates the changes to the branch DAG and triggers an update of the liked flags in the value tangle.

func (*Tangle) Shutdown

func (tangle *Tangle) Shutdown() *Tangle

Shutdown stops the worker pools and shuts down the object storage instances.

func (*Tangle) Transaction

func (tangle *Tangle) Transaction(transactionID transaction.ID) *transaction.CachedTransaction

Transaction loads the given transaction from the objectstorage.

func (*Tangle) TransactionMetadata

func (tangle *Tangle) TransactionMetadata(transactionID transaction.ID) *CachedTransactionMetadata

TransactionMetadata retrieves the metadata of a value payload from the object storage.

func (*Tangle) TransactionOutput

func (tangle *Tangle) TransactionOutput(outputID transaction.OutputID) *CachedOutput

TransactionOutput loads the given output from the objectstorage.

func (*Tangle) ValidateTransactionToAttach

func (tangle *Tangle) ValidateTransactionToAttach(tx *transaction.Transaction) (err error)

ValidateTransactionToAttach checks that the given transaction spends all funds from its inputs and that its the signature is valid.

func (*Tangle) ValuePayloadsConfirmed

func (tangle *Tangle) ValuePayloadsConfirmed(payloadIDs ...payload.ID) (confirmed bool)

ValuePayloadsConfirmed is checking if the Payloads referenced by the passed in IDs are all confirmed.

func (*Tangle) ValuePayloadsLiked

func (tangle *Tangle) ValuePayloadsLiked(payloadIDs ...payload.ID) (liked bool)

ValuePayloadsLiked is checking if the Payloads referenced by the passed in IDs are all liked.

type TransactionMetadata

type TransactionMetadata struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

TransactionMetadata contains the information of a Transaction, that are based on our local perception of things (i.e. if it is solid, or when we it became solid).

func NewTransactionMetadata

func NewTransactionMetadata(id transaction.ID) *TransactionMetadata

NewTransactionMetadata is the constructor for the TransactionMetadata type.

func ParseTransactionMetadata

func ParseTransactionMetadata(marshalUtil *marshalutil.MarshalUtil) (result *TransactionMetadata, err error)

ParseTransactionMetadata is a wrapper for simplified unmarshaling of TransactionMetadata objects from a byte stream using the marshalUtil package.

func TransactionMetadataFromBytes

func TransactionMetadataFromBytes(bytes []byte) (result *TransactionMetadata, consumedBytes int, err error)

TransactionMetadataFromBytes unmarshals a TransactionMetadata object from a sequence of bytes. It either creates a new object or fills the optionally provided object with the parsed information.

func (*TransactionMetadata) BranchID

func (transactionMetadata *TransactionMetadata) BranchID() branchmanager.BranchID

BranchID returns the identifier of the Branch, that this transaction is booked into.

func (*TransactionMetadata) Bytes

func (transactionMetadata *TransactionMetadata) Bytes() []byte

Bytes marshals the TransactionMetadata object into a sequence of bytes.

func (*TransactionMetadata) Confirmed

func (transactionMetadata *TransactionMetadata) Confirmed() bool

Confirmed returns true if the Transaction was marked as confirmed.

func (*TransactionMetadata) Conflicting

func (transactionMetadata *TransactionMetadata) Conflicting() bool

Conflicting returns true if the Transaction has been forked into its own Branch and there is a vote going on.

func (*TransactionMetadata) FinalizationTime

func (transactionMetadata *TransactionMetadata) FinalizationTime() time.Time

FinalizationTime returns the time when this transaction was finalized.

func (*TransactionMetadata) Finalized

func (transactionMetadata *TransactionMetadata) Finalized() bool

Finalized returns true, if the decision if this transaction is liked or not has been finalized by consensus already.

func (*TransactionMetadata) ID

func (transactionMetadata *TransactionMetadata) ID() transaction.ID

ID return the id of the Transaction that this TransactionMetadata is associated to.

func (*TransactionMetadata) Liked

func (transactionMetadata *TransactionMetadata) Liked() bool

Liked returns true if the Transaction was marked as liked.

func (*TransactionMetadata) ObjectStorageKey

func (transactionMetadata *TransactionMetadata) ObjectStorageKey() []byte

ObjectStorageKey returns the key that is used to identify the TransactionMetadata in the objectstorage.

func (*TransactionMetadata) ObjectStorageValue

func (transactionMetadata *TransactionMetadata) ObjectStorageValue() []byte

ObjectStorageValue marshals the TransactionMetadata object into a sequence of bytes and matches the encoding.BinaryMarshaler interface.

func (*TransactionMetadata) Preferred

func (transactionMetadata *TransactionMetadata) Preferred() (result bool)

Preferred returns true if the transaction is considered to be the first valid spender of all of its Inputs.

func (*TransactionMetadata) Rejected

func (transactionMetadata *TransactionMetadata) Rejected() bool

Rejected returns true if the Transaction was marked as confirmed.

func (*TransactionMetadata) Solid

func (transactionMetadata *TransactionMetadata) Solid() (result bool)

Solid returns true if the Transaction has been marked as solid.

func (*TransactionMetadata) SolidificationTime

func (transactionMetadata *TransactionMetadata) SolidificationTime() time.Time

SolidificationTime returns the time when the Transaction was marked to be solid.

func (*TransactionMetadata) String

func (transactionMetadata *TransactionMetadata) String() string

String creates a human readable version of the metadata (for debug purposes).

func (*TransactionMetadata) Update

func (transactionMetadata *TransactionMetadata) Update(other objectstorage.StorableObject)

Update is disabled and panics if it ever gets called - updates are supposed to happen through the setters.

type ValueObjectFactory

type ValueObjectFactory struct {
	Events *ValueObjectFactoryEvents
	// contains filtered or unexported fields
}

ValueObjectFactory acts as a factory to create new value objects.

func NewValueObjectFactory

func NewValueObjectFactory(tangle *Tangle, tipManager *tipmanager.TipManager) *ValueObjectFactory

NewValueObjectFactory creates a new ValueObjectFactory.

func (*ValueObjectFactory) IssueTransaction

func (v *ValueObjectFactory) IssueTransaction(tx *transaction.Transaction) (valueObject *payload.Payload, err error)

IssueTransaction creates a new value object including tip selection and returns it. It also triggers the ValueObjectConstructed event once it's done.

type ValueObjectFactoryEvents

type ValueObjectFactoryEvents struct {
	// Fired when a value object is built including tips.
	ValueObjectConstructed *events.Event
}

ValueObjectFactoryEvents represent events happening on a ValueObjectFactory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL