forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
codec.go
56 lines (44 loc) · 1.17 KB
/
codec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package txs
import (
"reflect"
"github.com/MetalBlockchain/metalgo/codec"
"github.com/MetalBlockchain/metalgo/utils/logging"
"github.com/MetalBlockchain/metalgo/utils/timer/mockable"
"github.com/MetalBlockchain/metalgo/utils/wrappers"
"github.com/MetalBlockchain/metalgo/vms/secp256k1fx"
)
var (
_ codec.Registry = (*codecRegistry)(nil)
_ secp256k1fx.VM = (*fxVM)(nil)
)
type codecRegistry struct {
codecs []codec.Registry
index int
typeToIndex map[reflect.Type]int
}
func (cr *codecRegistry) RegisterType(val interface{}) error {
valType := reflect.TypeOf(val)
cr.typeToIndex[valType] = cr.index
errs := wrappers.Errs{}
for _, c := range cr.codecs {
errs.Add(c.RegisterType(val))
}
return errs.Err
}
type fxVM struct {
typeToFxIndex map[reflect.Type]int
clock *mockable.Clock
log logging.Logger
codecRegistry codec.Registry
}
func (vm *fxVM) Clock() *mockable.Clock {
return vm.clock
}
func (vm *fxVM) CodecRegistry() codec.Registry {
return vm.codecRegistry
}
func (vm *fxVM) Logger() logging.Logger {
return vm.log
}