2023-01-09 11:22:59 +00:00
|
|
|
package frostfs
|
2020-03-30 13:59:54 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-07 11:06:21 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
2020-12-09 13:27:39 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
2020-07-16 12:06:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
2020-07-16 15:59:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
2021-02-09 11:55:58 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
2021-09-20 15:41:46 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
2021-02-11 15:55:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
2021-09-20 15:41:46 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
|
2021-03-12 12:16:36 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
2020-03-30 13:59:54 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
)
|
|
|
|
|
2020-05-27 12:23:44 +00:00
|
|
|
type (
|
2020-07-16 15:59:49 +00:00
|
|
|
record struct {
|
|
|
|
key []byte
|
|
|
|
val []byte
|
|
|
|
}
|
2020-05-27 12:23:44 +00:00
|
|
|
)
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2020-05-27 12:23:44 +00:00
|
|
|
const (
|
2021-11-16 10:03:51 +00:00
|
|
|
// CandidateFeeConfigKey contains fee for a candidate registration.
|
|
|
|
CandidateFeeConfigKey = "InnerRingCandidateFee"
|
2021-04-20 14:44:36 +00:00
|
|
|
withdrawFeeConfigKey = "WithdrawFee"
|
2020-07-20 13:09:40 +00:00
|
|
|
|
2021-04-27 10:48:40 +00:00
|
|
|
alphabetKey = "alphabet"
|
|
|
|
candidatesKey = "candidates"
|
|
|
|
notaryDisabledKey = "notary"
|
2020-07-20 13:09:40 +00:00
|
|
|
|
2021-04-20 14:44:36 +00:00
|
|
|
processingContractKey = "processingScriptHash"
|
|
|
|
|
2021-06-30 10:59:32 +00:00
|
|
|
maxBalanceAmount = 9000 // Max integer of Fixed12 in JSON bound (2**53-1)
|
2022-07-06 09:22:43 +00:00
|
|
|
maxBalanceAmountGAS = int64(maxBalanceAmount) * 1_0000_0000
|
2020-12-09 13:27:39 +00:00
|
|
|
|
|
|
|
// hardcoded value to ignore deposit notification in onReceive
|
|
|
|
ignoreDepositNotification = "\x57\x0b"
|
2020-05-27 12:23:44 +00:00
|
|
|
)
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2021-02-11 16:13:49 +00:00
|
|
|
var (
|
|
|
|
configPrefix = []byte("config")
|
|
|
|
)
|
2020-07-16 15:59:49 +00:00
|
|
|
|
2021-05-12 08:31:07 +00:00
|
|
|
// _deploy sets up initial alphabet node keys.
|
|
|
|
func _deploy(data interface{}, isUpdate bool) {
|
2022-03-21 11:01:45 +00:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
2023-03-07 08:21:11 +00:00
|
|
|
common.RmAndCheckNotaryDisabledKey(data, notaryDisabledKey)
|
|
|
|
|
2021-06-03 07:49:07 +00:00
|
|
|
if isUpdate {
|
2022-02-01 08:36:18 +00:00
|
|
|
args := data.([]interface{})
|
|
|
|
common.CheckVersion(args[len(args)-1].(int))
|
2021-06-03 07:49:07 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:34:11 +00:00
|
|
|
args := data.(struct {
|
2023-03-07 08:21:11 +00:00
|
|
|
//TODO(@acid-ant): #9 remove notaryDisabled in future version
|
2021-11-29 16:34:11 +00:00
|
|
|
notaryDisabled bool
|
|
|
|
addrProc interop.Hash160
|
|
|
|
keys []interop.PublicKey
|
|
|
|
config [][]byte
|
|
|
|
})
|
2021-05-12 08:31:07 +00:00
|
|
|
|
2021-11-29 16:34:11 +00:00
|
|
|
if len(args.keys) == 0 {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("at least one alphabet key must be provided")
|
2020-09-17 08:08:41 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 16:43:01 +00:00
|
|
|
if len(args.addrProc) != interop.Hash160Len {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("incorrect length of contract script hash")
|
2021-04-20 14:44:36 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 16:34:11 +00:00
|
|
|
for i := 0; i < len(args.keys); i++ {
|
|
|
|
pub := args.keys[i]
|
2021-11-29 16:43:01 +00:00
|
|
|
if len(pub) != interop.PublicKeyCompressedLen {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("incorrect public key length")
|
2020-09-17 08:08:41 +00:00
|
|
|
}
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 12:06:49 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
// initialize all storage slices
|
2022-03-21 11:01:45 +00:00
|
|
|
common.SetSerialized(ctx, alphabetKey, args.keys)
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2021-11-29 16:34:11 +00:00
|
|
|
storage.Put(ctx, processingContractKey, args.addrProc)
|
2021-02-11 15:55:32 +00:00
|
|
|
|
2021-11-29 16:34:11 +00:00
|
|
|
ln := len(args.config)
|
2021-07-29 12:02:25 +00:00
|
|
|
if ln%2 != 0 {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("bad configuration")
|
2021-07-29 12:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < ln/2; i++ {
|
2021-11-29 16:34:11 +00:00
|
|
|
key := args.config[i*2]
|
|
|
|
val := args.config[i*2+1]
|
2021-07-29 12:02:25 +00:00
|
|
|
|
|
|
|
setConfig(ctx, key, val)
|
|
|
|
}
|
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
runtime.Log("frostfs: contract initialized")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 12:06:49 +00:00
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// Update method updates contract source code and manifest. It can be invoked
|
|
|
|
// only by sidechain committee.
|
2021-09-21 12:58:37 +00:00
|
|
|
func Update(script []byte, manifest []byte, data interface{}) {
|
2021-09-20 15:41:46 +00:00
|
|
|
blockHeight := ledger.CurrentIndex()
|
2022-01-11 08:25:10 +00:00
|
|
|
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
2021-09-20 15:41:46 +00:00
|
|
|
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
2021-03-09 19:15:58 +00:00
|
|
|
|
2023-02-10 15:07:44 +00:00
|
|
|
if !runtime.CheckWitness(alphabetCommittee) {
|
|
|
|
panic(common.ErrAlphabetWitnessFailed)
|
|
|
|
}
|
2021-02-11 15:55:32 +00:00
|
|
|
|
2023-06-19 08:17:51 +00:00
|
|
|
management.UpdateWithData(script, manifest, common.AppendVersion(data))
|
2023-01-09 11:22:59 +00:00
|
|
|
runtime.Log("frostfs contract updated")
|
2021-02-11 15:55:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// AlphabetAddress returns 2\3n+1 multisignature address of alphabet nodes.
|
|
|
|
// It is used in sidechain notary disabled environment.
|
2021-04-20 14:27:15 +00:00
|
|
|
func AlphabetAddress() interop.Hash160 {
|
|
|
|
ctx := storage.GetReadOnlyContext()
|
2022-03-21 11:04:21 +00:00
|
|
|
return multiaddress(getAlphabetNodes(ctx))
|
2021-04-20 14:27:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// InnerRingCandidates returns an array of structures that contain an Inner Ring
|
2021-07-16 06:03:34 +00:00
|
|
|
// candidate node key.
|
2021-02-02 18:26:34 +00:00
|
|
|
func InnerRingCandidates() []common.IRNode {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetReadOnlyContext()
|
2021-11-16 10:03:51 +00:00
|
|
|
nodes := []common.IRNode{}
|
|
|
|
|
|
|
|
it := storage.Find(ctx, candidatesKey, storage.KeysOnly|storage.RemovePrefix)
|
|
|
|
for iterator.Next(it) {
|
|
|
|
pub := iterator.Value(it).([]byte)
|
|
|
|
nodes = append(nodes, common.IRNode{PublicKey: pub})
|
|
|
|
}
|
|
|
|
return nodes
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// InnerRingCandidateRemove removes a key from a list of Inner Ring candidates.
|
|
|
|
// It can be invoked by Alphabet nodes or the candidate itself.
|
2021-07-16 06:03:34 +00:00
|
|
|
//
|
2022-04-14 11:56:51 +00:00
|
|
|
// This method does not return fee back to the candidate.
|
2021-05-21 11:37:31 +00:00
|
|
|
func InnerRingCandidateRemove(key interop.PublicKey) {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetContext()
|
2021-04-29 13:15:29 +00:00
|
|
|
|
|
|
|
keyOwner := runtime.CheckWitness(key)
|
|
|
|
|
|
|
|
if !keyOwner {
|
2023-03-07 08:21:11 +00:00
|
|
|
multiaddr := AlphabetAddress()
|
|
|
|
if !runtime.CheckWitness(multiaddr) {
|
|
|
|
panic("this method must be invoked by candidate or alphabet")
|
2021-04-29 13:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 10:03:51 +00:00
|
|
|
prefix := []byte(candidatesKey)
|
|
|
|
stKey := append(prefix, key...)
|
|
|
|
if storage.Get(ctx, stKey) != nil {
|
|
|
|
storage.Delete(ctx, stKey)
|
|
|
|
runtime.Log("candidate has been removed")
|
|
|
|
}
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// InnerRingCandidateAdd adds a key to a list of Inner Ring candidates.
|
|
|
|
// It can be invoked only by the candidate itself.
|
2021-07-16 06:03:34 +00:00
|
|
|
//
|
2022-04-14 11:56:51 +00:00
|
|
|
// This method transfers fee from a candidate to the contract account.
|
2023-01-09 11:22:59 +00:00
|
|
|
// Fee value is specified in FrostFS network config with the key InnerRingCandidateFee.
|
2021-05-21 11:37:31 +00:00
|
|
|
func InnerRingCandidateAdd(key interop.PublicKey) {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
2021-11-29 12:21:40 +00:00
|
|
|
common.CheckWitness(key)
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2021-11-16 10:03:51 +00:00
|
|
|
stKey := append([]byte(candidatesKey), key...)
|
|
|
|
if storage.Get(ctx, stKey) != nil {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("candidate already in the list")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
from := contract.CreateStandardAccount(key)
|
|
|
|
to := runtime.GetExecutingScriptHash()
|
2021-11-16 10:03:51 +00:00
|
|
|
fee := getConfig(ctx, CandidateFeeConfigKey).(int)
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2021-02-09 11:55:58 +00:00
|
|
|
transferred := gas.Transfer(from, to, fee, []byte(ignoreDepositNotification))
|
2020-08-26 09:15:07 +00:00
|
|
|
if !transferred {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("failed to transfer funds, aborting")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-15 08:51:49 +00:00
|
|
|
|
2021-11-16 10:03:51 +00:00
|
|
|
storage.Put(ctx, stKey, []byte{1})
|
2021-11-30 09:02:59 +00:00
|
|
|
runtime.Log("candidate has been added")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2021-02-08 15:14:03 +00:00
|
|
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
2022-04-14 11:56:51 +00:00
|
|
|
// It takes no more than 9000.0 GAS. Native GAS has precision 8, and
|
2023-01-09 11:22:59 +00:00
|
|
|
// FrostFS balance contract has precision 12. Values bigger than 9000.0 can
|
2021-07-16 06:03:34 +00:00
|
|
|
// break JSON limits for integers when precision is converted.
|
2021-02-08 15:14:03 +00:00
|
|
|
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
2020-12-09 13:27:39 +00:00
|
|
|
rcv := data.(interop.Hash160)
|
2021-02-02 17:36:20 +00:00
|
|
|
if common.BytesEqual(rcv, []byte(ignoreDepositNotification)) {
|
2020-12-09 13:27:39 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-17 06:30:39 +00:00
|
|
|
if amount <= 0 {
|
2021-11-30 09:44:05 +00:00
|
|
|
common.AbortWithMessage("amount must be positive")
|
2022-07-06 09:22:43 +00:00
|
|
|
} else if maxBalanceAmountGAS < int64(amount) {
|
2021-11-30 09:44:05 +00:00
|
|
|
common.AbortWithMessage("out of max amount limit")
|
2021-05-17 06:30:39 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 13:27:39 +00:00
|
|
|
caller := runtime.GetCallingScriptHash()
|
2021-03-04 19:21:49 +00:00
|
|
|
if !common.BytesEqual(caller, interop.Hash160(gas.Hash)) {
|
2021-11-30 09:44:05 +00:00
|
|
|
common.AbortWithMessage("only GAS can be accepted for deposit")
|
2020-12-09 13:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch len(rcv) {
|
|
|
|
case 20:
|
|
|
|
case 0:
|
|
|
|
rcv = from
|
|
|
|
default:
|
2021-11-30 09:44:05 +00:00
|
|
|
common.AbortWithMessage("invalid data argument, expected Hash160")
|
2020-12-09 13:27:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 09:02:59 +00:00
|
|
|
runtime.Log("funds have been transferred")
|
2020-12-09 13:27:39 +00:00
|
|
|
|
|
|
|
tx := runtime.GetScriptContainer()
|
|
|
|
runtime.Notify("Deposit", from, amount, rcv, tx.Hash)
|
|
|
|
}
|
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// Withdraw initializes gas asset withdraw from FrostFS. It can be invoked only
|
2021-07-16 06:03:34 +00:00
|
|
|
// by the specified user.
|
|
|
|
//
|
2022-04-14 11:56:51 +00:00
|
|
|
// This method produces Withdraw notification to lock assets in the sidechain and
|
|
|
|
// transfers withdraw fee from a user account to each Alphabet node. If notary
|
|
|
|
// is enabled in the mainchain, fee is transferred to Processing contract.
|
2023-01-09 11:22:59 +00:00
|
|
|
// Fee value is specified in FrostFS network config with the key WithdrawFee.
|
2021-05-21 11:37:31 +00:00
|
|
|
func Withdraw(user interop.Hash160, amount int) {
|
2020-08-26 09:15:07 +00:00
|
|
|
if !runtime.CheckWitness(user) {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("you should be the owner of the wallet")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-05-28 14:04:32 +00:00
|
|
|
|
2020-08-26 09:19:40 +00:00
|
|
|
if amount < 0 {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("non positive amount number")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2020-10-26 15:26:04 +00:00
|
|
|
if amount > maxBalanceAmount {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("out of max amount limit")
|
2020-10-26 15:26:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 14:44:36 +00:00
|
|
|
ctx := storage.GetContext()
|
2021-04-29 13:15:29 +00:00
|
|
|
|
|
|
|
// transfer fee to proxy contract to pay cheque invocation
|
2021-04-20 14:44:36 +00:00
|
|
|
fee := getConfig(ctx, withdrawFeeConfigKey).(int)
|
2020-08-26 09:19:40 +00:00
|
|
|
|
2023-03-07 08:21:11 +00:00
|
|
|
processingAddr := storage.Get(ctx, processingContractKey).(interop.Hash160)
|
2021-04-29 13:15:29 +00:00
|
|
|
|
2023-03-07 08:21:11 +00:00
|
|
|
transferred := gas.Transfer(user, processingAddr, fee, []byte{})
|
|
|
|
if !transferred {
|
|
|
|
panic("failed to transfer withdraw fee, aborting")
|
2021-04-20 14:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// notify alphabet nodes
|
|
|
|
amount = amount * 100000000
|
2020-08-26 09:15:07 +00:00
|
|
|
tx := runtime.GetScriptContainer()
|
2021-04-20 14:44:36 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
runtime.Notify("Withdraw", user, amount, tx.Hash)
|
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// Cheque transfers GAS back to the user from the contract account, if assets were
|
2023-01-09 11:22:59 +00:00
|
|
|
// successfully locked in FrostFS balance contract. It can be invoked only by
|
2021-07-16 06:03:34 +00:00
|
|
|
// Alphabet nodes.
|
|
|
|
//
|
2022-04-14 11:56:51 +00:00
|
|
|
// This method produces Cheque notification to burn assets in sidechain.
|
2021-05-21 11:37:31 +00:00
|
|
|
func Cheque(id []byte, user interop.Hash160, amount int, lockAcc []byte) {
|
2023-02-10 15:07:44 +00:00
|
|
|
common.CheckAlphabetWitness()
|
2020-05-28 14:04:32 +00:00
|
|
|
|
2021-04-20 14:30:43 +00:00
|
|
|
from := runtime.GetExecutingScriptHash()
|
2020-07-16 08:02:19 +00:00
|
|
|
|
2021-04-20 14:30:43 +00:00
|
|
|
transferred := gas.Transfer(from, user, amount, nil)
|
|
|
|
if !transferred {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("failed to transfer funds, aborting")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 08:02:19 +00:00
|
|
|
|
2021-11-30 09:02:59 +00:00
|
|
|
runtime.Log("funds have been transferred")
|
2021-04-20 14:30:43 +00:00
|
|
|
runtime.Notify("Cheque", id, user, amount, lockAcc)
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 08:02:19 +00:00
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// Bind method produces notification to bind the specified public keys in FrostFSID
|
2022-04-14 11:56:51 +00:00
|
|
|
// contract in the sidechain. It can be invoked only by specified user.
|
2021-07-16 06:03:34 +00:00
|
|
|
//
|
2022-04-14 11:56:51 +00:00
|
|
|
// This method produces Bind notification. This method panics if keys are not
|
|
|
|
// 33 byte long. User argument must be a valid 20 byte script hash.
|
2021-05-21 11:37:31 +00:00
|
|
|
func Bind(user []byte, keys []interop.PublicKey) {
|
2020-08-26 09:15:07 +00:00
|
|
|
if !runtime.CheckWitness(user) {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("you should be the owner of the wallet")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 08:02:19 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
for i := 0; i < len(keys); i++ {
|
2020-08-28 06:42:06 +00:00
|
|
|
pubKey := keys[i]
|
2021-11-29 16:43:01 +00:00
|
|
|
if len(pubKey) != interop.PublicKeyCompressedLen {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("incorrect public key size")
|
2020-07-16 14:23:52 +00:00
|
|
|
}
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
runtime.Notify("Bind", user, keys)
|
|
|
|
}
|
2020-07-16 14:23:52 +00:00
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// Unbind method produces notification to unbind the specified public keys in FrostFSID
|
2022-04-14 11:56:51 +00:00
|
|
|
// contract in the sidechain. It can be invoked only by the specified user.
|
2021-07-16 06:03:34 +00:00
|
|
|
//
|
2022-04-14 11:56:51 +00:00
|
|
|
// This method produces Unbind notification. This method panics if keys are not
|
|
|
|
// 33 byte long. User argument must be a valid 20 byte script hash.
|
2021-05-21 11:37:31 +00:00
|
|
|
func Unbind(user []byte, keys []interop.PublicKey) {
|
2020-08-26 09:15:07 +00:00
|
|
|
if !runtime.CheckWitness(user) {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("you should be the owner of the wallet")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 14:23:52 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
for i := 0; i < len(keys); i++ {
|
2020-08-28 06:42:06 +00:00
|
|
|
pubKey := keys[i]
|
2021-11-29 16:43:01 +00:00
|
|
|
if len(pubKey) != interop.PublicKeyCompressedLen {
|
2021-11-29 10:51:57 +00:00
|
|
|
panic("incorrect public key size")
|
2020-03-30 13:59:54 +00:00
|
|
|
}
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-03-30 13:59:54 +00:00
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
runtime.Notify("Unbind", user, keys)
|
|
|
|
}
|
2020-05-20 09:38:11 +00:00
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// Config returns configuration value of FrostFS configuration. If the key does
|
2021-07-16 06:03:34 +00:00
|
|
|
// not exists, returns nil.
|
2020-08-26 09:15:07 +00:00
|
|
|
func Config(key []byte) interface{} {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetReadOnlyContext()
|
2020-08-26 09:15:07 +00:00
|
|
|
return getConfig(ctx, key)
|
|
|
|
}
|
2020-07-16 15:59:49 +00:00
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// SetConfig key-value pair as a FrostFS runtime configuration value. It can be invoked
|
2021-07-16 06:03:34 +00:00
|
|
|
// only by Alphabet nodes.
|
2021-05-21 11:37:31 +00:00
|
|
|
func SetConfig(id, key, val []byte) {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetContext()
|
2021-04-29 13:15:29 +00:00
|
|
|
|
2023-02-10 15:07:44 +00:00
|
|
|
common.CheckAlphabetWitness()
|
2020-07-16 15:59:49 +00:00
|
|
|
|
2021-04-20 14:30:43 +00:00
|
|
|
setConfig(ctx, key, val)
|
2020-07-16 15:59:49 +00:00
|
|
|
|
2021-04-20 14:30:43 +00:00
|
|
|
runtime.Notify("SetConfig", id, key, val)
|
2021-11-30 09:02:59 +00:00
|
|
|
runtime.Log("configuration has been updated")
|
2020-08-26 09:15:07 +00:00
|
|
|
}
|
2020-07-16 15:59:49 +00:00
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// ListConfig returns an array of structures that contain a key and a value of all
|
2023-01-09 11:22:59 +00:00
|
|
|
// FrostFS configuration records. Key and value are both byte arrays.
|
2020-08-26 09:15:07 +00:00
|
|
|
func ListConfig() []record {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetReadOnlyContext()
|
|
|
|
|
2020-08-26 09:15:07 +00:00
|
|
|
var config []record
|
2020-07-16 15:59:49 +00:00
|
|
|
|
2021-02-08 15:23:08 +00:00
|
|
|
it := storage.Find(ctx, configPrefix, storage.None)
|
2020-08-26 09:15:07 +00:00
|
|
|
for iterator.Next(it) {
|
2021-12-01 17:28:58 +00:00
|
|
|
pair := iterator.Value(it).(struct {
|
|
|
|
key []byte
|
|
|
|
val []byte
|
|
|
|
})
|
|
|
|
r := record{key: pair.key[len(configPrefix):], val: pair.val}
|
2020-08-26 09:15:07 +00:00
|
|
|
|
|
|
|
config = append(config, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2021-07-16 06:03:34 +00:00
|
|
|
// Version returns version of the contract.
|
2020-08-26 09:15:07 +00:00
|
|
|
func Version() int {
|
2021-07-29 11:44:53 +00:00
|
|
|
return common.Version
|
2020-03-30 13:59:54 +00:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// getAlphabetNodes returns a deserialized slice of nodes from storage.
|
2022-03-21 11:04:21 +00:00
|
|
|
func getAlphabetNodes(ctx storage.Context) []interop.PublicKey {
|
|
|
|
data := storage.Get(ctx, alphabetKey)
|
2020-07-15 16:26:24 +00:00
|
|
|
if data != nil {
|
2022-03-21 11:01:45 +00:00
|
|
|
return std.Deserialize(data.([]byte)).([]interop.PublicKey)
|
2020-07-15 16:26:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 11:01:45 +00:00
|
|
|
return []interop.PublicKey{}
|
2020-07-15 16:26:24 +00:00
|
|
|
}
|
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// getConfig returns the installed frostfs configuration value or nil if it is not set.
|
2020-07-16 15:59:49 +00:00
|
|
|
func getConfig(ctx storage.Context, key interface{}) interface{} {
|
|
|
|
postfix := key.([]byte)
|
|
|
|
storageKey := append(configPrefix, postfix...)
|
|
|
|
|
|
|
|
return storage.Get(ctx, storageKey)
|
|
|
|
}
|
|
|
|
|
2023-01-09 11:22:59 +00:00
|
|
|
// setConfig sets a frostfs configuration value in the contract storage.
|
2020-07-16 15:59:49 +00:00
|
|
|
func setConfig(ctx storage.Context, key, val interface{}) {
|
|
|
|
postfix := key.([]byte)
|
|
|
|
storageKey := append(configPrefix, postfix...)
|
|
|
|
|
|
|
|
storage.Put(ctx, storageKey, val)
|
|
|
|
}
|
|
|
|
|
2022-04-14 11:56:51 +00:00
|
|
|
// multiaddress returns a multisignature address from the list of IRNode structures
|
2021-04-20 14:27:15 +00:00
|
|
|
// with m = 2/3n+1.
|
2022-03-21 11:01:45 +00:00
|
|
|
func multiaddress(keys []interop.PublicKey) []byte {
|
|
|
|
threshold := len(keys)*2/3 + 1
|
2021-04-20 14:27:15 +00:00
|
|
|
|
|
|
|
return contract.CreateMultisigAccount(threshold, keys)
|
|
|
|
}
|