forked from TrueCloudLab/neoneo-go
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.
|
||||
|
|
|
@ -323,7 +323,10 @@ func newDescriptor(name string, ret smartcontract.ParamType, ps ...manifest.Para
|
|||
}
|
||||
}
|
||||
|
||||
func newMethodAndPrice(f interop.Method, cpuFee int64, flags callflag.CallFlag, activeFrom ...config.Hardfork) *interop.MethodAndPrice {
|
||||
// newMethodAndPrice builds method with the provided descriptor and ActiveFrom/ActiveTill hardfork
|
||||
// values consequently specified via activations. [config.HFDefault] specfied as ActiveFrom is treated
|
||||
// as active starting from the genesis block.
|
||||
func newMethodAndPrice(f interop.Method, cpuFee int64, flags callflag.CallFlag, activations ...config.Hardfork) *interop.MethodAndPrice {
|
||||
md := &interop.MethodAndPrice{
|
||||
HFSpecificMethodAndPrice: interop.HFSpecificMethodAndPrice{
|
||||
Func: f,
|
||||
|
@ -331,8 +334,13 @@ func newMethodAndPrice(f interop.Method, cpuFee int64, flags callflag.CallFlag,
|
|||
RequiredFlags: flags,
|
||||
},
|
||||
}
|
||||
if len(activeFrom) != 0 {
|
||||
md.ActiveFrom = &activeFrom[0]
|
||||
if len(activations) > 0 {
|
||||
if activations[0] != config.HFDefault {
|
||||
md.ActiveFrom = &activations[0]
|
||||
}
|
||||
}
|
||||
if len(activations) > 1 {
|
||||
md.ActiveTill = &activations[1]
|
||||
}
|
||||
return md
|
||||
}
|
||||
|
@ -347,14 +355,19 @@ func newEventDescriptor(name string, ps ...manifest.Parameter) *manifest.Event {
|
|||
}
|
||||
}
|
||||
|
||||
func newEvent(desc *manifest.Event, activeFrom ...config.Hardfork) interop.Event {
|
||||
// newEvent builds event with the provided descriptor and ActiveFrom/ActiveTill hardfork
|
||||
// values consequently specified via activations.
|
||||
func newEvent(desc *manifest.Event, activations ...config.Hardfork) interop.Event {
|
||||
md := interop.Event{
|
||||
HFSpecificEvent: interop.HFSpecificEvent{
|
||||
MD: desc,
|
||||
},
|
||||
}
|
||||
if len(activeFrom) != 0 {
|
||||
md.ActiveFrom = &activeFrom[0]
|
||||
if len(activations) > 0 {
|
||||
md.ActiveFrom = &activations[0]
|
||||
}
|
||||
if len(activations) > 1 {
|
||||
md.ActiveTill = &activations[1]
|
||||
}
|
||||
return md
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue