blzrb 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 351d1bb155a8161ce5f8c0dc0f3824ff1989451c0171efb8e616aba016c3f158
4
- data.tar.gz: 382283e39673273d615d5978643cd97f73ec30c614fb39a5fcf81856f98983ed
3
+ metadata.gz: bd02528911fc0d78c13559d2ea88a1e6f3e8920a076fb31c49322557d2716508
4
+ data.tar.gz: 946441a8d816a9d7d2b7a96496f156cc9e8f335ad6b9ccd4d0aeb50c92326d22
5
5
  SHA512:
6
- metadata.gz: 6fb36b6bd44c4e3f50743bc05c22ce9443776920242135d5670a960919d647d9bae8b8b3e49620879c2a63a920c30481d59dcb53236690d9709ca0379bdd0c25
7
- data.tar.gz: e127258b384113b02de38946c3ea6b5621d70725ecef22a2bb846909e5c22bc6ebf3a2e5547a5a6958d128856661bb7476cb0071fc9477b85d12c23358ed3da6
6
+ metadata.gz: f4826fda86023cd7f3aac830ae39b29f8976e4288bfe1109f2dc74eb57c32c76d39456b52bb0045c76ac31e428ef9349f894439e37baf5e0a8aa68e07f806ca7
7
+ data.tar.gz: 7d80d07d95cbddf018fdbdfbf047f58b301c39e3a0aaaa4ca2b64cb990433fd8d69aaf01feb694554228049137662fdf0ad5bcdfa8dbacf5e1183a5109b78a6c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blzrb (0.1.0)
4
+ blzrb (0.2.0)
5
5
  bip_mnemonic
6
6
  bitcoin-ruby
7
7
  bitcoin-secp256k1
@@ -0,0 +1,446 @@
1
+ # API documentation
2
+ Read below for detailed documentation on how to use the Bluzelle database service.
3
+
4
+ ### Bluzelle::Swarm::Client.new\({...}\)
5
+
6
+ Configures the Bluzelle connection. Multiple clients can be created by creating new instances of this class.
7
+
8
+ ```ruby
9
+ require 'bluzelle'
10
+
11
+ api = Bluzelle::Swarm::Client.new({
12
+ mnemonic: 'volcano arrest ceiling physical concert sunset absent hungry tobacco canal census era pretty car code crunch inside behind afraid express giraffe reflect stadium luxury',
13
+ endpoint: "http://localhost:1317",
14
+ uuid: "20fc19d4-7c9d-4b5c-9578-8cedd756e0ea",
15
+ chain_id: "bluzelle"
16
+ });
17
+ ```
18
+
19
+ | Argument | Description |
20
+ | :--- | :--- |
21
+ | **mnemonic** | The mnemonic of the private key for your Bluzelle account |
22
+ | endpoint | \(Optional\) The hostname and port of your rest server. Default: http://localhost:1317 |
23
+ | uuid | \(Optional\) Bluzelle uses `UUID`'s to identify distinct databases on a single swarm. We recommend using [Version 4 of the universally unique identifier](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_%28random%29). Defaults to the account address. |
24
+ | chain_id | \(Optional\) The chain id of your Bluzelle account. Default: bluzelle |
25
+
26
+
27
+ The calls below are methods of the instance created by instantiating the `Bluzelle::Swarm::Client` class.
28
+
29
+ ## General Functions
30
+
31
+ ### version\()
32
+
33
+ Retrieve the version of the Bluzelle service.
34
+
35
+ ```ruby
36
+ api.version
37
+ ```
38
+
39
+ Returns a string containing the version information, e.g.
40
+
41
+ ```
42
+ 0.0.0-39-g8895e3e
43
+ ```
44
+
45
+ Throws an exception if a response is not received from the connection.
46
+
47
+
48
+ ### account\()
49
+
50
+ Retrieve information about the currently active Bluzelle account.
51
+
52
+ ```ruby
53
+ api.account
54
+ ```
55
+
56
+ Returns JSON object representing the account information, e.g.
57
+
58
+ Throws an exception if a response is not received from the connection.
59
+
60
+
61
+ ## Database Functions
62
+
63
+ ### create\(key, value , gas_info[, lease_info]\)
64
+
65
+ Create a field in the database.
66
+
67
+ ```ruby
68
+ api.create 'mykey', '{ a: 13 }', {gax_fee: '400001'}, {days: 100};
69
+ ```
70
+
71
+ | Argument | Description |
72
+ | :--- | :--- |
73
+ | key | The name of the key to create |
74
+ | value | The string value to set the key |
75
+ | gas_info | Object containing gas parameters (see above) |
76
+ | lease_info (optional) | Minimum time for key to remain in database (see above) |
77
+
78
+ Returns nothing.
79
+
80
+ Throws an exception when a response is not received from the connection, the key already exists, or invalid value.
81
+
82
+ ### read\(key, prove\)
83
+
84
+ Retrieve the value of a key without consensus verification. Can optionally require the result to have a cryptographic proof (slower).
85
+
86
+ ```ruby
87
+ value = api.read 'mykey', {gax_fee: '400001'}
88
+ ```
89
+
90
+ | Argument | Description |
91
+ | :--- | :--- |
92
+ | key | The key to retrieve |
93
+ | prove | A proof of the value is required from the network (requires 'config trust-node false' to be set) |
94
+
95
+ Returns the string value of the key.
96
+
97
+ Throws an exception when the key does not exist in the database.
98
+ Throws an exception when the prove is true and the result fails verification.
99
+
100
+ ### tx_read\(key, gas_info\)
101
+
102
+ Retrieve the value of a key via a transaction (i.e. uses consensus).
103
+
104
+ ```ruby
105
+ value = api.tx_read 'mykey', {max_fee: '400001'}
106
+ ```
107
+
108
+ | Argument | Description |
109
+ | :--- | :--- |
110
+ | key | The key to retrieve |
111
+ | gas_info | Object containing gas parameters (see above) |
112
+
113
+ Returns the string value of the key.
114
+
115
+ Throws an exception when the key does not exist in the database.
116
+
117
+ ### update\(key, value, gas_info[, lease_info]\)
118
+
119
+ Update a field in the database.
120
+
121
+ ```ruby
122
+ api.update 'mykey', { a: 13 }, {max_fee: '400001'}, {days: 100}
123
+ ```
124
+
125
+ | Argument | Description |
126
+ | :--- | :--- |
127
+ | key | The name of the key to create |
128
+ | value | The string value to set the key |
129
+ | gas_info | Object containing gas parameters (see above) |
130
+ | lease_info (optional) | Positive or negative amount of time to alter the lease by. If not specified, the existing lease will not be changed. |
131
+
132
+ Returns nothing.
133
+
134
+ Throws an exception when the key doesn't exist, or invalid value.
135
+
136
+ ### delete\(key, gas_info\)
137
+
138
+ Delete a field from the database.
139
+
140
+ ```ruby
141
+ api.delete 'mykey', {max_fee: '400001'}
142
+ ```
143
+
144
+ | Argument | Description |
145
+ | :--- | :--- |
146
+ | key | The name of the key to delete |
147
+ | gas_info | Object containing gas parameters (see above) |
148
+
149
+ Returns nothing.
150
+
151
+ Throws an exception when the key is not in the database.
152
+
153
+ ### has\(key\)
154
+
155
+ Query to see if a key is in the database. This function bypasses the consensus and cryptography mechanisms in favor of speed.
156
+
157
+
158
+ ```ruby
159
+ hasMyKey = api.has 'mykey'
160
+ ```
161
+
162
+ | Argument | Description |
163
+ | :--- | :--- |
164
+ | key | The name of the key to query |
165
+
166
+ Returns a boolean value - `true` or `false`, representing whether the key is in the database.
167
+
168
+ ### tx_has\(key, gas_info\)
169
+
170
+ Query to see if a key is in the database via a transaction (i.e. uses consensus).
171
+
172
+ ```ruby
173
+ hasMyKey = api.tx_has 'mykey', {gas_price: 10}
174
+ ```
175
+
176
+ | Argument | Description |
177
+ | :--- | :--- |
178
+ | key | The name of the key to query |
179
+ | gas_info | Object containing gas parameters (see above) |
180
+
181
+ Returns a boolean value - `true` or `false`, representing whether the key is in the database.
182
+
183
+ ### keys\(\)
184
+
185
+ Retrieve a list of all keys. This function bypasses the consensus and cryptography mechanisms in favor of speed.
186
+
187
+ ```ruby
188
+ keys = api.keys
189
+ ```
190
+
191
+ Returns an array of strings. ex. `["key1", "key2", ...]`.
192
+
193
+ ### tx_keys\(gas_info\)
194
+
195
+ Retrieve a list of all keys via a transaction (i.e. uses consensus).
196
+
197
+ ```ruby
198
+ keys = api.tx_keys { gas_price: 10 }
199
+ ```
200
+
201
+ | Argument | Description |
202
+ | :--- | :--- |
203
+ | gas_info | Object containing gas parameters (see above) |
204
+
205
+ Returns an array of strings. ex. `["key1", "key2", ...]`.
206
+
207
+ ### rename\(key, new_key, gas_info\)
208
+
209
+ Change the name of an existing key.
210
+
211
+ ```ruby
212
+ api.rename 'key', 'newkey', {gas_price: 10}
213
+ ```
214
+
215
+ | Argument | Description |
216
+ | :--- | :--- |
217
+ | key | The name of the key to rename |
218
+ | new_key | The new name for the key |
219
+ | gas_info | Object containing gas parameters (see above) |
220
+
221
+ Returns nothing.
222
+
223
+ Throws an exception if the key doesn't exist.
224
+
225
+
226
+ | Argument | Description |
227
+ | :--- | :--- |
228
+ | key | The name of the key to query |
229
+
230
+ Returns to a boolean value - `true` or `false`, representing whether the key is in the database.
231
+
232
+ ### count\(\)
233
+
234
+ Retrieve the number of keys in the current database/uuid. This function bypasses the consensus and cryptography mechanisms in favor of speed.
235
+
236
+ ```ruby
237
+ number = api.count
238
+ ```
239
+
240
+ Returns an integer value.
241
+
242
+ ### tx_count\(gas_info\)
243
+
244
+ Retrieve the number of keys in the current database/uuid via a transaction.
245
+
246
+ ```ruby
247
+ number = api.tx_count {gas_price: 10}
248
+ ```
249
+
250
+ | Argument | Description |
251
+ | :--- | :--- |
252
+ | gas_info | Object containing gas parameters (see above) |
253
+
254
+ Returns an integer value.
255
+
256
+ ### delete_all\(gas_info\)
257
+
258
+ Remove all keys in the current database/uuid.
259
+
260
+ ```ruby
261
+ api.delete_all {gas_price: 10}
262
+ ```
263
+
264
+ | Argument | Description |
265
+ | :--- | :--- |
266
+ | gas_info | Object containing gas parameters (see above) |
267
+
268
+ Returns nothing.
269
+
270
+ ### key_values\(\)
271
+
272
+ Enumerate all keys and values in the current database/uuid. This function bypasses the consensus and cryptography mechanisms in favor of speed.
273
+
274
+ ```ruby
275
+ kvs = api.key_values;
276
+ ```
277
+
278
+ Returns a JSON array containing key/value pairs, e.g.
279
+
280
+ ```
281
+ [{"key": "key1", "value": "value1"}, {"key": "key2", "value": "value2"}]
282
+ ```
283
+
284
+ ### tx_key_values\(gas_info\)
285
+
286
+ Enumerate all keys and values in the current database/uuid via a transaction.
287
+
288
+ ```ruby
289
+ kvs = api.tx_key_values {gas_price: 10}
290
+ ```
291
+
292
+ | Argument | Description |
293
+ | :--- | :--- |
294
+ | gas_info | Object containing gas parameters (see above) |
295
+
296
+ Returns a JSON array containing key/value pairs, e.g.
297
+
298
+ ```
299
+ [{"key": "key1", "value": "value1"}, {"key": "key2", "value": "value2"}]
300
+ ```
301
+
302
+ ### multi_update\(key_values, gas_info\)
303
+
304
+ Update multiple fields in the database.
305
+
306
+ ```ruby
307
+ api.multi_update([{key: "key1", value: "value1"}, {key: "key2", value: "value2"}, {gas_price: 10})
308
+ ```
309
+
310
+ | Argument | Description |
311
+ | :--- | :--- |
312
+ | key_values | An array of objects containing keys and values (see example avove) |
313
+ | gas_info | Object containing gas parameters (see above) |
314
+
315
+ Returns nothing.
316
+
317
+ Throws an exception when any of the keys doesn't exist.
318
+
319
+
320
+ ### get_lease\(key\)
321
+
322
+ Retrieve the minimum time remaining on the lease for a key. This function bypasses the consensus and cryptography mechanisms in favor of speed.
323
+
324
+ ```ruby
325
+ value = api.get_lease 'mykey'
326
+ ```
327
+
328
+ | Argument | Description |
329
+ | :--- | :--- |
330
+ | key | The key to retrieve the lease information for |
331
+
332
+ Returns the minimum length of time remaining for the key's lease, in seconds.
333
+
334
+ Throws an exception when the key does not exist in the database.
335
+
336
+ ### tx_get_lease\(key, gas_info\)
337
+
338
+ Retrieve the minimum time remaining on the lease for a key, using a transaction.
339
+
340
+ ```ruby
341
+ value = api.tx_get_lease 'mykey', {gas_price: 10}
342
+ ```
343
+
344
+ | Argument | Description |
345
+ | :--- | :--- |
346
+ | key | The key to retrieve the lease information for |
347
+ | gas_info | Object containing gas parameters (see above) |
348
+
349
+ Returns the minimum length of time remaining for the key's lease, in seconds.
350
+
351
+ Throws an exception when the key does not exist in the database.
352
+
353
+ ### renew_lease\(key, gas_info[, lease_info]\)
354
+
355
+ Update the minimum time remaining on the lease for a key.
356
+
357
+ ```ruby
358
+ value = api.renew_lease 'mykey', {max_fee: '400001'}, { days: 100 }
359
+ ```
360
+
361
+ | Argument | Description |
362
+ | :--- | :--- |
363
+ | key | The key to retrieve the lease information for |
364
+ | gas_info | Object containing gas parameters (see above) |
365
+ | lease_info (optional) | Minimum time for key to remain in database (see above) |
366
+
367
+ Returns the minimum length of time remaining for the key's lease.
368
+
369
+ Throws an exception when the key does not exist in the database.
370
+
371
+
372
+ ### renew_lease_all\(gas_info[, lease_info]\)
373
+
374
+ Update the minimum time remaining on the lease for all keys.
375
+
376
+ ```ruby
377
+ value = api.renew_lease_all {max_fee: '400001'}, { days: 100 }
378
+ ```
379
+
380
+ | Argument | Description |
381
+ | :--- | :--- |
382
+ | gas_info | Object containing gas parameters (see above) |
383
+ | lease_info (optional) | Minimum time for key to remain in database (see above) |
384
+
385
+ Returns the minimum length of time remaining for the key's lease.
386
+
387
+ Throws an exception when the key does not exist in the database.
388
+
389
+
390
+ ### get_n_shortest_lease\(n\)
391
+
392
+ Retrieve a list of the n keys in the database with the shortest leases. This function bypasses the consensus and cryptography mechanisms in favor of speed.
393
+
394
+ ```ruby
395
+
396
+ keys = api.get_n_shortest_lease 10
397
+
398
+ ```
399
+
400
+ | Argument | Description |
401
+ | :--- | :--- |
402
+ | n | The number of keys to retrieve the lease information for |
403
+
404
+ Returns a JSON array of objects containing key, lease (in seconds), e.g.
405
+ ```
406
+ [ { key: "mykey", lease: { seconds: "12345" } }, {...}, ...]
407
+ ```
408
+
409
+ ### tx_get_n_shortest_lease\(n, gas_info\)
410
+
411
+ Retrieve a list of the N keys/values in the database with the shortest leases, using a transaction.
412
+
413
+ ```ruby
414
+
415
+ keys = api.tx_get_n_shortest_lease 10, {max_fee: '400001'}
416
+
417
+ ```
418
+
419
+ | Argument | Description |
420
+ | :--- | :--- |
421
+ | n | The number of keys to retrieve the lease information for |
422
+ | gas_info | Object containing gas parameters (see above) |
423
+
424
+ Returns a JSON array of objects containing key, lifetime (in seconds), e.g.
425
+ ```
426
+ [ { key: "mykey", lifetime: "12345" }, {...}, ...]
427
+ ```
428
+
429
+ ## Development
430
+
431
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
432
+
433
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
434
+
435
+ ## Contributing
436
+
437
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mul53/bluzelle. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mul53/bluzelle/blob/master/CODE_OF_CONDUCT.md).
438
+
439
+
440
+ ## License
441
+
442
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
443
+
444
+ ## Code of Conduct
445
+
446
+ Everyone interacting in the Bluzelle project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mul53/bluzelle/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,48 @@
1
+ # Example
2
+ This is an example of how to use blzrb
3
+
4
+ ## Installation(ubuntu 18.04)
5
+
6
+ ### Install dependencies
7
+ 1. `sudo apt-get update`
8
+ 2. `sudo apt-get install g++`
9
+ 3. install ruby, rbenv
10
+ ```
11
+ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
12
+ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
13
+ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
14
+ exec $SHELL
15
+
16
+ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
17
+ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
18
+ exec $SHELL
19
+
20
+ rbenv install 2.7.1
21
+ rbenv global 2.7.1
22
+ ruby -v
23
+ ```
24
+ 4. `sudo apt-get install libsecp256k1-dev`
25
+
26
+ ### Setup project
27
+ 1. Create a folder for your project
28
+ 2. Init the proejct with composer `bundle init`
29
+ 3. Add this line to your Gemfile `gem 'blzrb'`
30
+ 4. Run `bundle install`
31
+ 4. Create a file called `main.rb` and include the code below
32
+
33
+ ```ruby
34
+ require 'bluzelle'
35
+
36
+ bz = Bluzelle::Swarm::Client.new(
37
+ mnemonic: 'around buzz diagram captain obtain detail salon mango muffin brother morning jeans display attend knife carry green dwarf vendor hungry fan route pumpkin car',
38
+ endpoint: 'http://testnet.public.bluzelle.com:1317',
39
+ chain_id: 'bluzelle',
40
+ uuid: '20fc19d4-7c9d-4b5c-9578-8cedd756e0ea',
41
+ )
42
+
43
+ bz.create 'somekey', 'somevalue', { 'max_fee': '400000000' }
44
+ puts bz.read 'somekey'
45
+ ```
46
+ 5. Run the file `ruby main.rb`
47
+
48
+ To run more tests copy the script in `examples/main.rb` to your file and run your file
@@ -84,8 +84,8 @@ puts client.tx_key_values gas_info
84
84
  puts "\n#multi_update"
85
85
  puts 'update key=database, value=mongodb | key=fs, value=unix'
86
86
  puts client.multi_update([
87
- { 'ey' => 'db', 'Value' => 'mongodb' },
88
- { 'Key' => 'fs', 'Value' => 'unix' }
87
+ { 'key' => 'database', 'value' => 'mongodb' },
88
+ { 'key' => 'fs', 'value' => 'unix' }
89
89
  ], gas_info)
90
90
 
91
91
  puts "\n#key_values"
@@ -1,3 +1,3 @@
1
1
  module Bluzelle
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blzrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mulenga Bowa
@@ -111,6 +111,8 @@ files:
111
111
  - README.md
112
112
  - Rakefile
113
113
  - bluzelle.gemspec
114
+ - docs/README.md
115
+ - examples/README.md
114
116
  - examples/main.rb
115
117
  - lib/bluzelle.rb
116
118
  - lib/bluzelle/constants.rb