blockchain

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Contracts exposes blockchain network SmartContracts pool.
	Contracts = struct {
		Devices      *DevicesContract
		Assets       *AssetsContract
		Requirements *RequirementsContract
		Readings     *ReadingsContract
	}{
		Devices:      &DevicesContract{},
		Assets:       &AssetsContract{},
		Requirements: &RequirementsContract{},
		Readings:     &ReadingsContract{},
	}
)

Functions

func Close

func Close()

Close closes connection to blockchain network and clears allocated resources.

func Init

func Init() (err error)

Init performs initialization sequence of the blockchain client with given config.

Types

type AssetsContract

type AssetsContract struct {
	// contains filtered or unexported fields
}

AssetsContract defines interface for communication with assets-managing Smart Contract.

func (*AssetsContract) Receive

func (ac *AssetsContract) Receive(query requests.AssetsQuery) ([]*models.Asset, error)

Receive retrieves models.Asset records from blockchain ledger by a given `query`.

func (*AssetsContract) Subscribe

func (ac *AssetsContract) Subscribe(ctx context.Context, event string, action func(*models.Asset, string) error) error

Subscribe starts listening to blockchain events related to assets and triggers `action` on each event occurrence.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client defines an interface for communicating with blockchain network.

type DevicesContract

type DevicesContract struct {
	// contains filtered or unexported fields
}

DevicesContract defines access to blockchain Smart Contract for managing device.

func (*DevicesContract) Exists

func (dc *DevicesContract) Exists(id string) (bool, error)

Exists verify whether the device with `id` exists on the blockchain ledger.

func (*DevicesContract) ListenCommands

func (dc *DevicesContract) ListenCommands(
	ctx context.Context, deviceID string,
	handler func(id string, cmd models.DeviceCommand, args ...interface{}) error,
) error

ListenCommands subscribes and starts listening for device commands from the blockchain network.

func (*DevicesContract) Retrieve

func (dc *DevicesContract) Retrieve(id string) (*models.Device, error)

Retrieve fetches models.Device from the blockchain ledger.

func (*DevicesContract) SubmitCommandResults

func (dc *DevicesContract) SubmitCommandResults(id string, req requests.DeviceCommandResultsSubmitRequest) error

SubmitCommandResults submits command execution results to log them in the blockchain ledger.

func (*DevicesContract) Subscribe

func (dc *DevicesContract) Subscribe(
	ctx context.Context, event string,
	action func(*models.Device, string) error,
) error

Subscribe listens to blockchain events related to device and triggers `action` on each event occurrence.

func (*DevicesContract) Unbind

func (dc *DevicesContract) Unbind(id string) error

Unbind removes device from the blockchain ledger.

func (*DevicesContract) Update

Update updates device on the blockchain ledger.

type ReadingsContract

type ReadingsContract struct {
	// contains filtered or unexported fields
}

ReadingsContract defines access to blockchain Smart Contract for managing metric readings.

func (*ReadingsContract) Post

func (rc *ReadingsContract) Post(readings models.MetricReadings) error

Post sends models.MetricReadings record to blockchain network for processing.

type RequirementsContract

type RequirementsContract struct {
	// contains filtered or unexported fields
}

RequirementsContract defines access to blockchain Smart Contract for managing requirements.

func (*RequirementsContract) ReceiveFor

func (rc *RequirementsContract) ReceiveFor(assets ...string) ([]*models.Requirements, error)

ReceiveFor retrieves models.Requirements records from blockchain ledger for a given `assets`.

func (*RequirementsContract) Subscribe

func (rc *RequirementsContract) Subscribe(ctx context.Context, event string, action func(*models.Requirements, string) error) error

Subscribe starts listening to blockchain events related to requirements and triggers `action` on each event occurrence.

Jump to

Keyboard shortcuts

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