Class: Neb::Client::API

Inherits:
Object
  • Object
show all
Defined in:
lib/neb/client/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPI

Returns a new instance of API.



12
13
14
15
16
# File 'lib/neb/client/api.rb', line 12

def initialize
  @host        = CONFIG[:host]
  @api_version = CONFIG[:api_version]
  @endpoint    = CONFIG[:api_endpoint]
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



10
11
12
# File 'lib/neb/client/api.rb', line 10

def api_version
  @api_version
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



10
11
12
# File 'lib/neb/client/api.rb', line 10

def endpoint
  @endpoint
end

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/neb/client/api.rb', line 10

def host
  @host
end

Instance Method Details

#call(from:, to:, value:, nonce:, gas_price: 1_000_000, gas_limit: 20_000, contract: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/neb/client/api.rb', line 30

def call(from:, to:, value:, nonce:, gas_price: 1_000_000, gas_limit: 20_000, contract: nil)
  params = {
    from:      from,
    to:        to,
    value:     value.to_i,
    nonce:     nonce.to_i,
    gas_price: gas_price.to_i,
    gas_limit: gas_limit.to_i,
    contract:  contract
  }

  send_request(:post, "/call", params)
end

#estimate_gas(from:, to:, value:, nonce:, gas_price: 1_000_000, gas_limit: 20_000, contract: nil, binary: nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/neb/client/api.rb', line 73

def estimate_gas(from:, to:, value:, nonce:, gas_price: 1_000_000, gas_limit: 20_000, contract: nil, binary: nil)
  params = {
    from:      from,
    to:        to,
    value:     value.to_i,
    nonce:     nonce.to_i,
    gas_price: gas_price.to_i,
    gas_limit: gas_limit.to_i,
    contract:  contract,
    binary:    binary
  }

  send_request(:post, "/estimateGas", params)
end

#get_account_state(address:, height: 0) ⇒ Object



26
27
28
# File 'lib/neb/client/api.rb', line 26

def (address: , height: 0)
  send_request(:post, "/accountstate", address: address, height: height)
end

#get_block_by_hash(hash:, is_full: true) ⇒ Object



48
49
50
# File 'lib/neb/client/api.rb', line 48

def get_block_by_hash(hash:, is_full: true)
  send_request(:post, "/getBlockByHash", hash: hash, full_fill_transaction: is_full)
end

#get_block_by_height(height:, is_full: true) ⇒ Object



52
53
54
# File 'lib/neb/client/api.rb', line 52

def get_block_by_height(height:, is_full: true)
  send_request(:post, "/getBlockByHeight", height: height, full_fill_transaction: is_full)
end

#get_dynasty(height:) ⇒ Object



92
93
94
# File 'lib/neb/client/api.rb', line 92

def get_dynasty(height:)
  send_request(:post, "/dynasty", height: height)
end

#get_events_by_hash(hash:) ⇒ Object



88
89
90
# File 'lib/neb/client/api.rb', line 88

def get_events_by_hash(hash:)
  send_request(:post, "/getEventsByHash", hash: hash)
end

#get_gas_priceObject Also known as: gas_price



68
69
70
# File 'lib/neb/client/api.rb', line 68

def get_gas_price
  send_request(:get, "/getGasPrice")
end

#get_neb_stateObject



18
19
20
# File 'lib/neb/client/api.rb', line 18

def get_neb_state
  send_request(:get, "/nebstate")
end

#get_transaction_by_contract(address:) ⇒ Object



60
61
62
# File 'lib/neb/client/api.rb', line 60

def get_transaction_by_contract(address:)
  send_request(:post, "/getTransactionByContract", address: address)
end

#get_transaction_receipt(hash:) ⇒ Object



56
57
58
# File 'lib/neb/client/api.rb', line 56

def get_transaction_receipt(hash:)
  send_request(:post, "/getTransactionReceipt", hash: hash)
end

#latest_irreversible_blockObject



22
23
24
# File 'lib/neb/client/api.rb', line 22

def latest_irreversible_block
  send_request(:get, "/lib")
end

#send_raw_transaction(data:) ⇒ Object



44
45
46
# File 'lib/neb/client/api.rb', line 44

def send_raw_transaction(data:)
  send_request(:post, "/rawtransaction", data: data)
end

#subscribe(topics: []) ⇒ Object



64
65
66
# File 'lib/neb/client/api.rb', line 64

def subscribe(topics: [])
  send_request(:post, "/subscribe", topics: topics)
end