Skip to content

Commit

Permalink
actor: add SignerAccounts() API
Browse files Browse the repository at this point in the history
Allow to retrieve the list easily.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Jun 21, 2024
1 parent 8336b1b commit cc3f528
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 13 additions & 0 deletions pkg/rpcclient/actor/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,19 @@ func (a *Actor) SendUncheckedRun(script []byte, sysfee int64, attrs []transactio
return a.sendWrapper(a.MakeUncheckedRun(script, sysfee, attrs, txHook))
}

// SignerAccounts returns the array of actor's signers/accounts. It's useful in
// case you need it elsewhere like for notary-related processing. Returned slice
// is a newly allocated one with signers deeply copied, accounts however are not
// so changing received account internals is an error.
func (a *Actor) SignerAccounts() []SignerAccount {
var res = make([]SignerAccount, len(a.signers))
for i := range a.signers {
res[i].Signer = *a.signers[i].Signer.Copy()
res[i].Account = a.signers[i].Account
}
return res
}

// Sender return the sender address that will be used in transactions created
// by Actor.
func (a *Actor) Sender() util.Uint160 {
Expand Down
11 changes: 8 additions & 3 deletions pkg/rpcclient/actor/actor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ func TestNew(t *testing.T) {
// Good simple.
a, err := NewSimple(client, acc)
require.NoError(t, err)
require.Equal(t, 1, len(a.signers))
require.Equal(t, []SignerAccount{{
Signer: transaction.Signer{
Account: acc.ScriptHash(),
Scopes: transaction.CalledByEntry,
},
Account: acc,
}}, a.SignerAccounts())
require.Equal(t, 1, len(a.txSigners))
require.Equal(t, transaction.CalledByEntry, a.signers[0].Signer.Scopes)
require.Equal(t, transaction.CalledByEntry, a.txSigners[0].Scopes)

// Contractless account.
Expand Down Expand Up @@ -158,7 +163,7 @@ func TestNew(t *testing.T) {
signers[0].Signer.Account = acc.Contract.ScriptHash()
a, err = New(client, signers)
require.NoError(t, err)
require.Equal(t, 2, len(a.signers))
require.Equal(t, signers, a.SignerAccounts())
require.Equal(t, 2, len(a.txSigners))

// Good tuned
Expand Down

0 comments on commit cc3f528

Please sign in to comment.