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 +4 -4
- data/lib/iost_sdk/models/transaction_info.rb +2 -1
- data/lib/iost_sdk.rb +35 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ae4d86edc0a4c5467a5ac2918ef5739252de9144d931b4d436244625266d9fe
|
4
|
+
data.tar.gz: 2a86a47227582a663620cfd5b84f5ad82ec69d1cbd2d72f289596d6a4c738072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dca53e2d1f8e0916d66fe15c59fee923f97ae6fa520784fa354943cdc29430e6853e5023188efc121ba2ce219f2cd90c2af12de8ce5a9f9169fcbe2ea298b9b3
|
7
|
+
data.tar.gz: 75548eb1ae935863f164ecf98ba939855154d3f20b6f931b1a1550618a237cd71bc1d12f114ce0a34020dcf46208b6caadab1560f1ab7168c4ed838f50806552
|
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.
|
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
|
+
date: 2019-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|