github.com/klaytn/klaytn@v1.12.1/api/api_public_debug.go (about) 1 // Modifications Copyright 2019 The klaytn Authors 2 // Copyright 2015 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser 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-ethereum 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 Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from internal/ethapi/api.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package api 22 23 import ( 24 "context" 25 "fmt" 26 27 "github.com/klaytn/klaytn/networks/rpc" 28 "github.com/klaytn/klaytn/rlp" 29 ) 30 31 // PublicDebugAPI is the collection of Klaytn APIs exposed over the public 32 // debugging endpoint. 33 type PublicDebugAPI struct { 34 b Backend 35 } 36 37 // NewPublicDebugAPI creates a new API definition for the public debug methods 38 // of the Klaytn service. 39 func NewPublicDebugAPI(b Backend) *PublicDebugAPI { 40 return &PublicDebugAPI{b: b} 41 } 42 43 // GetBlockRlp retrieves the RLP encoded for of a single block. 44 func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (string, error) { 45 block, _ := api.b.BlockByNumberOrHash(ctx, blockNrOrHash) 46 if block == nil { 47 blockNumberOrHashString, _ := blockNrOrHash.NumberOrHashString() 48 return "", fmt.Errorf("block %v not found", blockNumberOrHashString) 49 } 50 encoded, err := rlp.EncodeToBytes(block) 51 if err != nil { 52 return "", err 53 } 54 return fmt.Sprintf("%x", encoded), nil 55 }