invoker: add Signers() API

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 <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2024-06-20 17:12:35 +03:00
parent 4ff2063539
commit 8336b1b518
2 changed files with 30 additions and 0 deletions

View file

@ -137,6 +137,20 @@ 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))
for i := range v.signers {
res[i] = *v.signers[i].Copy()
}
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) {

View file

@ -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())
}