From de118c4e0ce6b0de994490cba226656332f1fdd9 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 11 Dec 2024 19:31:10 +0300 Subject: [PATCH] container/put: allow using a single method for every container put The old (already released) ways are kept. Not it is possible to call "put" as Put (4 args), PutNamed (6 args) and PutMeta (7 args). On the client side, it is acceptable to always call "put" with 7 args and just be sure that the last 3 are meaningful. Signed-off-by: Pavel Karpy --- contracts/container/config.yml | 1 + contracts/container/contract.go | 19 ++++++++++++----- contracts/container/contract.nef | Bin 8937 -> 8954 bytes contracts/container/manifest.json | 2 +- rpc/container/rpcbinding.go | 34 ++++++++++++++++++++++++------ tests/container_test.go | 12 +++++------ 6 files changed, 50 insertions(+), 18 deletions(-) diff --git a/contracts/container/config.yml b/contracts/container/config.yml index 051c9497..6e1bbe61 100644 --- a/contracts/container/config.yml +++ b/contracts/container/config.yml @@ -42,3 +42,4 @@ events: type: Map overloads: putMeta: put + putNamedOverloaded: put diff --git a/contracts/container/contract.go b/contracts/container/contract.go index 3ba1b8b2..5cd1ace5 100644 --- a/contracts/container/contract.go +++ b/contracts/container/contract.go @@ -296,16 +296,18 @@ func getFromMap(m map[string]any, key string) any { return m[key] } -// PutMeta is the same as [Put] (and exposed as put from the contract via -// overload), but allows container's meta-information be handled and notified -// using the chain. -func PutMeta(container []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte, metaOnChain bool) { +// PutMeta is the same as [Put] and [PutNamed] (and exposed as put from +// the contract via overload), but allows named containers and container's +// meta-information be handled and notified using the chain. If name and +// zone are non-empty strings, it behaves the same as [PutNamed]; empty +// strings make a regular [Put] call. +func PutMeta(container []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte, name, zone string, metaOnChain bool) { if metaOnChain { ctx := storage.GetContext() cID := crypto.Sha256(container) storage.Put(ctx, append([]byte{containersWithMetaPrefix}, cID...), []byte{}) } - Put(container, signature, publicKey, token) + PutNamed(container, signature, publicKey, token, name, zone) } // Put method creates a new container if it has been invoked by Alphabet nodes @@ -320,8 +322,15 @@ func Put(container []byte, signature interop.Signature, publicKey interop.Public PutNamed(container, signature, publicKey, token, "", "") } +// PutNamedOverloaded is the same as [Put] (and exposed as put from the contract via +// overload), but allows named container creation via NNS contract. +func PutNamedOverloaded(container []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte, name, zone string) { + PutNamed(container, signature, publicKey, token, name, zone) +} + // PutNamed is similar to put but also sets a TXT record in nns contract. // Note that zone must exist. +// DEPRECATED: call [Put] with the same args instead. func PutNamed(container []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte, name, zone string) { diff --git a/contracts/container/contract.nef b/contracts/container/contract.nef index 9648075777ac6d07dc8d6f5c066917ae0d7856f1..a6eca852b0fe3515cd4cfcbce530e4b46eca5756 100755 GIT binary patch delta 196 zcmV;#06YKbMfydsHUa^@vo``93IVB;R19bW2Y!>j3^X8oeHK+TAwX9E1bBIRdkg>! z02Wm=5kOY}26%aTdwhM90S)d6Z}QL zy#eC0lo5yn1X=U{|C8|-6O$Sm8M90kjRFCjv)UI90|AYb=^7saB9jRloB`UirW;EF y5`^mi|7dtnHGu>G06jf3^Wf^Gy_0a00ek>dV3523;>f7 z4ekkm_y7NQ328M}vk49x0S9yW|Nm+=NwX^ty8!{Kljjh<0rRt^5r_i;YO^jCyaEBO zv+EZQ0|B0s`WhbrGm{z{oB`{zw;M|W5|!%z|7dtnHGu>G06