github.com/turingchain2020/turingchain@v1.1.21/system/dapp/manage/types/types.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package types 管理插件相关的定义 6 package types 7 8 import ( 9 "reflect" 10 11 "github.com/turingchain2020/turingchain/common/address" 12 "github.com/turingchain2020/turingchain/types" 13 ) 14 15 var ( 16 // ManageX defines a global string 17 ManageX = "manage" 18 actionName = map[string]int32{ 19 "Modify": ManageActionModifyConfig, 20 } 21 logmap = map[int64]*types.LogInfo{ 22 // 这里reflect.TypeOf类型必须是proto.Message类型,且是交易的回持结构 23 TyLogModifyConfig: {Ty: reflect.TypeOf(types.ReceiptConfig{}), Name: "LogModifyConfig"}, 24 } 25 ) 26 27 func init() { 28 types.AllowUserExec = append(types.AllowUserExec, []byte(ManageX)) 29 types.RegFork(ManageX, InitFork) 30 types.RegExec(ManageX, InitExecutor) 31 } 32 33 //InitFork init 34 func InitFork(cfg *types.TuringchainConfig) { 35 cfg.RegisterDappFork(ManageX, "Enable", 120000) 36 cfg.RegisterDappFork(ManageX, "ForkManageExec", 400000) 37 } 38 39 //InitExecutor init Executor 40 func InitExecutor(cfg *types.TuringchainConfig) { 41 types.RegistorExecutor(ManageX, NewType(cfg)) 42 } 43 44 // ManageType defines managetype 45 type ManageType struct { 46 types.ExecTypeBase 47 } 48 49 // NewType new a managetype object 50 func NewType(cfg *types.TuringchainConfig) *ManageType { 51 c := &ManageType{} 52 c.SetChild(c) 53 c.SetConfig(cfg) 54 return c 55 } 56 57 // GetPayload return manageaction 58 func (m *ManageType) GetPayload() types.Message { 59 return &ManageAction{} 60 } 61 62 // ActionName return action a string name 63 func (m ManageType) ActionName(tx *types.Transaction) string { 64 return "config" 65 } 66 67 // Amount amount 68 func (m ManageType) Amount(tx *types.Transaction) (int64, error) { 69 return 0, nil 70 } 71 72 // GetLogMap get log for map 73 func (m *ManageType) GetLogMap() map[int64]*types.LogInfo { 74 return logmap 75 } 76 77 // GetRealToAddr main reason for overloading this function is because of the manage protocol 78 // during implementation, to address specification varies fron height to height 79 func (m ManageType) GetRealToAddr(tx *types.Transaction) string { 80 if len(tx.To) == 0 { 81 // 如果To地址为空,则认为是早期低于types.ForkV11ManageExec高度的交易,直接返回合约地址 82 return address.ExecAddress(string(tx.Execer)) 83 } 84 return tx.To 85 } 86 87 // GetTypeMap return typename of actionname 88 func (m ManageType) GetTypeMap() map[string]int32 { 89 return actionName 90 } 91 92 // GetName reset name 93 func (m *ManageType) GetName() string { 94 return ManageX 95 }