iota-ruby 1.1.1 → 1.1.2

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: c32740331750eaf99d815b46b70e295edeac4ab4
4
- data.tar.gz: 229099a8efc82398f840dd6a997a4262aefeaf2b
3
+ metadata.gz: 56550726895238e50668114981fc85deed729c9d
4
+ data.tar.gz: 74bce50a977d7116ce1e39f1fd27bda535bbae8e
5
5
  SHA512:
6
- metadata.gz: bd529fd2768766e1e41b99a96bc270273c4a49b0c374fe3ea1c404193dcfa4e9ea8e1a60e510c68705f4e69bab70d812dec7c84cd1e8ff2ac3b6d850c65b7ea3
7
- data.tar.gz: 1bee6775b242bf06712cd45dbf7c3834169d2529d6f4615674525250e06595d659bd902ea2b22d8b7ffc0ffc46fcff9a1025f16a70ac64ad3dd34dfb43058daf
6
+ metadata.gz: 9d5f10d81ccfd9c24dd42875ba4a66444d0abeba8bc4db683ba9be5bd4a3d451d858cd6cb916e6a77b9f8a3639dbc803fa26eb0fd6537d9c292532181366dd3a
7
+ data.tar.gz: b8044e97b83756fe5e0a627c816b1013b854bd30597808d41b4c62986b56cfa73e553eb901a4c7b5e9aa9a4d4f2f888b278e68213de5cc94fd7a085b8cfdf1b1
data/README.md CHANGED
@@ -1,25 +1,25 @@
1
1
  # IOTA Ruby Gem
2
2
 
