github.com/codingfuture/orig-energi3@v0.8.4/energi/common/enode.go (about) 1 // Copyright 2019 The Energi Core Authors 2 // This file is part of the Energi Core library. 3 // 4 // The Energi Core 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 Energi Core 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 Energi Core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package common 18 19 import ( 20 "net" 21 22 "github.com/ethereum/go-ethereum/crypto" 23 "github.com/ethereum/go-ethereum/log" 24 "github.com/ethereum/go-ethereum/p2p/enode" 25 "github.com/ethereum/go-ethereum/params" 26 ) 27 28 func MastenodeEnode(ipv4address uint32, pubkey [2][32]byte, cfg *params.ChainConfig) *enode.Node { 29 ip := net.IPv4( 30 byte(ipv4address>>24), 31 byte(ipv4address>>16), 32 byte(ipv4address>>8), 33 byte(ipv4address), 34 ) 35 36 pubkey_buf := make([]byte, 33) 37 copy(pubkey_buf[:32], pubkey[0][:]) 38 copy(pubkey_buf[32:33], pubkey[1][:]) 39 pk, err := crypto.DecompressPubkey(pubkey_buf) 40 if err != nil { 41 log.Error("Failed to unmarshal Masternode pubkey") 42 return nil 43 } 44 45 return enode.NewV4(pk, ip, int(cfg.ChainID.Int64()), int(cfg.ChainID.Int64())) 46 }