handler

package
v0.0.0-...-39f44e7 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package handler defines the commands and command handlers that storage service's reply controller supports

Index

Constants

View Source
const (
	// GetAbi Direct
	GetAbi string = "abi_get"
	// SetAbi Through the router
	SetAbi string = "abi_set"
	// GetConfiguration Through the router
	GetConfiguration string = "configuration_get"
	// SetConfiguration Through the router
	SetConfiguration string = "configuration_set"
	// SetSmartcontract Through the router
	SetSmartcontract string = "smartcontract_set"
	// GetSmartcontract Direct
	GetSmartcontract string = "smartcontract_get"
)

Variables

View Source
var AbiGet = func(request message.Request, _ *log.Logger, extensions ...*remote.ClientSocket) message.Reply {
	dbCon := remote.FindClient(extensions, "github.com/ahmetson/w3storage-extension")
	if dbCon == nil {
		return message.Fail("missing extension")
	}

	var reqParameters GetAbiRequest
	err := request.Parameters.Interface(&reqParameters)
	if err != nil {
		return message.Fail("request.Parameters -> Command Parameter: " + err.Error())
	}
	if len(reqParameters.Id) == 0 {
		return message.Fail("missing abi id")
	}

	var selectedAbi = abi.Abi{Id: reqParameters.Id}
	saveErr := selectedAbi.Select(dbCon)
	if saveErr != nil {
		return message.Fail("database error:" + saveErr.Error())
	}

	replyMessage, err := command.Reply(selectedAbi)
	if err != nil {
		return message.Fail("failed to reply")
	}
	return replyMessage
}

AbiGet returns the abi Depends on the database extension

View Source
var ConfigurationRegister = func(request message.Request, _ *log.Logger, extensions ...*remote.ClientSocket) message.Reply {
	var conf SetConfigurationRequest
	err := request.Parameters.Interface(&conf)
	if err != nil {
		return message.Fail("failed to parse data")
	}
	if err := conf.Validate(); err != nil {
		return message.Fail("validation: " + err.Error())
	}

	dbCon := remote.FindClient(extensions, "github.com/ahmetson/w3storage-extension")
	if dbCon == nil {
		return message.Fail("missing extension")
	}
	var crud database.Crud = &conf
	if err = crud.Insert(dbCon); err != nil {
		return message.Fail("Configuration saving in the database failed: " + err.Error())
	}

	var reply = conf
	replyMessage, err := command.Reply(&reply)
	if err != nil {
		return message.Fail("failed to reply")
	}

	return replyMessage
}

ConfigurationRegister Register a new smartcontract in the configuration. It requires smartcontract address. First call smartcontract_register command.

View Source
var SmartcontractGet = func(request message.Request, _ *log.Logger, extensions ...*remote.ClientSocket) message.Reply {
	var key GetSmartcontractRequest
	err := request.Parameters.Interface(&key)
	if err != nil {
		return message.Fail("failed to parse data")
	}
	if err := key.Validate(); err != nil {
		return message.Fail("key.Validate: " + err.Error())
	}

	dbCon := remote.FindClient(extensions, "github.com/ahmetson/w3storage-extension")
	if dbCon == nil {
		return message.Fail("missing extension")
	}
	var selected = smartcontract.Smartcontract{}
	err = selected.Select(dbCon)
	if err != nil {
		return message.Fail("failed to get configuration from the database: " + err.Error())
	}

	replyMessage, err := command.Reply(&selected)
	if err != nil {
		return message.Fail("failed to reply")
	}

	return replyMessage
}

SmartcontractGet Returns configuration and smartcontract information related to the configuration

Functions

func AbiRegister

func AbiRegister(request message.Request, _ *log.Logger, extensions ...*remote.ClientSocket) message.Reply

func ConfigurationGet

func ConfigurationGet(request message.Request, _ *log.Logger, extensions ...*remote.ClientSocket) message.Reply

ConfigurationGet Returns configuration and smartcontract information related to the configuration

func RegisterCommands

func RegisterCommands(c *controller.Controller, extensions ...string)

RegisterCommands registers the commands and their handlers in the controller

func SmartcontractRegister

func SmartcontractRegister(request message.Request, _ *log.Logger, extensions ...*remote.ClientSocket) message.Reply

SmartcontractRegister Register a new smartcontract. It means we are adding smartcontract parameters into smartcontract database table. Requires abi_id parameter. First call abi_register method first.

Types

type GetAbiReply

type GetAbiReply = abi.Abi

type GetAbiRequest

type GetAbiRequest struct {
	Id string `json:"abi_id"`
}

type GetConfigurationReply

type GetConfigurationReply = configuration.Configuration

type GetConfigurationRequest

type GetConfigurationRequest = topic.Topic

type GetSmartcontractReply

type GetSmartcontractReply = smartcontract.Smartcontract

type GetSmartcontractRequest

type GetSmartcontractRequest = smartcontract_key.Key

type SetAbiReply

type SetAbiReply = abi.Abi

type SetAbiRequest

type SetAbiRequest struct {
	Body interface{} `json:"body"`
}

type SetConfigurationReply

type SetConfigurationReply = configuration.Configuration

type SetConfigurationRequest

type SetConfigurationRequest = configuration.Configuration

type SetSmartcontractReply

type SetSmartcontractReply = smartcontract.Smartcontract

type SetSmartcontractRequest

type SetSmartcontractRequest = smartcontract.Smartcontract

Jump to

Keyboard shortcuts

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