Class: Synthra::Types::Crypto::EthereumAddress

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/crypto/crypto.rb

Overview

EthereumAddress type

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



64
65
66
# File 'lib/synthra/types/crypto/crypto.rb', line 64

def generate_edge(rng, context, args)
  ["0x0000000000000000000000000000000000000000", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



68
69
70
# File 'lib/synthra/types/crypto/crypto.rb', line 68

def generate_invalid(rng, context, args)
  [nil, "not an address", "invalid", [], {}].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ String

Generate random Ethereum address

Parameters:

Returns:

  • (String)

    generated Ethereum address



57
58
59
60
61
62
# File 'lib/synthra/types/crypto/crypto.rb', line 57

def generate_random(rng, context, args)
  # Ethereum addresses are 40 hex characters (20 bytes)
  hex_chars = ("0".."9").to_a + ("a".."f").to_a + ("A".."F").to_a
  address = 40.times.map { rng.sample(hex_chars) }.join
  "0x#{address}"
end