github.com/lmittmann/w3@v0.20.0/module/admin/admin.go (about) 1 /* 2 Package admin implements RPC API bindings for methods in the "admin" namespace. 3 */ 4 package admin 5 6 import ( 7 "math/big" 8 "net" 9 10 "github.com/ethereum/go-ethereum/common" 11 "github.com/ethereum/go-ethereum/p2p/enode" 12 "github.com/lmittmann/w3/internal/module" 13 "github.com/lmittmann/w3/w3types" 14 ) 15 16 // AddPeer adds the given peer to the node's peer set and returns a bool 17 // indicating success. 18 func AddPeer(url *enode.Node) w3types.RPCCallerFactory[bool] { 19 return module.NewFactory[bool]( 20 "admin_addPeer", 21 []any{url}, 22 ) 23 } 24 25 // RemovePeer disconnects from the given peer if the connection exists and 26 // returns a bool indicating success. 27 func RemovePeer(url *enode.Node) w3types.RPCCallerFactory[bool] { 28 return module.NewFactory[bool]( 29 "admin_removePeer", 30 []any{url}, 31 ) 32 } 33 34 // AddTrustedPeer adds the given peer to the trusted peers list and returns a 35 // bool indicating success. 36 func AddTrustedPeer(url *enode.Node) w3types.RPCCallerFactory[bool] { 37 return module.NewFactory[bool]( 38 "admin_addTrustedPeer", 39 []any{url}, 40 ) 41 } 42 43 // RemoveTrustedPeer removes a remote node from the trusted peers list and 44 // returns a bool indicating success. 45 func RemoveTrustedPeer(url *enode.Node) w3types.RPCCallerFactory[bool] { 46 return module.NewFactory[bool]( 47 "admin_removeTrustedPeer", 48 []any{url}, 49 ) 50 } 51 52 // NodeInfo returns information about the running node. 53 func NodeInfo() w3types.RPCCallerFactory[*NodeInfoResponse] { 54 return module.NewFactory[*NodeInfoResponse]( 55 "admin_nodeInfo", 56 []any{}, 57 ) 58 } 59 60 type NodeInfoResponse struct { 61 Enode *enode.Node `json:"enode"` 62 ID string `json:"id"` 63 IP net.IP `json:"ip"` 64 ListenAddr string `json:"listenAddr"` 65 Name string `json:"name"` 66 Ports *PortsInfo `json:"ports"` 67 Protocols map[string]*ProtocolInfo `json:"protocols"` 68 } 69 70 type PortsInfo struct { 71 Discovery int `json:"discovery"` 72 Listener int `json:"listener"` 73 } 74 75 type ProtocolInfo struct { 76 Difficulty *big.Int `json:"difficulty"` 77 Genesis common.Hash `json:"genesis"` 78 Head common.Hash `json:"head"` 79 Network int `json:"network"` 80 }