mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-21 23:29:38 +00:00
actor: add SignerAccounts() API
Allow to retrieve the list easily. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
8336b1b518
commit
cc3f528eb6
2 changed files with 21 additions and 3 deletions
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue