[#134] container: Use Hash256 for container ID in Delete()
All checks were successful
DCO action / DCO (pull_request) Successful in 53s
Code generation / Generate wrappers (pull_request) Successful in 1m53s
Tests / Tests (pull_request) Successful in 1m57s

This is what we use inside Put(). It leads to a better auto-generated
code.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-12-05 11:25:05 +03:00
parent 7e0f9b8b8e
commit 762d7f9f9f
Signed by: fyrchik
SSH key fingerprint: SHA256:m/TTwCzjnRkXgnzEx9X92ccxy1CcVeinOgDb3NPWWmg
3 changed files with 17 additions and 7 deletions

View file

@ -29,7 +29,7 @@ events:
- name: DeleteSuccess - name: DeleteSuccess
parameters: parameters:
- name: containerID - name: containerID
type: ByteArray type: Hash256
- name: SetEACLSuccess - name: SetEACLSuccess
parameters: parameters:
- name: containerID - name: containerID

View file

@ -279,7 +279,7 @@ func checkNiceNameAvailable(nnsContractAddr interop.Hash160, domain string) bool
// API. // API.
// //
// If the container doesn't exist, it panics with NotFoundError. // If the container doesn't exist, it panics with NotFoundError.
func Delete(containerID []byte, signature interop.Signature, publicKey interop.PublicKey, token []byte) { func Delete(containerID interop.Hash256, signature interop.Signature, publicKey interop.PublicKey, token []byte) {
ctx := storage.GetContext() ctx := storage.GetContext()
ownerID := getOwnerByID(ctx, containerID) ownerID := getOwnerByID(ctx, containerID)

View file

@ -25,7 +25,7 @@ type PutSuccessEvent struct {
// DeleteSuccessEvent represents "DeleteSuccess" event emitted by the contract. // DeleteSuccessEvent represents "DeleteSuccess" event emitted by the contract.
type DeleteSuccessEvent struct { type DeleteSuccessEvent struct {
ContainerID []byte ContainerID util.Uint256
} }
// SetEACLSuccessEvent represents "SetEACLSuccess" event emitted by the contract. // SetEACLSuccessEvent represents "SetEACLSuccess" event emitted by the contract.
@ -163,14 +163,14 @@ func (c *ContractReader) Version() (*big.Int, error) {
// Delete creates a transaction invoking `delete` method of the contract. // Delete creates a transaction invoking `delete` method of the contract.
// This transaction is signed and immediately sent to the network. // This transaction is signed and immediately sent to the network.
// The values returned are its hash, ValidUntilBlock value and error if any. // The values returned are its hash, ValidUntilBlock value and error if any.
func (c *Contract) Delete(containerID []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) { func (c *Contract) Delete(containerID util.Uint256, signature []byte, publicKey *keys.PublicKey, token []byte) (util.Uint256, uint32, error) {
return c.actor.SendCall(c.hash, "delete", containerID, signature, publicKey, token) return c.actor.SendCall(c.hash, "delete", containerID, signature, publicKey, token)
} }
// DeleteTransaction creates a transaction invoking `delete` method of the contract. // DeleteTransaction creates a transaction invoking `delete` method of the contract.
// This transaction is signed, but not sent to the network, instead it's // This transaction is signed, but not sent to the network, instead it's
// returned to the caller. // returned to the caller.
func (c *Contract) DeleteTransaction(containerID []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { func (c *Contract) DeleteTransaction(containerID util.Uint256, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
return c.actor.MakeCall(c.hash, "delete", containerID, signature, publicKey, token) return c.actor.MakeCall(c.hash, "delete", containerID, signature, publicKey, token)
} }
@ -178,7 +178,7 @@ func (c *Contract) DeleteTransaction(containerID []byte, signature []byte, publi
// This transaction is not signed, it's simply returned to the caller. // This transaction is not signed, it's simply returned to the caller.
// Any fields of it that do not affect fees can be changed (ValidUntilBlock, // Any fields of it that do not affect fees can be changed (ValidUntilBlock,
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well. // Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
func (c *Contract) DeleteUnsigned(containerID []byte, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) { func (c *Contract) DeleteUnsigned(containerID util.Uint256, signature []byte, publicKey *keys.PublicKey, token []byte) (*transaction.Transaction, error) {
return c.actor.MakeUnsignedCall(c.hash, "delete", nil, containerID, signature, publicKey, token) return c.actor.MakeUnsignedCall(c.hash, "delete", nil, containerID, signature, publicKey, token)
} }
@ -480,7 +480,17 @@ func (e *DeleteSuccessEvent) FromStackItem(item *stackitem.Array) error {
err error err error
) )
index++ index++
e.ContainerID, err = arr[index].TryBytes() e.ContainerID, err = func(item stackitem.Item) (util.Uint256, error) {
b, err := item.TryBytes()
if err != nil {
return util.Uint256{}, err
}
u, err := util.Uint256DecodeBytesBE(b)
if err != nil {
return util.Uint256{}, err
}
return u, nil
}(arr[index])
if err != nil { if err != nil {
return fmt.Errorf("field ContainerID: %w", err) return fmt.Errorf("field ContainerID: %w", err)
} }