[#119] frostfsid: Add 'GetValueForSubjectKey'
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
5f956751d4
commit
db79f79f72
3 changed files with 30 additions and 0 deletions
|
@ -7,6 +7,7 @@ safemethods:
|
|||
- "getGroupByName"
|
||||
- "getNamespace"
|
||||
- "getNamespaceExtended"
|
||||
- "getValueForSubjectKey"
|
||||
- "getSubject"
|
||||
- "getSubjectExtended"
|
||||
- "getSubjectByKey"
|
||||
|
|
|
@ -472,6 +472,30 @@ func GetSubjectKeyByName(ns, name string) interop.PublicKey {
|
|||
return subjKey
|
||||
}
|
||||
|
||||
// GetValueForSubjectKey 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)
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue