2021-03-19 09:11:48 +00:00
|
|
|
/*
|
2022-04-20 18:30:09 +00:00
|
|
|
Package management provides an interface to ContractManagement native contract.
|
2021-03-19 09:11:48 +00:00
|
|
|
It allows to get/deploy/update contracts as well as get/set deployment fee.
|
|
|
|
*/
|
2021-02-08 08:59:25 +00:00
|
|
|
package management
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
2022-09-20 13:09:34 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
2021-12-08 19:33:03 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
2021-02-08 08:59:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hash represents Management contract hash.
|
2021-02-15 13:40:44 +00:00
|
|
|
const Hash = "\xfd\xa3\xfa\x43\x46\xea\x53\x2a\x25\x8f\xc4\x97\xdd\xad\xdb\x64\x37\xc9\xfd\xff"
|
2021-02-08 08:59:25 +00:00
|
|
|
|
2022-09-20 13:09:34 +00:00
|
|
|
// IDHash is an ID/Hash pair returned by the iterator from the GetContractHashes method.
|
|
|
|
type IDHash struct {
|
|
|
|
// ID is a 32-bit number, but it's represented in big endian form
|
|
|
|
// natively, because that's the key scheme used by ContractManagement.
|
|
|
|
ID []byte
|
|
|
|
Hash interop.Hash160
|
|
|
|
}
|
|
|
|
|
2021-02-08 08:59:25 +00:00
|
|
|
// Deploy represents `deploy` method of Management native contract.
|
|
|
|
func Deploy(script, manifest []byte) *Contract {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "deploy",
|
2022-03-21 11:28:28 +00:00
|
|
|
int(contract.All), script, manifest).(*Contract)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeployWithData represents `deploy` method of Management native contract.
|
|
|
|
func DeployWithData(script, manifest []byte, data interface{}) *Contract {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "deploy",
|
2022-03-21 11:28:28 +00:00
|
|
|
int(contract.All), script, manifest, data).(*Contract)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy represents `destroy` method of Management native contract.
|
|
|
|
func Destroy() {
|
2021-12-08 19:33:03 +00:00
|
|
|
neogointernal.CallWithTokenNoRet(Hash, "destroy", int(contract.States|contract.AllowNotify))
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetContract represents `getContract` method of Management native contract.
|
|
|
|
func GetContract(addr interop.Hash160) *Contract {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "getContract", int(contract.ReadStates), addr).(*Contract)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 13:09:34 +00:00
|
|
|
// GetContractByID represents `getContractById` method of the Management native contract.
|
|
|
|
func GetContractByID(id int) *Contract {
|
|
|
|
return neogointernal.CallWithToken(Hash, "getContractById", int(contract.ReadStates), id).(*Contract)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetContractHashes represents `getContractHashes` method of the Management
|
|
|
|
// native contract. It returns an Iterator over the list of non-native contract
|
|
|
|
// hashes. Each iterator value can be cast to IDHash. Use [iterator] interop
|
|
|
|
// package to work with the returned Iterator.
|
|
|
|
func GetContractHashes() iterator.Iterator {
|
|
|
|
return neogointernal.CallWithToken(Hash, "getContractHashes", int(contract.ReadStates)).(iterator.Iterator)
|
|
|
|
}
|
|
|
|
|
2021-02-08 08:59:25 +00:00
|
|
|
// GetMinimumDeploymentFee represents `getMinimumDeploymentFee` method of Management native contract.
|
|
|
|
func GetMinimumDeploymentFee() int {
|
2021-12-08 19:33:03 +00:00
|
|
|
return neogointernal.CallWithToken(Hash, "getMinimumDeploymentFee", int(contract.ReadStates)).(int)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:56:48 +00:00
|
|
|
// HasMethod represents `hasMethod` method of Management native contract. It allows to check
|
|
|
|
// if the "hash" contract has a method named "method" with parameters number equal to "pcount".
|
|
|
|
func HasMethod(hash interop.Hash160, method string, pcount int) bool {
|
|
|
|
return neogointernal.CallWithToken(Hash, "hasMethod", int(contract.ReadStates), hash, method, pcount).(bool)
|
|
|
|
}
|
|
|
|
|
2021-02-08 08:59:25 +00:00
|
|
|
// SetMinimumDeploymentFee represents `setMinimumDeploymentFee` method of Management native contract.
|
|
|
|
func SetMinimumDeploymentFee(value int) {
|
2021-12-08 19:33:03 +00:00
|
|
|
neogointernal.CallWithTokenNoRet(Hash, "setMinimumDeploymentFee", int(contract.States), value)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update represents `update` method of Management native contract.
|
|
|
|
func Update(script, manifest []byte) {
|
2021-12-08 19:33:03 +00:00
|
|
|
neogointernal.CallWithTokenNoRet(Hash, "update",
|
2022-03-21 11:28:28 +00:00
|
|
|
int(contract.All), script, manifest)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateWithData represents `update` method of Management native contract.
|
|
|
|
func UpdateWithData(script, manifest []byte, data interface{}) {
|
2021-12-08 19:33:03 +00:00
|
|
|
neogointernal.CallWithTokenNoRet(Hash, "update",
|
2022-03-21 11:28:28 +00:00
|
|
|
int(contract.All), script, manifest, data)
|
2021-02-08 08:59:25 +00:00
|
|
|
}
|