dag

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: GPL-3.0 Imports: 34 Imported by: 1

Documentation

Overview

Package dag is a generated GoMock package.

Index

Constants

View Source
const AnyPayloadType = "*"

AnyPayloadType is a wildcard that matches with any payload type.

Variables

View Source
var ErrInvalidLamportClockValue = errors.New("transaction has an invalid lamport clock value")

ErrInvalidLamportClockValue indicates the lamport clock value for the transaction is wrong.

View Source
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.

Functions

func CreateDAG

func CreateDAG(t *testing.T) *bboltDAG

func MaxTime

func MaxTime() time.Time

MaxTime returns the maximum value for time.Time. Taken from https://stackoverflow.com/questions/25065055/what-is-the-maximum-time-time-in-go

func MinTime

func MinTime() time.Time

MinTime returns the minimum value for time.Time

func ValidatePayloadType

func ValidatePayloadType(payloadType string) bool

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(_ context.Context, 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(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 EventType

type EventType string

EventType defines a type for specifying the kind of events that can be published/subscribed on the Publisher.

const (
	// TransactionAddedEvent is called when a transaction is added to the DAG. Its payload may not be present.
	TransactionAddedEvent EventType = "TRANSACTION_ADDED"
	// TransactionPayloadAddedEvent is called when a transaction is added to the DAG including its payload.
	TransactionPayloadAddedEvent EventType = "TRANSACTION_PAYLOAD_ADDED"
)

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 MockPayloadReader

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

MockPayloadReader is a mock of PayloadReader interface.

func NewMockPayloadReader

func NewMockPayloadReader(ctrl *gomock.Controller) *MockPayloadReader

NewMockPayloadReader creates a new mock instance.

func (*MockPayloadReader) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPayloadReader) IsPayloadPresent

func (m *MockPayloadReader) IsPayloadPresent(ctx context.Context, payloadHash hash.SHA256Hash) (bool, error)

IsPayloadPresent mocks base method.

func (*MockPayloadReader) ReadPayload

func (m *MockPayloadReader) ReadPayload(ctx context.Context, payloadHash hash.SHA256Hash) ([]byte, error)

ReadPayload mocks base method.

type MockPayloadReaderMockRecorder

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

MockPayloadReaderMockRecorder is the mock recorder for MockPayloadReader.

func (*MockPayloadReaderMockRecorder) IsPayloadPresent

func (mr *MockPayloadReaderMockRecorder) IsPayloadPresent(ctx, payloadHash interface{}) *gomock.Call

IsPayloadPresent indicates an expected call of IsPayloadPresent.

func (*MockPayloadReaderMockRecorder) ReadPayload

func (mr *MockPayloadReaderMockRecorder) ReadPayload(ctx, payloadHash interface{}) *gomock.Call

ReadPayload indicates an expected call of ReadPayload.

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

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPayloadStore) IsPayloadPresent

func (m *MockPayloadStore) IsPayloadPresent(ctx context.Context, payloadHash hash.SHA256Hash) (bool, error)

IsPayloadPresent mocks base method.

func (*MockPayloadStore) ReadManyPayloads

func (m *MockPayloadStore) ReadManyPayloads(ctx context.Context, consumer func(context.Context, PayloadReader) error) error

ReadManyPayloads mocks base method.

func (*MockPayloadStore) ReadPayload

func (m *MockPayloadStore) ReadPayload(ctx context.Context, payloadHash hash.SHA256Hash) ([]byte, error)

ReadPayload mocks base method.

func (*MockPayloadStore) WritePayload

func (m *MockPayloadStore) WritePayload(ctx context.Context, payloadHash hash.SHA256Hash, data []byte) error

WritePayload mocks base method.

type MockPayloadStoreMockRecorder

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

MockPayloadStoreMockRecorder is the mock recorder for MockPayloadStore.

func (*MockPayloadStoreMockRecorder) IsPayloadPresent

