forked from TrueCloudLab/frostfs-node
[#556] morph/neofs: Implement contract client
Implement NeoFS contact's client which is responsible for collecting call arguments and parsing stack items. Initially key binding and unbinding are supported. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
b8a7c11e57
commit
9dc741d43e
2 changed files with 155 additions and 0 deletions
63
pkg/morph/client/neofs/bind.go
Normal file
63
pkg/morph/client/neofs/bind.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package neofscontract
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// BindKeysArgs groups the arguments
|
||||
// of key binding call.
|
||||
type BindKeysArgs struct {
|
||||
commonBindArgs
|
||||
}
|
||||
|
||||
// UnbindKeysArgs groups the arguments
|
||||
// of key unbinding call.
|
||||
type UnbindKeysArgs struct {
|
||||
commonBindArgs
|
||||
}
|
||||
|
||||
type commonBindArgs struct {
|
||||
scriptHash []byte // script hash of account identifier
|
||||
|
||||
keys [][]byte // list of serialized public keys
|
||||
}
|
||||
|
||||
// SetScriptHash sets script hash of the NeoFS account identifier.
|
||||
func (x *commonBindArgs) SetScriptHash(v []byte) {
|
||||
x.scriptHash = v
|
||||
}
|
||||
|
||||
// SetKeys sets list of public keys in a binary format.
|
||||
func (x *commonBindArgs) SetKeys(v [][]byte) {
|
||||
x.keys = v
|
||||
}
|
||||
|
||||
// BindKeys invokes the call of key binding method
|
||||
// of NeoFS contract.
|
||||
func (x *Client) BindKeys(args BindKeysArgs) error {
|
||||
err := x.client.Invoke(
|
||||
x.bindKeysMethod,
|
||||
args.scriptHash,
|
||||
args.keys,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", x.bindKeysMethod, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnbindKeys invokes the call of key unbinding method
|
||||
// of NeoFS contract.
|
||||
func (x *Client) UnbindKeys(args UnbindKeysArgs) error {
|
||||
err := x.client.Invoke(
|
||||
x.unbindKeysMethod,
|
||||
args.scriptHash,
|
||||
args.keys,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", x.unbindKeysMethod, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue