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