Documentation
¶
Overview ¶
Package dag is a generated GoMock package.
Package dag is a generated GoMock package.
Index ¶
- Constants
- Variables
- func CreateDAG(t *testing.T) *dag
- func ValidatePayloadType(payloadType string) bool
- type Addressable
- type DotGraphVisitor
- type EncryptedPAL
- type Event
- type EventFatal
- type LabelStyle
- type MockNotifier
- func (m *MockNotifier) Close() error
- func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder
- func (m *MockNotifier) Finished(arg0 hash.SHA256Hash) error
- func (m *MockNotifier) GetFailedEvents() ([]Event, error)
- func (m *MockNotifier) Name() string
- func (m *MockNotifier) Notify(event Event)
- func (m *MockNotifier) Run() error
- func (m *MockNotifier) Save(tx stoabs.WriteTx, event Event) error
- type MockNotifierMockRecorder
- func (mr *MockNotifierMockRecorder) Close() *gomock.Call
- func (mr *MockNotifierMockRecorder) Finished(arg0 any) *gomock.Call
- func (mr *MockNotifierMockRecorder) GetFailedEvents() *gomock.Call
- func (mr *MockNotifierMockRecorder) Name() *gomock.Call
- func (mr *MockNotifierMockRecorder) Notify(event any) *gomock.Call
- func (mr *MockNotifierMockRecorder) Run() *gomock.Call
- func (mr *MockNotifierMockRecorder) Save(tx, event any) *gomock.Call
- type MockPayloadStore
- type MockPayloadStoreMockRecorder
- type MockState
- func (m *MockState) Add(ctx context.Context, transactions Transaction, payload []byte) error
- func (m *MockState) Configure(config core.ServerConfig) error
- func (m *MockState) CorrectStateDetected()
- func (m *MockState) Diagnostics() []core.DiagnosticResult
- func (m *MockState) EXPECT() *MockStateMockRecorder
- func (m *MockState) FindBetweenLC(ctx context.Context, startInclusive, endExclusive uint32) ([]Transaction, error)
- func (m *MockState) GetTransaction(ctx context.Context, arg1 hash.SHA256Hash) (Transaction, error)
- func (m *MockState) Head(ctx context.Context) (hash.SHA256Hash, error)
- func (m *MockState) IBLT(reqClock uint32) (tree.Iblt, uint32)
- func (m *MockState) IncorrectStateDetected()
- func (m *MockState) IsPayloadPresent(ctx context.Context, payloadHash hash.SHA256Hash) (bool, error)
- func (m *MockState) IsPresent(arg0 context.Context, arg1 hash.SHA256Hash) (bool, error)
- func (m *MockState) Migrate() error
- func (m *MockState) Notifier(name string, receiver ReceiverFn, filters ...NotifierOption) (Notifier, error)
- func (m *MockState) Notifiers() []Notifier
- func (m *MockState) ReadPayload(ctx context.Context, payloadHash hash.SHA256Hash) ([]byte, error)
- func (m *MockState) Shutdown() error
- func (m *MockState) Start() error
- func (m *MockState) Verify(ctx context.Context) error
- func (m *MockState) WritePayload(ctx context.Context, transaction Transaction, payloadHash hash.SHA256Hash, ...) error
- func (m *MockState) XOR(reqClock uint32) (hash.SHA256Hash, uint32)
- type MockStateMockRecorder
- func (mr *MockStateMockRecorder) Add(ctx, transactions, payload any) *gomock.Call
- func (mr *MockStateMockRecorder) Configure(config any) *gomock.Call
- func (mr *MockStateMockRecorder) CorrectStateDetected() *gomock.Call
- func (mr *MockStateMockRecorder) Diagnostics() *gomock.Call
- func (mr *MockStateMockRecorder) FindBetweenLC(ctx, startInclusive, endExclusive any) *gomock.Call
- func (mr *MockStateMockRecorder) GetTransaction(ctx, arg1 any) *gomock.Call
- func (mr *MockStateMockRecorder) Head(ctx any) *gomock.Call
- func (mr *MockStateMockRecorder) IBLT(reqClock any) *gomock.Call
- func (mr *MockStateMockRecorder) IncorrectStateDetected() *gomock.Call
- func (mr *MockStateMockRecorder) IsPayloadPresent(ctx, payloadHash any) *gomock.Call
- func (mr *MockStateMockRecorder) IsPresent(arg0, arg1 any) *gomock.Call
- func (mr *MockStateMockRecorder) Migrate() *gomock.Call
- func (mr *MockStateMockRecorder) Notifier(name, receiver any, filters ...any) *gomock.Call
- func (mr *MockStateMockRecorder) Notifiers() *gomock.Call
- func (mr *MockStateMockRecorder) ReadPayload(ctx, payloadHash any) *gomock.Call
- func (mr *MockStateMockRecorder) Shutdown() *gomock.Call
- func (mr *MockStateMockRecorder) Start() *gomock.Call
- func (mr *MockStateMockRecorder) Verify(ctx any) *gomock.Call
- func (mr *MockStateMockRecorder) WritePayload(ctx, transaction, payloadHash, data any) *gomock.Call
- func (mr *MockStateMockRecorder) XOR(reqClock any) *gomock.Call
- type NetworkHeader
- type NotificationFilter
- type Notifier
- type NotifierOption
- type PAL
- type PayloadReferencer
- type PayloadStore
- type ReceiverFn
- type Referencable
- type Signable
- type SourceTXKeyResolver
- type State
- type Statistics
- type Transaction
- func CreateSignedTestTransaction(payloadNum uint32, signingTime time.Time, pal [][]byte, payloadType string, ...) Transaction
- func CreateTestTransaction(num uint32, prevs ...Transaction) (Transaction, string, crypto.PublicKey)
- func CreateTestTransactionEx(num uint32, payloadHash hash.SHA256Hash, participants EncryptedPAL, ...) (Transaction, string, crypto.PublicKey)
- func CreateTestTransactionWithJWK(num uint32, prevs ...Transaction) Transaction
- func ParseTransaction(input []byte) (Transaction, error)
- type TransactionSigner
- type UnsignedTransaction
- type Verifier
- type Version
- type Visitor
Constants ¶
const ( // TransactionEventType is used as Type in an Event when a transaction is added to the DAG. TransactionEventType = "transaction" // PayloadEventType is used as Type in an Event when a payload is written to the DB. PayloadEventType = "payload" )
const ( // PageSize specifies the Lamport Clock range over which data is summarized and is used in set reconciliation. PageSize = uint32(512) // IbltNumBuckets is the number of buckets in the IBLT used in set reconciliation. IbltNumBuckets = 1024 )
const MaxLamportClock = math.MaxUint32
MaxLamportClock is the highest Lamport Clock value a transaction on the DAG can have.
const TransactionCountDiagnostic = "transaction_count"
TransactionCountDiagnostic is the name of the diagnostics result for the transaction count
Variables ¶
var ErrInvalidLamportClockValue = errors.New("transaction has an invalid lamport clock value")
ErrInvalidLamportClockValue indicates the lamport clock value for the transaction is wrong.
var ErrPayloadNotFound = errors.New("payload not found")
ErrPayloadNotFound is returned when the requested payload is not found
var ErrPreviousTransactionMissing = errors.New("transaction is referring to non-existing previous transaction")
ErrPreviousTransactionMissing indicates one or more of the previous transactions (which the transaction refers to) is missing.
var ErrTransactionNotFound = errors.New("transaction not found")
ErrTransactionNotFound is returned when a requested transaction is not found on the DAG
Functions ¶
func ValidatePayloadType ¶
ValidatePayloadType checks whether the payload type is valid according to RFC004.
Types ¶
type Addressable ¶
type Addressable interface {
// PAL contains the encrypted addresses of the participants
PAL() [][]byte
}
Addressable contains the Pal function which allows returning the addresses of the recipients
type DotGraphVisitor ¶
type DotGraphVisitor struct {
// contains filtered or unexported fields
}
DotGraphVisitor is a graph visitor that outputs the walked path as "dot" diagram. The is currently unused, but can be used to debug the DAG to see how transactions relate to each other. The output can be viewed using a DOT plugin or when rendering the DOT file to SVG/PNG, etc.
func NewDotGraphVisitor ¶
func NewDotGraphVisitor(labelStyle LabelStyle) *DotGraphVisitor
NewDotGraphVisitor creates a new DotGraphVisitor
func (*DotGraphVisitor) Accept ¶
func (d *DotGraphVisitor) Accept(transaction Transaction) bool
Accept adds a transaction to the dot graph. Should be called by the DAG walker.
func (*DotGraphVisitor) Render ¶
func (d *DotGraphVisitor) Render() string
Render returns the walked DAG visualized as dot graph.
type EncryptedPAL ¶
type EncryptedPAL [][]byte
EncryptedPAL holds the list of participants of a transaction, but encrypted. It can be decrypted into a PAL.
func (EncryptedPAL) Decrypt ¶
func (epal EncryptedPAL) Decrypt(ctx context.Context, keyAgreementKIDs []string, decryptor crypto.Decrypter) (PAL, error)
Decrypt decrypts the given encrypted PAL header, yielding the decoded transaction participant DIDs. It attempts to decrypt the PAL header with the given keyAgreement keys, specified by key ID. If the header can't be decrypted with any of the given keys, nil (without an error) is returned. - If the header can be decrypted with (one of) the given keys, the DIDs are decoded and returned. An error is returned in the following cases: - If one of the attempted keyAgreement keys is not found or of an unsupported type, an error is returned. - If one of the decrypted participants isn't a valid DID.
type Event ¶
type Event struct {
// Type of event, can be used to filter
Type string `json:"type,omitempty"`
// Hash is the ID of the Event, usually the same as the dag.Transaction.Ref()
Hash hash.SHA256Hash `json:"Hash"`
// Retries is the current number of retries
Retries int `json:"retries"`
// Latest records the timestamp of the last notification attempt. It is not used in the backoff calculation.
Latest *time.Time `json:"latest,omitempty"`
// Transaction that was added to the DAG or for which the Payload was written. Mandatory.
Transaction Transaction `json:"transaction"`
// Payload that was written to the PayloadStore, optional (private TXs).
Payload []byte `json:"payload,omitempty"`
// Error contains the error of the last try if any.
Error string `json:"error,omitempty"`
}
Event is the metadata that is stored for a notifier specific event The Hash is used as identifier for the Event.
func (*Event) UnmarshalJSON ¶
type EventFatal ¶
type EventFatal struct {
Err error
}
EventFatal signals that an Event receiver encountered a fatal error and that the Event should not be retried.
func (EventFatal) Error ¶
func (e EventFatal) Error() string
func (EventFatal) Unwrap ¶
func (e EventFatal) Unwrap() error
type LabelStyle ¶
type LabelStyle int
LabelStyle defines node label styles for DotGraphVisitor.
const ( // ShowAliasLabelStyle is a style that uses integer aliases for node labels. ShowAliasLabelStyle LabelStyle = iota // ShowRefLabelStyle is a style that uses the references of nodes as label. ShowRefLabelStyle LabelStyle = iota // ShowShortRefLabelStyle is a style that uses a shorter version of the references of nodes as label. ShowShortRefLabelStyle LabelStyle = iota )
type MockNotifier ¶
type MockNotifier struct {
// contains filtered or unexported fields
}
MockNotifier is a mock of Notifier interface.
func NewMockNotifier ¶
func NewMockNotifier(ctrl *gomock.Controller) *MockNotifier
NewMockNotifier creates a new mock instance.
func (*MockNotifier) EXPECT ¶
func (m *MockNotifier) EXPECT() *MockNotifierMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockNotifier) Finished ¶
func (m *MockNotifier) Finished(arg0 hash.SHA256Hash) error
Finished mocks base method.
func (*MockNotifier) GetFailedEvents ¶
func (m *MockNotifier) GetFailedEvents() ([]Event, error)
GetFailedEvents mocks base method.
type MockNotifierMockRecorder ¶
type MockNotifierMockRecorder struct {
// contains filtered or unexported fields
}
MockNotifierMockRecorder is the mock recorder for MockNotifier.
func (*MockNotifierMockRecorder) Close ¶
func (mr *MockNotifierMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close.
func (*MockNotifierMockRecorder) Finished ¶
func (mr *MockNotifierMockRecorder) Finished(arg0 any) *gomock.Call
Finished indicates an expected call of Finished.
func (*MockNotifierMockRecorder) GetFailedEvents ¶
func (mr *MockNotifierMockRecorder) GetFailedEvents() *gomock.Call
GetFailedEvents indicates an expected call of GetFailedEvents.
func (*MockNotifierMockRecorder) Name ¶
func (mr *MockNotifierMockRecorder) Name() *gomock.Call
Name indicates an expected call of Name.
func (*MockNotifierMockRecorder) Notify ¶
func (mr *MockNotifierMockRecorder) Notify(event any) *gomock.Call
Notify indicates an expected call of Notify.
func (*MockNotifierMockRecorder) Run ¶
func (mr *MockNotifierMockRecorder) Run() *gomock.Call
Run indicates an expected call of Run.
type MockPayloadStore ¶
type MockPayloadStore struct {
// contains filtered or unexported fields
}
MockPayloadStore is a mock of PayloadStore interface.
func NewMockPayloadStore ¶
func NewMockPayloadStore(ctrl *gomock.Controller) *MockPayloadStore
NewMockPayloadStore creates a new mock instance.
func (*MockPayloadStore) EXPECT ¶
func (m *MockPayloadStore) EXPECT() *MockPayloadStoreMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockPayloadStoreMockRecorder ¶
type MockPayloadStoreMockRecorder struct {
// contains filtered or unexported fields
}
MockPayloadStoreMockRecorder is the mock recorder for MockPayloadStore.
type MockState ¶
type MockState struct {
// contains filtered or unexported fields
}
MockState is a mock of State interface.
func NewMockState ¶
func NewMockState(ctrl *gomock.Controller) *MockState
NewMockState creates a new mock instance.
func (*MockState) Configure ¶
func (m *MockState) Configure(config core.ServerConfig) error
Configure mocks base method.
func (*MockState) CorrectStateDetected ¶
func (m *MockState) CorrectStateDetected()
CorrectStateDetected mocks base method.
func (*MockState) Diagnostics ¶
func (m *MockState) Diagnostics() []core.DiagnosticResult
Diagnostics mocks base method.
func (*MockState) EXPECT ¶
func (m *MockState) EXPECT() *MockStateMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockState) FindBetweenLC ¶
func (m *MockState) FindBetweenLC(ctx context.Context, startInclusive, endExclusive uint32) ([]Transaction, error)
FindBetweenLC mocks base method.
func (*MockState) GetTransaction ¶
func (m *MockState) GetTransaction(ctx context.Context, arg1 hash.SHA256Hash) (Transaction, error)
GetTransaction mocks base method.
func (*MockState) IncorrectStateDetected ¶
func (m *MockState) IncorrectStateDetected()
IncorrectStateDetected mocks base method.
func (*MockState) IsPayloadPresent ¶
func (m *MockState) IsPayloadPresent(ctx context.Context, payloadHash hash.SHA256Hash) (bool, error)
IsPayloadPresent mocks base method.
func (*MockState) Notifier ¶
func (m *MockState) Notifier(name string, receiver ReceiverFn, filters ...NotifierOption) (Notifier, error)
Notifier mocks base method.
func (*MockState) ReadPayload ¶
ReadPayload mocks base method.
func (*MockState) WritePayload ¶
func (m *MockState) WritePayload(ctx context.Context, transaction Transaction, payloadHash hash.SHA256Hash, data []byte) error
WritePayload mocks base method.
type MockStateMockRecorder ¶
type MockStateMockRecorder struct {
// contains filtered or unexported fields
}
MockStateMockRecorder is the mock recorder for MockState.
func (*MockStateMockRecorder) Add ¶
func (mr *MockStateMockRecorder) Add(ctx, transactions, payload any) *gomock.Call
Add indicates an expected call of Add.
func (*MockStateMockRecorder) Configure ¶
func (mr *MockStateMockRecorder) Configure(config any) *gomock.Call
Configure indicates an expected call of Configure.
func (*MockStateMockRecorder) CorrectStateDetected ¶
func (mr *MockStateMockRecorder) CorrectStateDetected() *gomock.Call
CorrectStateDetected indicates an expected call of CorrectStateDetected.
func (*MockStateMockRecorder) Diagnostics ¶
func (mr *MockStateMockRecorder) Diagnostics() *gomock.Call
Diagnostics indicates an expected call of Diagnostics.
func (*MockStateMockRecorder) FindBetweenLC ¶
func (mr *MockStateMockRecorder) FindBetweenLC(ctx, startInclusive, endExclusive any) *gomock.Call
FindBetweenLC indicates an expected call of FindBetweenLC.
func (*MockStateMockRecorder) GetTransaction ¶
func (mr *MockStateMockRecorder) GetTransaction(ctx, arg1 any) *gomock.Call
GetTransaction indicates an expected call of GetTransaction.
func (*MockStateMockRecorder) Head ¶
func (mr *MockStateMockRecorder) Head(ctx any) *gomock.Call
Head indicates an expected call of Head.
func (*MockStateMockRecorder) IBLT ¶
func (mr *MockStateMockRecorder) IBLT(reqClock any) *gomock.Call
IBLT indicates an expected call of IBLT.
func (*MockStateMockRecorder) IncorrectStateDetected ¶
func (mr *MockStateMockRecorder) IncorrectStateDetected() *gomock.Call
IncorrectStateDetected indicates an expected call of IncorrectStateDetected.
func (*MockStateMockRecorder) IsPayloadPresent ¶
func (mr *MockStateMockRecorder) IsPayloadPresent(ctx, payloadHash any) *gomock.Call
IsPayloadPresent indicates an expected call of IsPayloadPresent.
func (*MockStateMockRecorder) IsPresent ¶
func (mr *MockStateMockRecorder) IsPresent(arg0, arg1 any) *gomock.Call
IsPresent indicates an expected call of IsPresent.
func (*MockStateMockRecorder) Migrate ¶
func (mr *MockStateMockRecorder) Migrate() *gomock.Call
Migrate indicates an expected call of Migrate.
func (*MockStateMockRecorder) Notifier ¶
func (mr *MockStateMockRecorder) Notifier(name, receiver any, filters ...any) *gomock.Call
Notifier indicates an expected call of Notifier.
func (*MockStateMockRecorder) Notifiers ¶
func (mr *MockStateMockRecorder) Notifiers() *gomock.Call
Notifiers indicates an expected call of Notifiers.
func (*MockStateMockRecorder) ReadPayload ¶
func (mr *MockStateMockRecorder) ReadPayload(ctx, payloadHash any) *gomock.Call
ReadPayload indicates an expected call of ReadPayload.
func (*MockStateMockRecorder) Shutdown ¶
func (mr *MockStateMockRecorder) Shutdown() *gomock.Call
Shutdown indicates an expected call of Shutdown.
func (*MockStateMockRecorder) Start ¶
func (mr *MockStateMockRecorder) Start() *gomock.Call
Start indicates an expected call of Start.
func (*MockStateMockRecorder) Verify ¶
func (mr *MockStateMockRecorder) Verify(ctx any) *gomock.Call
Verify indicates an expected call of Verify.
func (*MockStateMockRecorder) WritePayload ¶
func (mr *MockStateMockRecorder) WritePayload(ctx, transaction, payloadHash, data any) *gomock.Call
WritePayload indicates an expected call of WritePayload.
type NetworkHeader ¶
type NetworkHeader interface {
// Previous returns the references of the previous transactions this transaction points to.
Previous() []hash.SHA256Hash
// Version returns the version number of the distributed transaction format.
Version() Version
}
NetworkHeader groups methods for working with a transaction header.
type NotificationFilter ¶
NotificationFilter can be added to a notifier to filter out any unwanted events Returns true if the filter applies and the Event is to be received
type Notifier ¶
type Notifier interface {
// Name returns the name of the notifier
Name() string
// Save an event that needs to be retried even after a crash.
// It will not yet be sent, use Notify to notify the receiver.
// The event may be ignored due to configured filters.
// Returns nil if event already exists.
// An error is returned if there's a problem with the underlying storage.
Save(tx stoabs.WriteTx, event Event) error
// Notify the receiver, if an error occurs it'll be retried later.
// This does not store the event in the DB, use Save for that.
Notify(event Event)
// Finished marks the job as finished and removes it from the scheduler
// An error is returned if there's a problem with the underlying storage.
Finished(hash hash.SHA256Hash) error
// Run retries all existing events.
Run() error
// GetFailedEvents retrieves the hashes of failed events.
// If the notifier is not persistent it'll always return 0.
GetFailedEvents() ([]Event, error)
// Close cancels all running events. It does not remove them from the DB
Close() error
}
Notifier defines methods for a persistent retry mechanism. Storing the event in the DB is separated from notifying the subscribers. The event is sent to subscribers after the transaction is committed to prevent timing issues.
func NewNotifier ¶
func NewNotifier(name string, receiverFn ReceiverFn, options ...NotifierOption) Notifier
NewNotifier returns a Notifier that handles transaction events with the given function. Various settings can be changed via a NotifierOption A default retry delay of 10 seconds is used.
type NotifierOption ¶
type NotifierOption func(notifier *notifier)
NotifierOption sets an option on a notifier
func WithContext ¶
func WithContext(ctx context.Context) NotifierOption
WithContext adds the given context as parent context.
func WithPersistency ¶
func WithPersistency(db stoabs.KVStore) NotifierOption
WithPersistency sets the DB to be used for persisting the events. Without persistency, the event is lost between restarts.
func WithRetryDelay ¶
func WithRetryDelay(delay time.Duration) NotifierOption
WithRetryDelay sets a custom delay for the notifier. Between each execution the delay is doubled.
func WithSelectionFilter ¶
func WithSelectionFilter(filter NotificationFilter) NotifierOption
WithSelectionFilter adds a filter to the notifier. Any unwanted events can be filtered out.
type PAL ¶
PAL holds the list of participants of a transaction.
func (PAL) Encrypt ¶
func (pal PAL) Encrypt(keyResolver resolver.KeyResolver) (EncryptedPAL, error)
Encrypt encodes and encrypts the given participant DIDs. It uses the given types.KeyResolver to look up the public encryption key for each participant, and then encrypts the PAL header using each.
type PayloadReferencer ¶
type PayloadReferencer interface {
// PayloadHash returns the hash of the payload of the transaction.
PayloadHash() hash.SHA256Hash
// PayloadType returns the MIME-formatted type of the payload. It must contain the context and specific type of the
// payload, e.g. 'registry/endpoint'.
PayloadType() string
}
PayloadReferencer allows implementers to reference to a payload. It provides an uniform interface to payload properties such as the type and the hash.
type PayloadStore ¶
type PayloadStore interface {
// contains filtered or unexported methods
}
PayloadStore defines the interface for types that store and read transaction payloads.
func NewPayloadStore ¶
func NewPayloadStore() PayloadStore
NewPayloadStore creates a new payload store.
type ReceiverFn ¶
ReceiverFn is the function type that needs to be registered for a notifier Returns true if event is received and done, false otherwise The Notifier's retry mechanism is aborted when this function's error is wrapped by EventFatal
type Referencable ¶
type Referencable interface {
// Ref returns a unique sha256 hash of the implementing object.
Ref() hash.SHA256Hash
}
Referencable contains the Ref function which allows implementors to return a unique reference
type Signable ¶
type Signable interface {
// SigningKey returns the key that was used to sign the transaction as JWK.
// If this field is not set SigningKeyID must be used to resolve the signing key.
SigningKey() jwk.Key
// SigningKeyID returns the ID of the key that was used to sign the transaction. It can be used to look up the key.
SigningKeyID() string
// SigningTime returns the time that the transaction was signed.
SigningTime() time.Time
// SigningAlgorithm returns the name of the JOSE signing algorithm that was used to sign the transaction.
SigningAlgorithm() string
}
Signable groups a set of functions to access information about a implementors signature.
type SourceTXKeyResolver ¶
type SourceTXKeyResolver struct {
Resolver resolver.DIDResolver
}
SourceTXKeyResolver implements the SourceTXKeyResolver interface.
func (SourceTXKeyResolver) ResolvePublicKey ¶
func (r SourceTXKeyResolver) ResolvePublicKey(kid string, sourceTransactionsRefs []hash.SHA256Hash) (crypto.PublicKey, error)
type State ¶
type State interface {
core.Diagnosable
core.Migratable
core.Configurable
// WritePayload writes contents for the specified payload, identified by the given hash.
// It also calls observers and therefore requires the transaction.
WritePayload(ctx context.Context, transaction Transaction, payloadHash hash.SHA256Hash, data []byte) error
// IsPayloadPresent checks whether the contents for the given transaction are present.
IsPayloadPresent(ctx context.Context, payloadHash hash.SHA256Hash) (bool, error)
// ReadPayload reads the contents for the specified payload, identified by the given hash. If contents can't be found,
// ErrPayloadNotFound is returned. If something (else) goes wrong an error is returned.
ReadPayload(ctx context.Context, payloadHash hash.SHA256Hash) ([]byte, error)
// Add a transaction to the DAG. If it can't be added an error is returned.
// If the transaction already exists, nothing is added and no observers are notified.
// The payload may be passed as well. Allowing for better notification of observers
Add(ctx context.Context, transactions Transaction, payload []byte) error
// FindBetweenLC finds all transactions which lamport clock value lies between startInclusive and endExclusive.
// They are returned in order: first sorted on lamport clock value, then on transaction reference (byte order).
FindBetweenLC(ctx context.Context, startInclusive uint32, endExclusive uint32) ([]Transaction, error)
// GetTransaction returns the transaction from local storage.
// If contents can't be found, ErrTransactionNotFound is returned.
GetTransaction(ctx context.Context, hash hash.SHA256Hash) (Transaction, error)
// IsPresent returns true if a transaction is present in the DAG
IsPresent(context.Context, hash.SHA256Hash) (bool, error)
// Notifier creates a new Notifier.
// It lets another part of the application receive events on new transactions. When a new transaction is received
// the `receiver` function is called. Notifiers can be persistent and will survive restarts.
// The name is used to keep different notifiers apart.
// Filters can be used to receive specific transactions. Filters are added via the WithSelectionFilter() option.
// A Notifier should only be created during `configuration` step since the `start` step will redeliver all events that have not been delivered yet.
// Returns an error when the Notifier already exists
Notifier(name string, receiver ReceiverFn, filters ...NotifierOption) (Notifier, error)
// Notifiers returns all registered notifiers
Notifiers() []Notifier
// Head returns the reference to a transactions that has not been referenced in the prevs of other transactions.
// Returns hash.EmptyHash when no head is stored.
Head(ctx context.Context) (hash.SHA256Hash, error)
// Shutdown the DB
Shutdown() error
// Start the publisher and verifier
Start() error
// Verify checks the integrity of the DAG. Should be called when it's loaded, e.g. from disk.
Verify(ctx context.Context) error
// XOR returns the xor of all transaction references between the DAG root and the clock closest to the requested clock value.
// This closest clock value is also returned, and is defined as the lowest of:
// - upper-limit of the page that contains the requested clock
// - highest lamport clock in the DAG
// A requested clock of math.MaxUint32 will return the xor of the entire DAG
XOR(reqClock uint32) (hash.SHA256Hash, uint32)
// IBLT returns the iblt of all transaction references between the DAG root and the clock closest to the requested clock value.
// This closest clock value is also returned, and is defined as the lowest of:
// - upper-limit of the page that contains the requested clock
// - highest lamport clock in the DAG
// A requested clock of math.MaxUint32 will return the iblt of the entire DAG
IBLT(reqClock uint32) (tree.Iblt, uint32)
// IncorrectStateDetected is called when the xor and LC value from a gossip message do NOT match the local state.
IncorrectStateDetected()
// CorrectStateDetected is called when the xor and LC value from a gossip message match the local state.
CorrectStateDetected()
}
State represents the Node transactional state. Mutations are done via this abstraction layer. Notifications are also done via this layer
type Statistics ¶
type Statistics struct {
// NumberOfTransactions contains the number of transactions on the DAG
NumberOfTransactions uint
// DataSize contains the size of the DAG in bytes
DataSize int64
}
Statistics holds data about the current state of the DAG.
type Transaction ¶
type Transaction interface {
UnsignedTransaction
Signable
Referencable
Addressable
json.Marshaler
// Data returns the byte representation of this transaction which can be used for transport.
Data() []byte
}
Transaction defines a signed distributed transaction as described by RFC004 - Distributed Transaction Format.
func CreateSignedTestTransaction ¶
func CreateSignedTestTransaction(payloadNum uint32, signingTime time.Time, pal [][]byte, payloadType string, attach bool, prevs ...Transaction) Transaction
CreateSignedTestTransaction creates a signed transaction with more control
func CreateTestTransaction ¶
func CreateTestTransaction(num uint32, prevs ...Transaction) (Transaction, string, crypto.PublicKey)
CreateTestTransaction creates a transaction with the given num as payload hash and signs it with a random EC key.
func CreateTestTransactionEx ¶
func CreateTestTransactionEx(num uint32, payloadHash hash.SHA256Hash, participants EncryptedPAL, prevs ...Transaction) (Transaction, string, crypto.PublicKey)
CreateTestTransactionEx creates a transaction with the given payload hash and signs it with a random EC key.
func CreateTestTransactionWithJWK ¶
func CreateTestTransactionWithJWK(num uint32, prevs ...Transaction) Transaction
CreateTestTransactionWithJWK creates a transaction with the given num as payload hash and signs it with a random EC key. The JWK is attached, rather than referred to using the kid.
func ParseTransaction ¶
func ParseTransaction(input []byte) (Transaction, error)
ParseTransaction parses the input as Nuts Network Transaction according to RFC004.
type TransactionSigner ¶
type TransactionSigner interface {
// Sign signs the unsigned transaction, including the signingTime parameter as header.
Sign(ctx context.Context, input UnsignedTransaction, signingTime time.Time) (Transaction, error)
}
TransactionSigner defines functions to sign transactions.
func NewTransactionSigner ¶
func NewTransactionSigner(signer nutsCrypto.JWTSigner, kid string, key crypto.PublicKey) TransactionSigner
NewTransactionSigner creates a TransactionSigner that signs the transaction using the given key. The public key is included in the signed transaction when given. If not, the `kid` header is added which refers to the ID of the used key.
type UnsignedTransaction ¶
type UnsignedTransaction interface {
NetworkHeader
Addressable
PayloadReferencer
// Clock returns the Lamport clock value
Clock() uint32
}
UnsignedTransaction holds the base properties of a transaction which can be signed to create a Transaction.
func NewTransaction ¶
func NewTransaction(payload hash.SHA256Hash, payloadType string, prevs []hash.SHA256Hash, pal EncryptedPAL, lamportClock uint32) (UnsignedTransaction, error)
NewTransaction creates a new unsigned transaction. Parameters payload and payloadType can't be empty, but prevs is optional. Prevs must not contain empty or invalid hashes. Duplicate prevs will be removed when given. The pal byte slice (may be nil) holds the encrypted recipient address, if it is a private transaction.
type Verifier ¶
type Verifier func(tx stoabs.ReadTx, transaction Transaction) error
Verifier defines the API of a DAG verifier, used to check the validity of a transaction.
func NewPrevTransactionsVerifier ¶
func NewPrevTransactionsVerifier() Verifier
NewPrevTransactionsVerifier creates a transaction verifier that asserts that all previous transactions are known. It also checks if the lamportClock value is correct (if given).
func NewTransactionSignatureVerifier ¶
func NewTransactionSignatureVerifier(resolver resolver.NutsKeyResolver) Verifier
NewTransactionSignatureVerifier creates a transaction verifier that checks the signature of the transaction. It uses the given KeyResolver to resolves keys that aren't embedded in the transaction.
type Visitor ¶
type Visitor func(transaction Transaction) bool
Visitor defines the contract for a function that visits the DAG. If the function returns `false` it stops walking the DAG.