Class: Keoken::Bitprim::Transaction
- Inherits:
-
Object
- Object
- Keoken::Bitprim::Transaction
- Defined in:
- lib/keoken/bitprim/transaction.rb
Instance Method Summary collapse
-
#assets_by_address(address) ⇒ Array
Get tokens from address.
-
#estimate_fee ⇒ Json
Get estimate fee.
-
#send_tx(raw) ⇒ String
Broadcast a raw transaction.
-
#tx(txid) ⇒ Array
Get transaction details from transaction hash.
-
#utxos(address) ⇒ Array
Get utxos from address.
Instance Method Details
#assets_by_address(address) ⇒ Array
Get tokens from 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_fee ⇒ Json
Get estimate fee.
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.
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.
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.
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 |