2021-07-04 11:00:56 +00:00
|
|
|
package processing
|
2021-04-20 14:40:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"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 15:41:46 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
|
2021-04-20 14:40:18 +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-04-20 14:40:18 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
|
|
|
"github.com/nspcc-dev/neofs-contract/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
neofsContractKey = "neofsScriptHash"
|
|
|
|
|
|
|
|
multiaddrMethod = "alphabetAddress"
|
|
|
|
)
|
|
|
|
|
2021-07-07 15:33:53 +00:00
|
|
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
2021-04-20 14:40:18 +00:00
|
|
|
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
|
|
|
caller := runtime.GetCallingScriptHash()
|
|
|
|
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
|
|
|
panic("onNEP17Payment: processing contract accepts GAS only")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 08:31:07 +00:00
|
|
|
func _deploy(data interface{}, isUpdate bool) {
|
2021-06-03 07:49:07 +00:00
|
|
|
if isUpdate {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-12 08:31:07 +00:00
|
|
|
arr := data.([]interop.Hash160)
|
2021-09-20 15:41:46 +00:00
|
|
|
addrNeoFS := arr[0]
|
2021-05-12 08:31:07 +00:00
|
|
|
|
2021-04-20 14:40:18 +00:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
|
|
|
if len(addrNeoFS) != 20 {
|
|
|
|
panic("init: incorrect length of contract script hash")
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.Put(ctx, neofsContractKey, addrNeoFS)
|
|
|
|
|
|
|
|
runtime.Log("processing contract initialized")
|
|
|
|
}
|
|
|
|
|
2021-09-21 08:02:24 +00:00
|
|
|
// Update method updates contract source code and manifest. Can be invoked
|
2021-09-20 15:41:46 +00:00
|
|
|
// only by side chain 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()
|
|
|
|
alphabetKeys := roles.GetDesignatedByRole(roles.NeoFSAlphabet, uint32(blockHeight))
|
|
|
|
alphabetCommittee := common.Multiaddress(alphabetKeys, true)
|
2021-04-20 14:40:18 +00:00
|
|
|
|
2021-09-20 15:41:46 +00:00
|
|
|
if !runtime.CheckWitness(alphabetCommittee) {
|
|
|
|
panic("only side chain committee can update contract")
|
2021-04-20 14:40:18 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 10:59:32 +00:00
|
|
|
contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data)
|
2021-04-20 14:40:18 +00:00
|
|
|
runtime.Log("processing contract updated")
|
|
|
|
}
|
|
|
|
|
2021-07-07 15:33:53 +00:00
|
|
|
// Verify method returns true if transaction contains valid multi signature of
|
|
|
|
// Alphabet nodes of the Inner Ring.
|
2021-04-20 14:40:18 +00:00
|
|
|
func Verify() bool {
|
|
|
|
ctx := storage.GetContext()
|
|
|
|
neofsContractAddr := storage.Get(ctx, neofsContractKey).(interop.Hash160)
|
|
|
|
multiaddr := contract.Call(neofsContractAddr, multiaddrMethod, contract.ReadOnly).(interop.Hash160)
|
|
|
|
|
|
|
|
return runtime.CheckWitness(multiaddr)
|
|
|
|
}
|
|
|
|
|
2021-07-07 15:33:53 +00:00
|
|
|
// Version returns version of the contract.
|
2021-04-20 14:40:18 +00:00
|
|
|
func Version() int {
|
2021-07-29 11:44:53 +00:00
|
|
|
return common.Version
|
2021-04-20 14:40:18 +00:00
|
|
|
}
|