3
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vivekmarakana/iota.lib.rb/master/LICENSE)
3
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/vivekmarakana/iota.lib.rb/master/LICENSE) [![Gem Version](https://badge.fury.io/rb/iota-ruby.svg)](https://badge.fury.io/rb/iota-ruby)
4
4
 
5
- This is the **unofficial** Ruby gem for the IOTA Core. It implements both the [official API](https://iota.readme.io/), as well as newly proposed functionality (such as signing, bundles, utilities and conversion).
6
-
7
- This gem is a **beta release**. If you find any bug or face issue, please [post it here](https://github.com/vivekmarakana/iota.lib.rb/issues).
8
-
9
- **Note: This release does not have multi signature support. It will be added after successful testing of this version**
5
+ This is the **unofficial** Ruby gem for the IOTA Core. It implements both the [official API](https://iota.readme.io/), as well as newly proposed functionality (such as signing, bundles, utilities, conversion, multi signature support and reattch/promote).
10
6
 
11
7
  ## Installation
12
8
 
13
9
  Add this line to your application's Gemfile:
14
10
 
15
11
  ```ruby
16
- gem 'iota-ruby', '~> 1.1.1', require: 'iota'
12
+ gem 'iota-ruby', '~> 1.1.2'
17
13
  ```
18
14
 
19
15
  And then execute:
20
16
 
21
17
  $ bundle
22
18
 
19
+ Or install it yourself as:
20
+
21
+ $ gem install iota-ruby
22
+
23
23
 
24
24
  # Documentation
25
25
 
@@ -41,6 +41,8 @@ The optional settings object can have the following values:
41
41
  You can either supply the remote node directly via the `provider` option, or individually with `host` and `port`, as can be seen in the example below:
42
42
 
43
43
  ```ruby
44
+ require 'iota'
45
+
44
46
  # Create client with host and port as provider
45
47
  client = IOTA::Client.new(host: 'http://localhost', port: 14265)
46
48
 
data/lib/iota/api/api.rb CHANGED
@@ -130,13 +130,13 @@ module IOTA
130
130
  sendCommand(@commands.getTips, &callback)
131
131
  end
132
132
 
133
- def getTransactionsToApprove(depth, &callback)
133
+ def getTransactionsToApprove(depth, reference = nil, &callback)
134
134
  # Check if correct depth
135
135
  if !@validator.isValue(depth)
136
136
  return sendData(false, "Invalid inputs provided", &callback)
137
137
  end
138
138
 
139
- sendCommand(@commands.getTransactionsToApprove(depth), &callback)
139
+ sendCommand(@commands.getTransactionsToApprove(depth, reference), &callback)
140
140
  end
141
141
 
142
142
  def attachToTangle(trunkTransaction, branchTransaction, minWeightMagnitude, trytes, &callback)
@@ -185,6 +185,14 @@ module IOTA
185
185
  sendCommand(@commands.storeTransactions(trytes), &callback)
186
186
  end
187
187
 
188
+ def checkConsistency(tails, &callback)
189
+ if !@validator.isArrayOfHashes(tails)
190
+ return sendData(false, "Invalid tails provided", &callback)
191
+ end
192
+
193
+ sendCommand(@commands.checkConsistency(tails), &callback)
194
+ end
195
+
188
196
  private
189
197
  def sendData(status, data, &callback)
190
198
  callback ? callback.call(status, data) : [status, data]
@@ -60,11 +60,11 @@ module IOTA
60
60
  { command: 'getTips' }
61
61
  end
62
62
 
63
- def getTransactionsToApprove(depth)
63
+ def getTransactionsToApprove(depth, reference = nil)
64
64
  {
65
65
  command: 'getTransactionsToApprove',
66
66
  depth: depth
67
- }
67
+ }.merge(reference.nil? ? {} : { reference: reference })
68
68
  end
69
69
 
70
70
  def attachToTangle(trunkTransaction, branchTransaction, minWeightMagnitude, trytes)
@@ -94,6 +94,13 @@ module IOTA
94
94
  trytes: trytes
95
95
  }
96
96
  end
97
+
98
+ def checkConsistency(tails)
99
+ {
100
+ command: 'checkConsistency',
101
+ tails: tails
102
+ }
103
+ end
97
104
  end
98
105
  end
99
106
  end
@@ -67,13 +67,15 @@ module IOTA
67
67
  end
68
68
  end
69
69
 
70
- def sendTrytes(trytes, depth, minWeightMagnitude, &callback)
70
+ def sendTrytes(trytes, depth, minWeightMagnitude, options = {}, &callback)
71
71
  # Check if correct depth and minWeightMagnitude
72
72
  if !@validator.isValue(depth) || !@validator.isValue(minWeightMagnitude)
73
73
  return sendData(false, "Invalid inputs provided", &callback)
74
74
  end
75
75
 
76
- getTransactionsToApprove(depth) do |status, approval_data|
76
+ reference = options[:reference] || options['reference']
77
+
78
+ getTransactionsToApprove(depth, reference) do |status, approval_data|
77
79
  if !status
78
80
  return sendData(false, approval_data, &callback)
79
81
  end
@@ -213,7 +215,8 @@ module IOTA
213
215
  end
214
216
  end
215
217
 
216
- def replayBundle(tail, depth, minWeightMagnitude, &callback)
218
+ # Replays or promote transactions based on tail consistency
219
+ def replayBundle(tail, depth, minWeightMagnitude, forcedReplay = false, &callback)
217
220
  # Check if correct tail hash
218
221
  if !@validator.isHash(tail)
219
222
  return sendData(false, "Invalid trytes provided", &callback)
@@ -224,17 +227,42 @@ module IOTA
224
227
  return sendData(false, "Invalid inputs provided", &callback)
225
228
  end
226
229
 
230
+ isPromotable = false
231
+ if !forcedReplay
232
+ checkConsistency([tail]) do |status, isConsistent|
233
+ isPromotable = status && isConsistent
234
+ end
235
+ end
236
+
227
237
  getBundle(tail) do |status, transactions|
228
238
  if !status
229
239
  return sendData(false, transactions, &callback)
230
240
  end
231
241
 
232
- bundleTrytes = []
233
- transactions.each do |trx|
234
- bundleTrytes << @utils.transactionTrytes(trx);
235
- end
242
+ if !isPromotable
243
+ bundleTrytes = []
244
+ transactions.each do |trx|
245
+ bundleTrytes << @utils.transactionTrytes(trx);
246
+ end
236
247
 
237
- return sendTrytes(bundleTrytes.reverse, depth, minWeightMagnitude, &callback)
248
+ return sendTrytes(bundleTrytes.reverse, depth, minWeightMagnitude, &callback)
249
+ else
250
+ account = IOTA::Models::Account.new(nil, transactions.first.address, self, @validator, @utils)
251
+
252
+ transfers = [{
253
+ address: '9' * 81,
254
+ value: 0,
255
+ message: '',
256
+ tag: ''
257
+ }]
258
+
259
+ begin
260
+ account.sendTransfer(depth, minWeightMagnitude, transfers, { reference: tail })
261
+ return sendData(status, transactions, &callback)
262
+ rescue => e
263
+ return sendData(false, e.message, &callback)
264
+ end
265
+ end
238
266
  end
239
267
  end
240
268
 
@@ -405,7 +433,7 @@ module IOTA
405
433
 
406
434
  data = []
407
435
 
408
- hashes.in_groups_of(batchSize, false) do |group|
436
+ hashes.each_slice(batchSize) do |group|
409
437
  getTrytes(group) do |status, trytes|
410
438
  if !status
411
439
  return sendData(false, trytes, &callback)
@@ -3,10 +3,10 @@ module IOTA
3
3
  class Account < Base
4
4
  attr_reader :client, :seed, :latestAddress, :addresses, :transfers, :inputs, :balance
5
5
 
6
- def initialize(client, seed)
7
- @api = client.api
8
- @validator = client.validator
9
- @utils = client.utils
6
+ def initialize(client, seed, api = nil, validator = nil, utils = nil)
7
+ @api = client ? client.api : api
8
+ @validator = client ? client.validator : validator
9
+ @utils = client ? client.utils : utils
10
10
  @seed = seed.class == String ? Seed.new(seed) : seed
11
11
 
12
12
  reset
@@ -188,7 +188,7 @@ module IOTA
188
188
  end
189
189
 
190
190
  # Get inputs if we are sending tokens
191
- if totalValue
191
+ if totalValue > 0
192
192
  # Case 1: user provided inputs
193
193
  #
194
194
  # Validate the inputs by calling getBalances
@@ -263,7 +263,8 @@ module IOTA
263
263
  end
264
264
 
265
265
  trytes = prepareTransfers(transfers, options)
266
- @api.sendTrytes(trytes, depth, minWeightMagnitude) do |status, data|
266
+
267
+ @api.sendTrytes(trytes, depth, minWeightMagnitude, options) do |status, data|
267
268
  if !status
268
269
  raise StandardError, data
269
270
  else
@@ -358,8 +359,14 @@ module IOTA
358
359
  # Final function for signing inputs
359
360
  return signInputs(inputs, bundle, signatureFragments, hmacKey)
360
361
  elsif remainder > 0
362
+ index = 0
363
+ (0...inputs.length).step(1) do |k|
364
+ index = [inputs[k].keyIndex, index].max
365
+ end
366
+ index += 1
367
+
361
368
  # Generate a new Address by calling getNewAddress
362
- address = getNewAddress({security: security})
369
+ address = getNewAddress({index: index, security: security})
363
370
  timestamp = Time.now.utc.to_i
364
371
 
365
372
  # Remainder bundle entry
@@ -97,7 +97,8 @@ module IOTA
97
97
  'findTransactions' => 'hashes',
98
98
  'getTrytes' => 'trytes',
99
99
  'getInclusionStates' => 'states',
100
- 'attachToTangle' => 'trytes'
100
+ 'attachToTangle' => 'trytes',
101
+ 'checkConsistency' => 'state'
101
102
  }
102
103
 
103
104
  # If correct result and we want to prepare the result
data/lib/iota/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IOTA
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iota-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek Marakana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-13 00:00:00.000000000 Z
11
+ date: 2017-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler