iost_sdk 0.1.1 → 0.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
  SHA256:
3
- metadata.gz: 679b1144353fd3517a8dc065af4da1484c8fb1a709082a3ba9291309256dc485
4
- data.tar.gz: 1d7fdf43f81cecbff0b7ae584d834a6f9c0981d6afac52c01a9814af4f8f3f23
3
+ metadata.gz: 9ae4d86edc0a4c5467a5ac2918ef5739252de9144d931b4d436244625266d9fe
4
+ data.tar.gz: 2a86a47227582a663620cfd5b84f5ad82ec69d1cbd2d72f289596d6a4c738072
5
5
  SHA512:
6
- metadata.gz: 15477b875bf5cbd22baac496701eb648cb99409c1b175646d6d3dfbb5ce114f06ea54c7586cc172cff55c0c270f83ca54cfd825fba644d2ff35fe69504059034
7
- data.tar.gz: 6643cc69becc0e6bcf6bd6158aadc60b55b4485e6b2aec90e17e40a0ffaab002b61ef0f8b04f7737a3570eec00e91534136c89208637733bb865c610f1ca10ab
6
+ metadata.gz: dca53e2d1f8e0916d66fe15c59fee923f97ae6fa520784fa354943cdc29430e6853e5023188efc121ba2ce219f2cd90c2af12de8ce5a9f9169fcbe2ea298b9b3
7
+ data.tar.gz: 75548eb1ae935863f164ecf98ba939855154d3f20b6f931b1a1550618a237cd71bc1d12f114ce0a34020dcf46208b6caadab1560f1ab7168c4ed838f50806552
@@ -11,7 +11,8 @@ module IOSTSdk
11
11
  def self.attr_names
12
12
  [
13
13
  'status',
14
- 'transaction'
14
+ 'transaction',
15
+ 'block_number'
15
16
  ]
16
17
  end
17
18
  end
data/lib/iost_sdk.rb CHANGED
@@ -25,6 +25,13 @@ module IOSTSdk
25
25
  approval_limit_amount: :unlimited
26
26
  }.freeze
27
27
 
28
+ TXN_POLL_CAP = 90
29
+ TXN_STATUS = {
30
+ pending: 'pending',
31
+ success: 'success',
32
+ failed: 'failed'
33
+ }.freeze
34
+
28
35
  #
29
36
  # @param endpoint [String] a URL of the JSON RPC endpoint of IOST
30
37
  def initialize(endpoint:)
@@ -40,11 +47,38 @@ module IOSTSdk
40
47
 
41
48
  def sign_and_send(account_name:, key_pair:)
42
49
  if @transaction
43
- @client.send_tx(
50
+ resp = @client.send_tx(
44
51
  transaction: @transaction,
45
52
  account_name: account_name,
46
53
  key_pair: key_pair
47
54
  )
55
+
56
+ if resp['pre_tx_receipt']['status_code'] != TXN_STATUS[:success].upcase
57
+ {
58
+ status: TXN_STATUS[:failed],
59
+ txn_hash: resp['hash']
60
+ }
61
+ else
62
+ txn_hash = resp['hash']
63
+ num_tries = 0
64
+ txn_status = TXN_STATUS[:pending]
65
+ txn_receipt = nil
66
+ # poll transaction receipt by hash
67
+ while ![TXN_STATUS[:success], TXN_STATUS[:failed]].include?(txn_status) && num_tries <= TXN_POLL_CAP do
68
+ begin
69
+ txn_receipt = @client.get_tx_receipt_by_tx_hash(hash_value: txn_hash)
70
+ rescue
71
+ end
72
+ txn_status = txn_receipt.status_code.downcase if txn_receipt && txn_receipt.status_code
73
+ num_tries += 1
74
+ sleep(1)
75
+ end
76
+
77
+ {
78
+ status: txn_status,
79
+ txn_hash: txn_receipt.tx_hash
80
+ }
81
+ end
48
82
  end
49
83
  end
50
84
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iost_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Han Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-11 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler