persistence

package
v0.0.0-...-7608d4d Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2020 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// MetadataFile is the expected location of the metadata json document
	// in the top level of the chaincode package.
	MetadataFile = "metadata.json"

	// CodePackageFile is the expected location of the code package in the
	// top level of the chaincode package
	CodePackageFile = "code.tar.gz"
)

Variables

View Source
var LabelRegexp = regexp.MustCompile(`^[[:alnum:]][[:alnum:]_.+-]*$`)

LabelRegexp is the regular expression controlling the allowed characters for the package label.

Functions

func CCFileName

func CCFileName(packageID string) string

func ValidateLabel

func ValidateLabel(label string) error

ValidateLabel return an error if the provided label contains any invalid characters, as determined by LabelRegexp.

Types

type ChaincodePackage

type ChaincodePackage struct {
	Metadata    *ChaincodePackageMetadata
	CodePackage []byte
	DBArtifacts []byte
}

ChaincodePackage represents the un-tar-ed format of the chaincode package.

type ChaincodePackageLocator

type ChaincodePackageLocator struct {
	ChaincodeDir string
}

func (*ChaincodePackageLocator) ChaincodePackageStreamer

func (cpl *ChaincodePackageLocator) ChaincodePackageStreamer(packageID string) *ChaincodePackageStreamer

type ChaincodePackageMetadata

type ChaincodePackageMetadata struct {
	Type  string `json:"type"`
	Path  string `json:"path"`
	Label string `json:"label"`
}

ChaincodePackageMetadata contains the information necessary to understand the embedded code package.

type ChaincodePackageParser

type ChaincodePackageParser struct {
	MetadataProvider MetadataProvider
}

ChaincodePackageParser provides the ability to parse chaincode packages.

func (ChaincodePackageParser) Parse

func (ccpp ChaincodePackageParser) Parse(source []byte) (*ChaincodePackage, error)

Parse parses a set of bytes as a chaincode package and returns the parsed package as a struct

type ChaincodePackageStreamer

type ChaincodePackageStreamer struct {
	PackagePath string
}

func (*ChaincodePackageStreamer) Code

func (*ChaincodePackageStreamer) Exists

func (cps *ChaincodePackageStreamer) Exists() bool

func (*ChaincodePackageStreamer) File

func (cps *ChaincodePackageStreamer) File(name string) (tarFileStream *TarFileStream, err error)

func (*ChaincodePackageStreamer) Metadata

func (*ChaincodePackageStreamer) MetadataBytes

func (cps *ChaincodePackageStreamer) MetadataBytes() ([]byte, error)

type CodePackageNotFoundErr

type CodePackageNotFoundErr struct {
	PackageID string
}

CodePackageNotFoundErr is the error returned when a code package cannot be found in the persistence store

func (CodePackageNotFoundErr) Error

func (e CodePackageNotFoundErr) Error() string

type FallbackPackageLocator

type FallbackPackageLocator struct {
	ChaincodePackageLocator *ChaincodePackageLocator
	LegacyCCPackageLocator  LegacyCCPackageLocator
}

func (*FallbackPackageLocator) GetChaincodePackage

func (fpl *FallbackPackageLocator) GetChaincodePackage(packageID string) (*ChaincodePackageMetadata, []byte, io.ReadCloser, error)

type FilesystemIO

type FilesystemIO struct {
}

FilesystemIO is the production implementation of the IOWriter interface

func (*FilesystemIO) Exists

func (*FilesystemIO) Exists(path string) (bool, error)

Exists checks whether a file exists

func (*FilesystemIO) MakeDir

func (f *FilesystemIO) MakeDir(dirname string, mode os.FileMode) error

MakeDir makes a directory on the filesystem (and any necessary parent directories).

func (*FilesystemIO) ReadDir

func (f *FilesystemIO) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir reads a directory from the filesystem

func (*FilesystemIO) ReadFile

func (f *FilesystemIO) ReadFile(filename string) ([]byte, error)

ReadFile reads a file from the filesystem

func (*FilesystemIO) Remove

func (f *FilesystemIO) Remove(name string) error

Remove removes a file from the filesystem - used for rolling back an in-flight Save operation upon a failure

func (*FilesystemIO) WriteFile

func (f *FilesystemIO) WriteFile(path, name string, data []byte) error

WriteFile writes a file to the filesystem; it does so atomically by first writing to a temp file and then renaming the file so that if the operation crashes midway we're not stuck with a bad package

type IOReadWriter

type IOReadWriter interface {
	ReadDir(string) ([]os.FileInfo, error)
	ReadFile(string) ([]byte, error)
	Remove(name string) error
	WriteFile(string, string, []byte) error
	MakeDir(string, os.FileMode) error
	Exists(path string) (bool, error)
}

IOReadWriter defines the interface needed for reading, writing, removing, and checking for existence of a specified file

type LegacyCCPackageLocator

type LegacyCCPackageLocator interface {
	GetChaincodeDepSpec(nameVersion string) (*pb.ChaincodeDeploymentSpec, error)
}

type MetadataProvider

type MetadataProvider interface {
	GetDBArtifacts(codePackage []byte) ([]byte, error)
}

MetadataProvider provides the means to retrieve metadata information (for instance the DB indexes) from a code package.

type Store

type Store struct {
	Path       string
	ReadWriter IOReadWriter
}

Store holds the information needed for persisting a chaincode install package

func NewStore

func NewStore(path string) *Store

NewStore creates a new chaincode persistence store using the provided path on the filesystem.

func (*Store) Delete

func (s *Store) Delete(packageID string) error

Delete deletes a persisted chaincode. Note, there is no locking, so this should only be performed if the chaincode has already been marked built.

func (*Store) GetChaincodeInstallPath

func (s *Store) GetChaincodeInstallPath() string

GetChaincodeInstallPath returns the path where chaincodes are installed

func (*Store) Initialize

func (s *Store) Initialize()

Initialize checks for the existence of the _lifecycle chaincodes directory and creates it if it has not yet been created.

func (*Store) ListInstalledChaincodes

func (s *Store) ListInstalledChaincodes() ([]chaincode.InstalledChaincode, error)

ListInstalledChaincodes returns an array with information about the chaincodes installed in the persistence store

func (*Store) Load

func (s *Store) Load(packageID string) ([]byte, error)

Load loads a persisted chaincode install package bytes with the given packageID.

func (*Store) Save

func (s *Store) Save(label string, ccInstallPkg []byte) (string, error)

Save persists chaincode install package bytes. It returns the hash of the chaincode install package

type TarFileStream

type TarFileStream struct {
	TarFile    io.Reader
	FileStream io.Closer
}

func (*TarFileStream) Close

func (tfs *TarFileStream) Close() error

func (*TarFileStream) Read

func (tfs *TarFileStream) Read(p []byte) (int, error)

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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