Class: Bitcoin::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name, params = []) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bitcoin/request.rb', line 6

def initialize(service_name, params = [])
  @service_name = service_name
  @params = params.dup
  
  # bitcoin rejects null values even for optional params. Since
  # even params following those may have default non-nil values,
  # we'll assume the first non-nil value marks a set of optional
  # params, and drop it and everything following it.
  #
  # ex:
  #   [nil]          => []
  #   [1,nil,nil]    => [1]
  #   [1,nil,nil,1]  => [1]
  if index = @params.index(nil)
    @params = @params[0...index]
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/bitcoin/request.rb', line 4

def params
  @params
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



4
5
6
# File 'lib/bitcoin/request.rb', line 4

def service_name
  @service_name
end

Instance Method Details

#to_hashObject



24
25
26
27
28
29
30
# File 'lib/bitcoin/request.rb', line 24

def to_hash
  {
    :method => service_name,
    :params => params,
    :id => "jsonrpc"
  }
end

#to_post_dataObject



32
33
34
# File 'lib/bitcoin/request.rb', line 32

def to_post_data
  to_hash.to_json
end