2021-07-04 14:00:56 +03:00
|
|
|
package processing
|
2021-04-20 17:40:18 +03:00
|
|
|
|
|
|
|
import (
|
2023-03-07 14:06:21 +03:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
2021-04-20 17:40:18 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
2021-09-20 18:41:46 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
2021-04-20 17:40:18 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
2021-09-20 18:41:46 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
|
2021-04-20 17:40:18 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-01-09 14:31:34 +03:00
|
|
|
frostfsContractKey = "frostfsScriptHash"
|
2021-04-20 17:40:18 +03:00
|
|
|
|
|
|
|
multiaddrMethod = "alphabetAddress"
|
|
|
|
)
|
|
|
|
|
2021-07-07 18:33:53 +03:00
|
|
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
2023-11-07 15:18:48 +03:00
|
|
|
func OnNEP17Payment(from interop.Hash160, amount int, data any) {
|
2021-04-20 17:40:18 +03:00
|
|
|
caller := runtime.GetCallingScriptHash()
|
|
|
|
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
2021-11-30 12:44:05 +03:00
|
|
|
common.AbortWithMessage("processing contract accepts GAS only")
|
2021-04-20 17:40:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 15:18:48 +03:00
|
|
|
func _deploy(data any, isUpdate bool) {
|
2021-06-03 10:49:07 +03:00
|
|
|
if isUpdate {
|
2023-11-07 15:18:48 +03:00
|
|
|
args := data.([]any)
|
2021-12-27 11:49:30 +03:00
|
|
|
common.CheckVersion(args[len(args)-1].(int))
|
2021-06-03 10:49:07 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-29 19:34:11 +03:00
|
|
|
args := data.(struct {
|
2023-01-09 14:31:34 +03:00
|
|
|
addrFrostFS interop.Hash160
|
2021-11-29 19:34:11 +03:00
|
|
|
})
|
2021-05-12 11:31:07 +03:00
|
|
|
|
2021-04-20 17:40:18 +03:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
2023-01-09 14:31:34 +03:00
|
|
|
if len(args.addrFrostFS) != interop.Hash160Len {
|
2021-11-29 13:51:57 +03:00
|
|
|
panic("incorrect length of contract script hash")
|
2021-04-20 17:40:18 +03:00
|
|
|
}
|
|
|
|
|
2023-01-09 14:31:34 +03:00
|
|
|
storage.Put(ctx, frostfsContractKey, args.addrFrostFS)
|
2021-04-20 17:40:18 +03:00
|
|
|
|
|
|
|
runtime.Log("processing contract initialized")
|
|
|
|
}
|
|
|
|
|
2022-04-14 14:56:51 +03:00
|
|
|
// Update method updates contract source code and manifest. It can be invoked
|
|
|
|
// only by the sidechain committee.
|
2023-11-07 15:18:48 +03:00
|
|
|
func Update(script []byte, manifest []byte, data any) {
|
2021-09-20 18:41:46 +03:00
|
|
|
blockHeight := ledger.CurrentIndex()
|
2022-01-11 11:25:10 +03:00
|
|
|
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight+1))
|
2021-09-20 18:41:46 +03:00
|
|
|
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
2021-04-20 17:40:18 +03:00
|
|
|
|
2021-09-20 18:41:46 +03:00
|
|
|
if !runtime.CheckWitness(alphabetCommittee) {
|
|
|
|
panic("only side chain committee can update contract")
|
2021-04-20 17:40:18 +03:00
|
|
|
}
|
|
|
|
|
2023-06-19 11:17:51 +03:00
|
|
|
management.UpdateWithData(script, manifest, common.AppendVersion(data))
|
2021-04-20 17:40:18 +03:00
|
|
|
runtime.Log("processing contract updated")
|
|
|
|
}
|
|
|
|
|
2022-04-14 14:56:51 +03:00
|
|
|
// Verify method returns true if transaction contains valid multisignature of
|
2021-07-07 18:33:53 +03:00
|
|
|
// Alphabet nodes of the Inner Ring.
|
2021-04-20 17:40:18 +03:00
|
|
|
func Verify() bool {
|
|
|
|
ctx := storage.GetContext()
|
2023-01-09 14:31:34 +03:00
|
|
|
frostfsContractAddr := storage.Get(ctx, frostfsContractKey).(interop.Hash160)
|
|
|
|
multiaddr := contract.Call(frostfsContractAddr, multiaddrMethod, contract.ReadOnly).(interop.Hash160)
|
2021-04-20 17:40:18 +03:00
|
|
|
|
|
|
|
return runtime.CheckWitness(multiaddr)
|
|
|
|
}
|
|
|
|
|
2022-04-14 14:56:51 +03:00
|
|
|
// Version returns the version of the contract.
|
2021-04-20 17:40:18 +03:00
|
|
|
func Version() int {
|
2021-07-29 14:44:53 +03:00
|
|
|
return common.Version
|
2021-04-20 17:40:18 +03:00
|
|
|
}
|