func (mr *MockPayloadStoreMockRecorder) IsPayloadPresent(ctx, payloadHash interface{}) *gomock.Call

IsPayloadPresent indicates an expected call of IsPayloadPresent.

func (*MockPayloadStoreMockRecorder) ReadManyPayloads

func (mr *MockPayloadStoreMockRecorder) ReadManyPayloads(ctx, consumer interface{}) *gomock.Call

ReadManyPayloads indicates an expected call of ReadManyPayloads.

func (*MockPayloadStoreMockRecorder) ReadPayload

func (mr *MockPayloadStoreMockRecorder) ReadPayload(ctx, payloadHash interface{}) *gomock.Call

ReadPayload indicates an expected call of ReadPayload.

func (*MockPayloadStoreMockRecorder) WritePayload

func (mr *MockPayloadStoreMockRecorder) WritePayload(ctx, payloadHash, data interface{}) *gomock.Call

WritePayload indicates an expected call of WritePayload.

type MockPayloadWriter

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

MockPayloadWriter is a mock of PayloadWriter interface.

func NewMockPayloadWriter

func NewMockPayloadWriter(ctrl *gomock.Controller) *MockPayloadWriter

NewMockPayloadWriter creates a new mock instance.

func (*MockPayloadWriter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPayloadWriter) WritePayload

func (m *MockPayloadWriter) WritePayload(ctx context.Context, payloadHash hash.SHA256Hash, data []byte) error

WritePayload mocks base method.

type MockPayloadWriterMockRecorder

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

MockPayloadWriterMockRecorder is the mock recorder for MockPayloadWriter.

func (*MockPayloadWriterMockRecorder) WritePayload

func (mr *MockPayloadWriterMockRecorder) WritePayload(ctx, payloadHash, data interface{}) *gomock.Call

WritePayload indicates an expected call of WritePayload.

type MockPublisher

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

MockPublisher is a mock of Publisher interface.

func NewMockPublisher

func NewMockPublisher(ctrl *gomock.Controller) *MockPublisher

NewMockPublisher creates a new mock instance.

func (*MockPublisher) ConfigureCallbacks

func (m *MockPublisher) ConfigureCallbacks(state State)

ConfigureCallbacks mocks base method.

func (*MockPublisher) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPublisher) Start

func (m *MockPublisher) Start() error

Start mocks base method.

func (*MockPublisher) Subscribe

func (m *MockPublisher) Subscribe(eventType EventType, payloadType string, receiver Receiver)

Subscribe mocks base method.

type MockPublisherMockRecorder

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

MockPublisherMockRecorder is the mock recorder for MockPublisher.

func (*MockPublisherMockRecorder) ConfigureCallbacks

func (mr *MockPublisherMockRecorder) ConfigureCallbacks(state interface{}) *gomock.Call

ConfigureCallbacks indicates an expected call of ConfigureCallbacks.

func (*MockPublisherMockRecorder) Start

func (mr *MockPublisherMockRecorder) Start() *gomock.Call

Start indicates an expected call of Start.

func (*MockPublisherMockRecorder) Subscribe

func (mr *MockPublisherMockRecorder) Subscribe(eventType, payloadType, receiver interface{}) *gomock.Call

Subscribe indicates an expected call of Subscribe.

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

func (m *MockState) Add(ctx context.Context, transactions Transaction, payload []byte) error

Add 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) FindBetween

func (m *MockState) FindBetween(ctx context.Context, startInclusive, endExclusive time.Time) ([]Transaction, error)

FindBetween mocks base method.

func (*MockState) GetByPayloadHash

func (m *MockState) GetByPayloadHash(ctx context.Context, payloadHash hash.SHA256Hash) ([]Transaction, error)

GetByPayloadHash mocks base method.

func (*MockState) GetTransaction

func (m *MockState) GetTransaction(ctx context.Context, hash hash.SHA256Hash) (Transaction, error)

GetTransaction mocks base method.

func (*MockState) IsPayloadPresent

