mine

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OPSIGN int32 = iota
)

Variables

View Source
var (
	// ErrNotFound is the error returned when issuer with given batch ID does not exist.
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type ChainState

type ChainState struct {
	Block uint64 // The block number of the last postage event.
}

ChainState contains data the batch service reads from the chain.

type EventUpdater

type EventUpdater interface {
	Miner(node []byte, deposit, active bool, txHash []byte, blockNumber uint64) error
	Trust(node []byte, trust bool, txHash []byte) error

	// Create(id []byte, owner []byte, normalisedBalance *big.Int, depth, bucketDepth uint8, immutable bool, txHash []byte) error
	// TopUp(id []byte, normalisedBalance *big.Int, txHash []byte) error
	// UpdateDepth(id []byte, depth uint8, normalisedBalance *big.Int, txHash []byte) error
	// UpdatePrice(price *big.Int, txHash []byte) error
	UpdateBlockNumber(blockNumber uint64) error

	TransactionStart() error
	TransactionEnd() error
}

EventUpdater interface definitions reflect the updates triggered by events emitted by the postage contract on the blockchain.

type MineContract

type MineContract interface {
	IsWorking(ctx context.Context, node common.Hash) (bool, error)
	Token(ctx context.Context) (common.Address, error)
	Lockup(ctx context.Context) (common.Address, error)
	MinersReceived(ctx context.Context, node common.Hash) (common.Address, error)
	MinersWithdraw(ctx context.Context, node common.Hash) (*big.Int, error)
	ExpireOf(ctx context.Context, node common.Hash) (*big.Int, error)
	Reward(ctx context.Context, node common.Hash) (*big.Int, error)
	CheckDeposit(ctx context.Context, node common.Hash) (bool, error)
	Withdraw(ctx context.Context, node common.Hash) (common.Hash, error)
	ValidateTrusts(ctx context.Context) (*big.Int, error)
	Deposit(ctx context.Context, node common.Hash, cate, price, deadline *big.Int, signatrues []byte) (common.Hash, error)
	WaitForDeposit(ctx context.Context, hash common.Hash) error
	CashDeposit(ctx context.Context, node common.Hash) (common.Hash, error)
	Active(ctx context.Context, node common.Hash, cate, deadline *big.Int, signatures []byte) (common.Hash, error)
	WaitForActive(ctx context.Context, hash common.Hash) error
	Inactives(ctx context.Context, nodes []common.Hash, deadline *big.Int, signatures []byte) (common.Hash, error)
	Dishonesty(ctx context.Context, node common.Hash, deadline *big.Int, signatures []byte) (common.Hash, error)
}

type Node

type Node struct {
	Node       common.Hash // node id
	Trust      bool        // trust node
	Deposit    bool
	Active     bool
	LastBlock  uint64
	EthAddress common.Address

	InactionTx *common.Hash // memory
}

Batch represents a postage batch, a payment on the blockchain.

func (*Node) MarshalBinary

func (n *Node) MarshalBinary() ([]byte, error)

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)|BucketDepth(1)|depth(1)|immutable(1)

func (*Node) UnmarshalBinary

func (n *Node) UnmarshalBinary(buf []byte) error

UnmarshalBinary implements BinaryUnmarshaller. It will attempt deserialize the given byte slice into the batch.

type NodeService

type NodeService interface {
	Start(startBlock uint64) (<-chan struct{}, error)
	TrustOf(node swarm.Address) bool
	UpdateNodeLastBlock(node swarm.Address, blockNumber uint64) error
	TrustAddress(filter func(swarm.Address) bool) []swarm.Address
	ExpireMiners() ([]swarm.Address, error)
	MineAddress(node common.Hash, contract MineContract) (common.Address, error)
	UpdateNodeInactionTxHash(node swarm.Address, hash common.Hash)
	SubscribeRollCall() (<-chan uint64, func())
}

type Options added in v0.1.0

type Options struct {
	Store              storage.StateStorer
	Backend            transaction.Backend
	TransactionService transaction.Service
	OverlayEthAddress  common.Address
	DeployGasPrice     string
}

type Oracle added in v0.1.0

type Oracle interface {
	Price() *big.Int
}

type Service

type Service interface {
	Start(startBlock uint64) (<-chan struct{}, error)
	Close() error
	SetTrust(rollcall Trust)

	NotifyTrustSignature(pper swarm.Address, expire int64, data []byte) error
	NotifyTrustRollCall(peer swarm.Address, expire int64, data []byte) error
	NotifyTrustRollCallSign(peer swarm.Address, expire int64, data []byte) error

	Status(ctx context.Context) (bool, *big.Int, *big.Int, *big.Int, error)
	Withdraw(ctx context.Context) (common.Hash, error)
	CashDeposit(ctx context.Context) (common.Hash, error)
}

Service is the miner service interface.

func NewService

func NewService(
	base swarm.Address,
	contract MineContract,
	nodes NodeService,
	signer crypto.Signer,
	oracle Oracle,
	logger logging.Logger,
	warmupTime time.Duration,
	opt Options,
) Service

NewService constructs a new Service.

type Storer

type Storer interface {
	Get(id common.Hash) (*Node, error)
	Put(*Node) error
	Miners() ([]*Node, error)
	PutChainState(*ChainState) error
	GetChainState() *ChainState

	Reset() error
}

Storer represents the persistence layer for batches on the current (highest available) block.

type Trust

type Trust interface {
	TrustsSignature(ctx context.Context, expire int64, data []byte, num uint64, peer ...swarm.Address) ([]byte, error)
	PushSignatures(ctx context.Context, id uint32, expire int64, data []byte, target swarm.Address, peer swarm.Address) error
	PushTrustSign(ctx context.Context, expire int64, data []byte, target swarm.Address, peer swarm.Address) error
	PushSelfTrustSign(ctx context.Context, expire int64, data []byte, target swarm.Address) error
	PushRollCall(ctx context.Context, expire int64, data []byte, skips ...swarm.Address) error
}

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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