[#328] morph/container: Add client methods related to size estimations

Implement API methods of the Container contracts client  corresponding
to the calls of the contract for storing the used space of the container
("putContainerSize", "getContainerSize", "listContainerSizes"). Extend
the wrapper over the client with methods abstracted from sidechen calls.
In particular, the method of storing the value will be used to record
the estimates of the used space of containers calculated by the network
participants.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-28 18:58:57 +03:00 committed by Leonard Lyubich
parent 4415f8dc5b
commit 1c6d37e821
3 changed files with 353 additions and 0 deletions

View file

@ -29,6 +29,9 @@ type Option func(*cfg)
type cfg struct {
putMethod, // put container method name for invocation
putSizeMethod, // put container size method name for invocation
listSizesMethod, // list container sizes method name for invocation
getSizeMethod, // get container size method name for invocation
deleteMethod, // delete container method name for invocation
getMethod, // get container method name for invocation
listMethod, // list container method name for invocation
@ -48,6 +51,10 @@ const (
defaultStartEstimation = "startContainerEstimation"
defaultStopEstimation = "stopContainerEstimation"
defaultPutSizeMethod = "putContainerSize" // default "put container size" method name
defaultListSizesMethod = "listContainerSizes" // default "list container sizes" method name
defaultGetSizeMethod = "getContainerSize" // default "get container size" method name
)
func defaultConfig() *cfg {
@ -60,6 +67,10 @@ func defaultConfig() *cfg {
eaclMethod: defaultEACLMethod,
startEstimation: defaultStartEstimation,
stopEstimation: defaultStopEstimation,
putSizeMethod: defaultPutSizeMethod,
listSizesMethod: defaultListSizesMethod,
getSizeMethod: defaultGetSizeMethod,
}
}
@ -76,6 +87,9 @@ func defaultConfig() *cfg {
// * get eACL method name: EACL.
// * start estimation method name: startContainerEstimation
// * stop estimation method name: stopContainerEstimation
// * put container size method name: putContainerSize
// * get container size method name: getContainerSize
// * list container sizes method name: listContainerSizes
//
// If desired option satisfies the default value, it can be omitted.
// If multiple options of the same config value are supplied,
@ -209,3 +223,45 @@ func WithStopEstimationMethod(n string) Option {
}
}
}
// WithPutSizeMethod returns a client constructor option that
// specifies the method name of "put container size" operation.
//
// Ignores empty value.
//
// If option not provided, "putContainerSize" is used.
func WithPutSizeMethod(n string) Option {
return func(c *cfg) {
if n != "" {
c.putSizeMethod = n
}
}
}
// WithListSizesMethod returns a client constructor option that
// specifies the method name of "list container sizes" operation.
//
// Ignores empty value.
//
// If option not provided, "listContainerSizes" is used.
func WithListSizesMethod(n string) Option {
return func(c *cfg) {
if n != "" {
c.listSizesMethod = n
}
}
}
// WithGetSizeMethod returns a client constructor option that
// specifies the method name of "get container size" operation.
//
// Ignores empty value.
//
// If option not provided, "getContainerSize" is used.
func WithGetSizeMethod(n string) Option {
return func(c *cfg) {
if n != "" {
c.getSizeMethod = n
}
}
}