[#119] frostfsid: Add 'getSubjectKV'
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
5f956751d4
commit
ffd2763094
4 changed files with 40 additions and 0 deletions
|
@ -96,6 +96,7 @@ const (
|
||||||
createSubjectMethod = "createSubject"
|
createSubjectMethod = "createSubject"
|
||||||
getSubjectMethod = "getSubject"
|
getSubjectMethod = "getSubject"
|
||||||
getSubjectExtendedMethod = "getSubjectExtended"
|
getSubjectExtendedMethod = "getSubjectExtended"
|
||||||
|
getSubjectKVMethod = "getSubjectKV"
|
||||||
listSubjectsMethod = "listSubjects"
|
listSubjectsMethod = "listSubjects"
|
||||||
addSubjectKeyMethod = "addSubjectKey"
|
addSubjectKeyMethod = "addSubjectKey"
|
||||||
removeSubjectKeyMethod = "removeSubjectKey"
|
removeSubjectKeyMethod = "removeSubjectKey"
|
||||||
|
@ -266,6 +267,11 @@ func (c Client) GetSubjectExtended(addr util.Uint160) (*SubjectExtended, error)
|
||||||
return ParseSubjectExtended(items)
|
return ParseSubjectExtended(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSubjectKV invokes `getSubjectKV` method of contract.
|
||||||
|
func (c Client) GetSubjectKV(addr util.Uint160, name string) (string, error) {
|
||||||
|
return unwrap.UTF8String(c.act.Call(c.contract, getSubjectKVMethod, addr, name))
|
||||||
|
}
|
||||||
|
|
||||||
// ListSubjects gets all subjects.
|
// ListSubjects gets all subjects.
|
||||||
func (c Client) ListSubjects() ([]util.Uint160, error) {
|
func (c Client) ListSubjects() ([]util.Uint160, error) {
|
||||||
return UnwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listSubjectsMethod))
|
return UnwrapArrayOfUint160(commonclient.ReadIteratorItems(c.act, iteratorBatchSize, c.contract, listSubjectsMethod))
|
||||||
|
|
|
@ -7,6 +7,7 @@ safemethods:
|
||||||
- "getGroupByName"
|
- "getGroupByName"
|
||||||
- "getNamespace"
|
- "getNamespace"
|
||||||
- "getNamespaceExtended"
|
- "getNamespaceExtended"
|
||||||
|
- "getSubjectKV"
|
||||||
- "getSubject"
|
- "getSubject"
|
||||||
- "getSubjectExtended"
|
- "getSubjectExtended"
|
||||||
- "getSubjectByKey"
|
- "getSubjectByKey"
|
||||||
|
|
|
@ -472,6 +472,34 @@ func GetSubjectKeyByName(ns, name string) interop.PublicKey {
|
||||||
return subjKey
|
return subjKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSubjectKV GetSubjectKey returns the value associated with the key for the subject.
|
||||||
|
func GetSubjectKV(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)
|
||||||
|
|
||||||
|
if sbj.KV == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range sbj.KV {
|
||||||
|
if k == name {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func ListSubjects() iterator.Iterator {
|
func ListSubjects() iterator.Iterator {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
return storage.Find(ctx, []byte{subjectKeysPrefix}, storage.KeysOnly|storage.RemovePrefix)
|
return storage.Find(ctx, []byte{subjectKeysPrefix}, storage.KeysOnly|storage.RemovePrefix)
|
||||||
|
|
|
@ -222,6 +222,11 @@ func (c *ContractReader) GetSubjectExtended(addr util.Uint160) ([]stackitem.Item
|
||||||
return unwrap.Array(c.invoker.Call(c.hash, "getSubjectExtended", addr))
|
return unwrap.Array(c.invoker.Call(c.hash, "getSubjectExtended", addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSubjectKV invokes `getSubjectKV` method of contract.
|
||||||
|
func (c *ContractReader) GetSubjectKV(addr util.Uint160, name string) (string, error) {
|
||||||
|
return unwrap.UTF8String(c.invoker.Call(c.hash, "getSubjectKV", addr, name))
|
||||||
|
}
|
||||||
|
|
||||||
// GetSubjectKeyByName invokes `getSubjectKeyByName` method of contract.
|
// GetSubjectKeyByName invokes `getSubjectKeyByName` method of contract.
|
||||||
func (c *ContractReader) GetSubjectKeyByName(ns string, name string) (*keys.PublicKey, error) {
|
func (c *ContractReader) GetSubjectKeyByName(ns string, name string) (*keys.PublicKey, error) {
|
||||||
return unwrap.PublicKey(c.invoker.Call(c.hash, "getSubjectKeyByName", ns, name))
|
return unwrap.PublicKey(c.invoker.Call(c.hash, "getSubjectKeyByName", ns, name))
|
||||||
|
|
Loading…
Reference in a new issue