[#496] morph/client: fallback to simple invoke in NotaryInvoke

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-05-21 10:39:21 +03:00 committed by Alex Vanin
parent 2e31cd34e6
commit b5cda8cd41
7 changed files with 23 additions and 104 deletions

View file

@ -27,9 +27,5 @@ func AlphabetVote(cli *client.Client, con util.Uint160, fee SideFeeProvider, epo
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), voteMethod, int64(epoch), keys)
}
return cli.NotaryInvoke(con, voteMethod, int64(epoch), keys)
return cli.NotaryInvoke(con, fee.SideChainFee(), voteMethod, int64(epoch), keys)
}

View file

@ -37,15 +37,7 @@ func Mint(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *MintBurn
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), mintMethod,
p.ScriptHash,
p.Amount,
p.Comment,
)
}
return cli.NotaryInvoke(con, mintMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), mintMethod,
p.ScriptHash,
p.Amount,
p.Comment,
@ -58,15 +50,7 @@ func Burn(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *MintBurn
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), burnMethod,
p.ScriptHash,
p.Amount,
p.Comment,
)
}
return cli.NotaryInvoke(con, burnMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), burnMethod,
p.ScriptHash,
p.Amount,
p.Comment,
@ -79,17 +63,7 @@ func LockAsset(cli *client.Client, con util.Uint160, fee SideFeeProvider, p *Loc
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), lockMethod,
p.ID,
p.User.BytesBE(),
p.LockAccount.BytesBE(),
p.Amount,
int64(p.Until),
)
}
return cli.NotaryInvoke(con, lockMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), lockMethod,
p.ID,
p.User.BytesBE(),
p.LockAccount.BytesBE(),

View file

@ -32,15 +32,7 @@ func RegisterContainer(cli *client.Client, con util.Uint160, fee SideFeeProvider
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), putContainerMethod,
p.Container,
p.Signature,
p.Key.Bytes(),
)
}
return cli.NotaryInvoke(con, putContainerMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), putContainerMethod,
p.Container,
p.Signature,
p.Key.Bytes(),
@ -53,14 +45,7 @@ func RemoveContainer(cli *client.Client, con util.Uint160, fee SideFeeProvider,
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), deleteContainerMethod,
p.ContainerID,
p.Signature,
)
}
return cli.NotaryInvoke(con, deleteContainerMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), deleteContainerMethod,
p.ContainerID,
p.Signature,
)

View file

@ -36,16 +36,7 @@ func CashOutCheque(cli *client.Client, con util.Uint160, fee MainFeeProvider, p
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.MainChainFee(), chequeMethod,
p.ID,
p.User.BytesBE(),
p.Amount,
p.LockAccount.BytesBE(),
)
}
return cli.NotaryInvoke(con, chequeMethod,
return cli.NotaryInvoke(con, fee.MainChainFee(), chequeMethod,
p.ID,
p.User.BytesBE(),
p.Amount,
@ -59,9 +50,5 @@ func AlphabetUpdate(cli *client.Client, con util.Uint160, fee MainFeeProvider, i
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.MainChainFee(), alphabetUpdateMethod, id, list)
}
return cli.NotaryInvoke(con, alphabetUpdateMethod, id, list)
return cli.NotaryInvoke(con, fee.MainChainFee(), alphabetUpdateMethod, id, list)
}

View file

@ -59,11 +59,7 @@ func SetNewEpoch(cli *client.Client, con util.Uint160, fee SideFeeProvider, epoc
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), setNewEpochMethod, int64(epoch))
}
return cli.NotaryInvoke(con, setNewEpochMethod, int64(epoch))
return cli.NotaryInvoke(con, fee.SideChainFee(), setNewEpochMethod, int64(epoch))
}
// ApprovePeer invokes addPeer method.
@ -72,11 +68,7 @@ func ApprovePeer(cli *client.Client, con util.Uint160, fee SideFeeProvider, peer
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), approvePeerMethod, peer)
}
return cli.NotaryInvoke(con, approvePeerMethod, peer)
return cli.NotaryInvoke(con, fee.SideChainFee(), approvePeerMethod, peer)
}
// UpdatePeerState invokes addPeer method.
@ -85,14 +77,7 @@ func UpdatePeerState(cli *client.Client, con util.Uint160, fee SideFeeProvider,
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), updatePeerStateMethod,
int64(args.Status.ToV2()),
args.Key.Bytes(),
)
}
return cli.NotaryInvoke(con, updatePeerStateMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), updatePeerStateMethod,
int64(args.Status.ToV2()),
args.Key.Bytes(),
)
@ -104,15 +89,7 @@ func SetConfig(cli *client.Client, con util.Uint160, fee SideFeeProvider, args *
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), setConfigMethod,
args.ID,
args.Key,
args.Value,
)
}
return cli.NotaryInvoke(con, setConfigMethod,
return cli.NotaryInvoke(con, fee.SideChainFee(), setConfigMethod,
args.ID,
args.Key,
args.Value,
@ -126,11 +103,7 @@ func SetInnerRing(cli *client.Client, con util.Uint160, fee SideFeeProvider, lis
return client.ErrNilClient
}
if !cli.NotaryEnabled() {
return cli.Invoke(con, fee.SideChainFee(), setInnerRingMethod, list)
}
return cli.NotaryInvoke(con, setInnerRingMethod, list)
return cli.NotaryInvoke(con, fee.SideChainFee(), setInnerRingMethod, list)
}
// NetmapSnapshot returns current netmap node infos.

View file

@ -200,14 +200,14 @@ func (c *Client) UpdateNeoFSAlphabetList(list keys.PublicKeys) error {
}
// NotaryInvoke invokes contract method by sending tx to notary contract in
// blockchain. Fallback tx is a `RET`. Notary support should be enabled
// in client to use this function.
// blockchain. Fallback tx is a `RET`. If Notary support is not enabled
// it fallbacks to a simple `Invoke()`.
//
// This function must be invoked after `EnableNotarySupport()` otherwise it
// throws panic.
func (c *Client) NotaryInvoke(contract util.Uint160, method string, args ...interface{}) error {
func (c *Client) NotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, method string, args ...interface{}) error {
if c.notary == nil {
panic(notaryNotEnabledPanicMsg)
return c.Invoke(contract, fee, method, args...)
}
return c.notaryInvoke(false, contract, method, args...)

View file

@ -63,10 +63,14 @@ func (s StaticClient) TestInvoke(method string, args ...interface{}) ([]stackite
}
// NotaryInvoke calls NotaryInvoke method of Client with static internal
// script hash. Returns error if notary support was not enabled in underlying
// script hash. Panics if notary support was not enabled in underlying
// moprh client.
func (s StaticClient) NotaryInvoke(method string, args ...interface{}) error {
return s.client.NotaryInvoke(
if s.client.notary == nil {
panic(notaryNotEnabledPanicMsg)
}
return s.client.notaryInvoke(
false,
s.scScriptHash,
method,
args...,