Skip to content

Commit

Permalink
morph/static: make it possible to wait for TX inclusion
Browse files Browse the repository at this point in the history
Will be helpful for new meta-data handling policies.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Dec 11, 2024
1 parent 2f44f7d commit 863a404
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/innerring/processors/alphabet/process_emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (ap *Processor) processEmit() {
}

// there is no signature collecting, so we don't need extra fee
err := ap.morphClient.Invoke(contract, 0, emitMethod)
err := ap.morphClient.Invoke(contract, false, 0, emitMethod)
if err != nil {
ap.log.Warn("can't invoke alphabet emit method", zap.Error(err))

Expand Down
5 changes: 4 additions & 1 deletion pkg/morph/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,17 @@ func (e *notHaltStateError) Error() string {

// Invoke invokes contract method by sending transaction into blockchain.
// Supported args types: int64, string, util.Uint160, []byte and bool.
func (c *Client) Invoke(contract util.Uint160, fee fixedn.Fixed8, method string, args ...any) error {
func (c *Client) Invoke(contract util.Uint160, await bool, fee fixedn.Fixed8, method string, args ...any) error {
var conn = c.conn.Load()

if conn == nil {
return ErrConnectionLost
}

txHash, vub, err := conn.rpcActor.SendTunedCall(contract, method, nil, addFeeCheckerModifier(int64(fee)), args...)
if await {
_, err = conn.rpcActor.Wait(txHash, vub, err)
}
if err != nil {
return fmt.Errorf("could not invoke %s: %w", method, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/morph/client/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (c *Client) UpdateNeoFSAlphabetList(alphas keys.PublicKeys, txHash util.Uin
// `nonce` and `vub` are used only if notary is enabled.
func (c *Client) NotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce uint32, vub *uint32, method string, args ...any) error {
if c.notary == nil {
return c.Invoke(contract, fee, method, args...)
return c.Invoke(contract, false, fee, method, args...)
}

return c.notaryInvoke(false, true, contract, nonce, vub, method, args...)
Expand All @@ -324,7 +324,7 @@ func (c *Client) NotaryInvoke(contract util.Uint160, fee fixedn.Fixed8, nonce ui
// Considered to be used by non-IR nodes.
func (c *Client) NotaryInvokeNotAlpha(contract util.Uint160, fee fixedn.Fixed8, method string, args ...any) error {
if c.notary == nil {
return c.Invoke(contract, fee, method, args...)
return c.Invoke(contract, false, fee, method, args...)
}

return c.notaryInvoke(false, false, contract, rand.Uint32(), nil, method, args...)
Expand Down
9 changes: 9 additions & 0 deletions pkg/morph/client/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ func (s StaticClient) Morph() *Client {
type InvokePrm struct {
TestInvokePrm

await bool

// optional parameters
InvokePrmOptional
}

// Await makes invokation block until TX is included in chain OR
// Valid Until Block is reached. Works _only_ for non-notary requests.
func (i *InvokePrm) Await() {
i.await = true
}

// InvokePrmOptional groups optional parameters of the Invoke operation.
type InvokePrmOptional struct {
// hash is an optional hash of the transaction
Expand Down Expand Up @@ -145,6 +153,7 @@ func (s StaticClient) Invoke(prm InvokePrm) error {

return s.client.Invoke(
s.scScriptHash,
prm.await,
fee,
prm.method,
prm.args...,
Expand Down

0 comments on commit 863a404

Please sign in to comment.