Class: Keoken::Bitprim::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/keoken/bitprim/transaction.rb

Instance Method Summary collapse

Instance Method Details

#get_assets_by_address(address) ⇒ Array

Get tokens from address.

Parameters:

  • address (String)

    The address that contains the tokens.

Returns:

  • (Array)

    Detailed info from tokens associated to the address.


32
33
34
35
36
37
38
39
# File 'lib/keoken/bitprim/transaction.rb', line 32

def get_assets_by_address(address)
  uri = URI("#{root_keoken_url}/get_assets_by_address")
  params = { address: address }
  uri.query = URI.encode_www_form(params)
  response = Net::HTTP.get_response(uri)

  JSON.parse(response.body.tr('\'', '"'))
end

#send_tx(raw) ⇒ String

Broadcast a raw transaction.

Parameters:

  • raw (String)

    The raw transaction.

Returns:

  • (String)

    Value from response.


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/keoken/bitprim/transaction.rb', line 14

def send_tx(raw)
  uri = URI("#{root_node_url}/tx/send")
  request = Net::HTTP::Post.new(uri)
  request.set_form_data(rawtx: raw)

  response = Net::HTTP.start(uri.hostname, uri.port) do |http|
    http.request(request)
  end

  response.value
end