Skip to content

Commit

Permalink
core: unexport generic native contract methods and events
Browse files Browse the repository at this point in the history
External users should use HF-specific methods and events.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
  • Loading branch information
AnnaShaleva committed Apr 5, 2024
1 parent 528fcc0 commit 3d947f5
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions pkg/core/interop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ type ContractMD struct {
Hash util.Uint160
Name string
// TODO: remove Methods and Events at all, build HF-specific MD in-place for every hardfork and cache them.
// 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.
Methods []MethodAndPrice
// Events is a generic set of contract events with activation hardforks. Any HF-dependent part of events must not be
methods []MethodAndPrice
// 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.
Events []Event
events []Event
// ActiveHFs is a map of hardforks that contract should react to. Contract update or deploy should be called for
// active hardforks. This map is being initialized on contract creation and used as a read-only, hens, not protected
// by mutex.
Expand Down Expand Up @@ -264,14 +264,14 @@ func (c *ContractMD) buildHFSpecificMD(hf *config.Hardfork) *HFSpecificContractM
// If not, then value from the previous hardfork may safely be reused.

var (
abiMethods = make([]manifest.Method, 0, len(c.Methods))
methods = make([]HFSpecificMethodAndPrice, 0, len(c.Methods))
abiEvents = make([]manifest.Event, 0, len(c.Events))
events = make([]HFSpecificEvent, 0, len(c.Events))
abiMethods = make([]manifest.Method, 0, len(c.methods))
methods = make([]HFSpecificMethodAndPrice, 0, len(c.methods))
abiEvents = make([]manifest.Event, 0, len(c.events))
events = make([]HFSpecificEvent, 0, len(c.events))
)
w := io.NewBufBinWriter()
for i := range c.Methods {
m := c.Methods[i]
for i := range c.methods {
m := c.methods[i]
if !(m.ActiveFrom == nil || (hf != nil && (*m.ActiveFrom).Cmp(*hf) <= 0)) {
continue

Check warning on line 276 in pkg/core/interop/context.go

View check run for this annotation

Codecov / codecov/patch

pkg/core/interop/context.go#L276

Added line #L276 was not covered by tests
}
Expand All @@ -292,8 +292,8 @@ func (c *ContractMD) buildHFSpecificMD(hf *config.Hardfork) *HFSpecificContractM
if w.Err != nil {
panic(fmt.Errorf("can't create native contract script: %w", w.Err))
}
for i := range c.Events {
e := c.Events[i]
for i := range c.events {
e := c.events[i]
if !(e.ActiveFrom == nil || (hf != nil && (*e.ActiveFrom).Cmp(*hf) <= 0)) {
continue

Check warning on line 298 in pkg/core/interop/context.go

View check run for this annotation

Codecov / codecov/patch

pkg/core/interop/context.go#L298

Added line #L298 was not covered by tests
}
Expand Down Expand Up @@ -345,16 +345,16 @@ func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
md.MD = desc
desc.Safe = md.RequiredFlags&(callflag.All^callflag.ReadOnly) == 0

index := sort.Search(len(c.Methods), func(i int) bool {
md := c.Methods[i].MD
index := sort.Search(len(c.methods), func(i int) bool {
md := c.methods[i].MD
if md.Name != desc.Name {
return md.Name >= desc.Name
}
return len(md.Parameters) > len(desc.Parameters)
})
c.Methods = append(c.Methods, MethodAndPrice{})
copy(c.Methods[index+1:], c.Methods[index:])
c.Methods[index] = *md
c.methods = append(c.methods, MethodAndPrice{})
copy(c.methods[index+1:], c.methods[index:])
c.methods[index] = *md

if md.ActiveFrom != nil {
c.ActiveHFs[*md.ActiveFrom] = struct{}{}
Expand Down Expand Up @@ -395,7 +395,7 @@ func (c *HFSpecificContractMD) GetMethod(name string, paramCount int) (HFSpecifi

// AddEvent adds a new event to the native contract.
func (c *ContractMD) AddEvent(md Event) {
c.Events = append(c.Events, md)
c.events = append(c.events, md)

if md.ActiveFrom != nil {
c.ActiveHFs[*md.ActiveFrom] = struct{}{}
Expand Down

0 comments on commit 3d947f5

Please sign in to comment.