Class: Neb::Client::Admin

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdmin

Returns a new instance of Admin.



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

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

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



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

def api_version
  @api_version
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

Instance Method Details

#accountsObject



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

def accounts
  send_request(:get, "/accounts")
end

#get_configObject



82
83
84
# File 'lib/neb/client/admin.rb', line 82

def get_config
  send_request(:get, "/getConfig")
end

#lock_account(address:) ⇒ Object



39
40
41
# File 'lib/neb/client/admin.rb', line 39

def (address:)
  send_request(:post, "/account/lock", address: address)
end

#new_account(passphrase:) ⇒ Object



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

def (passphrase:)
  send_request(:post, "/account/new", passphrase: passphrase)
end

#node_infoObject



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

def node_info
  send_request(:get, "/nodeinfo")
end

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



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/neb/client/admin.rb', line 43

def send_transaction(from:, to:, value:, nonce:, gas_price: 1_000_000, gas_limit: 20_000)
  params = {
    from:      from,
    to:        to,
    value:     value.to_i.to_s,
    nonce:     nonce.to_i.to_s,
    gas_price: gas_price.to_i.to_s,
    gas_limit: gas_limit.to_i.to_s
  }
  send_request(:post, "/transaction", params)
end

#sign_hash(address:, hash:, alg: 1) ⇒ Object



55
56
57
# File 'lib/neb/client/admin.rb', line 55

def sign_hash(address:, hash:, alg: 1)
  send_request(:post, "/sign/hash", address: address, hash: hash, alg: alg)
end

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/neb/client/admin.rb', line 59

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

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

#start_pprof(listen:) ⇒ Object



78
79
80
# File 'lib/neb/client/admin.rb', line 78

def start_pprof(listen:)
  send_request(:post, "/pprof", listen: listen)
end

#unlock_account(address:, passphrase:, duration: '30000000000') ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/neb/client/admin.rb', line 30

def (address:, passphrase:, duration: '30000000000')
  params = {
    address:    address,
    passphrase: passphrase,
    duration:   duration
  }
  send_request(:post, "/account/unlock", params)
end