Documentation ¶
Index ¶
Constants ¶
const StampSize = 97
StampSize is the number of bytes in the serialisation of a stamp
Variables ¶
var ( // ErrOwnerMismatch is the error given for invalid signatures. ErrOwnerMismatch = errors.New("owner mismatch") // ErrStampInvalid is the error given if stamp cannot deserialise. ErrStampInvalid = errors.New("invalid stamp") )
var ( // ErrBucketFull is the error when a collision bucket is full. ErrBucketFull = errors.New("bucket full") )
var ( // ErrNotFound is the error returned when issuer with given batch ID does not exist. ErrNotFound = errors.New("not found") )
Functions ¶
Types ¶
type Batch ¶
type Batch struct { ID []byte // batch ID Value *big.Int // normalised balance of the batch Start uint64 // block number the batch was created Owner []byte // owner's ethereum address Depth uint8 // batch depth, i.e., size = 2^{depth} Radius uint8 // reserve radius, non-serialised }
Batch represents a postage batch, a payment on the blockchain.
func (*Batch) MarshalBinary ¶
MarshalBinary implements BinaryMarshaller. It will attempt to serialize the postage batch to a byte slice. serialised as ID(32)|big endian value(32)|start block(8)|owner addr(20)|depth(1)
func (*Batch) UnmarshalBinary ¶
UnmarshalBinary implements BinaryUnmarshaller. It will attempt deserialize the given byte slice into the batch.
type ChainState ¶
type ChainState struct { Block uint64 `json:"block"` // The block number of the last postage event. Total *big.Int `json:"total"` // Cumulative amount paid per stamp. Price *big.Int `json:"price"` // Bzz/chunk/block normalised price. }
ChainState contains data the batch service reads from the chain.
type EventUpdater ¶
type EventUpdater interface { Create(id []byte, owner []byte, normalisedBalance *big.Int, depth uint8) error TopUp(id []byte, normalisedBalance *big.Int) error UpdateDepth(id []byte, depth uint8, normalisedBalance *big.Int) error UpdatePrice(price *big.Int) error UpdateBlockNumber(blockNumber uint64) error Start() <-chan struct{} }
EventUpdater interface definitions reflect the updates triggered by events emitted by the postage contract on the blockchain.
type Listener ¶
type Listener interface { io.Closer Listen(from uint64, updater EventUpdater) <-chan struct{} }
Listener provides a blockchain event iterator.
type RadiusSetter ¶
type RadiusSetter interface {
SetRadius(uint8)
}
type Reservestate ¶
type Service ¶
type Service interface { Add(*StampIssuer) StampIssuers() []*StampIssuer GetStampIssuer([]byte) (*StampIssuer, error) io.Closer }
Service is the postage service interface.
func NewService ¶
func NewService(store storage.StateStorer, chainID int64) (Service, error)
NewService constructs a new Service.
type Stamp ¶
type Stamp struct {
// contains filtered or unexported fields
}
Stamp represents a postage stamp as attached to a chunk.
func (*Stamp) MarshalBinary ¶
MarshalBinary gives the byte slice serialisation of a stamp: batchID[32]|Signature[65].
func (*Stamp) UnmarshalBinary ¶
UnmarshalBinary parses a serialised stamp into id and signature.
func (*Stamp) Valid ¶
Valid checks the validity of the postage stamp; in particular: - authenticity - check batch is valid on the blockchain - authorisation - the batch owner is the stamp signer the validity check is only meaningful in its association of a chunk this chunk address needs to be given as argument
type StampIssuer ¶
type StampIssuer struct {
// contains filtered or unexported fields
}
StampIssuer is a local extension of a batch issuing stamps for uploads. A StampIssuer instance extends a batch with bucket collision tracking embedded in multiple Stampers, can be used concurrently.
func NewStampIssuer ¶
func NewStampIssuer(label, keyID string, batchID []byte, batchDepth, bucketDepth uint8) *StampIssuer
NewStampIssuer constructs a StampIssuer as an extension of a batch for local upload.
bucketDepth must always be smaller than batchDepth otherwise inc() panics.
func (*StampIssuer) Label ¶
func (st *StampIssuer) Label() string
Label returns the label of the issuer.
func (*StampIssuer) MarshalBinary ¶
func (st *StampIssuer) MarshalBinary() ([]byte, error)
MarshalBinary gives the byte slice serialisation of a StampIssuer: = label[32]|keyID[32]|batchID[32]|batchDepth[1]|bucketDepth[1]|size_0[4]|size_1[4]|....
func (*StampIssuer) UnmarshalBinary ¶
func (st *StampIssuer) UnmarshalBinary(buf []byte) error
UnmarshalBinary parses a serialised StampIssuer into the receiver struct.
func (*StampIssuer) Utilization ¶
func (st *StampIssuer) Utilization() uint32
Utilization returns the batch utilization in the form of an integer between 0 and 4294967295. Batch fullness can be calculated with: max_bucket_value / 2 ^ (batch_depth - bucket_depth)
type Stamper ¶
Stamper can issue stamps from the given address.
func NewStamper ¶
func NewStamper(st *StampIssuer, signer crypto.Signer) Stamper
NewStamper constructs a Stamper.
type Storer ¶
type Storer interface { Get(id []byte) (*Batch, error) Put(*Batch, *big.Int, uint8) error PutChainState(*ChainState) error GetChainState() *ChainState GetReserveState() *Reservestate SetRadiusSetter(RadiusSetter) }
Storer represents the persistence layer for batches on the current (highest available) block.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package batchstore implements the reserve the reserve serves to maintain chunks in the area of responsibility it has two components - the batchstore reserve which maintains information about batches, their values, priorities and synchronises with the blockchain - the localstore which stores chunks and manages garbage collection when a new chunk arrives in the localstore, the batchstore reserve is asked to check the batch used in the postage stamp attached to the chunk.
|
Package batchstore implements the reserve the reserve serves to maintain chunks in the area of responsibility it has two components - the batchstore reserve which maintains information about batches, their values, priorities and synchronises with the blockchain - the localstore which stores chunks and manages garbage collection when a new chunk arrives in the localstore, the batchstore reserve is asked to check the batch used in the postage stamp attached to the chunk. |