native: support native method/event removal
Port a part of https://github.com/neo-project/neo/issues/3210. A part of #3440. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
2d4993a837
commit
df1ed68d98
2 changed files with 31 additions and 8 deletions
|
@ -144,6 +144,7 @@ type Method = func(ic *Context, args []stackitem.Item) stackitem.Item
|
|||
type MethodAndPrice struct {
|
||||
HFSpecificMethodAndPrice
|
||||
ActiveFrom *config.Hardfork
|
||||
ActiveTill *config.Hardfork
|
||||
}
|
||||
|
||||
// HFSpecificMethodAndPrice is a hardfork-specific native contract method descriptor.
|
||||
|
@ -160,6 +161,7 @@ type HFSpecificMethodAndPrice struct {
|
|||
type Event struct {
|
||||
HFSpecificEvent
|
||||
ActiveFrom *config.Hardfork
|
||||
ActiveTill *config.Hardfork
|
||||
}
|
||||
|
||||
// HFSpecificEvent is a hardfork-specific native contract event descriptor.
|
||||
|
@ -289,7 +291,8 @@ func (c *ContractMD) buildHFSpecificMD(hf config.Hardfork) {
|
|||
w := io.NewBufBinWriter()
|
||||
for i := range c.methods {
|
||||
m := c.methods[i]
|
||||
if !(m.ActiveFrom == nil || (hf != config.HFDefault && (*m.ActiveFrom).Cmp(hf) >= 0)) {
|
||||
if !(m.ActiveFrom == nil || (hf != config.HFDefault && (*m.ActiveFrom).Cmp(hf) >= 0)) ||
|
||||
(m.ActiveTill != nil && (*m.ActiveTill).Cmp(hf) <= 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -311,7 +314,8 @@ func (c *ContractMD) buildHFSpecificMD(hf config.Hardfork) {
|
|||
}
|
||||
for i := range c.events {
|
||||
e := c.events[i]
|
||||
if !(e.ActiveFrom == nil || (hf != config.HFDefault && (*e.ActiveFrom).Cmp(hf) >= 0)) {
|
||||
if !(e.ActiveFrom == nil || (hf != config.HFDefault && (*e.ActiveFrom).Cmp(hf) >= 0)) ||
|
||||
(e.ActiveTill != nil && (*e.ActiveTill).Cmp(hf) <= 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -369,6 +373,9 @@ func (c *ContractMD) AddMethod(md *MethodAndPrice, desc *manifest.Method) {
|
|||
if md.ActiveFrom != nil {
|
||||
c.ActiveHFs[*md.ActiveFrom] = struct{}{}
|
||||
}
|
||||
if md.ActiveTill != nil {
|
||||
c.ActiveHFs[*md.ActiveTill] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// GetMethodByOffset returns method with the provided offset.
|
||||
|
@ -410,6 +417,9 @@ func (c *ContractMD) AddEvent(md Event) {
|
|||
if md.ActiveFrom != nil {
|
||||
c.ActiveHFs[*md.ActiveFrom] = struct{}{}
|
||||
}
|
||||
if md.ActiveTill != nil {
|
||||
c.ActiveHFs[*md.ActiveTill] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort sorts interop functions by id.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue