lisk 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d527806f8f47279705cb1cfd3e6ce771387fa69
4
- data.tar.gz: 0716014534de9e321302f44f8ddfb417279294bb
3
+ metadata.gz: 8eafe7fb9b6dbf55042554ee4a579a0e0f5d418f
4
+ data.tar.gz: e22f1dd7407b0d147c8fd9094a4b344894d43f28
5
5
  SHA512:
6
- metadata.gz: e1060e59743ff5d8b476a558af469ba43e37d2ecc1da96b308f3605c3011f8cefd76e0b8e5482e9e55b371f9923fec0d36f84e3523c3dbb1e410ee44959a5985
7
- data.tar.gz: ba79a7a558efb74293b4783e020bf4c186ed7aa92dd0f2a8698fdde0d3af5a3a81de4f210496fe3889acc84f0ee4a443e779342349999a09efb91d0f535d5325
6
+ metadata.gz: 0f361fd322d242a1c91dd3c7cf2befbd4ea04bc1f2a5240cce08a761c043ce79b86ab19c5bba7599e8710d969ae7d5b75ba0634d081daf961d4098424505ec3f
7
+ data.tar.gz: 4ceb3c01274c177097f4a187747a8d55f51747a4831217870f09606948c147b9b9ca05408fffa6fa36495c473c9104bb280246cf5f75c18233ebac9db3b9f2ec
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  A simple Ruby wrapper for the Lisk API. 💎
4
4
 
5
+ ![Live-Preview.](examples/4fryn-lisk-rb.gif)
6
+
5
7
  ## Note before using
6
8
 
7
9
  This is very early work-in-progress. The idea is to publish this `gem` as soon as it is fully compatible with Lisk Core 1.0.0, which, however, is not released yet. The current implementation of the lisk.rb gem is pure minimal by design and barely allows checking the node status.
@@ -9,7 +11,7 @@ This is very early work-in-progress. The idea is to publish this `gem` as soon a
9
11
  API Implemententation Status:
10
12
 
11
13
  - `Lisk::Legacy` 48/62 APIs for Lisk Core 0.8.0+ ([#4](https://github.com/4fryn/lisk.rb/issues/4))
12
- - `Lisk::API` 0/34 APIs for Lisk Core 1.0.0+ ([#1](https://github.com/4fryn/lisk.rb/issues/1))
14
+ - `Lisk::Raw` 0/34 APIs for Lisk Core 1.0.0+ ([#1](https://github.com/4fryn/lisk.rb/issues/1))
13
15
 
14
16
  ## Installation
15
17
 
@@ -42,49 +44,55 @@ require 'lisk'
42
44
  To get started, point the lisk.rb to any Lisk-API endpoint. By default, lisk.rb assumes a running Lisk testnet node on localhost port 7000.
43
45
 
44
46
  ```ruby
45
- client = Lisk::Client.new "127.0.0.1", 7000
47
+ node = Lisk::Client.new "127.0.0.1", 7000
46
48
  ```
47
49
 
48
- Get access to the Lisk-0.8.0 legacy API (see [#4](https://github.com/4fryn/lisk.rb/issues/4)).
50
+ For convenience, check if the Lisk node is connected, fully synchronized, and active by pinging it.
49
51
 
50
52
  ```ruby
51
- legacy_api = Lisk::Legacy.new client
53
+ if node.is_alive?
54
+ # only do stuff if client is connected, fully synchronized, and active ...
55
+ end
52
56
  ```
53
57
 
54
- For convenience, check if the Lisk node is connected, fully synchronized, and active by pinging it.
58
+ Get access to the Lisk-0.8.0 legacy API (see [#4](https://github.com/4fryn/lisk.rb/issues/4)).
55
59
 
56
60
  ```ruby
57
- if legacy_api.loader_status_ping
58
- # only do stuff if client is connected, fully synchronized, and active ...
59
- end
61
+ lisk = Lisk::API.new node
60
62
  ```
61
63
 
62
64
  Get the version of the connected Lisk node.
63
65
 
64
66
  ```ruby
65
- version = legacy_api.peers_version
66
- p "Lisk node version #{version["version"]} build #{version["build"]}..."
67
+ version = lisk.get_version
68
+ build = lisk.get_version_build
69
+ p "Lisk node version #{version} build #{build}..."
67
70
  ```
68
71
 
69
72
  Get the status of the connected Lisk node.
70
73
 
71
74
  ```ruby
72
- status = legacy_api.loader_status
73
- p "Lisk node is connected: #{status["success"]}... Blockchain loaded: #{status["loaded"]}..."
75
+ connected = node.is_alive?
76
+ loaded = lisk.is_chain_loaded?
77
+ p "Lisk node is connected: #{connected}... Blockchain loaded: #{loaded}..."
74
78
  ```
75
79
 
76
80
  Figure out if the node is still synchronizing.
77
81
 
78
82
  ```ruby
79
- syncing = legacy_api.loader_status_sync
80
- p "Lisk node is syncing: #{syncing["syncing"]}... #{syncing["blocks"]} remaining blocks to latest block #{syncing["height"]}..."
83
+ syncing = lisk.is_syncing?
84
+ remaining = lisk.get_remaining_blocks
85
+ best = lisk.get_chain_best_block
86
+ p "Lisk node is syncing: #{syncing}... #{remaining} remaining blocks to latest block #{best}..."
81
87
  ```
82
88
 
83
89
  Get some global Lisk blockchain stats.
84
90
 
85
91
  ```ruby
86
- chain = legacy_api.blocks_get_status
87
- p "Lisk chain latest block: #{chain["height"]}... total supply: #{chain["supply"] / 1e8}... block reward: #{chain["reward"] / 1e8}"
92
+ height = lisk.get_best_block
93
+ reward = lisk.get_block_reward / 1e8
94
+ supply = lisk.get_available_supply / 1e8
95
+ p "Lisk chain latest block: #{height}... total supply: #{supply}... block reward: #{reward}"
88
96
  ```
89
97
 
90
98
  See `examples/*.rb` for more examples implementing the Lisk API.
data/bin/debug CHANGED
@@ -7,5 +7,6 @@ rm pkg/*.gem
7
7
  git add -A
8
8
  bundle exec rake install
9
9
  ruby examples/status.rb
10
- ruby examples/payout.rb
11
- ruby examples/legacy_api.rb
10
+ #ruby examples/payout.rb
11
+ #ruby examples/legacy_api.rb
12
+ ruby examples/delegates.rb
Binary file
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lisk'
4
+
5
+ node = Lisk::Client.new
6
+ api = Lisk::API.new node
7
+
8
+ delegate = Lisk::Delegate.new api, "4fryn"
9
+ p delegate.is_registered?
10
+
11
+ delegate = Lisk::Delegate.new api, "not_4fryn"
12
+ p delegate.is_registered?
13
+
14
+ delegate.set_secrets "lorem ipsum foo bar", "foo bar lorem ipsum"
15
+ p delegate.register
data/examples/payout.rb CHANGED
@@ -14,51 +14,52 @@ if legacy_api.loader_status_ping
14
14
 
15
15
  # Get the desired delegate by name.
16
16
  delegate = legacy_api.delegates_get_by_name "4fryn"
17
- p "Delegate #{delegate["username"]} is rank \##{delegate["rank"]} with #{delegate["approval"]}\% approval and #{delegate["productivity"]}\% productivity."
18
-
19
- # Get a list of voters for a delegate.
20
- deleagte_public_key = delegate["publicKey"]
21
- deleagte_address = delegate["address"]
22
- deleagte_voters = legacy_api.delegates_voters deleagte_public_key
23
-
24
- # Get the total vote weight of our delegate
25
- deleagte_total_weight = delegate["vote"].to_f
26
-
27
- # Get the forging rewards from balance
28
- payout_balance = legacy_api.accounts_get_balance deleagte_address
29
- payout_balance = payout_balance["balance"].to_f
30
-
31
- # Our pool is sharing 80%, and keeping 20%
32
- pool_share = 0.80
33
-
34
- # Filter out voters with out any Lisk
35
- voter_threshold = 0
36
-
37
- _debug_payout_sum = 0
38
-
39
- # Iterate all voters
40
- deleagte_voters.each do | voter |
41
- voter_balance = voter["balance"].to_f
42
-
43
- # Only handle voters with balance above threshold
44
- if voter_balance > voter_threshold # and not voter["address"].eql? deleagte_address
45
- voter_share = voter["balance"].to_f / deleagte_total_weight
46
- payout = voter_share * payout_balance * pool_share
47
- # @TODO: do some handling of dust amounts
48
- # @TODO: do sanity checks and create transactions here ...
49
- p "Sending #{payout / 1e8} LSK to voter #{voter["address"]}..."
50
- _debug_payout_sum += payout
17
+ if not delegate.nil?
18
+ p "Delegate #{delegate["username"]} is rank \##{delegate["rank"]} with #{delegate["approval"]}\% approval and #{delegate["productivity"]}\% productivity."
19
+
20
+ # Get a list of voters for a delegate.
21
+ deleagte_public_key = delegate["publicKey"]
22
+ deleagte_address = delegate["address"]
23
+ deleagte_voters = legacy_api.delegates_voters deleagte_public_key
24
+
25
+ # Get the total vote weight of our delegate
26
+ deleagte_total_weight = delegate["vote"].to_f
27
+
28
+ # Get the forging rewards from balance
29
+ payout_balance = legacy_api.accounts_get_balance deleagte_address
30
+ payout_balance = payout_balance["balance"].to_f
31
+
32
+ # Our pool is sharing 80%, and keeping 20%
33
+ pool_share = 0.80
34
+
35
+ # Filter out voters with out any Lisk
36
+ voter_threshold = 0
37
+
38
+ _debug_payout_sum = 0
39
+
40
+ # Iterate all voters
41
+ deleagte_voters.each do | voter |
42
+ voter_balance = voter["balance"].to_f
43
+
44
+ # Only handle voters with balance above threshold
45
+ if voter_balance > voter_threshold # and not voter["address"].eql? deleagte_address
46
+ voter_share = voter["balance"].to_f / deleagte_total_weight
47
+ payout = voter_share * payout_balance * pool_share
48
+ # @TODO: do some handling of dust amounts
49
+ # @TODO: do sanity checks and create transactions here ...
50
+ p "Sending #{payout / 1e8} LSK to voter #{voter["address"]}..."
51
+ _debug_payout_sum += payout
52
+ end
51
53
  end
52
- end
53
54
 
54
- # @TODO: sending 20% delegate share to her private address
55
- p "Sending #{payout_balance * 0.20 / 1e8} LSK to delegate private funds..."
56
-
57
- # _debug_payout_diff should be 0
58
- _debug_payout_sum += payout_balance * 0.20
59
- _debug_payout_diff = payout_balance - _debug_payout_sum
60
- p "#{_debug_payout_diff === 0}"
55
+ # @TODO: sending 20% delegate share to her private address
56
+ p "Sending #{payout_balance * 0.20 / 1e8} LSK to delegate private funds..."
61
57
 
58
+ # _debug_payout_diff should be 0
59
+ _debug_payout_sum += payout_balance * 0.20
60
+ _debug_payout_diff = payout_balance - _debug_payout_sum
61
+ p "#{_debug_payout_diff === 0}"
62
+ end
62
63
  else
63
64
  p 'Lisk node disconnected, inactive, or not fully synchronized ...'
64
65
  end
data/examples/status.rb CHANGED
@@ -3,52 +3,49 @@
3
3
  require 'lisk'
4
4
 
5
5
  # Try to connect a local Lisk client.
6
- client = Lisk::Client.new
6
+ node = Lisk::Client.new
7
7
 
8
8
  # Configure host and port of the Lisk client.
9
- client = client.configure "127.0.0.1", 8000
9
+ node = node.configure "127.0.0.1", 7000
10
10
 
11
11
  # Same as above, just in one line, let's stick to test network for now.
12
- client = Lisk::Client.new "127.0.0.1", 7000
13
-
14
- # The pre-1.0.0 legacy API connected to the client.
15
- legacy_api = Lisk::Legacy.new client
12
+ node = Lisk::Client.new "127.0.0.1", 7000
16
13
 
17
14
  # Only proceed if the client is connected, active, and fully synchronized.
18
- if legacy_api.loader_status_ping
15
+ if node.is_alive?
16
+
17
+ # Lisk tools wraps the raw API in meaningful methods.
18
+ api = Lisk::API.new node
19
19
 
20
20
  # Lisk version API example.
21
- version = legacy_api.peers_version
22
- p "Lisk node version #{version["version"]} build #{version["build"]}..."
21
+ version = api.get_version
22
+ commit = api.get_version_commit
23
+ build = api.get_version_build
24
+ p "Lisk node version #{version} commit #{commit} build #{build}..."
23
25
 
24
26
  # Lisk node status API example.
25
- status = legacy_api.loader_status
26
- p "Lisk node is connected: #{status["success"]}... Blockchain loaded: #{status["loaded"]}..."
27
+ connected = node.is_alive?
28
+ loaded = api.is_chain_loaded?
29
+ p "Lisk node is connected: #{connected}... Blockchain loaded: #{loaded}..."
27
30
 
28
31
  # Lisk node syncing API example.
29
- syncing = legacy_api.loader_status_sync
30
- p "Lisk node is syncing: #{syncing["syncing"]}... #{syncing["blocks"]} remaining blocks to latest block #{syncing["height"]}..."
32
+ synced = api.is_syncing?
33
+ blocks = api.get_remaining_blocks
34
+ height = api.get_best_block
35
+ p "Lisk node is syncing: #{synced}... #{blocks} remaining blocks to latest block #{height}..."
31
36
 
32
37
  # Lisk node peers API example.
33
- peers = legacy_api.peers
34
- cond = 0
35
- disd = 0
36
- band = 0
37
- peers.each do | peer |
38
- case peer["state"]
39
- when 0
40
- band += 1
41
- when 1
42
- disd += 1
43
- when 2
44
- cond += 1
45
- end
46
- end
47
- p "Lisk node saw #{peers.count} peers... #{cond} connected, #{disd} disconnected, #{band} banned..."
38
+ cond = api.get_connected_peers.count
39
+ disd = api.get_disconnected_peers.count
40
+ band = api.get_banned_peers.count
41
+ all = api.get_peer_count
42
+ p "Lisk node saw #{all} peers... #{cond} connected, #{disd} disconnected, #{band} banned..."
48
43
 
49
44
  # Lisk blockchain API example.
50
- chain = legacy_api.blocks_get_status
51
- p "Lisk chain latest block: #{chain["height"]}... total supply: #{chain["supply"] / 1e8}... block reward: #{chain["reward"] / 1e8}"
45
+ chain_height = api.get_chain_best_block
46
+ block_reward = api.get_block_reward
47
+ total_supply = api.get_available_supply
48
+ p "Lisk chain latest block: #{chain_height}... total supply: #{total_supply / 1e8}... block reward: #{block_reward / 1e8}"
52
49
 
53
50
  else
54
51
  p 'Lisk node disconnected, inactive, or not fully synchronized ...'
data/lib/lisk/api.rb CHANGED
@@ -1,184 +1,187 @@
1
+ require "time"
2
+
1
3
  # The Lisk API Ruby wrapper gem.
2
4
  module Lisk
3
5
 
4
- # Implements APIs of the Lisk Core node.
5
- class API
6
-
7
- # A "lisk/client" connecting to a Lisk Core API node.
8
- attr_accessor :client
6
+ # Helper functions to wrap raw legacy APIs into meaningul methods.
7
+ class API < Legacy
9
8
 
10
- # Initializing the API with a Lisk Core API client.
11
- def initialize client
12
- if not client.nil?
13
- @client = client
14
- return self
9
+ # Returns true if chain is syncing.
10
+ def is_syncing?
11
+ synced = self.loader_status_sync
12
+ if synced["success"]
13
+ return synced["syncing"]
15
14
  else
16
15
  return nil
17
16
  end
18
17
  end
19
18
 
20
- #############################################
21
- # https://github.com/4fryn/lisk.rb/issues/1 #
22
- #############################################
23
-
24
- # The "accounts" API
25
- def accounts
26
- todo "#{self}::#{__method__} UNIMPLEMENTED"
27
- end
28
-
29
- # The "blocks" API
30
- def blocks
31
- todo "#{self}::#{__method__} UNIMPLEMENTED"
32
- end
33
-
34
- # The "dapps" API
35
- def dapps
36
- todo "#{self}::#{__method__} UNIMPLEMENTED"
37
- end
38
-
39
- # The "delegates" API
40
- def delegates
41
- todo "#{self}::#{__method__} UNIMPLEMENTED"
42
- end
43
-
44
- # The "delegates/forgers" API
45
- def delegates_forgers
46
- todo "#{self}::#{__method__} UNIMPLEMENTED"
47
- end
48
-
49
- # The "delegates/forging" API
50
- def delegates_forging
51
- todo "#{self}::#{__method__} UNIMPLEMENTED"
52
- end
53
-
54
- # The "node/constants" API
55
- def node_constants
56
- todo "#{self}::#{__method__} UNIMPLEMENTED"
57
- end
58
-
59
- # The "node/status" API
60
- def node_status
61
- todo "#{self}::#{__method__} UNIMPLEMENTED"
62
- end
63
-
64
- # The "peers" API
65
- def peers
66
- todo "#{self}::#{__method__} UNIMPLEMENTED"
67
- end
68
-
69
- # The "signatures" API
70
- def signatures
71
- todo "#{self}::#{__method__} UNIMPLEMENTED"
72
- end
73
-
74
- # The "transactions" API
75
- def transactions
76
- todo "#{self}::#{__method__} UNIMPLEMENTED"
77
- end
78
-
79
- # The "transactions/unsigned" API
80
- def transactions_unsigned
81
- todo "#{self}::#{__method__} UNIMPLEMENTED"
19
+ # Returns true if chain is loaded.
20
+ def is_chain_loaded?
21
+ loaded = self.loader_status
22
+ if loaded["success"]
23
+ return loaded["loaded"]
24
+ else
25
+ return nil
26
+ end
82
27
  end
83
28
 
84
- # The "transactions/unconfirmed" API
85
- def transactions_unconfirmed
86
- todo "#{self}::#{__method__} UNIMPLEMENTED"
29
+ # Get the Lisk node version string.
30
+ def get_version
31
+ version = self.peers_version
32
+ if version["success"]
33
+ return version["version"]
34
+ else
35
+ return nil
36
+ end
87
37
  end
88
38
 
89
- # The "transactions/unprocessed" API
90
- def transactions_unprocessed
91
- todo "#{self}::#{__method__} UNIMPLEMENTED"
39
+ # Get the Lisk node version build date.
40
+ def get_version_build
41
+ version = self.peers_version
42
+ if version["success"]
43
+ return version["build"]
44
+ else
45
+ return nil
46
+ end
92
47
  end
93
48
 
94
- # The "votes" API
95
- def votes
96
- todo "#{self}::#{__method__} UNIMPLEMENTED"
49
+ # Get the Lisk node version commit.
50
+ def get_version_commit
51
+ version = self.peers_version
52
+ if version["success"]
53
+ return version["commit"]
54
+ else
55
+ return nil
56
+ end
97
57
  end
98
58
 
99
- # The "voters" API
100
- def voters
101
- todo "#{self}::#{__method__} UNIMPLEMENTED"
59
+ # Get the height of the local best known block.
60
+ def get_best_block
61
+ synced = self.loader_status_sync
62
+ if synced["success"]
63
+ return synced["height"]
64
+ else
65
+ return nil
66
+ end
102
67
  end
103
68
 
104
- # The "accounts" API
105
- def accounts
106
- todo "#{self}::#{__method__} UNIMPLEMENTED"
69
+ # Get the number of remaining local sync blocks.
70
+ def get_remaining_blocks
71
+ synced = self.loader_status_sync
72
+ if synced["success"]
73
+ return synced["blocks"]
74
+ else
75
+ return nil
76
+ end
107
77
  end
108
78
 
109
- # The "blocks" API
110
- def blocks
111
- todo "#{self}::#{__method__} UNIMPLEMENTED"
79
+ # Get the global best block in the network.
80
+ def get_chain_best_block
81
+ blocks = self.blocks_get_height
82
+ if blocks["success"]
83
+ return blocks["height"]
84
+ else
85
+ return nil
86
+ end
112
87
  end
113
88
 
114
- # The "dapps" API
115
- def dapps
116
- todo "#{self}::#{__method__} UNIMPLEMENTED"
89
+ # Get the broad hash.
90
+ def get_broadhash
91
+ blocks = self.blocks_get_status
92
+ if blocks["success"]
93
+ return blocks["broadhash"]
94
+ else
95
+ return nil
96
+ end
117
97
  end
118
98
 
119
- # The "delegates" API
120
- def delegates
121
- todo "#{self}::#{__method__} UNIMPLEMENTED"
99
+ # Get the net hash.
100
+ def get_nethash
101
+ blocks = self.blocks_get_nethash
102
+ if blocks["success"]
103
+ return blocks["nethash"]
104
+ else
105
+ return nil
106
+ end
122
107
  end
123
108
 
124
- # The "delegates/forgers" API
125
- def delegates_forgers
126
- todo "#{self}::#{__method__} UNIMPLEMENTED"
109
+ # Get the current epoch date.
110
+ def get_epoch
111
+ blocks = self.blocks_get_status
112
+ if blocks["success"]
113
+ epoch = Time.parse blocks["epoch"]
114
+ return epoch
115
+ else
116
+ return nil
117
+ end
127
118
  end
128
119
 
129
- # The "delegates/forging" API
130
- def delegates_forging
131
- todo "#{self}::#{__method__} UNIMPLEMENTED"
120
+ # Get the current milestone.
121
+ def get_milestone
122
+ blocks = self.blocks_get_milestone
123
+ if blocks["success"]
124
+ return blocks["milestone"]
125
+ else
126
+ return nil
127
+ end
132
128
  end
133
129
 
134
- # The "node/constants" API
135
- def node_constants
136
- todo "#{self}::#{__method__} UNIMPLEMENTED"
130
+ # Get the current block reward.
131
+ def get_block_reward
132
+ blocks = self.blocks_get_reward
133
+ if blocks["success"]
134
+ return blocks["reward"]
135
+ else
136
+ return nil
137
+ end
137
138
  end
138
139
 
139
- # The "node/status" API
140
- def node_status
141
- todo "#{self}::#{__method__} UNIMPLEMENTED"
140
+ # Get the available supply.
141
+ def get_available_supply
142
+ blocks = self.blocks_get_supply
143
+ if blocks["success"]
144
+ return blocks["supply"]
145
+ else
146
+ return nil
147
+ end
142
148
  end
143
149
 
144
- # The "peers" API
145
- def peers
146
- todo "#{self}::#{__method__} UNIMPLEMENTED"
147
- end
148
150
 
149
- # The "signatures" API
150
- def signatures
151
- todo "#{self}::#{__method__} UNIMPLEMENTED"
152
- end
151
+ #{}"fee"=>10000000
153
152
 
154
- # The "transactions" API
155
- def transactions
156
- todo "#{self}::#{__method__} UNIMPLEMENTED"
157
- end
158
153
 
159
- # The "transactions/unsigned" API
160
- def transactions_unsigned
161
- todo "#{self}::#{__method__} UNIMPLEMENTED"
154
+ # Get an array of all known peers.
155
+ def get_peers
156
+ peers = self.peers
162
157
  end
163
158
 
164
- # The "transactions/unconfirmed" API
165
- def transactions_unconfirmed
166
- todo "#{self}::#{__method__} UNIMPLEMENTED"
159
+ # Get the number of all known peers.
160
+ def get_peer_count
161
+ peers = self.get_peers
162
+ if not peers.nil?
163
+ count = peers.count
164
+ else
165
+ count = 0
166
+ end
167
167
  end
168
168
 
169
- # The "transactions/unprocessed" API
170
- def transactions_unprocessed
171
- todo "#{self}::#{__method__} UNIMPLEMENTED"
169
+ # Get an array of all connected peers.
170
+ def get_connected_peers
171
+ filter_by_state = { :state => 2 }
172
+ connected = self.peers filter_by_state
172
173
  end
173
174
 
174
- # The "votes" API
175
- def votes
176
- todo "#{self}::#{__method__} UNIMPLEMENTED"
175
+ # Get an array of all disconnected peers.
176
+ def get_disconnected_peers
177
+ filter_by_state = { :state => 1 }
178
+ disconnected = self.peers filter_by_state
177
179
  end
178
180
 
179
- # The "voters" API
180
- def voters
181
- todo "#{self}::#{__method__} UNIMPLEMENTED"
181
+ # Get an array of all banned peers.
182
+ def get_banned_peers
183
+ filter_by_state = { :state => 0 }
184
+ banned = self.peers filter_by_state
182
185
  end
183
186
 
184
187
  # Handles unimplemented methods
data/lib/lisk/client.rb CHANGED
@@ -9,7 +9,7 @@ module Lisk
9
9
  class Client
10
10
 
11
11
  # Host and port of the API endpoint.
12
- attr_accessor :host, :port, :ssl
12
+ attr_accessor :host, :port, :ssl, :active
13
13
 
14
14
  # Initializes the Lisk HTTP client and defaults to localhost port 7000.
15
15
  def initialize host = "127.0.0.1", port = 7000
@@ -17,8 +17,10 @@ module Lisk
17
17
  @port = port
18
18
  @ssl = false
19
19
  if self.is_alive?
20
+ @active = true
20
21
  return self
21
22
  else
23
+ @active = false
22
24
  return nil
23
25
  end
24
26
  end
@@ -30,11 +32,14 @@ module Lisk
30
32
  @port = port
31
33
  @ssl = false
32
34
  if self.is_alive?
35
+ @active = true
33
36
  return self
34
37
  else
38
+ @active = false
35
39
  return nil
36
40
  end
37
41
  else
42
+ @active = false
38
43
  return nil
39
44
  end
40
45
  end
@@ -43,7 +48,7 @@ module Lisk
43
48
  # Returns true if block was received in the past 120 seconds.
44
49
  def is_alive?
45
50
  connected = self.query_get "loader/status/ping"
46
- connected["success"]
51
+ @active = connected["success"]
47
52
  end
48
53
 
49
54
  # Handles GET requests to the given Lisk Core API endpoint
@@ -58,12 +63,16 @@ module Lisk
58
63
  end
59
64
  request = ::Net::HTTP::Get.new uri
60
65
  response = node.request request
66
+ @active = true
61
67
  result = JSON::parse response.body
62
68
  rescue Timeout::Error => e
69
+ @active = false
63
70
  p "Can't connect to the Lisk node: Timeout!"
64
71
  rescue Errno::EHOSTUNREACH => e
72
+ @active = false
65
73
  p "Can't connect to the Lisk node: Host Unreachable!"
66
74
  rescue Errno::ECONNREFUSED => e
75
+ @active = false
67
76
  p "Can't connect to the Lisk node: Connection Refused!"
68
77
  end
69
78
  end
@@ -80,12 +89,16 @@ module Lisk
80
89
  request = ::Net::HTTP::Post.new uri, header
81
90
  request.body = params.to_json
82
91
  response = node.request request
92
+ @active = true
83
93
  result = JSON::parse response.body
84
94
  rescue Timeout::Error => e
95
+ @active = false
85
96
  p "Can't connect to the Lisk node: Timeout!"
86
97
  rescue Errno::EHOSTUNREACH => e
98
+ @active = false
87
99
  p "Can't connect to the Lisk node: Host Unreachable!"
88
100
  rescue Errno::ECONNREFUSED => e
101
+ @active = false
89
102
  p "Can't connect to the Lisk node: Connection Refused!"
90
103
  end
91
104
  end
@@ -103,12 +116,16 @@ module Lisk
103
116
  request = ::Net::HTTP::Put.new uri, header
104
117
  request.body = params.to_json
105
118
  response = node.request request
119
+ @active = true
106
120
  result = JSON::parse response.body
107
121
  rescue Timeout::Error => e
122
+ @active = false
108
123
  p "Can't connect to the Lisk node: Timeout!"
109
124
  rescue Errno::EHOSTUNREACH => e
125
+ @active = false
110
126
  p "Can't connect to the Lisk node: Host Unreachable!"
111
127
  rescue Errno::ECONNREFUSED => e
128
+ @active = false
112
129
  p "Can't connect to the Lisk node: Connection Refused!"
113
130
  end
114
131
  end
@@ -0,0 +1,55 @@
1
+ module Lisk
2
+
3
+ class Delegate
4
+
5
+ attr_accessor :api
6
+ attr_accessor :delegate_name
7
+ attr_accessor :address
8
+ attr_accessor :public_key
9
+ attr_accessor :secret
10
+ attr_accessor :secret_secondary
11
+ attr_accessor :registered
12
+
13
+ def initialize api, delegate_name
14
+ @api = api
15
+ @delegate_name = delegate_name
16
+ delegate = @api.delegates_get_by_name delegate_name
17
+ if delegate.nil?
18
+ @registered = false
19
+ else
20
+ @registered = true
21
+ @address = delegate["address"]
22
+ @public_key = delegate["publicKey"]
23
+ end
24
+ end
25
+
26
+ def is_registered?
27
+ return registered
28
+ end
29
+
30
+ def set_secrets secret, second_secret = nil
31
+ @secret = secret
32
+ @secret_secondary = second_secret
33
+ end
34
+
35
+ def register
36
+ if not self.is_registered?
37
+ delegate = {}
38
+ delegate[:username] = @delegate_name
39
+ if not @secret_secondary.nil?
40
+ delegate[:secondSecret] = @secret_secondary
41
+ end
42
+ if not @secret.nil?
43
+ delegate[:secret] = @secret
44
+ registration = api.delegates_put delegate
45
+ return registration
46
+ else
47
+ return false
48
+ end
49
+ else
50
+ return false
51
+ end
52
+ end
53
+
54
+ end
55
+ end
data/lib/lisk/legacy.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # The Lisk API Ruby wrapper gem.
2
2
  module Lisk
3
3
 
4
- # Implements legacy APIs of the Lisk Core pre-1.0.0 node.
4
+ # Implements raw legacy APIs of the Lisk Core pre-1.0.0 node.
5
5
  class Legacy
6
6
 
7
7
  # A "lisk/client" connecting to a Lisk Core API node.
data/lib/lisk/raw.rb ADDED
@@ -0,0 +1,190 @@
1
+ # The Lisk API Ruby wrapper gem.
2
+ module Lisk
3
+
4
+ # Implements raw APIs of the Lisk Core node.
5
+ class Raw
6
+
7
+ # A "lisk/client" connecting to a Lisk Core API node.
8
+ attr_accessor :client
9
+
10
+ # Initializing the API with a Lisk Core API client.
11
+ def initialize client
12
+ if not client.nil?
13
+ @client = client
14
+ return self
15
+ else
16
+ return nil
17
+ end
18
+ end
19
+
20
+ #############################################
21
+ # https://github.com/4fryn/lisk.rb/issues/1 #
22
+ #############################################
23
+
24
+ # The "accounts" API
25
+ def accounts
26
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
27
+ end
28
+
29
+ # The "blocks" API
30
+ def blocks
31
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
32
+ end
33
+
34
+ # The "dapps" API
35
+ def dapps
36
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
37
+ end
38
+
39
+ # The "delegates" API
40
+ def delegates
41
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
42
+ end
43
+
44
+ # The "delegates/forgers" API
45
+ def delegates_forgers
46
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
47
+ end
48
+
49
+ # The "delegates/forging" API
50
+ def delegates_forging
51
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
52
+ end
53
+
54
+ # The "node/constants" API
55
+ def node_constants
56
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
57
+ end
58
+
59
+ # The "node/status" API
60
+ def node_status
61
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
62
+ end
63
+
64
+ # The "peers" API
65
+ def peers
66
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
67
+ end
68
+
69
+ # The "signatures" API
70
+ def signatures
71
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
72
+ end
73
+
74
+ # The "transactions" API
75
+ def transactions
76
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
77
+ end
78
+
79
+ # The "transactions/unsigned" API
80
+ def transactions_unsigned
81
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
82
+ end
83
+
84
+ # The "transactions/unconfirmed" API
85
+ def transactions_unconfirmed
86
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
87
+ end
88
+
89
+ # The "transactions/unprocessed" API
90
+ def transactions_unprocessed
91
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
92
+ end
93
+
94
+ # The "votes" API
95
+ def votes
96
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
97
+ end
98
+
99
+ # The "voters" API
100
+ def voters
101
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
102
+ end
103
+
104
+ # The "accounts" API
105
+ def accounts
106
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
107
+ end
108
+
109
+ # The "blocks" API
110
+ def blocks
111
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
112
+ end
113
+
114
+ # The "dapps" API
115
+ def dapps
116
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
117
+ end
118
+
119
+ # The "delegates" API
120
+ def delegates
121
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
122
+ end
123
+
124
+ # The "delegates/forgers" API
125
+ def delegates_forgers
126
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
127
+ end
128
+
129
+ # The "delegates/forging" API
130
+ def delegates_forging
131
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
132
+ end
133
+
134
+ # The "node/constants" API
135
+ def node_constants
136
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
137
+ end
138
+
139
+ # The "node/status" API
140
+ def node_status
141
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
142
+ end
143
+
144
+ # The "peers" API
145
+ def peers
146
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
147
+ end
148
+
149
+ # The "signatures" API
150
+ def signatures
151
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
152
+ end
153
+
154
+ # The "transactions" API
155
+ def transactions
156
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
157
+ end
158
+
159
+ # The "transactions/unsigned" API
160
+ def transactions_unsigned
161
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
162
+ end
163
+
164
+ # The "transactions/unconfirmed" API
165
+ def transactions_unconfirmed
166
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
167
+ end
168
+
169
+ # The "transactions/unprocessed" API
170
+ def transactions_unprocessed
171
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
172
+ end
173
+
174
+ # The "votes" API
175
+ def votes
176
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
177
+ end
178
+
179
+ # The "voters" API
180
+ def voters
181
+ todo "#{self}::#{__method__} UNIMPLEMENTED"
182
+ end
183
+
184
+ # Handles unimplemented methods
185
+ def method_missing name, *args, &block
186
+ todo "#{self}::#{name} METHOD MISSING"
187
+ end
188
+
189
+ end
190
+ end
data/lib/lisk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lisk
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/lisk.rb CHANGED
@@ -3,9 +3,11 @@ require "todonotes"
3
3
 
4
4
  # The Lisk API Ruby wrapper gem.
5
5
  module Lisk
6
- require "lisk/api"
7
6
  require "lisk/client"
8
7
  require "lisk/legacy"
8
+ require "lisk/raw"
9
+ require "lisk/api"
10
+ require "lisk/delegate"
9
11
 
10
12
  # Handles unimplemented methods
11
13
  def method_missing name, *args, &block
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 4fryn Dings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2017-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,13 +84,17 @@ files:
84
84
  - bin/console
85
85
  - bin/debug
86
86
  - bin/setup
87
+ - examples/4fryn-lisk-rb.gif
88
+ - examples/delegates.rb
87
89
  - examples/legacy_api.rb
88
90
  - examples/payout.rb
89
91
  - examples/status.rb
90
92
  - lib/lisk.rb
91
93
  - lib/lisk/api.rb
92
94
  - lib/lisk/client.rb
95
+ - lib/lisk/delegate.rb
93
96
  - lib/lisk/legacy.rb
97
+ - lib/lisk/raw.rb
94
98
  - lib/lisk/version.rb
95
99
  - lisk.gemspec
96
100
  homepage: https://github.com/4fryn/lisk.rb