iost_sdk 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iost_sdk/errors.rb +6 -0
- data/lib/iost_sdk/models/query/transaction.rb +20 -0
- data/lib/iost_sdk/version.rb +1 -1
- data/lib/iost_sdk.rb +2 -5
- 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: 6ad731fd51e432cb3e208830e9bac05b6791929a5b10b3160292e2c9dabbf32d
|
4
|
+
data.tar.gz: 2acb03fbf50d62203bbe8727c66ee17a038b0c909355b643ce2ba5e1092485b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3282a86197eb10e5f0aeedbfea442200e0504ff619f031e66f4d6f99dcbdf56b873a41b64406c5064157226be9483b12990958a56846ed642d95f64f0f49daf1
|
7
|
+
data.tar.gz: a5ae133dc8048a86c2cf0ff0a52fec861c1ad876eb9a5a7469f0ad4167f08f7ec7e731684514fd7a0572ac4c1846f09df4754cb06175b64b024dbfb55d13a37e
|
data/lib/iost_sdk/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json'
|
4
|
+
require 'iost_sdk/errors'
|
4
5
|
require 'iost_sdk/models'
|
5
6
|
require 'iost_sdk/models/amount_limit'
|
6
7
|
require 'iost_sdk/models/action'
|
@@ -12,6 +13,10 @@ module IOSTSdk
|
|
12
13
|
class Transaction
|
13
14
|
include Models
|
14
15
|
|
16
|
+
GAS_LIMIT_RANGE = [6000, 4_000_000].freeze
|
17
|
+
GAS_RATIO_RANGE = [1, 100].freeze
|
18
|
+
NUMERIC_REGEX = /^\d+(\.\d+)?$/.freeze
|
19
|
+
|
15
20
|
attr_accessor :chain_id
|
16
21
|
|
17
22
|
def self.attr_names
|
@@ -62,6 +67,9 @@ module IOSTSdk
|
|
62
67
|
# @param token [String] name of the token
|
63
68
|
# @param amount [Integer|String] amount of the token or 'unlimited'
|
64
69
|
def add_approve(token:, amount:)
|
70
|
+
raise IOSTSdk::Errors::InvalidTransactionError.new('approve token should not be *') if token == '*'
|
71
|
+
raise IOSTSdk::Errors::InvalidTransactionError.new('approve amount should be numeric') unless amount.is_a?(Numeric)
|
72
|
+
|
65
73
|
@amount_limit << IOSTSdk::Models::AmountLimit.new.populate(
|
66
74
|
model_data: {
|
67
75
|
'token' => token.to_s,
|
@@ -69,6 +77,18 @@ module IOSTSdk
|
|
69
77
|
}
|
70
78
|
)
|
71
79
|
end
|
80
|
+
|
81
|
+
# Verify if the transaction object is valid
|
82
|
+
def is_valid?
|
83
|
+
[
|
84
|
+
# check gas limit
|
85
|
+
gas_limit.is_a?(Numeric) && gas_limit.between?(GAS_LIMIT_RANGE.first, GAS_LIMIT_RANGE.last),
|
86
|
+
# check gas ratio
|
87
|
+
gas_ratio.is_a?(Numeric) && gas_ratio.between?(GAS_RATIO_RANGE.first, GAS_RATIO_RANGE.last),
|
88
|
+
# check approve token and amount
|
89
|
+
amount_limit.all? { |al| al.token != '*' || /^\d+(\.\d+)?$/ =~ al.value }
|
90
|
+
].all?
|
91
|
+
end
|
72
92
|
end
|
73
93
|
end
|
74
94
|
end
|
data/lib/iost_sdk/version.rb
CHANGED
data/lib/iost_sdk.rb
CHANGED
@@ -46,7 +46,7 @@ module IOSTSdk
|
|
46
46
|
def_delegators :@client, *IOSTSdk::Http::Client.read_apis.keys
|
47
47
|
|
48
48
|
def sign_and_send(account_name:, key_pair:)
|
49
|
-
if @transaction
|
49
|
+
if @transaction && @transaction.is_valid?
|
50
50
|
resp = @client.send_tx(
|
51
51
|
transaction: @transaction,
|
52
52
|
account_name: account_name,
|
@@ -91,7 +91,6 @@ module IOSTSdk
|
|
91
91
|
def call_abi(contract_id:, abi_name:, abi_args:)
|
92
92
|
transaction = init_transaction
|
93
93
|
transaction.add_action(contract_id: contract_id, action_name: abi_name, action_data: abi_args)
|
94
|
-
transaction.add_approve(token: '*', amount: :unlimited)
|
95
94
|
transaction.set_time_params(expiration: expiration, delay: delay)
|
96
95
|
|
97
96
|
@transaction = transaction
|
@@ -110,7 +109,7 @@ module IOSTSdk
|
|
110
109
|
call_abi(
|
111
110
|
contract_id: 'token.iost',
|
112
111
|
abi_name: :transfer,
|
113
|
-
abi_args: [token, from, to, amount, memo]
|
112
|
+
abi_args: [token, from, to, amount.to_s, memo]
|
114
113
|
)
|
115
114
|
@transaction.add_approve(token: :iost, amount: amount)
|
116
115
|
@transaction.set_time_params(expiration: expiration, delay: delay)
|
@@ -151,8 +150,6 @@ module IOSTSdk
|
|
151
150
|
end
|
152
151
|
|
153
152
|
transaction.set_time_params(expiration: expiration, delay: delay)
|
154
|
-
transaction.add_approve(token: '*', amount: approval_limit_amount)
|
155
|
-
|
156
153
|
@transaction = transaction
|
157
154
|
self
|
158
155
|
end
|
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.4
|
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-
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|