forked from TrueCloudLab/frostfs-contract
[#129] frostfsid: Return subject by an additional address
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
7a8c64b966
commit
a2c2791146
2 changed files with 27 additions and 11 deletions
|
@ -416,9 +416,14 @@ func GetSubject(addr interop.Hash160) Subject {
|
|||
ctx := storage.GetReadOnlyContext()
|
||||
sKey := subjectKeyFromAddr(addr)
|
||||
data := storage.Get(ctx, sKey).([]byte)
|
||||
if data == nil {
|
||||
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)
|
||||
}
|
||||
|
@ -469,18 +474,22 @@ func GetSubjectByKey(key interop.PublicKey) Subject {
|
|||
return std.Deserialize(data).(Subject)
|
||||
}
|
||||
|
||||
saPrefix := subjectAdditionalPrefix(key)
|
||||
it := storage.Find(ctx, saPrefix, storage.KeysOnly|storage.RemovePrefix)
|
||||
for iterator.Next(it) {
|
||||
addr := iterator.Value(it).([]byte)
|
||||
addr := getPrimaryAddr(ctx, contract.CreateStandardAccount(key))
|
||||
sKey = subjectKeyFromAddr(addr)
|
||||
data = storage.Get(ctx, sKey).([]byte)
|
||||
if data != nil {
|
||||
return std.Deserialize(data).(Subject)
|
||||
}
|
||||
break
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
|
|
|
@ -238,6 +238,13 @@ func TestFrostFSID_SubjectManagement(t *testing.T) {
|
|||
subj = parseSubject(t, s)
|
||||
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) {
|
||||
anonInvoker.InvokeFail(t, notWitnessedError, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||
invoker.Invoke(t, stackitem.Null{}, removeSubjectKeyMethod, subjKeyAddr, subjNewKey.PublicKey().Bytes())
|
||||
|
|
Loading…
Reference in a new issue