frostfsid: Return subject by an additional address #129
2 changed files with 27 additions and 11 deletions
|
@ -417,7 +417,12 @@ func GetSubject(addr interop.Hash160) Subject {
|
||||||
sKey := subjectKeyFromAddr(addr)
|
sKey := subjectKeyFromAddr(addr)
|
||||||
data := storage.Get(ctx, sKey).([]byte)
|
data := storage.Get(ctx, sKey).([]byte)
|
||||||
if data == nil {
|
if data == nil {
|
||||||
panic("subject not found")
|
a := getPrimaryAddr(ctx, addr)
|
||||||
|
sKey = subjectKeyFromAddr(a)
|
||||||
|
data = storage.Get(ctx, sKey).([]byte)
|
||||||
|
if data == nil {
|
||||||
|
panic("subject not found")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return std.Deserialize(data).(Subject)
|
return std.Deserialize(data).(Subject)
|
||||||
|
@ -469,21 +474,25 @@ func GetSubjectByKey(key interop.PublicKey) Subject {
|
||||||
return std.Deserialize(data).(Subject)
|
return std.Deserialize(data).(Subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
saPrefix := subjectAdditionalPrefix(key)
|
addr := getPrimaryAddr(ctx, contract.CreateStandardAccount(key))
|
||||||
it := storage.Find(ctx, saPrefix, storage.KeysOnly|storage.RemovePrefix)
|
sKey = subjectKeyFromAddr(addr)
|
||||||
for iterator.Next(it) {
|
data = storage.Get(ctx, sKey).([]byte)
|
||||||
addr := iterator.Value(it).([]byte)
|
if data != nil {
|
||||||
sKey = subjectKeyFromAddr(addr)
|
return std.Deserialize(data).(Subject)
|
||||||
data = storage.Get(ctx, sKey).([]byte)
|
|
||||||
if data != nil {
|
|
||||||
return std.Deserialize(data).(Subject)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
panic("subject not found")
|
panic("subject not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPrimaryAddr(ctx storage.Context, addr interop.Hash160) interop.Hash160 {
|
||||||
|
saPrefix := append([]byte{additionalKeysPrefix}, addr...)
|
||||||
|
it := storage.Find(ctx, saPrefix, storage.KeysOnly|storage.RemovePrefix)
|
||||||
|
if iterator.Next(it) {
|
||||||
|
return iterator.Value(it).([]byte)
|
||||||
|
}
|
||||||
|
panic("subject not found")
|
||||||
|
}
|
||||||
|
|
||||||
// GetSubjectByName retrieves the subject with the specified name within the given namespace.
|
// GetSubjectByName retrieves the subject with the specified name within the given namespace.
|
||||||
func GetSubjectByName(ns, name string) Subject {
|
func GetSubjectByName(ns, name string) Subject {
|
||||||
key := GetSubjectKeyByName(ns, name)
|
key := GetSubjectKeyByName(ns, name)
|
||||||
|
|
|
@ -238,6 +238,13 @@ func TestFrostFSID_SubjectManagement(t *testing.T) {
|
||||||
subj = parseSubject(t, s)
|
subj = parseSubject(t, s)
|
||||||
require.True(t, subjKey.PublicKey().Equal(&subj.PrimaryKey), "keys must be the same")
|
require.True(t, subjKey.PublicKey().Equal(&subj.PrimaryKey), "keys must be the same")
|
||||||
|
|
||||||
|
t.Run("with GetSubject", func(t *testing.T) {
|
||||||
|
s, err = anonInvoker.TestInvoke(t, getSubjectMethod, subjKey.PublicKey().GetScriptHash())
|
||||||
|
require.NoError(t, err)
|
||||||
|
subj = parseSubject(t, s)
|
||||||
|
require.True(t, subjKey.PublicKey().Equal(&subj.PrimaryKey), "keys must be the same")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("remove subject key", func(t *testing.T) {
|
t.Run("remove subject key", func(t *testing.T) {
|
||||||
anonInvoker.InvokeFail(t, notWitnessedError, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
anonInvoker.InvokeFail(t, notWitnessedError, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||||
invoker.Invoke(t, stackitem.Null{}, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
invoker.Invoke(t, stackitem.Null{}, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||||
|
|
Loading…
Reference in a new issue