Module: Neo

Defined in:
lib/neo.rb,
lib/neo/rpc.rb,
lib/neo/block.rb,
lib/neo/version.rb,
lib/neo/configuration.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Block, Configuration

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config


7
8
9
# File 'lib/neo/configuration.rb', line 7

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Used to configure the Neo library.

Examples:

Neo.configure do |c|
  c.network = 'MainNet'
end

Yields:

  • the configuration block

Yield Parameters:


41
42
43
# File 'lib/neo/configuration.rb', line 41

def self.configure
  yield config
end

.rpc(method, *params) ⇒ Hash

Make a call to a Neo node's JSON-RPC interface


11
12
13
14
15
16
17
18
# File 'lib/neo/rpc.rb', line 11

def self.rpc(method, *params)
  # TODO: Do somethign better than just randomly picking a seed
  uri = URI(Neo.config.seeds.to_a.sample)
  options = { jsonrpc: '2.0', method: method, params: params.to_s, id: 1 }
  uri.query = URI.encode_www_form(options)
  response = Net::HTTP.get(uri)
  JSON.parse(response)['result']
end

.versionString

Note:

This string also has singleton methods:

  • `major` [Integer] The major version.

  • `minor` [Integer] The minor version.

  • `patch` [Integer] The patch version.

  • `parts` [Array<Integer>] List of the version parts.

rubocop:disable MethodLength


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/neo/version.rb', line 11

def version
  @version ||= begin
    string = '0.0.0'

    def string.parts
      split('.').map(&:to_i)
    end

    def string.major
      parts[0]
    end

    def string.minor
      parts[1]
    end

    def string.patch
      parts[2]
    end

    string
  end
end