2021-02-19 14:47:41 +00:00
|
|
|
package proxycontract
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
2021-03-24 08:12:44 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/neo"
|
2021-02-19 14:47:41 +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 (
|
|
|
|
version = 1
|
|
|
|
|
|
|
|
netmapContractKey = "netmapScriptHash"
|
|
|
|
)
|
|
|
|
|
|
|
|
func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
|
|
|
|
caller := runtime.GetCallingScriptHash()
|
|
|
|
if !common.BytesEqual(caller, []byte(gas.Hash)) {
|
2021-04-20 14:45:22 +00:00
|
|
|
panic("onNEP17Payment: proxy contract accepts GAS only")
|
2021-02-19 14:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 08:31:07 +00:00
|
|
|
func _deploy(data interface{}, isUpdate bool) {
|
|
|
|
args := data.([]interface{})
|
|
|
|
owner := args[0].(interop.Hash160)
|
|
|
|
addrNetmap := args[1].(interop.Hash160)
|
|
|
|
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetContext()
|
|
|
|
|
2021-02-19 14:47:41 +00:00
|
|
|
if !common.HasUpdateAccess(ctx) {
|
|
|
|
panic("only owner can reinitialize contract")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(addrNetmap) != 20 {
|
|
|
|
panic("init: incorrect length of contract script hash")
|
|
|
|
}
|
|
|
|
|
|
|
|
storage.Put(ctx, common.OwnerKey, owner)
|
|
|
|
storage.Put(ctx, netmapContractKey, addrNetmap)
|
|
|
|
|
|
|
|
runtime.Log("proxy contract initialized")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Migrate(script []byte, manifest []byte) bool {
|
2021-03-09 19:15:58 +00:00
|
|
|
ctx := storage.GetReadOnlyContext()
|
|
|
|
|
2021-02-19 14:47:41 +00:00
|
|
|
if !common.HasUpdateAccess(ctx) {
|
|
|
|
runtime.Log("only owner can update contract")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
management.Update(script, manifest)
|
|
|
|
runtime.Log("proxy contract updated")
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func Verify() bool {
|
2021-03-24 08:12:44 +00:00
|
|
|
alphabet := neo.GetCommittee()
|
|
|
|
sig := common.Multiaddress(alphabet, false)
|
2021-03-09 19:15:58 +00:00
|
|
|
|
2021-03-10 14:01:57 +00:00
|
|
|
if !runtime.CheckWitness(sig) {
|
2021-03-24 08:12:44 +00:00
|
|
|
sig = common.Multiaddress(alphabet, true)
|
2021-03-10 14:01:57 +00:00
|
|
|
return runtime.CheckWitness(sig)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2021-02-19 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Version() int {
|
|
|
|
return version
|
|
|
|
}
|