Documentation ¶
Overview ¶
Package batch batches multiple operations in a single file (batch file) and stores the batch files in a distributed content-addressable storage (DCAS or CAS). A reference to the operation batch is then anchored on the blockchain as Sidetree transaction.
Batch Writer basic flow:
1) accept operations being delivered via Add method 2) 'cut' configurable number of operations into batch file 3) store batch file into CAS (content addressable storage) 4) create Merkle tree from batch operations 5) create an anchor file based on batch file address and Merkle tree root 6) store anchor file into CAS 7) write the address of anchor file to the underlying blockchain
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockchainClient ¶
type BlockchainClient interface { // WriteAnchor writes the anchor file hash as a transaction to blockchain WriteAnchor(anchor string) error // Read ledger transaction Read(sinceTransactionNumber int) (bool, *observer.SidetreeTxn) }
BlockchainClient defines an interface to access the underlying blockchain
type CASClient ¶
type CASClient interface { // Write writes the given content to CASClient. // returns the SHA256 hash in base64url encoding which represents the address of the content. Write(content []byte) (string, error) // Read reads the content of the given address in CASClient. // returns the content of the given address. Read(address string) ([]byte, error) }
CASClient defines interface for accessing the underlying content addressable storage
type Context ¶
type Context interface { Protocol() protocol.Client CAS() CASClient Blockchain() BlockchainClient }
Context contains batch writer context 1) protocol information client 2) content addressable storage client 3) blockchain client
type OperationHandler ¶
type OperationHandler interface { // CreateBatchFile will create batch file bytes CreateBatchFile(operations [][]byte) ([]byte, error) // CreateAnchorFile will create anchor file bytes for Sidetree transaction CreateAnchorFile(operations [][]byte, batchAddress string, multihashCode uint) ([]byte, error) }
OperationHandler defines an interface for creating batch and anchor files
type Option ¶
Option defines Writer options such as batch timeout
func WithBatchTimeout ¶
WithBatchTimeout allows for specifying batch timeout
func WithOperationHandler ¶
func WithOperationHandler(opsHandler OperationHandler) Option
WithOperationHandler allows for specifying handler for creating anchor/batch files
type Options ¶
type Options struct { BatchTimeout time.Duration OpsHandler OperationHandler }
Options allows the user to specify more advanced options
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements batch writer
func New ¶
New creates a new Writer. Writer accepts operations being delivered via Add, orders them, and then uses the batch cutter to form the operations batch file. This batch file will then be used to generate Merkle tree and create an anchor file. The hash of anchor file will be written to the given ledger.
func (*Writer) Add ¶
Add the given operation to a queue of operations to be batched and anchored on blockchain.