forked from TrueCloudLab/frostfs-contract
[#54] policy: Accept []byte as name
Strings cannot contain non-UTF8 bytes, this is ensured in JSON marshaling/unmarshaling. At the same time using human-readable strings can be rather restrictive, because we have 64-byte key limit. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
f30fb324ff
commit
edf3c26047
2 changed files with 19 additions and 19 deletions
|
@ -74,14 +74,14 @@ func getAdmin(ctx storage.Context) interop.Hash160 {
|
|||
return storage.Get(ctx, []byte{ownerKeyPrefix}).(interop.Hash160)
|
||||
}
|
||||
|
||||
func storageKey(prefix Kind, entityName, name string) []byte {
|
||||
func storageKey(prefix Kind, entityName string, name []byte) []byte {
|
||||
ln := len(entityName)
|
||||
key := append([]byte{byte(prefix)}, byte(ln&0xFF), byte(ln>>8))
|
||||
key = append(key, entityName...)
|
||||
return append(key, name...)
|
||||
}
|
||||
|
||||
func AddChain(entity Kind, entityName, name string, chain []byte) {
|
||||
func AddChain(entity Kind, entityName string, name []byte, chain []byte) {
|
||||
ctx := storage.GetContext()
|
||||
checkAuthorization(ctx)
|
||||
|
||||
|
@ -89,7 +89,7 @@ func AddChain(entity Kind, entityName, name string, chain []byte) {
|
|||
storage.Put(ctx, key, chain)
|
||||
}
|
||||
|
||||
func GetChain(entity Kind, entityName, name string) []byte {
|
||||
func GetChain(entity Kind, entityName string, name []byte) []byte {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
key := storageKey(entity, entityName, name)
|
||||
data := storage.Get(ctx, key).([]byte)
|
||||
|
@ -100,7 +100,7 @@ func GetChain(entity Kind, entityName, name string) []byte {
|
|||
return data
|
||||
}
|
||||
|
||||
func RemoveChain(entity Kind, entityName string, name string) {
|
||||
func RemoveChain(entity Kind, entityName string, name []byte) {
|
||||
ctx := storage.GetContext()
|
||||
checkAuthorization(ctx)
|
||||
|
||||
|
@ -108,7 +108,7 @@ func RemoveChain(entity Kind, entityName string, name string) {
|
|||
storage.Delete(ctx, key)
|
||||
}
|
||||
|
||||
func RemoveChainsByPrefix(entity Kind, entityName string, name string) {
|
||||
func RemoveChainsByPrefix(entity Kind, entityName string, name []byte) {
|
||||
ctx := storage.GetContext()
|
||||
checkAuthorization(ctx)
|
||||
|
||||
|
@ -121,7 +121,7 @@ func RemoveChainsByPrefix(entity Kind, entityName string, name string) {
|
|||
|
||||
// ListChains lists all chains for the namespace by prefix.
|
||||
// container may be empty.
|
||||
func ListChains(namespace, container, name string) [][]byte {
|
||||
func ListChains(namespace, container string, name []byte) [][]byte {
|
||||
result := ListChainsByPrefix(Namespace, namespace, name)
|
||||
|
||||
if container != "" {
|
||||
|
@ -132,7 +132,7 @@ func ListChains(namespace, container, name string) [][]byte {
|
|||
}
|
||||
|
||||
// ListChainsByPrefix list all chains for the provided kind and entity by prefix.
|
||||
func ListChainsByPrefix(entity Kind, entityName, prefix string) [][]byte {
|
||||
func ListChainsByPrefix(entity Kind, entityName string, prefix []byte) [][]byte {
|
||||
ctx := storage.GetReadOnlyContext()
|
||||
|
||||
result := [][]byte{}
|
||||
|
|
|
@ -58,31 +58,31 @@ func (c *ContractReader) GetAdmin() (util.Uint160, error) {
|
|||
}
|
||||
|
||||
// GetChain invokes `getChain` method of contract.
|
||||
func (c *ContractReader) GetChain(entity *big.Int, entityName string, name string) ([]byte, error) {
|
||||
func (c *ContractReader) GetChain(entity *big.Int, entityName string, name []byte) ([]byte, error) {
|
||||
return unwrap.Bytes(c.invoker.Call(c.hash, "getChain", entity, entityName, name))
|
||||
}
|
||||
|
||||
// ListChains invokes `listChains` method of contract.
|
||||
func (c *ContractReader) ListChains(namespace string, container string, name string) ([]stackitem.Item, error) {
|
||||
func (c *ContractReader) ListChains(namespace string, container string, name []byte) ([]stackitem.Item, error) {
|
||||
return unwrap.Array(c.invoker.Call(c.hash, "listChains", namespace, container, name))
|
||||
}
|
||||
|
||||
// ListChainsByPrefix invokes `listChainsByPrefix` method of contract.
|
||||
func (c *ContractReader) ListChainsByPrefix(entity *big.Int, entityName string, prefix string) ([]stackitem.Item, error) {
|
||||
func (c *ContractReader) ListChainsByPrefix(entity *big.Int, entityName string, prefix []byte) ([]stackitem.Item, error) {
|
||||
return unwrap.Array(c.invoker.Call(c.hash, "listChainsByPrefix", entity, entityName, prefix))
|
||||
}
|
||||
|
||||
// AddChain creates a transaction invoking `addChain` method of the contract.
|
||||
// This transaction is signed and immediately sent to the network.
|
||||
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||
func (c *Contract) AddChain(entity *big.Int, entityName string, name string, chain []byte) (util.Uint256, uint32, error) {
|
||||
func (c *Contract) AddChain(entity *big.Int, entityName string, name []byte, chain []byte) (util.Uint256, uint32, error) {
|
||||
return c.actor.SendCall(c.hash, "addChain", entity, entityName, name, chain)
|
||||
}
|
||||
|
||||
// AddChainTransaction creates a transaction invoking `addChain` method of the contract.
|
||||
// This transaction is signed, but not sent to the network, instead it's
|
||||
// returned to the caller.
|
||||
func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name string, chain []byte) (*transaction.Transaction, error) {
|
||||
func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name []byte, chain []byte) (*transaction.Transaction, error) {
|
||||
return c.actor.MakeCall(c.hash, "addChain", entity, entityName, name, chain)
|
||||
}
|
||||
|
||||
|
@ -90,21 +90,21 @@ func (c *Contract) AddChainTransaction(entity *big.Int, entityName string, name
|
|||
// 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,
|
||||
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||
func (c *Contract) AddChainUnsigned(entity *big.Int, entityName string, name string, chain []byte) (*transaction.Transaction, error) {
|
||||
func (c *Contract) AddChainUnsigned(entity *big.Int, entityName string, name []byte, chain []byte) (*transaction.Transaction, error) {
|
||||
return c.actor.MakeUnsignedCall(c.hash, "addChain", nil, entity, entityName, name, chain)
|
||||
}
|
||||
|
||||
// RemoveChain creates a transaction invoking `removeChain` method of the contract.
|
||||
// This transaction is signed and immediately sent to the network.
|
||||
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||
func (c *Contract) RemoveChain(entity *big.Int, entityName string, name string) (util.Uint256, uint32, error) {
|
||||
func (c *Contract) RemoveChain(entity *big.Int, entityName string, name []byte) (util.Uint256, uint32, error) {
|
||||
return c.actor.SendCall(c.hash, "removeChain", entity, entityName, name)
|
||||
}
|
||||
|
||||
// RemoveChainTransaction creates a transaction invoking `removeChain` method of the contract.
|
||||
// This transaction is signed, but not sent to the network, instead it's
|
||||
// returned to the caller.
|
||||
func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
|
||||
func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||
return c.actor.MakeCall(c.hash, "removeChain", entity, entityName, name)
|
||||
}
|
||||
|
||||
|
@ -112,21 +112,21 @@ func (c *Contract) RemoveChainTransaction(entity *big.Int, entityName string, na
|
|||
// 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,
|
||||
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||
func (c *Contract) RemoveChainUnsigned(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
|
||||
func (c *Contract) RemoveChainUnsigned(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||
return c.actor.MakeUnsignedCall(c.hash, "removeChain", nil, entity, entityName, name)
|
||||
}
|
||||
|
||||
// RemoveChainsByPrefix creates a transaction invoking `removeChainsByPrefix` method of the contract.
|
||||
// This transaction is signed and immediately sent to the network.
|
||||
// The values returned are its hash, ValidUntilBlock value and error if any.
|
||||
func (c *Contract) RemoveChainsByPrefix(entity *big.Int, entityName string, name string) (util.Uint256, uint32, error) {
|
||||
func (c *Contract) RemoveChainsByPrefix(entity *big.Int, entityName string, name []byte) (util.Uint256, uint32, error) {
|
||||
return c.actor.SendCall(c.hash, "removeChainsByPrefix", entity, entityName, name)
|
||||
}
|
||||
|
||||
// RemoveChainsByPrefixTransaction creates a transaction invoking `removeChainsByPrefix` method of the contract.
|
||||
// This transaction is signed, but not sent to the network, instead it's
|
||||
// returned to the caller.
|
||||
func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
|
||||
func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||
return c.actor.MakeCall(c.hash, "removeChainsByPrefix", entity, entityName, name)
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ func (c *Contract) RemoveChainsByPrefixTransaction(entity *big.Int, entityName s
|
|||
// 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,
|
||||
// Nonce), fee values (NetworkFee, SystemFee) can be increased as well.
|
||||
func (c *Contract) RemoveChainsByPrefixUnsigned(entity *big.Int, entityName string, name string) (*transaction.Transaction, error) {
|
||||
func (c *Contract) RemoveChainsByPrefixUnsigned(entity *big.Int, entityName string, name []byte) (*transaction.Transaction, error) {
|
||||
return c.actor.MakeUnsignedCall(c.hash, "removeChainsByPrefix", nil, entity, entityName, name)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue