[#118] frostfsid: Add 'GetValueForSubjectKey'

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2024-10-21 14:26:35 +03:00
parent 3f4f8feca7
commit dda8ad5246
Signed by: achuprov
GPG key ID: 2D916FFD803B0EDD
3 changed files with 30 additions and 0 deletions

View file

@ -7,6 +7,7 @@ safemethods:
- "getGroupByName"
- "getNamespace"
- "getNamespaceExtended"
- "getValueForSubjectKey"
- "getSubject"
- "getSubjectExtended"
- "getSubjectByKey"

View file

@ -472,6 +472,30 @@ func GetSubjectKeyByName(ns, name string) interop.PublicKey {
return subjKey
}
// GetSubjectKey returns the value associated with the key for the subject.
func GetValueForSubjectKey(addr interop.Hash160, name string) string {
if len(addr) != interop.Hash160Len {
panic("incorrect address length")
}
ctx := storage.GetReadOnlyContext()
sKey := subjectKeyFromAddr(addr)
data := storage.Get(ctx, sKey).([]byte)
if data == nil {
return ""
}
sbj := std.Deserialize(data).(Subject)
for k, v := range sbj.KV {
if k == name {
return v
}
}
return ""
}
func ListSubjects() iterator.Iterator {
ctx := storage.GetReadOnlyContext()
return storage.Find(ctx, []byte{subjectKeysPrefix}, storage.KeysOnly|storage.RemovePrefix)

View file

@ -227,6 +227,11 @@ func (c *ContractReader) GetSubjectKeyByName(ns string, name string) (*keys.Publ
return unwrap.PublicKey(c.invoker.Call(c.hash, "getSubjectKeyByName", ns, name))
}
// GetValueForSubjectKey invokes `getValueForSubjectKey` method of contract.
func (c *ContractReader) GetValueForSubjectKey(addr util.Uint160, name string) (string, error) {
return unwrap.UTF8String(c.invoker.Call(c.hash, "getValueForSubjectKey", addr, name))
}
// ListGroupSubjects invokes `listGroupSubjects` method of contract.
func (c *ContractReader) ListGroupSubjects(ns string, groupID *big.Int) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "listGroupSubjects", ns, groupID))