2021-07-04 14:00:56 +03:00
|
|
|
package proxy
|
2021-02-19 17:47:41 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
2021-06-30 13:59:32 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
2021-02-19 17:47:41 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
2021-03-24 11:12:44 +03:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
|
2021-02-19 17:47:41 +03: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 (
|
|
|
|
netmapContractKey = "netmapScriptHash"
|
|
|
|
)
|
|
|
|
|
2021-07-07 18:34:03 +03:00
|
|
|
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
|
2021-02-19 17:47:41 +03:00
|
|
|
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
|
|
|
caller := runtime.GetCallingScriptHash()
|
|
|
|
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
2021-04-20 17:45:22 +03:00
|
|
|
panic("onNEP17Payment: proxy contract accepts GAS only")
|
2021-02-19 17:47:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 11:31:07 +03:00
|
|
|
func _deploy(data interface{}, isUpdate bool) {
|
2021-06-03 10:49:07 +03:00
|
|
|
if isUpdate {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-12 11:31:07 +03:00
|
|
|
args := data.([]interface{})
|
2021-09-20 18:41:46 +03:00
|
|
|
addrNetmap := args[0].(interop.Hash160)
|
2021-05-12 11:31:07 +03:00
|
|
|
|
2021-03-09 22:15:58 +03:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
2021-02-19 17:47:41 +03:00
|
|
|
if len(addrNetmap) != 20 {
|
|
|
|
panic("init: incorrect length of contract script hash")
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.Put(ctx, netmapContractKey, addrNetmap)
|
|
|
|
|
|
|
|
runtime.Log("proxy contract initialized")
|
|
|
|
}
|
|
|
|
|
2021-09-21 11:02:24 +03:00
|
|
|
// Update method updates contract source code and manifest. Can be invoked
|
2021-09-20 18:41:46 +03:00
|
|
|
// only by committee.
|
2021-09-21 15:58:37 +03:00
|
|
|
func Update(script []byte, manifest []byte, data interface{}) {
|
2021-09-20 18:41:46 +03:00
|
|
|
if !common.HasUpdateAccess() {
|
|
|
|
panic("only committee can update contract")
|
2021-02-19 17:47:41 +03:00
|
|
|
}
|
|
|
|
|
2021-06-30 13:59:32 +03:00
|
|
|
contract.Call(interop.Hash160(management.Hash), "update", contract.All, script, manifest, data)
|
2021-02-19 17:47:41 +03:00
|
|
|
runtime.Log("proxy contract updated")
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:34:03 +03:00
|
|
|
// Verify method returns true if transaction contains valid multi signature of
|
|
|
|
// Alphabet nodes of the Inner Ring.
|
2021-02-19 17:47:41 +03:00
|
|
|
func Verify() bool {
|
2021-03-24 11:12:44 +03:00
|
|
|
alphabet := neo.GetCommittee()
|
|
|
|
sig := common.Multiaddress(alphabet, false)
|
2021-03-09 22:15:58 +03:00
|
|
|
|
2021-03-10 17:01:57 +03:00
|
|
|
if !runtime.CheckWitness(sig) {
|
2021-03-24 11:12:44 +03:00
|
|
|
sig = common.Multiaddress(alphabet, true)
|
2021-03-10 17:01:57 +03:00
|
|
|
return runtime.CheckWitness(sig)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2021-02-19 17:47:41 +03:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:34:03 +03:00
|
|
|
// Version returns version of the contract.
|
2021-02-19 17:47:41 +03:00
|
|
|
func Version() int {
|
2021-07-29 14:44:53 +03:00
|
|
|
return common.Version
|
2021-02-19 17:47:41 +03:00
|
|
|
}
|