github.com/igggame/nebulas-go@v2.1.0+incompatible/nf/nbre/types.go (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // the go-nebulas library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with the go-nebulas library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 19 package nbre 20 21 import ( 22 "errors" 23 24 "github.com/nebulasio/go-nebulas/core" 25 26 "encoding/json" 27 28 "github.com/nebulasio/go-nebulas/neblet/pb" 29 ) 30 31 // Error types 32 var ( 33 ErrConfigNotFound = errors.New("nbre config not found") 34 ErrNbreStartFailed = errors.New("nbre start failed") 35 ErrCommandNotFound = errors.New("nbre command not found") 36 ErrExecutionTimeout = errors.New("nbre execute timeout") 37 ErrHandlerNotFound = errors.New("nbre handler not found") 38 ErrNebCallbackTimeout = errors.New("nbre neb callback timeout") 39 ErrNbreCallbackFailed = errors.New("nbre callback failed") 40 ErrNbreCallbackTimeout = errors.New("nbre callback timeout") 41 ErrNbreCallbackException = errors.New("nbre callback exception") 42 ErrNbreCallbackNotReady = errors.New("nbre callback not ready") 43 ErrNbreCallbackCodeErr = errors.New("nbre callback code not found") 44 ) 45 46 // Command types 47 var ( 48 CommandVersion = "version" 49 CommandIRList = "irList" 50 CommandIRVersions = "irVersions" 51 CommandNRHandler = "nrHandler" 52 CommandNRListByHandle = "nrListByHandle" 53 CommandNRListByHeight = "nrListByHeight" 54 CommandNRSum = "nrSum" 55 CommandDIPList = "dipList" 56 ) 57 58 type Neblet interface { 59 Config() *nebletpb.Config 60 BlockChain() *core.BlockChain 61 } 62 63 type Version struct { 64 Major uint64 `json:"major"` 65 Minor uint64 `json:"minor"` 66 Patch uint64 `json:"patch"` 67 } 68 69 func (v *Version) ToBytes() ([]byte, error) { 70 return json.Marshal(v) 71 } 72 73 func (v *Version) FromBytes(data []byte) error { 74 if err := json.Unmarshal(data, v); err != nil { 75 return err 76 } 77 return nil 78 }