func (m *MockState) IsPayloadPresent(ctx context.Context, payloadHash hash.SHA256Hash) (bool, error)

IsPayloadPresent mocks base method.

func (*MockState) IsPresent

func (m *MockState) IsPresent(arg0 context.Context, arg1 hash.SHA256Hash) (bool, error)

IsPresent mocks base method.

func (*MockState) PayloadHashes

func (m *MockState) PayloadHashes(ctx context.Context, visitor func(hash.SHA256Hash) error) error

PayloadHashes mocks base method.

func (*MockState) ReadManyPayloads

func (m *MockState) ReadManyPayloads(ctx context.Context, consumer func(context.Context, PayloadReader) error) error

ReadManyPayloads mocks base method.

func (*MockState) ReadPayload

func (m *MockState) ReadPayload(ctx context.Context, payloadHash hash.SHA256Hash) ([]byte, error)

ReadPayload mocks base method.

func (*MockState) RegisterObserver

func (m *MockState) RegisterObserver(observer Observer, transactional bool)

RegisterObserver mocks base method.

func (*MockState) Shutdown

func (m *MockState) Shutdown() error

Shutdown mocks base method.

func (*MockState) Start

func (m *MockState) Start() error

Start mocks base method.

func (*MockState) Statistics

func (m *MockState) Statistics(ctx context.Context) Statistics

Statistics mocks base method.

func (*MockState) Subscribe

func (m *MockState) Subscribe(eventType EventType, payloadType string, receiver Receiver)

Subscribe mocks base method.

func (*MockState) Verify

func (m *MockState) Verify(ctx context.Context) error

Verify mocks base method.

func (*MockState) Walk

func (m *MockState) Walk(ctx context.Context, visitor Visitor, startAt hash.SHA256Hash) error

Walk mocks base method.

func (*MockState) WritePayload

func (m *MockState) WritePayload(ctx context.Context, 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 interface{}) *gomock.Call

Add indicates an expected call of Add.

func (*MockStateMockRecorder) Diagnostics

func (mr *MockStateMockRecorder) Diagnostics() *gomock.Call

Diagnostics indicates an expected call of Diagnostics.

func (*MockStateMockRecorder) FindBetween

func (mr *MockStateMockRecorder) FindBetween(ctx, startInclusive, endExclusive interface{}) *gomock.Call

FindBetween indicates an expected call of FindBetween.

func (*MockStateMockRecorder) GetByPayloadHash

func (mr *MockStateMockRecorder) GetByPayloadHash(ctx, payloadHash interface{}) *gomock.Call

GetByPayloadHash indicates an expected call of GetByPayloadHash.

func (*MockStateMockRecorder) GetTransaction

func (mr *MockStateMockRecorder) GetTransaction(ctx, hash interface{}) *gomock.Call

GetTransaction indicates an expected call of GetTransaction.

func (*MockStateMockRecorder) IsPayloadPresent

func (mr *MockStateMockRecorder) IsPayloadPresent(ctx, payloadHash interface{}) *gomock.Call

IsPayloadPresent indicates an expected call of IsPayloadPresent.

func (*MockStateMockRecorder) IsPresent

func (mr *MockStateMockRecorder) IsPresent(arg0, arg1 interface{}) *gomock.Call

IsPresent indicates an expected call of IsPresent.

func (*MockStateMockRecorder) PayloadHashes

func (mr *MockStateMockRecorder) PayloadHashes(ctx, visitor interface{}) *gomock.Call

PayloadHashes indicates an expected call of PayloadHashes.

func (*MockStateMockRecorder) ReadManyPayloads

func (mr *MockStateMockRecorder) ReadManyPayloads(ctx, consumer interface{}) *gomock.Call

ReadManyPayloads indicates an expected call of ReadManyPayloads.

func (*MockStateMockRecorder) ReadPayload

func (mr *MockStateMockRecorder) ReadPayload(ctx, payloadHash interface{}) *gomock.Call

ReadPayload indicates an expected call of ReadPayload.

