[#107] Add client method ListFullSubjects
Signed-off-by: d.zverev <d.zverev@yadro.com>
This commit is contained in:
parent
0befe361fe
commit
a6eb53ee59
1 changed files with 39 additions and 0 deletions
|
@ -2,16 +2,22 @@ package client
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/commonclient"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/waiter"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
)
|
||||
|
||||
|
@ -260,6 +266,39 @@ func (c Client) ListSubjects() ([]util.Uint160, error) {
|
|||
return UnwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listSubjectsMethod))
|
||||
}
|
||||
|
||||
// ListFullSubjects gets list of subjects.
|
||||
func (c Client) ListFullSubjects(hashes []util.Uint160) ([]*Subject, error) {
|
||||
w := io.NewBufBinWriter()
|
||||
|
||||
for _, hash := range hashes {
|
||||
emit.AppCall(w.BinWriter, c.contract, getSubjectMethod, callflag.All, hash)
|
||||
}
|
||||
|
||||
invoker, err := c.act.Run(w.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if invoker.State != vmstate.Halt.String() {
|
||||
return nil, fmt.Errorf("invocation failed: %s", invoker.FaultException)
|
||||
}
|
||||
subjects := make([]*Subject, 0, len(invoker.Stack))
|
||||
|
||||
for _, item := range invoker.Stack {
|
||||
arr, ok := item.Value().([]stackitem.Item)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid subject")
|
||||
}
|
||||
|
||||
subject, err := ParseSubject(arr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subjects = append(subjects, subject)
|
||||
}
|
||||
|
||||
return subjects, nil
|
||||
}
|
||||
|
||||
// AddSubjectKey adds extra public key to subject.
|
||||
// Must be invoked by contract owner.
|
||||
func (c Client) AddSubjectKey(addr util.Uint160, key *keys.PublicKey) (tx util.Uint256, vub uint32, err error) {
|
||||
|
|
Loading…
Reference in a new issue