iost_sdk 0.1.0 → 0.1.1

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: d0ba04a338a8f5867fc9f2e67972aef668c6cfd82f21ff03f3ebc3cc2366b1f1
4
- data.tar.gz: '069a286d08b085e971a37b608875be1e11fb09e123759bc6bf0e122ed21ac3fb'
3
+ metadata.gz: 679b1144353fd3517a8dc065af4da1484c8fb1a709082a3ba9291309256dc485
4
+ data.tar.gz: 1d7fdf43f81cecbff0b7ae584d834a6f9c0981d6afac52c01a9814af4f8f3f23
5
5
  SHA512:
6
- metadata.gz: 9c2b65bc592070cb2b943b2aaf6452b42e3b0d91176330fd108604d823af0f61d051f52d03ca2e92cb0b5b1044515dab0ea0c9513289667aca9e43055b3320d5
7
- data.tar.gz: 0cdaa59f203f23b3694b9a8cfebce19da9740f6a52ed3543da58fa886a7c26d47db4513157e880628c79f245a3451a961e7789498b8bbcf2d8e1bca1ff7f5c99
6
+ metadata.gz: 15477b875bf5cbd22baac496701eb648cb99409c1b175646d6d3dfbb5ce114f06ea54c7586cc172cff55c0c270f83ca54cfd825fba644d2ff35fe69504059034
7
+ data.tar.gz: 6643cc69becc0e6bcf6bd6158aadc60b55b4485e6b2aec90e17e40a0ffaab002b61ef0f8b04f7737a3570eec00e91534136c89208637733bb865c610f1ca10ab
@@ -11,7 +11,7 @@ module IOSTSdk
11
11
  class Client
12
12
  # key: method name
13
13
  # value: an array of args
14
- METHODS = {
14
+ READ_METHODS = {
15
15
  get_node_info: [],
16
16
  get_chain_info: [],
17
17
  get_gas_ratio: [],
@@ -24,11 +24,21 @@ module IOSTSdk
24
24
  get_token_balance: [:account_name, :token_name, :by_longest_chain],
25
25
  get_contract: [:id, :by_longest_chain],
26
26
  get_contract_storage: [:query],
27
- get_contract_storage_fields: [:query],
27
+ get_contract_storage_fields: [:query]
28
+ }.freeze
29
+
30
+ WRITE_METHODS = {
28
31
  send_tx: [:transaction, :account_name, :key_pair]
29
32
  # TODO: exec_tx
30
33
  # TODO: subscribe
31
- }
34
+ }.freeze
35
+
36
+ METHODS = READ_METHODS.merge(WRITE_METHODS)
37
+ .freeze
38
+
39
+ def self.read_apis
40
+ READ_METHODS
41
+ end
32
42
 
33
43
  def initialize(base_url:)
34
44
  @base_url = base_url
data/lib/iost_sdk.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'forwardable'
3
4
  require 'iost_sdk/version'
4
5
  require 'iost_sdk/crypto'
5
6
  require 'iost_sdk/errors'
@@ -9,6 +10,9 @@ require 'iost_sdk/models/query/signed_transaction'
9
10
 
10
11
  module IOSTSdk
11
12
  class Main
13
+ extend Forwardable
14
+
15
+ attr_reader :client
12
16
  attr_accessor :gas_limit, :gas_ratio, :delay,
13
17
  :expiration, :approval_limit_amount,
14
18
  :transaction
@@ -25,16 +29,18 @@ module IOSTSdk
25
29
  # @param endpoint [String] a URL of the JSON RPC endpoint of IOST
26
30
  def initialize(endpoint:)
27
31
  @endpoint = endpoint
32
+ @client = IOSTSdk::Http::Client.new(base_url: @endpoint)
28
33
 
29
34
  DEFAULTS.each do |k, v|
30
35
  instance_variable_set("@#{k}".to_sym, v)
31
36
  end
32
37
  end
33
38
 
34
- def send(account_name:, key_pair:)
39
+ def_delegators :@client, *IOSTSdk::Http::Client.read_apis.keys
40
+
41
+ def sign_and_send(account_name:, key_pair:)
35
42
  if @transaction
36
- client = IOSTSdk::Http::Client.new(base_url: @endpoint)
37
- client.send_tx(
43
+ @client.send_tx(
38
44
  transaction: @transaction,
39
45
  account_name: account_name,
40
46
  key_pair: key_pair
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.0
4
+ version: 0.1.1
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-09 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler