[#107] Add client method ListFullSubjects #107

Merged
fyrchik merged 1 commit from d.zverev/frostfs-contract:feature/frostfsid-add-list-subjects into master 2024-08-28 09:18:25 +00:00

View file

@ -7,11 +7,16 @@ import (
"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 +265,39 @@ func (c Client) ListSubjects() ([]util.Uint160, error) {
return UnwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listSubjectsMethod))
}
// ListFullSubjects gets list of subjects.

Please update comment accordingly to method.

Please update comment accordingly to method.

Fixed.

Fixed.
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))
fyrchik marked this conversation as resolved Outdated

please, just var subjects []*Subject or preallocate with make([]*Subject, 0, len(invoker.Stack))

please, just `var subjects []*Subject` or preallocate with `make([]*Subject, 0, len(invoker.Stack))`

Changed to var subjects []*Subject

Changed to `var subjects []*Subject`
dkirillov marked this conversation as resolved Outdated

Should we pre-allocatate memory for slice? It seems we know exact size

Should we pre-allocatate memory for slice? It seems we know exact size

Should we pre-allocatate memory for slice? It seems we know exact size

Should we pre-allocatate memory for slice? It seems we know exact size

We can, but according previous comment i choose another option.
I can change it to pre-allocated memory if you prefer this type of definition.

We can, but according previous [comment](https://git.frostfs.info/TrueCloudLab/frostfs-contract/pulls/107#issuecomment-49158) i choose another option. I can change it to pre-allocated memory if you prefer this type of definition.

Fixed.

Fixed.
for _, item := range invoker.Stack {
arr, ok := item.Value().([]stackitem.Item)

Do we need val here?

Do we need `val` here?

Yes, i miss type conversion check.
Add check.

Yes, i miss type conversion check. Add check.
if !ok {
return nil, fmt.Errorf("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) {