[#1224] morph: Call Alphabet methods flexibly

Call `UpdateStateIR` and `AddPeerIR` method instead of `UpdateState` and
`AddPeer` if calling client is configured as Alphabet in notary enabled
environment.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-05-13 21:35:37 +03:00 committed by LeL
parent a129fc98da
commit 71f18ba9ec
2 changed files with 23 additions and 5 deletions

View file

@ -22,22 +22,31 @@ func (a *AddPeerPrm) SetNodeInfo(nodeInfo *netmap.NodeInfo) {
// AddPeer registers peer in NeoFS network through
// Netmap contract call.
func (c *Client) AddPeer(p AddPeerPrm) error {
var method = addPeerMethod
if c.client.WithNotary() && c.client.IsAlpha() {
// In notary environments Alphabet must calls AddPeerIR method instead of AddPeer.
// It differs from AddPeer only by name, so we can do this in the same form.
// See https://github.com/nspcc-dev/neofs-contract/issues/154.
method += "IR"
}
if p.nodeInfo == nil {
return fmt.Errorf("nil node info (%s)", addPeerMethod)
return fmt.Errorf("nil node info (%s)", method)
}
rawNodeInfo, err := p.nodeInfo.Marshal()
if err != nil {
return fmt.Errorf("can't marshal node info (%s): %w", addPeerMethod, err)
return fmt.Errorf("can't marshal node info (%s): %w", method, err)
}
prm := client.InvokePrm{}
prm.SetMethod(addPeerMethod)
prm.SetMethod(method)
prm.SetArgs(rawNodeInfo)
prm.InvokePrmOptional = p.InvokePrmOptional
if err := c.client.Invoke(prm); err != nil {
return fmt.Errorf("could not invoke method (%s): %w", addPeerMethod, err)
return fmt.Errorf("could not invoke method (%s): %w", method, err)
}
return nil
}

View file

@ -27,8 +27,17 @@ func (u *UpdatePeerPrm) SetState(state netmap.NodeState) {
// UpdatePeerState changes peer status through Netmap contract call.
func (c *Client) UpdatePeerState(p UpdatePeerPrm) error {
method := updateStateMethod
if c.client.WithNotary() && c.client.IsAlpha() {
// In notary environments Alphabet must calls UpdateStateIR method instead of UpdateState.
// It differs from UpdateState only by name, so we can do this in the same form.
// See https://github.com/nspcc-dev/neofs-contract/issues/225.
method += "IR"
}
prm := client.InvokePrm{}
prm.SetMethod(updateStateMethod)
prm.SetMethod(method)
prm.SetArgs(int64(p.state.ToV2()), p.key)
prm.InvokePrmOptional = p.InvokePrmOptional