Skip to content

Commit

Permalink
invoker: add Signers() API
Browse files Browse the repository at this point in the history
Signers are very important for notary checks and keeping/passing an additional
copy of them is very inconvenient. Exposing them from invoker makes them
available in actors too.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Jun 20, 2024
1 parent 4ff2063 commit 9469f8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/rpcclient/invoker/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ func (h *historicConverter) TraverseIterator(sessionID, iteratorID uuid.UUID, ma
return h.client.TraverseIterator(sessionID, iteratorID, maxItemsCount)
}

// Signers returns the set of current invoker signers which is mostly useful
// when working with upper-layer actors. Returned slice is a newly allocated
// one (if this invoker has them), so it's safe to modify.
func (v *Invoker) Signers() []transaction.Signer {
if v.signers == nil {
return nil
}
var res = make([]transaction.Signer, len(v.signers))
copy(res, v.signers)
return res
}

// Call invokes a method of the contract with the given parameters (and
// Invoker-specific list of signers) and returns the result as is.
func (v *Invoker) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/rpcclient/invoker/invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,19 @@ func TestInvoker(t *testing.T) {
}
})
}

func TestInvokerSigners(t *testing.T) {
resExp := &result.Invoke{State: "HALT"}
ri := &rpcInv{resExp, true, nil, nil}
inv := New(ri, nil)

require.Nil(t, inv.Signers())

s := []transaction.Signer{}
inv = New(ri, s)
require.Equal(t, s, inv.Signers())

s = append(s, transaction.Signer{Account: util.Uint160{1, 2, 3}, Scopes: transaction.CalledByEntry})
inv = New(ri, s)
require.Equal(t, s, inv.Signers())
}

0 comments on commit 9469f8f

Please sign in to comment.