github.com/klaytn/klaytn@v1.12.1/cmd/homi/extra/encoder.go (about) 1 // Copyright 2018 The klaytn Authors 2 // Copyright 2017 AMIS Technologies 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 package extra 19 20 import ( 21 "bytes" 22 23 atypes "github.com/klaytn/klaytn/blockchain/types" 24 "github.com/klaytn/klaytn/common" 25 "github.com/klaytn/klaytn/common/hexutil" 26 "github.com/klaytn/klaytn/rlp" 27 ) 28 29 func Encode(vanity string, validators []common.Address) (string, error) { 30 newVanity, err := hexutil.Decode(vanity) 31 if err != nil { 32 return "", err 33 } 34 35 if len(newVanity) < atypes.IstanbulExtraVanity { 36 newVanity = append(newVanity, bytes.Repeat([]byte{0x00}, atypes.IstanbulExtraVanity-len(newVanity))...) 37 } 38 newVanity = newVanity[:atypes.IstanbulExtraVanity] 39 40 ist := &atypes.IstanbulExtra{ 41 Validators: validators, 42 Seal: make([]byte, atypes.IstanbulExtraSeal), 43 CommittedSeal: [][]byte{}, 44 } 45 46 payload, err := rlp.EncodeToBytes(&ist) 47 if err != nil { 48 return "", err 49 } 50 51 return "0x" + common.Bytes2Hex(append(newVanity, payload...)), nil 52 }