func (*MockStateMockRecorder) RegisterObserver

func (mr *MockStateMockRecorder) RegisterObserver(observer, transactional interface{}) *gomock.Call

RegisterObserver indicates an expected call of RegisterObserver.

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

func (mr *MockStateMockRecorder) Statistics(ctx interface{}) *gomock.Call

Statistics indicates an expected call of Statistics.

func (*MockStateMockRecorder) Subscribe

func (mr *MockStateMockRecorder) Subscribe(eventType, payloadType, receiver interface{}) *gomock.Call

Subscribe indicates an expected call of Subscribe.

func (*MockStateMockRecorder) Verify

func (mr *MockStateMockRecorder) Verify(ctx interface{}) *gomock.Call

Verify indicates an expected call of Verify.

func (*MockStateMockRecorder) Walk

func (mr *MockStateMockRecorder) Walk(ctx, visitor, startAt interface{}) *gomock.Call

Walk indicates an expected call of Walk.

func (*MockStateMockRecorder) WritePayload

func (mr *MockStateMockRecorder) WritePayload(ctx, payloadHash, data interface{}) *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 Observer

type Observer func(ctx context.Context, transaction Transaction, payload []byte)

Observer defines the signature of an observer which can be called by an Observable.

type PAL

type PAL []did.DID

PAL holds the list of participants of a transaction.

func (PAL) Contains

func (pal PAL) Contains(id did.DID) bool

Contains returns `true` when the given DID is in the PAL

func (PAL) Encrypt

func (pal PAL) Encrypt(keyResolver types.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 PayloadReader

type PayloadReader interface {
	// 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,
	// nil is returned. If something (else) goes wrong an error is returned.
	ReadPayload(ctx context.Context, payloadHash hash.SHA256Hash) ([]byte, error)
}

PayloadReader defines the interface for types that read transaction payloads.

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 {
	PayloadReader
	PayloadWriter
	// ReadManyPayloads allows the caller read many payloads in an optimized fashion.
	ReadManyPayloads(ctx context.Context, consumer func(context.Context, PayloadReader) error) error
}

PayloadStore defines the interface for types that store and read transaction payloads.

func NewBBoltPayloadStore

func NewBBoltPayloadStore(db *bbolt.DB) PayloadStore

NewBBoltPayloadStore creates a etcd/bbolt backed payload store using the given database.

type PayloadWriter

type PayloadWriter interface {
	// WritePayload writes contents for the specified payload, identified by the given hash. Implementations must make
	// sure the hash matches the given contents.
	WritePayload(ctx context.Context, payloadHash hash.SHA256Hash, data []byte) error
}

PayloadWriter defines the interface for types that store transaction payloads.

type Publisher

type Publisher interface {
	// ConfigureCallbacks subsribes the publisher on the state callbacks
	ConfigureCallbacks(state State)
	// Subscribe lets an application subscribe to a specific type of transaction. When a new transaction is received
	// the `receiver` function is called. If an asterisk (`*`) is specified as `payloadType` the receiver is subscribed
	// to all payload types.
	Subscribe(eventType EventType, payloadType string, receiver Receiver)
	// Start starts the publisher.
	Start() error
}

Publisher defines the interface for types that publish Nuts Network transactions.

func NewReplayingDAGPublisher

func NewReplayingDAGPublisher(payloadStore PayloadStore, dag *bboltDAG) Publisher

NewReplayingDAGPublisher creates a DAG publisher that replays the complete DAG to all subscribers when started.

type Receiver

type Receiver func(transaction Transaction, payload []byte) error

Receiver defines a function for processing transactions when walking the DAG.

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 State

type State interface {
	// PayloadStore interface for wrapping payloadStore behind TX
	PayloadStore
	core.Diagnosable

	// Add a transactions to the DAG. If it can't be added an error is returned.
	// The payload may be passed as well. Allowing for better notification of observers
	Add(ctx context.Context, transactions Transaction, payload []byte) error
	// FindBetween finds all transactions which signing time lies between startInclude and endExclusive.
	// It returns the transactions in DAG walking order.
	FindBetween(ctx context.Context, startInclusive time.Time, endExclusive time.Time) ([]Transaction, error)
	// GetByPayloadHash retrieves all transactions that refer to the specified payload.
	GetByPayloadHash(ctx context.Context, payloadHash hash.SHA256Hash) ([]Transaction, error)
	// GetTransaction returns the transaction from local storage
	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)
	// PayloadHashes applies the visitor function to the payload hashes of all transactions, in random order.
	PayloadHashes(ctx context.Context, visitor func(payloadHash hash.SHA256Hash) error) error
	// RegisterObserver allows observers to be notified when a transaction is added to the DAG.
	// If the observer needs to be called within the transaction, transactional must be true.
	RegisterObserver(observer Observer, transactional bool)
	// Subscribe lets an application subscribe to a specific type of transaction. When a new transaction is received
	// the `receiver` function is called. If an asterisk (`*`) is specified as `payloadType` the receiver is subscribed
	// to all payload types.
	Subscribe(eventType EventType, payloadType string, receiver Receiver)
	// Shutdown the DB
	Shutdown() error
	// Start the publisher and verifier
	Start() error
	// Statistics returns data for the statistics page
	Statistics(ctx context.Context) Statistics
	// Verify checks the integrity of the DAG. Should be called when it's loaded, e.g. from disk.
	Verify(ctx context.Context) error
	// Walk visits every node of the DAG, starting at the given hash working its way down each level until every leaf is visited.
	// when startAt is an empty hash, the walker starts at the root node.
	// The walker will resolve the given starting hash to a clock value.
	// The walk will be clock based so some transactions may be revisited due to existing branches.
	// Precautions must be taken to handle revisited transactions.
	Walk(ctx context.Context, visitor Visitor, startAt hash.SHA256Hash) error
}

