native: autogenerate nativehashes package
Ref. https://github.com/nspcc-dev/neo-go/pull/3402#discussion_r1577879141. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
02ecbeb519
commit
0aecddea10
13 changed files with 111 additions and 43 deletions
|
@ -610,7 +610,7 @@ func TestCallWithVersion(t *testing.T) {
|
||||||
e.DeployContract(t, ctr, nil)
|
e.DeployContract(t, ctr, nil)
|
||||||
c := e.CommitteeInvoker(ctr.Hash)
|
c := e.CommitteeInvoker(ctr.Hash)
|
||||||
|
|
||||||
policyH := nativehashes.Policy
|
policyH := nativehashes.PolicyContract
|
||||||
t.Run("good", func(t *testing.T) {
|
t.Run("good", func(t *testing.T) {
|
||||||
c.Invoke(t, e.Chain.GetBaseExecFee(), "callWithVersion", policyH.BytesBE(), 0, "getExecFeeFactor")
|
c.Invoke(t, e.Chain.GetBaseExecFee(), "callWithVersion", policyH.BytesBE(), 0, "getExecFeeFactor")
|
||||||
})
|
})
|
||||||
|
|
|
@ -2461,7 +2461,7 @@ func TestBlockchain_GenesisTransactionExtension(t *testing.T) {
|
||||||
emit.Syscall(script.BinWriter, interopnames.SystemRuntimeCheckWitness)
|
emit.Syscall(script.BinWriter, interopnames.SystemRuntimeCheckWitness)
|
||||||
emit.Bytes(script.BinWriter, to.BytesBE())
|
emit.Bytes(script.BinWriter, to.BytesBE())
|
||||||
emit.Syscall(script.BinWriter, interopnames.SystemRuntimeCheckWitness)
|
emit.Syscall(script.BinWriter, interopnames.SystemRuntimeCheckWitness)
|
||||||
emit.AppCall(script.BinWriter, nativehashes.Neo, "transfer", callflag.All, from, to, amount, nil)
|
emit.AppCall(script.BinWriter, nativehashes.NeoToken, "transfer", callflag.All, from, to, amount, nil)
|
||||||
emit.Opcodes(script.BinWriter, opcode.ASSERT)
|
emit.Opcodes(script.BinWriter, opcode.ASSERT)
|
||||||
|
|
||||||
var sysFee int64 = 1_0000_0000
|
var sysFee int64 = 1_0000_0000
|
||||||
|
|
|
@ -171,7 +171,7 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) {
|
||||||
switch name {
|
switch name {
|
||||||
case nativenames.Gas:
|
case nativenames.Gas:
|
||||||
expected = append(expected, state.NotificationEvent{
|
expected = append(expected, state.NotificationEvent{
|
||||||
ScriptHash: nativehashes.Gas,
|
ScriptHash: nativehashes.GasToken,
|
||||||
Name: "Transfer",
|
Name: "Transfer",
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
Item: stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.Null{},
|
stackitem.Null{},
|
||||||
|
@ -181,7 +181,7 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) {
|
||||||
})
|
})
|
||||||
case nativenames.Neo:
|
case nativenames.Neo:
|
||||||
expected = append(expected, state.NotificationEvent{
|
expected = append(expected, state.NotificationEvent{
|
||||||
ScriptHash: nativehashes.Neo,
|
ScriptHash: nativehashes.NeoToken,
|
||||||
Name: "Transfer",
|
Name: "Transfer",
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
Item: stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.Null{},
|
stackitem.Null{},
|
||||||
|
@ -191,7 +191,7 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
expected = append(expected, state.NotificationEvent{
|
expected = append(expected, state.NotificationEvent{
|
||||||
ScriptHash: nativehashes.Management,
|
ScriptHash: nativehashes.ContractManagement,
|
||||||
Name: "Deploy",
|
Name: "Deploy",
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
Item: stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.Make(state.CreateNativeContractHash(name)),
|
stackitem.Make(state.CreateNativeContractHash(name)),
|
||||||
|
@ -208,7 +208,7 @@ func TestManagement_NativeDeployUpdateNotifications(t *testing.T) {
|
||||||
expected = expected[:0]
|
expected = expected[:0]
|
||||||
for _, name := range []string{nativenames.CryptoLib, nativenames.Neo} {
|
for _, name := range []string{nativenames.CryptoLib, nativenames.Neo} {
|
||||||
expected = append(expected, state.NotificationEvent{
|
expected = append(expected, state.NotificationEvent{
|
||||||
ScriptHash: nativehashes.Management,
|
ScriptHash: nativehashes.ContractManagement,
|
||||||
Name: "Update",
|
Name: "Update",
|
||||||
Item: stackitem.NewArray([]stackitem.Item{
|
Item: stackitem.NewArray([]stackitem.Item{
|
||||||
stackitem.Make(state.CreateNativeContractHash(name)),
|
stackitem.Make(state.CreateNativeContractHash(name)),
|
||||||
|
|
70
pkg/core/native/nativehashes/gen.go
Normal file
70
pkg/core/native/nativehashes/gen.go
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
//go:build ignore
|
||||||
|
|
||||||
|
// This program generates hashes.go. It can be invoked by running
|
||||||
|
// go generate.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
)
|
||||||
|
|
||||||
|
// srcTmpl is a nativehashes package template.
|
||||||
|
const srcTmpl = `// Code generated by "go generate go run gen.go"; DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:generate go run gen.go
|
||||||
|
|
||||||
|
// package nativehashes contains hashes of all native contracts in their LE and Uint160 representation.
|
||||||
|
package nativehashes
|
||||||
|
|
||||||
|
import "github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
|
||||||
|
// Hashes of all native contracts.
|
||||||
|
var (
|
||||||
|
{{- range .Natives }}
|
||||||
|
// {{ .Name }} is a hash of native {{ .Name }} contract.
|
||||||
|
{{ .Name }} = {{ .Hash }}
|
||||||
|
{{- end }}
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Config contains parameters for the nativehashes package generation.
|
||||||
|
Config struct {
|
||||||
|
Natives []NativeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// NativeInfo contains information about native contract needed for
|
||||||
|
// nativehashes package generation.
|
||||||
|
NativeInfo struct {
|
||||||
|
Name string
|
||||||
|
Hash string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// srcTemplate is a parsed nativehashes package template.
|
||||||
|
var srcTemplate = template.Must(template.New("nativehashes").Parse(srcTmpl))
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
f, err := os.Create("hashes.go")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var cfg = Config{Natives: make([]NativeInfo, len(nativenames.All))}
|
||||||
|
for i, name := range nativenames.All {
|
||||||
|
var hash = state.CreateNativeContractHash(name)
|
||||||
|
cfg.Natives[i] = NativeInfo{
|
||||||
|
Name: name,
|
||||||
|
Hash: fmt.Sprintf("%#v", hash),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srcTemplate.Execute(f, cfg)
|
||||||
|
}
|
|
@ -1,34 +1,32 @@
|
||||||
|
// Code generated by "go generate go run gen.go"; DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:generate go run gen.go
|
||||||
|
|
||||||
|
// package nativehashes contains hashes of all native contracts in their LE and Uint160 representation.
|
||||||
package nativehashes
|
package nativehashes
|
||||||
|
|
||||||
import (
|
import "github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Hashes of all native contracts.
|
// Hashes of all native contracts.
|
||||||
var (
|
var (
|
||||||
Management util.Uint160
|
// ContractManagement is a hash of native ContractManagement contract.
|
||||||
Ledger util.Uint160
|
ContractManagement = util.Uint160{0xfd, 0xa3, 0xfa, 0x43, 0x46, 0xea, 0x53, 0x2a, 0x25, 0x8f, 0xc4, 0x97, 0xdd, 0xad, 0xdb, 0x64, 0x37, 0xc9, 0xfd, 0xff}
|
||||||
Neo util.Uint160
|
// StdLib is a hash of native StdLib contract.
|
||||||
Gas util.Uint160
|
StdLib = util.Uint160{0xc0, 0xef, 0x39, 0xce, 0xe0, 0xe4, 0xe9, 0x25, 0xc6, 0xc2, 0xa0, 0x6a, 0x79, 0xe1, 0x44, 0xd, 0xd8, 0x6f, 0xce, 0xac}
|
||||||
Policy util.Uint160
|
// CryptoLib is a hash of native CryptoLib contract.
|
||||||
Oracle util.Uint160
|
CryptoLib = util.Uint160{0x1b, 0xf5, 0x75, 0xab, 0x11, 0x89, 0x68, 0x84, 0x13, 0x61, 0xa, 0x35, 0xa1, 0x28, 0x86, 0xcd, 0xe0, 0xb6, 0x6c, 0x72}
|
||||||
Designation util.Uint160
|
// LedgerContract is a hash of native LedgerContract contract.
|
||||||
Notary util.Uint160
|
LedgerContract = util.Uint160{0xbe, 0xf2, 0x4, 0x31, 0x40, 0x36, 0x2a, 0x77, 0xc1, 0x50, 0x99, 0xc7, 0xe6, 0x4c, 0x12, 0xf7, 0x0, 0xb6, 0x65, 0xda}
|
||||||
CryptoLib util.Uint160
|
// NeoToken is a hash of native NeoToken contract.
|
||||||
StdLib util.Uint160
|
NeoToken = util.Uint160{0xf5, 0x63, 0xea, 0x40, 0xbc, 0x28, 0x3d, 0x4d, 0xe, 0x5, 0xc4, 0x8e, 0xa3, 0x5, 0xb3, 0xf2, 0xa0, 0x73, 0x40, 0xef}
|
||||||
|
// GasToken is a hash of native GasToken contract.
|
||||||
|
GasToken = util.Uint160{0xcf, 0x76, 0xe2, 0x8b, 0xd0, 0x6, 0x2c, 0x4a, 0x47, 0x8e, 0xe3, 0x55, 0x61, 0x1, 0x13, 0x19, 0xf3, 0xcf, 0xa4, 0xd2}
|
||||||
|
// PolicyContract is a hash of native PolicyContract contract.
|
||||||
|
PolicyContract = util.Uint160{0x7b, 0xc6, 0x81, 0xc0, 0xa1, 0xf7, 0x1d, 0x54, 0x34, 0x57, 0xb6, 0x8b, 0xba, 0x8d, 0x5f, 0x9f, 0xdd, 0x4e, 0x5e, 0xcc}
|
||||||
|
// RoleManagement is a hash of native RoleManagement contract.
|
||||||
|
RoleManagement = util.Uint160{0xe2, 0x95, 0xe3, 0x91, 0x54, 0x4c, 0x17, 0x8a, 0xd9, 0x4f, 0x3, 0xec, 0x4d, 0xcd, 0xff, 0x78, 0x53, 0x4e, 0xcf, 0x49}
|
||||||
|
// OracleContract is a hash of native OracleContract contract.
|
||||||
|
OracleContract = util.Uint160{0x58, 0x87, 0x17, 0x11, 0x7e, 0xa, 0xa8, 0x10, 0x72, 0xaf, 0xab, 0x71, 0xd2, 0xdd, 0x89, 0xfe, 0x7c, 0x4b, 0x92, 0xfe}
|
||||||
|
// Notary is a hash of native Notary contract.
|
||||||
|
Notary = util.Uint160{0x3b, 0xec, 0x35, 0x31, 0x11, 0x9b, 0xba, 0xd7, 0x6d, 0xd0, 0x44, 0x92, 0xb, 0xd, 0xe6, 0xc3, 0x19, 0x4f, 0xe1, 0xc1}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
Management = state.CreateNativeContractHash(nativenames.Management)
|
|
||||||
Ledger = state.CreateNativeContractHash(nativenames.Ledger)
|
|
||||||
Neo = state.CreateNativeContractHash(nativenames.Neo)
|
|
||||||
Gas = state.CreateNativeContractHash(nativenames.Gas)
|
|
||||||
Policy = state.CreateNativeContractHash(nativenames.Policy)
|
|
||||||
Oracle = state.CreateNativeContractHash(nativenames.Oracle)
|
|
||||||
Designation = state.CreateNativeContractHash(nativenames.Designation)
|
|
||||||
Notary = state.CreateNativeContractHash(nativenames.Notary)
|
|
||||||
CryptoLib = state.CreateNativeContractHash(nativenames.CryptoLib)
|
|
||||||
StdLib = state.CreateNativeContractHash(nativenames.StdLib)
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hash stores the hash of the native GAS contract.
|
// Hash stores the hash of the native GAS contract.
|
||||||
var Hash = nativehashes.Gas
|
var Hash = nativehashes.GasToken
|
||||||
|
|
||||||
// NewReader creates a NEP-17 reader for the GAS contract.
|
// NewReader creates a NEP-17 reader for the GAS contract.
|
||||||
func NewReader(invoker nep17.Invoker) *nep17.TokenReader {
|
func NewReader(invoker nep17.Invoker) *nep17.TokenReader {
|
||||||
|
|
|
@ -75,7 +75,7 @@ type HashesIterator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash stores the hash of the native ContractManagement contract.
|
// Hash stores the hash of the native ContractManagement contract.
|
||||||
var Hash = nativehashes.Management
|
var Hash = nativehashes.ContractManagement
|
||||||
|
|
||||||
// Event is the event emitted on contract deployment/update/destroy.
|
// Event is the event emitted on contract deployment/update/destroy.
|
||||||
// Even though these events are different they all have the same field inside.
|
// Even though these events are different they all have the same field inside.
|
||||||
|
|
|
@ -97,7 +97,7 @@ type ValidatorIterator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash stores the hash of the native NEOToken contract.
|
// Hash stores the hash of the native NEOToken contract.
|
||||||
var Hash = nativehashes.Neo
|
var Hash = nativehashes.NeoToken
|
||||||
|
|
||||||
// NewReader creates an instance of ContractReader to get data from the NEO
|
// NewReader creates an instance of ContractReader to get data from the NEO
|
||||||
// contract.
|
// contract.
|
||||||
|
|
|
@ -31,7 +31,7 @@ type Actor interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash stores the hash of the native OracleContract contract.
|
// Hash stores the hash of the native OracleContract contract.
|
||||||
var Hash = nativehashes.Oracle
|
var Hash = nativehashes.OracleContract
|
||||||
|
|
||||||
const priceSetter = "setPrice"
|
const priceSetter = "setPrice"
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ type Actor interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash stores the hash of the native PolicyContract contract.
|
// Hash stores the hash of the native PolicyContract contract.
|
||||||
var Hash = nativehashes.Policy
|
var Hash = nativehashes.PolicyContract
|
||||||
|
|
||||||
const (
|
const (
|
||||||
execFeeSetter = "setExecFeeFactor"
|
execFeeSetter = "setExecFeeFactor"
|
||||||
|
|
|
@ -31,7 +31,7 @@ type Actor interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash stores the hash of the native RoleManagement contract.
|
// Hash stores the hash of the native RoleManagement contract.
|
||||||
var Hash = nativehashes.Designation
|
var Hash = nativehashes.RoleManagement
|
||||||
|
|
||||||
const designateMethod = "designateAsRole"
|
const designateMethod = "designateAsRole"
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ func (o *Oracle) CreateResponseTx(gasForResponse int64, vub uint32, resp *transa
|
||||||
oracleSignContract := o.getOracleSignContract()
|
oracleSignContract := o.getOracleSignContract()
|
||||||
tx.Signers = []transaction.Signer{
|
tx.Signers = []transaction.Signer{
|
||||||
{
|
{
|
||||||
Account: nativehashes.Oracle,
|
Account: nativehashes.OracleContract,
|
||||||
Scopes: transaction.None,
|
Scopes: transaction.None,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -174,7 +174,7 @@ func (o *Oracle) testVerify(tx *transaction.Transaction) (int64, bool, error) {
|
||||||
ic.VM.GasLimit = o.Chain.GetMaxVerificationGAS()
|
ic.VM.GasLimit = o.Chain.GetMaxVerificationGAS()
|
||||||
|
|
||||||
o.oracleInfoLock.RLock()
|
o.oracleInfoLock.RLock()
|
||||||
ic.VM.LoadScriptWithHash(o.oracleScript, nativehashes.Oracle, callflag.ReadOnly)
|
ic.VM.LoadScriptWithHash(o.oracleScript, nativehashes.OracleContract, callflag.ReadOnly)
|
||||||
ic.VM.Context().Jump(o.verifyOffset)
|
ic.VM.Context().Jump(o.verifyOffset)
|
||||||
o.oracleInfoLock.RUnlock()
|
o.oracleInfoLock.RUnlock()
|
||||||
|
|
||||||
|
|
|
@ -826,7 +826,7 @@ func TestCalculateNetworkFee(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Set fee per Conflicts attribute.
|
// Set fee per Conflicts attribute.
|
||||||
script, err := smartcontract.CreateCallScript(nativehashes.Policy, "setAttributeFee", byte(transaction.ConflictsT), conflictsFee)
|
script, err := smartcontract.CreateCallScript(nativehashes.PolicyContract, "setAttributeFee", byte(transaction.ConflictsT), conflictsFee)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
txSetFee := transaction.New(script, 1_0000_0000)
|
txSetFee := transaction.New(script, 1_0000_0000)
|
||||||
txSetFee.ValidUntilBlock = chain.BlockHeight() + 1
|
txSetFee.ValidUntilBlock = chain.BlockHeight() + 1
|
||||||
|
|
Loading…
Reference in a new issue