Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container: add alias method, fix #343 #360

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion container/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "NeoFS Container"
safemethods: ["count", "containersOf", "get", "owner", "list", "eACL", "getContainerSize", "listContainerSizes", "iterateContainerSizes", "iterateAllContainerSizes", "version"]
safemethods: ["alias", "count", "containersOf", "get", "owner", "list", "eACL", "getContainerSize", "listContainerSizes", "iterateContainerSizes", "iterateAllContainerSizes", "version"]
permissions:
- methods: ["update", "addKey", "transferX",
"register", "registerTLD", "addRecord", "deleteRecords"]
Expand Down
13 changes: 13 additions & 0 deletions container/container_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,19 @@ func Owner(containerID []byte) []byte {
return owner
}

// Alias method returns a string with an alias of the container if it's set
// (Null otherwise).
//
// If the container doesn't exist, it panics with NotFoundError.
func Alias(cid []byte) string {
ctx := storage.GetReadOnlyContext()
owner := getOwnerByID(ctx, cid)
if owner == nil {
panic(NotFoundError)
}
return storage.Get(ctx, append([]byte(nnsHasAliasKey), cid...)).(string)
}

// Count method returns the number of registered containers.
func Count() int {
count := 0
Expand Down
5 changes: 5 additions & 0 deletions rpc/container/rpcbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ func New(actor Actor, hash util.Uint160) *Contract {
return &Contract{ContractReader{actor, hash}, actor, hash}
}

// Alias invokes `alias` method of contract.
func (c *ContractReader) Alias(cid []byte) (string, error) {
return unwrap.UTF8String(c.invoker.Call(c.hash, "alias", cid))
}

// ContainersOf invokes `containersOf` method of contract.
func (c *ContractReader) ContainersOf(owner []byte) (uuid.UUID, result.Iterator, error) {
return unwrap.SessionIterator(c.invoker.Call(c.hash, "containersOf", owner))
Expand Down
2 changes: 2 additions & 0 deletions tests/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func TestContainerPut(t *testing.T) {
cAcc.InvokeFail(t, common.ErrAlphabetWitnessFailed, "put", putArgs...)

c.Invoke(t, stackitem.Null{}, "put", putArgs...)
c.Invoke(t, stackitem.Null{}, "alias", cnt.id[:])

t.Run("with nice names", func(t *testing.T) {
ctrNNS := neotest.CompileFile(t, c.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml"))
Expand All @@ -196,6 +197,7 @@ func TestContainerPut(t *testing.T) {
})
cNNS := c.CommitteeInvoker(nnsHash)
cNNS.Invoke(t, expected, "resolve", "mycnt.neofs", int64(nns.TXT))
c.Invoke(t, stackitem.NewByteArray([]byte("mycnt.neofs")), "alias", cnt.id[:])

t.Run("name is already taken", func(t *testing.T) {
c.InvokeFail(t, "name is already taken", "putNamed", putArgs...)
Expand Down
Loading