State represents the Node transactional state. Mutations are done via this abstraction layer. Notifications are also done via this layer

func NewState

func NewState(dataDir string, verifiers ...Verifier) (State, error)

NewState returns a new State. The State is used as entry point, it's methods will start transactions and will notify observers from within those transactions.

type Statistics

type Statistics struct {
	// NumberOfTransactions contains the number of transactions on the DAG
	NumberOfTransactions int
	// DataSize contains the size of the DAG in bytes
	DataSize int
}

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 CreateLegacyTransactionWithJWK

func CreateLegacyTransactionWithJWK(num uint32, prevs ...Transaction) Transaction

CreateLegacyTransactionWithJWK 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. Deprecated: remove when V1 transactions are no longer possible

func CreateSignedLegacyTransaction

func CreateSignedLegacyTransaction(payloadNum uint32, signingTime time.Time, pal [][]byte, payloadType string, attach bool, prevs ...Transaction) Transaction

CreateSignedLegacyTransaction creates a signed transaction with more control Deprecated: remove when V1 transactions are no longer possible

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(input UnsignedTransaction, signingTime time.Time) (Transaction, error)
}

TransactionSigner defines functions to sign transactions.

func NewTransactionSigner

func NewTransactionSigner(key crypto.Key, attach bool) TransactionSigner

NewTransactionSigner creates a TransactionSigner that signs the transaction using the given key. The public key is included in the signed transaction if attach == true. If not attached, 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(ctx context.Context, tx Transaction, state State) 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 NewSigningTimeVerifier

func NewSigningTimeVerifier() Verifier

NewSigningTimeVerifier creates a transaction verifier that asserts that signing time of transactions aren't further than 1 day in the future, since that complicates head calculation.

func NewTransactionSignatureVerifier

func NewTransactionSignatureVerifier(resolver types.KeyResolver) 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 Version

type Version int

Version defines a type for distributed transaction format version.

type Visitor

type Visitor func(ctx context.Context, transaction Transaction) bool

Visitor defines the contract for a function that visits the DAG. If the function returns `false` it stops walking the DAG.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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