2019-12-19 19:37:49 +00:00
|
|
|
package actors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type update struct {
|
2019-12-19 20:00:59 +00:00
|
|
|
start uint64
|
2019-12-19 19:37:49 +00:00
|
|
|
method interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func withUpdates(updates ...update) interface{} {
|
|
|
|
sort.Slice(updates, func(i, j int) bool { // so we iterate from newest below
|
|
|
|
return updates[i].start > updates[j].start
|
|
|
|
})
|
|
|
|
|
|
|
|
// <script type="application/javascript">
|
|
|
|
|
|
|
|
typ := reflect.TypeOf(updates[0].method)
|
|
|
|
|
|
|
|
out := reflect.MakeFunc(typ, func(args []reflect.Value) (results []reflect.Value) {
|
|
|
|
vmctx := args[1].Interface().(types.VMContext)
|
|
|
|
|
|
|
|
for _, u := range updates {
|
2020-01-31 05:20:57 +00:00
|
|
|
if vmctx.BlockHeight() > u.start {
|
2019-12-19 19:37:49 +00:00
|
|
|
return reflect.ValueOf(u.method).Call(args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 08:31:59 +00:00
|
|
|
return reflect.ValueOf(notFound(vmctx)).Call([]reflect.Value{})
|
2019-12-19 19:37:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return out.Interface()
|
|
|
|
|
|
|
|
// </script>
|
|
|
|
}
|
|
|
|
|
|
|
|
func notFound(vmctx types.VMContext) func() ([]byte, ActorError) {
|
|
|
|
return func() ([]byte, ActorError) {
|
|
|
|
return nil, aerrors.Fatal("no code for method %d at height %d", vmctx.Message().Method, vmctx.BlockHeight())
|
|
|
|
}
|
2019-12-19 20:00:59 +00:00
|
|
|
}
|