anchors

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AnchorIDLength is the length in bytes of the AnchorID
	AnchorIDLength = 32

	// DocumentRootLength is the length in bytes of the DocumentRoot
	DocumentRootLength = 32

	// DocumentProofLength is the length in bytes of a single proof
	DocumentProofLength = 32
)
View Source
const (
	// BootstrappedAnchorService is used as a key to map the configured anchor service through context.
	BootstrappedAnchorService string = "BootstrappedAnchorService"

	// ErrAnchorRepoNotInitialised is a sentinel error when repository is not initialised
	ErrAnchorRepoNotInitialised = errors.Error("anchor repository not initialised")
)
View Source
const (
	// PreCommit is centrifuge chain module function name for pre-commit call.
	PreCommit = "Anchor.pre_commit"

	// Commit is centrifuge chain module function name for commit call.
	Commit = "Anchor.commit"

	// GetByID is centrifuge chain module function name for getAnchorByID call
	GetByID = "anchor_getAnchorById"
)

Variables

This section is empty.

Functions

func GenerateCommitHash

func GenerateCommitHash(anchorID AnchorID, centrifugeID identity.DID, documentRoot DocumentRoot) []byte

GenerateCommitHash generates Keccak256 message from AnchorID, CentID, DocumentRoot

Types

type AnchorData added in v1.0.0

type AnchorData struct {
	AnchorID     types.Hash `json:"id"`
	DocumentRoot types.Hash `json:"doc_root"`
	BlockNumber  uint32     `json:"anchored_block"`
}

AnchorData holds data returned from previously anchored data against centchain

type AnchorID

type AnchorID [AnchorIDLength]byte

AnchorID type is byte array of length AnchorIDLength

func ToAnchorID

func ToAnchorID(bytes []byte) (AnchorID, error)

ToAnchorID convert the bytes into AnchorID type returns an error if the bytes length != AnchorIDLength

func (*AnchorID) BigInt

func (a *AnchorID) BigInt() *big.Int

BigInt returns anchorID in bigInt form

func (*AnchorID) String

func (a *AnchorID) String() string

String returns anchorID in string form

type Bootstrapper

type Bootstrapper struct{}

Bootstrapper implements bootstrapper.Bootstrapper for package requirement initialisations.

func (Bootstrapper) Bootstrap

func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error

Bootstrap initializes the anchorRepositoryContract as well as the anchorConfirmationTask that depends on it. the anchorConfirmationTask is added to be registered on the Queue at queue.Bootstrapper.

type CommitData

type CommitData struct {
	AnchorID      AnchorID
	DocumentRoot  DocumentRoot
	DocumentProof [DocumentProofLength]byte
	SchemaVersion uint
}

CommitData holds required document details for anchoring

func NewCommitData

func NewCommitData(anchorID AnchorID, documentRoot DocumentRoot, proof [32]byte) (commitData *CommitData)

NewCommitData returns a CommitData with passed in details

type Config

type Config interface {
	GetEthereumContextWaitTimeout() time.Duration
	GetEthereumGasLimit(op config.ContractOp) uint64
	GetCentChainAnchorLifespan() time.Duration
}

Config defines required functions for the package Anchors

type DocumentRoot

type DocumentRoot [DocumentRootLength]byte

DocumentRoot type is byte array of length DocumentRootLength

func RandomDocumentRoot

func RandomDocumentRoot() DocumentRoot

RandomDocumentRoot returns a randomly generated DocumentRoot

func ToDocumentRoot

func ToDocumentRoot(bytes []byte) (DocumentRoot, error)

ToDocumentRoot converts bytes to DocumentRoot returns error if the bytes length != DocumentRootLength

type PreCommitData

type PreCommitData struct {
	AnchorID      AnchorID
	SigningRoot   DocumentRoot
	SchemaVersion uint
}

PreCommitData holds required document details for pre-commit

type Repository added in v1.0.0

type Repository interface {
	// PreCommit takes anchorID and signingRoot and submits an extrinsic to the Cent chain.
	// Returns the confirmation channel.
	PreCommit(
		ctx context.Context,
		anchorID AnchorID,
		signingRoot DocumentRoot) (confirmations chan error, err error)

	// Commit takes anchorID pre image, document root, and proof if pre-commit is submitted for this commit to commit an anchor
	// on chain.
	// Returns confirmations channel
	Commit(
		ctx context.Context,
		anchorIDPreImage AnchorID,
		documentRoot DocumentRoot,
		proof [32]byte,
		storedUntil time.Time) (confirmations chan error, err error)

	// GetAnchorByID returns the anchor stored on-chain
	GetAnchorByID(id *big.Int) (*AnchorData, error)
}

Repository defines required APIs to interact with Anchor Repository on Centrifuge Chain.

func NewRepository added in v1.0.0

func NewRepository(api centchain.API, jobsMan jobs.Manager) Repository

NewRepository returns a new Anchor repository.

type Service added in v1.0.0

type Service interface {

	// PreCommitAnchor will call the transaction PreCommit on the smart contract, to pre commit a document update
	PreCommitAnchor(ctx context.Context, anchorID AnchorID, signingRoot DocumentRoot) (confirmations chan error, err error)

	// CommitAnchor will send a commit transaction to Ethereum.
	CommitAnchor(ctx context.Context, anchorID AnchorID, documentRoot DocumentRoot, proof [32]byte) (chan error, error)

	// GetAnchorData takes an anchorID and returns the corresponding documentRoot from the chain.
	GetAnchorData(anchorID AnchorID) (docRoot DocumentRoot, anchoredTime time.Time, err error)
}

Service defines a set of functions that can be implemented by any type that stores and retrieves the anchoring, and pre anchoring details.

type WatchCommit

type WatchCommit struct {
	CommitData *CommitData
	Error      error
}

WatchCommit holds the commit data received from ethereum event

type WatchPreCommit

type WatchPreCommit struct {
	PreCommit *PreCommitData
	Error     error
}

WatchPreCommit holds the pre commit data received from ethereum event

Jump to

Keyboard shortcuts

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