Class: Keoken::Bitprim::Transaction

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

Instance Method Summary collapse

Instance Method Details

#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 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

#estimate_feeJson

Get estimate fee.

Returns:

  • (Json)

    Fee estimated per kb.



71
72
73
74
75
76
77
# File 'lib/keoken/bitprim/transaction.rb', line 71

def estimate_fee
  uri = URI("#{root_node_url}/utils/estimatefee")
  response = Net::HTTP.get_response(uri)

  result = JSON.parse(response.body)
  result['2']
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")
  response = Net::HTTP.post_form(uri, 'rawtx' => raw)

  case response
  when Net::HTTPSuccess then
    JSON.parse(response.body)
  else
    response.body
  end
end

#tx(txid) ⇒ Array

Get transaction details from transaction hash.

Parameters:

  • txid (String)

    The transaction id to get the info.

Returns:

  • (Array)

    Detailed info from transaction.



60
61
62
63
64
65
# File 'lib/keoken/bitprim/transaction.rb', line 60

def tx(txid)
  uri = URI("#{root_node_url}/tx/#{txid}")
  response = Net::HTTP.get_response(uri)

  JSON.parse(response.body)
end

#utxos(address) ⇒ Array

Get utxos from address.

Parameters:

  • address (String)

    The address that contains the utxos.

Returns:

  • (Array)

    Detailed info from utxos.



47
48
49
50
51
52
# File 'lib/keoken/bitprim/transaction.rb', line 47

def utxos(address)
  uri = URI("#{root_node_url}/addr/#{address}/utxo")
  response = Net::HTTP.get_response(uri)

  JSON.parse(response.body)
end