github.com/klaytn/klaytn@v1.10.2/datasync/chaindatafetcher/types/types.go (about) 1 // Copyright 2020 The klaytn Authors 2 // This file is part of the klaytn library. 3 // 4 // The klaytn library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The klaytn library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 16 17 package types 18 19 // RequestType informs which data should be exported such as block, transaction, transaction log, etc. 20 type RequestType uint 21 22 const ( 23 // RequestTypes for KAS (deprecated) 24 RequestTypeTransaction = RequestType(1) << iota 25 RequestTypeTokenTransfer 26 RequestTypeContract 27 RequestTypeTrace 28 29 // RequestTypes for Kafka 30 RequestTypeBlockGroup 31 RequestTypeTraceGroup 32 33 RequestTypeLength 34 ) 35 36 const ( 37 RequestTypeAll = RequestTypeTransaction | RequestTypeTokenTransfer | RequestTypeContract | RequestTypeTrace 38 RequestTypeGroupAll = RequestTypeBlockGroup | RequestTypeTraceGroup 39 ) 40 41 func (t RequestType) IsValid() bool { 42 return t == RequestTypeBlockGroup || t == RequestTypeTraceGroup || t == RequestTypeGroupAll 43 } 44 45 func (t RequestType) String() string { 46 switch t { 47 case RequestTypeGroupAll: 48 return "all" 49 case RequestTypeBlockGroup: 50 return "block" 51 case RequestTypeTraceGroup: 52 return "trace" 53 default: 54 return "unknown" 55 } 56 } 57 58 // Request contains a blockNumber which should be handled and the type of data which should be exported. 59 type Request struct { 60 ReqType RequestType 61 ShouldUpdateCheckpoint bool 62 BlockNumber uint64 63 } 64 65 func CheckRequestType(rt RequestType, targetType RequestType) bool { 66 return rt&targetType == targetType 67 } 68 69 func NewRequest(reqType RequestType, shouldUpdateCheckpoint bool, block uint64) *Request { 70 return &Request{ 71 ReqType: reqType, 72 ShouldUpdateCheckpoint: shouldUpdateCheckpoint, 73 BlockNumber: block, 74 } 75 }