core: unexport generic native contract methods and events

External users should use HF-specific methods and events.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-04-05 19:21:04 +03:00
parent 73c742a466
commit d74dc368e0

View file

@ -192,12 +192,12 @@ type ContractMD struct {
ID int32 ID int32
Hash util.Uint160 Hash util.Uint160
Name string Name string
// Methods is a generic set of contract methods with activation hardforks. Any HF-dependent part of included methods // methods is a generic set of contract methods with activation hardforks. Any HF-dependent part of included methods
// (offsets, in particular) must not be used, there's a mdCache field for that. // (offsets, in particular) must not be used, there's a mdCache field for that.
Methods []MethodAndPrice methods []MethodAndPrice
// Events is a generic set of contract events with activation hardforks. Any HF-dependent part of events must not be // events is a generic set of contract events with activation hardforks. Any HF-dependent part of events must not be
// used, there's a mdCache field for that. // used, there's a mdCache field for that.
Events []Event events []Event
// ActiveHFs is a map of hardforks that contract should react to. Contract update should be called for active // ActiveHFs is a map of hardforks that contract should react to. Contract update should be called for active
// hardforks. Note, that unlike the C# implementation, this map doesn't include contract's activation hardfork. // hardforks. Note, that unlike the C# implementation, this map doesn't include contract's activation hardfork.
// This map is being initialized on contract creation and used as a read-only, hence, not protected // This map is being initialized on contract creation and used as a read-only, hence, not protected
@ -259,14 +259,14 @@ func (c *ContractMD) HFSpecificContractMD(hf *config.Hardfork) *HFSpecificContra
// the specified hardfork or older. // the specified hardfork or older.
func (c *ContractMD) buildHFSpecificMD(hf *config.Hardfork) *HFSpecificContractMD { func (c *ContractMD) buildHFSpecificMD(hf *config.Hardfork) *HFSpecificContractMD {
var ( var (
abiMethods = make([]manifest.Method, 0, len(c.Methods)) abiMethods = make([]manifest.Method, 0, len(c.methods))
methods = make([]HFSpecificMethodAndPrice, 0, len(c.Methods)) methods = make([]HFSpecificMethodAndPrice, 0, len(c.methods))
abiEvents = make([]manifest.Event, 0, len(c.Events)) abiEvents = make([]manifest.Event, 0, len(c.events))
events = make([]HFSpecificEvent, 0, len(c.Events)) events = make([]HFSpecificEvent, 0, len(c.events))
) )
w := io.NewBufBinWriter() w := io.NewBufBinWriter()
for i := range c.Methods { for i := range c.methods {
m := c.Methods[i] m := c.methods[i]
if !(m.ActiveFrom == nil || (hf != nil && (*m.ActiveFrom).Cmp(*hf) >= 0)) { if !(m.ActiveFrom == nil || (hf != nil && (*m.ActiveFrom).Cmp(*hf) >= 0)) {
continue continue
} }
@ -287,8 +287,8 @@ func (c *ContractMD) buildHFSpecificMD(hf *config.Hardfork) *HFSpecificContractM
if w.Err != nil { if w.Err != nil {
panic(fmt.Errorf("can't create native contract script: %w", w.Err)) panic(fmt.Errorf("can't create native contract script: %w", w.Err))
} }
for i := range c.Events { for i := range c.events {
e := c.Events[i] e := c.events[i]
if !(e.ActiveFrom == nil || (hf != nil && (*e.ActiveFrom).Cmp(*hf) >= 0)) { if !(e.ActiveFrom == nil || (hf != nil && (*e.ActiveFrom).Cmp(*hf) >= 0)) {
continue continue
} }
@ -340,16 +340,16 @@ func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
md.MD = desc md.MD = desc
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0 desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0
index := sort.Search(len(c.Methods), func(i int) bool { index := sort.Search(len(c.methods), func(i int) bool {
md := c.Methods[i].MD md := c.methods[i].MD
if md.Name != desc.Name { if md.Name != desc.Name {
return md.Name >= desc.Name return md.Name >= desc.Name
} }
return len(md.Parameters) > len(desc.Parameters) return len(md.Parameters) > len(desc.Parameters)
}) })
c.Methods = append(c.Methods, MethodAndPrice{}) c.methods = append(c.methods, MethodAndPrice{})
copy(c.Methods[index+1:], c.Methods[index:]) copy(c.methods[index+1:], c.methods[index:])
c.Methods[index] = *md c.methods[index] = *md
if md.ActiveFrom != nil { if md.ActiveFrom != nil {
c.ActiveHFs[*md.ActiveFrom] = struct{}{} c.ActiveHFs[*md.ActiveFrom] = struct{}{}
@ -390,7 +390,7 @@ func (c *HFSpecificContractMD) GetMethod(name string, paramCount int) (HFSpecifi
// AddEvent adds a new event to the native contract. // AddEvent adds a new event to the native contract.
func (c *ContractMD) AddEvent(md Event) { func (c *ContractMD) AddEvent(md Event) {
c.Events = append(c.Events, md) c.events = append(c.events, md)
if md.ActiveFrom != nil { if md.ActiveFrom != nil {
c.ActiveHFs[*md.ActiveFrom] = struct{}{} c.ActiveHFs[*md.ActiveFrom] = struct{}{}