class Secp256k1::Ethereum::Enode

Overview

Implements an Ethereum devp2p enode containing a Keypair and an IP address.

Properties:

p2p = Secp256k1::Ethereum::Enode.new
p2p.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
p2p.to_s
# => "enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303"

Defined in:

ethereum.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(key_pair, host, port) #

Generates an Ethereum::Enode from a provided Keypair and a custom IP address with port.

key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
p2p = Secp256k1::Ethereum::Enode.new key, "192.168.13.37", 31337
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>

[View source]
def self.new(key_pair, port) #

Generates an Ethereum::Enode from a provided Keypair and a custom port.

key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
p2p = Secp256k1::Ethereum::Enode.new key, 50000
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>

Note, this tries to find out the public IP address and silently falls back to "127.0.0.1" if it fails.


[View source]
def self.new(key_pair) #

Generates an Ethereum::Enode from a provided Keypair.

key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
p2p = Secp256k1::Ethereum::Enode.new key
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>

Note, this tries to find out the public IP address and silently falls back to "127.0.0.1" if it fails.


[View source]
def self.new #

Generates a new Ethereum::Enode from a fresh random Keypair.

p2p = Secp256k1::Ethereum::Enode.new
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>

Note, this tries to find out the public IP address and silently falls back to "127.0.0.1" if it fails.


[View source]

Instance Method Detail

def address : Socket::IPAddress #

The public (or local) IP address with port.


[View source]
def address=(address : Socket::IPAddress) #

The public (or local) IP address with port.


[View source]
def get_my_ip #

Tries to find out the public IP address for the node.

It queries ident.me for a potential public IP and silently falls back to "127.0.0.1" if it fails without raising. Should be used with caution.

p2p.get_my_ip
# => "84.160.86.205"

[View source]
def get_secret #

Gets the private key as hexadecimal formatted string literal.

p2p.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"

[View source]
def key_pair : Keypair #

The Keypair containing the secret key.


[View source]
def key_pair=(key_pair : Keypair) #

The Keypair containing the secret key.


[View source]
def to_s #

Gets the Enode formatted as devp2p enode address.

p2p.to_s
# => "enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303"

[View source]