iost_sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/iost_sdk/crypto.rb +144 -0
- data/lib/iost_sdk/errors.rb +10 -0
- data/lib/iost_sdk/http/client.rb +58 -0
- data/lib/iost_sdk/http/get_account.rb +17 -0
- data/lib/iost_sdk/http/get_block_by_hash.rb +17 -0
- data/lib/iost_sdk/http/get_block_by_number.rb +17 -0
- data/lib/iost_sdk/http/get_chain_info.rb +17 -0
- data/lib/iost_sdk/http/get_contract.rb +17 -0
- data/lib/iost_sdk/http/get_contract_storage.rb +25 -0
- data/lib/iost_sdk/http/get_contract_storage_fields.rb +25 -0
- data/lib/iost_sdk/http/get_gas_ratio.rb +17 -0
- data/lib/iost_sdk/http/get_node_info.rb +17 -0
- data/lib/iost_sdk/http/get_ram_info.rb +17 -0
- data/lib/iost_sdk/http/get_token_balance.rb +17 -0
- data/lib/iost_sdk/http/get_tx_by_hash.rb +17 -0
- data/lib/iost_sdk/http/get_tx_receipt_by_tx_hash.rb +17 -0
- data/lib/iost_sdk/http/http_request_error.rb +11 -0
- data/lib/iost_sdk/http/send_tx.rb +26 -0
- data/lib/iost_sdk/models/abi.rb +20 -0
- data/lib/iost_sdk/models/account.rb +32 -0
- data/lib/iost_sdk/models/account_ram_info.rb +19 -0
- data/lib/iost_sdk/models/action.rb +24 -0
- data/lib/iost_sdk/models/amount_limit.rb +22 -0
- data/lib/iost_sdk/models/block.rb +30 -0
- data/lib/iost_sdk/models/block_info.rb +19 -0
- data/lib/iost_sdk/models/chain_info.rb +25 -0
- data/lib/iost_sdk/models/contract.rb +22 -0
- data/lib/iost_sdk/models/frozen_balance.rb +18 -0
- data/lib/iost_sdk/models/gas_info.rb +23 -0
- data/lib/iost_sdk/models/gas_ratio.rb +18 -0
- data/lib/iost_sdk/models/info.rb +19 -0
- data/lib/iost_sdk/models/network_info.rb +20 -0
- data/lib/iost_sdk/models/node_info.rb +21 -0
- data/lib/iost_sdk/models/peer_info.rb +18 -0
- data/lib/iost_sdk/models/permission.rb +20 -0
- data/lib/iost_sdk/models/permission_group.rb +19 -0
- data/lib/iost_sdk/models/permission_item.rb +20 -0
- data/lib/iost_sdk/models/pledge_info.rb +18 -0
- data/lib/iost_sdk/models/query/contract_storage.rb +24 -0
- data/lib/iost_sdk/models/query/contract_storage_fields.rb +23 -0
- data/lib/iost_sdk/models/query/signed_transaction.rb +114 -0
- data/lib/iost_sdk/models/query/transaction.rb +75 -0
- data/lib/iost_sdk/models/ram_info.rb +21 -0
- data/lib/iost_sdk/models/receipt.rb +18 -0
- data/lib/iost_sdk/models/signature.rb +42 -0
- data/lib/iost_sdk/models/token_balance.rb +19 -0
- data/lib/iost_sdk/models/transaction.rb +32 -0
- data/lib/iost_sdk/models/transaction_info.rb +19 -0
- data/lib/iost_sdk/models/tx_receipt.rb +24 -0
- data/lib/iost_sdk/models/util/serializer.rb +52 -0
- data/lib/iost_sdk/models/vote_info.rb +19 -0
- data/lib/iost_sdk/models.rb +276 -0
- data/lib/iost_sdk/string.rb +11 -0
- data/lib/iost_sdk/version.rb +3 -0
- data/lib/iost_sdk.rb +141 -0
- metadata +255 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d0ba04a338a8f5867fc9f2e67972aef668c6cfd82f21ff03f3ebc3cc2366b1f1
|
4
|
+
data.tar.gz: '069a286d08b085e971a37b608875be1e11fb09e123759bc6bf0e122ed21ac3fb'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c2b65bc592070cb2b943b2aaf6452b42e3b0d91176330fd108604d823af0f61d051f52d03ca2e92cb0b5b1044515dab0ea0c9513289667aca9e43055b3320d5
|
7
|
+
data.tar.gz: 0cdaa59f203f23b3694b9a8cfebce19da9740f6a52ed3543da58fa886a7c26d47db4513157e880628c79f245a3451a961e7789498b8bbcf2d8e1bca1ff7f5c99
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Crypto
|
5
|
+
require 'btcruby'
|
6
|
+
require 'ed25519'
|
7
|
+
require 'base58'
|
8
|
+
require 'sha3'
|
9
|
+
|
10
|
+
KEY_ALGOS = {
|
11
|
+
Secp256k1: 'secp256k1',
|
12
|
+
Ed25519: 'ED25519'
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
def self.key_algos
|
16
|
+
KEY_ALGOS
|
17
|
+
end
|
18
|
+
|
19
|
+
# Create an instance of KeyPair by generating a brand new pair of public-private keys
|
20
|
+
#
|
21
|
+
# @param algo [String] the algorithm should be used to generate the new key pair
|
22
|
+
# @return an instance of +KeyPair+
|
23
|
+
def self.new_keypair(algo:)
|
24
|
+
raise ArgumentError.new("Invalid keypair algo: #{algo}") unless Set.new(KEY_ALGOS.values).include?(algo)
|
25
|
+
|
26
|
+
public_key, private_key = if algo == KEY_ALGOS[:Secp256k1]
|
27
|
+
p_key = BTC::Key.random
|
28
|
+
[p_key.public_key, p_key.private_key]
|
29
|
+
elsif algo == KEY_ALGOS[:Ed25519]
|
30
|
+
private_key = Ed25519::SigningKey.generate
|
31
|
+
public_key = private_key.verify_key
|
32
|
+
|
33
|
+
[public_key, private_key]
|
34
|
+
end
|
35
|
+
KeyPair.new(algo: algo, public_key: public_key, private_key: private_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create an instance of KeyPair from a +private_key_hex+ in a given +algo+
|
39
|
+
#
|
40
|
+
# @param algo [String] the algorithm used to generate the key pair
|
41
|
+
# @param encoded_private_key [String] the Base58 encoded string of an existing private key
|
42
|
+
# @return an instance of +KeyPair+
|
43
|
+
def self.keypair_from_private_key(algo:, encoded_private_key:)
|
44
|
+
raise ArgumentError.new("Invalid algo: #{algo}") unless Set.new(KEY_ALGOS.values).include?(algo)
|
45
|
+
|
46
|
+
public_key, private_key = if algo == KEY_ALGOS[:Secp256k1]
|
47
|
+
p_key = BTC::Key.new(
|
48
|
+
private_key: Base58.base58_to_binary(encoded_private_key, :bitcoin)
|
49
|
+
)
|
50
|
+
[p_key.public_key, p_key.private_key]
|
51
|
+
elsif algo == KEY_ALGOS[:Ed25519]
|
52
|
+
private_key = Ed25519::SigningKey.new(
|
53
|
+
Base58.base58_to_binary(encoded_private_key, :bitcoin)
|
54
|
+
)
|
55
|
+
public_key = private_key.verify_key
|
56
|
+
|
57
|
+
[public_key, private_key]
|
58
|
+
end
|
59
|
+
|
60
|
+
KeyPair.new(algo: algo, public_key: public_key, private_key: private_key)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create an instance of KeyPair from an +Ed25519+ keypair string
|
64
|
+
#
|
65
|
+
# @param encoded_kaypair [String] a Base58 encoded Ed25519 keypair string
|
66
|
+
# @return an instance of KeyPair
|
67
|
+
def self.from_keypair(encoded_keypair:)
|
68
|
+
private_key = Ed25519::SigningKey.from_keypair(
|
69
|
+
Base58.base58_to_binary(encoded_keypair, :bitcoin)
|
70
|
+
)
|
71
|
+
|
72
|
+
KeyPair.new(
|
73
|
+
algo: IOSTSdk::Crypto::KEY_ALGOS[:Ed25519],
|
74
|
+
public_key: private_key.verify_key,
|
75
|
+
private_key: private_key
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
class KeyPair
|
80
|
+
attr_reader :algo
|
81
|
+
|
82
|
+
# Create an instance of KeyPair
|
83
|
+
#
|
84
|
+
# @param algo [String] the algorithm used to generate the key pair
|
85
|
+
# @param public_key [Ed25519::VerifyKey|OpenSSL::PKey::EC::Point] an instance of the public key
|
86
|
+
# @param private_key [Ed25519::SigningKey|OpenSSL::BN] an instance of the private key
|
87
|
+
# @return an instance of KeyPair
|
88
|
+
def initialize(algo:, public_key:, private_key:)
|
89
|
+
@algo = algo
|
90
|
+
@public_key = public_key
|
91
|
+
@private_key = private_key
|
92
|
+
end
|
93
|
+
|
94
|
+
def value
|
95
|
+
Base58.binary_to_base58(@private_key.keypair, :bitcoin) if
|
96
|
+
@algo == IOSTSdk::Crypto.key_algos[:Ed25519]
|
97
|
+
end
|
98
|
+
|
99
|
+
def public_key
|
100
|
+
Base58.binary_to_base58(public_key_raw, :bitcoin)
|
101
|
+
end
|
102
|
+
|
103
|
+
def public_key_raw
|
104
|
+
if @algo == IOSTSdk::Crypto.key_algos[:Secp256k1]
|
105
|
+
# @public_key is in bytes already
|
106
|
+
@public_key
|
107
|
+
elsif @algo == IOSTSdk::Crypto.key_algos[:Ed25519]
|
108
|
+
@public_key.to_bytes
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def private_key
|
113
|
+
Base58.binary_to_base58(private_key_raw, :bitcoin)
|
114
|
+
end
|
115
|
+
|
116
|
+
def private_key_raw
|
117
|
+
if @algo == IOSTSdk::Crypto.key_algos[:Secp256k1]
|
118
|
+
# @private_key is in bytes already
|
119
|
+
@private_key
|
120
|
+
elsif @algo == IOSTSdk::Crypto.key_algos[:Ed25519]
|
121
|
+
@private_key.to_bytes
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def id
|
126
|
+
public_key
|
127
|
+
end
|
128
|
+
|
129
|
+
def sign(message:)
|
130
|
+
if @algo == IOSTSdk::Crypto.key_algos[:Secp256k1]
|
131
|
+
p_key = BTC::Key.new(private_key: @private_key)
|
132
|
+
der_signature = p_key.ecdsa_signature(message)
|
133
|
+
decoded_der = OpenSSL::ASN1.decode(der_signature)
|
134
|
+
decoded_der.value
|
135
|
+
.map { |v| v.value.to_s(2) }
|
136
|
+
.flatten
|
137
|
+
.join
|
138
|
+
elsif @algo == IOSTSdk::Crypto.key_algos[:Ed25519]
|
139
|
+
@private_key.sign(message)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module IOSTSdk
|
2
|
+
module Errors
|
3
|
+
class InvalidModelDataError < StandardError
|
4
|
+
def initialize(class_name, expected, actual)
|
5
|
+
@message = "Model data for #{class_name} is invalid. Expecting attribute names: #{expected}, actual: #{actual}"
|
6
|
+
super(@message)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'httparty'
|
5
|
+
require 'iost_sdk/models/query/signed_transaction'
|
6
|
+
require 'iost_sdk/http/http_request_error'
|
7
|
+
require 'iost_sdk/string'
|
8
|
+
|
9
|
+
module IOSTSdk
|
10
|
+
module Http
|
11
|
+
class Client
|
12
|
+
# key: method name
|
13
|
+
# value: an array of args
|
14
|
+
METHODS = {
|
15
|
+
get_node_info: [],
|
16
|
+
get_chain_info: [],
|
17
|
+
get_gas_ratio: [],
|
18
|
+
get_ram_info: [],
|
19
|
+
get_tx_by_hash: [:hash_value],
|
20
|
+
get_tx_receipt_by_tx_hash: [:hash_value],
|
21
|
+
get_block_by_hash: [:hash_value, :complete],
|
22
|
+
get_block_by_number: [:number, :complete],
|
23
|
+
get_account: [:name, :by_longest_chain],
|
24
|
+
get_token_balance: [:account_name, :token_name, :by_longest_chain],
|
25
|
+
get_contract: [:id, :by_longest_chain],
|
26
|
+
get_contract_storage: [:query],
|
27
|
+
get_contract_storage_fields: [:query],
|
28
|
+
send_tx: [:transaction, :account_name, :key_pair]
|
29
|
+
# TODO: exec_tx
|
30
|
+
# TODO: subscribe
|
31
|
+
}
|
32
|
+
|
33
|
+
def initialize(base_url:)
|
34
|
+
@base_url = base_url
|
35
|
+
|
36
|
+
METHODS.each do |method_name, method_args|
|
37
|
+
# require the file
|
38
|
+
require "iost_sdk/http/#{method_name}"
|
39
|
+
# define the method
|
40
|
+
self.class.send(:define_method, method_name) do |**args|
|
41
|
+
# extract match args for the call
|
42
|
+
raise ArgumentError.new('Invalid method arguments.') unless
|
43
|
+
Set.new(method_args).subset?(Set.new(args.keys))
|
44
|
+
|
45
|
+
valid_args = method_args.reduce({}) do |memo, k|
|
46
|
+
memo[k] = args[k]
|
47
|
+
memo
|
48
|
+
end
|
49
|
+
# init and invoke
|
50
|
+
class_name = IOSTSdk::String.camelize(method_name)
|
51
|
+
clazz = IOSTSdk::String.classify("IOSTSdk::Http::#{class_name}")
|
52
|
+
clazz.new.invoke(valid_args.merge(base_url: @base_url))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetAccount
|
6
|
+
require 'iost_sdk/models/account'
|
7
|
+
|
8
|
+
def invoke(base_url:, name:, by_longest_chain:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getAccount/#{name}/#{by_longest_chain}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::Account.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetBlockByHash
|
6
|
+
require 'iost_sdk/models/block_info'
|
7
|
+
|
8
|
+
def invoke(base_url:, hash_value:, complete:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getBlockByHash/#{hash_value}/#{complete}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::BlockInfo.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetBlockByNumber
|
6
|
+
require 'iost_sdk/models/block_info'
|
7
|
+
|
8
|
+
def invoke(base_url:, number:, complete:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getBlockByNumber/#{number}/#{complete}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::BlockInfo.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetChainInfo
|
6
|
+
require 'iost_sdk/models/chain_info'
|
7
|
+
|
8
|
+
def invoke(base_url:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getChainInfo")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::ChainInfo.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetContract
|
6
|
+
require 'iost_sdk/models/contract'
|
7
|
+
|
8
|
+
def invoke(base_url:, id:, by_longest_chain:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getContract/#{id}/#{by_longest_chain}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::Contract.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'iost_sdk/models/query/contract_storage'
|
5
|
+
|
6
|
+
module IOSTSdk
|
7
|
+
module Http
|
8
|
+
class GetContractStorage
|
9
|
+
def invoke(base_url:, query:)
|
10
|
+
raise ArgumentError.new('query must be an instance of IOSTSdk::Models::Query::ContractStorage') unless
|
11
|
+
query.is_a?(IOSTSdk::Models::Query::ContractStorage)
|
12
|
+
|
13
|
+
resp = HTTParty.post(
|
14
|
+
"#{base_url}/getContractStorage",
|
15
|
+
body: JSON.generate(query.raw_data),
|
16
|
+
headers: { 'Content-Type' => 'application/json' }
|
17
|
+
)
|
18
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
19
|
+
resp.code == 200
|
20
|
+
|
21
|
+
{ data: JSON.parse(resp.body)['data'] }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'iost_sdk/models/query/contract_storage_fields'
|
5
|
+
|
6
|
+
module IOSTSdk
|
7
|
+
module Http
|
8
|
+
class GetContractStorageFields
|
9
|
+
def invoke(base_url:, query:)
|
10
|
+
raise ArgumentError.new('query must be an instance of IOSTSdk::Models::Query::ContractStorageFields') unless
|
11
|
+
query.is_a?(IOSTSdk::Models::Query::ContractStorageFields)
|
12
|
+
|
13
|
+
resp = HTTParty.post(
|
14
|
+
"#{base_url}/getContractStorageFields",
|
15
|
+
body: JSON.generate(query.raw_data),
|
16
|
+
headers: { 'Content-Type' => 'application/json' }
|
17
|
+
)
|
18
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
19
|
+
resp.code == 200
|
20
|
+
|
21
|
+
{ fields: JSON.parse(resp.body)['fields'] }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetGasRatio
|
6
|
+
require 'iost_sdk/models/gas_ratio'
|
7
|
+
|
8
|
+
def invoke(base_url:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getGasRatio")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::GasRatio.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetNodeInfo
|
6
|
+
require 'iost_sdk/models/node_info'
|
7
|
+
|
8
|
+
def invoke(base_url:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getNodeInfo")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::NodeInfo.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetRamInfo
|
6
|
+
require 'iost_sdk/models/ram_info'
|
7
|
+
|
8
|
+
def invoke(base_url:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getRAMInfo")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::RAMInfo.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetTokenBalance
|
6
|
+
require 'iost_sdk/models/token_balance'
|
7
|
+
|
8
|
+
def invoke(base_url:, account_name:, token_name:, by_longest_chain:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getTokenBalance/#{account_name}/#{token_name}/#{by_longest_chain}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::TokenBalance.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetTxByHash
|
6
|
+
require 'iost_sdk/models/transaction_info'
|
7
|
+
|
8
|
+
def invoke(base_url:, hash_value:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getTxByHash/#{hash_value}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::TransactionInfo.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IOSTSdk
|
4
|
+
module Http
|
5
|
+
class GetTxReceiptByTxHash
|
6
|
+
require 'iost_sdk/models/tx_receipt'
|
7
|
+
|
8
|
+
def invoke(base_url:, hash_value:)
|
9
|
+
resp = HTTParty.get("#{base_url}/getTxReceiptByTxHash/#{hash_value}")
|
10
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
11
|
+
resp.code == 200
|
12
|
+
|
13
|
+
IOSTSdk::Models::TxReceipt.new.populate(model_data: JSON.parse(resp.body))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'iost_sdk/models/query/signed_transaction'
|
5
|
+
|
6
|
+
module IOSTSdk
|
7
|
+
module Http
|
8
|
+
class SendTx
|
9
|
+
def invoke(base_url:, transaction:, account_name:, key_pair:)
|
10
|
+
# sign the transaction first
|
11
|
+
signed_txn = IOSTSdk::Models::Query::SignedTransaction.from_transaction(transaction: transaction)
|
12
|
+
final_txn = signed_txn.sign(account_name: account_name, key_pair: key_pair)
|
13
|
+
|
14
|
+
resp = HTTParty.post(
|
15
|
+
"#{base_url}/sendTx",
|
16
|
+
body: JSON.generate(final_txn.raw_data),
|
17
|
+
headers: { 'Content-Type' => 'application/json' }
|
18
|
+
)
|
19
|
+
raise HttpRequestError.new(status_code: resp.code, body: resp.body) unless
|
20
|
+
resp.code == 200
|
21
|
+
|
22
|
+
JSON.parse(resp.body)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iost_sdk/models'
|
4
|
+
require 'iost_sdk/models/amount_limit'
|
5
|
+
|
6
|
+
module IOSTSdk
|
7
|
+
module Models
|
8
|
+
class ABI
|
9
|
+
include Models
|
10
|
+
|
11
|
+
def self.attr_names
|
12
|
+
[
|
13
|
+
'name',
|
14
|
+
'args',
|
15
|
+
'amount_limit'
|
16
|
+
]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iost_sdk/models'
|
4
|
+
|
5
|
+
module IOSTSdk
|
6
|
+
module Models
|
7
|
+
class Account
|
8
|
+
include Models
|
9
|
+
|
10
|
+
require 'iost_sdk/models/permission'
|
11
|
+
require 'iost_sdk/models/permission_group'
|
12
|
+
require 'iost_sdk/models/permission_item'
|
13
|
+
require 'iost_sdk/models/gas_info'
|
14
|
+
require 'iost_sdk/models/account_ram_info'
|
15
|
+
require 'iost_sdk/models/frozen_balance'
|
16
|
+
require 'iost_sdk/models/vote_info'
|
17
|
+
|
18
|
+
def self.attr_names
|
19
|
+
[
|
20
|
+
'name',
|
21
|
+
'balance',
|
22
|
+
'gas_info',
|
23
|
+
'ram_info',
|
24
|
+
'permissions',
|
25
|
+
'groups',
|
26
|
+
'frozen_balances',
|
27
|
+
'vote_infos'
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'iost_sdk/models'
|
5
|
+
|
6
|
+
module IOSTSdk
|
7
|
+
module Models
|
8
|
+
class Action
|
9
|
+
include Models
|
10
|
+
|
11
|
+
def self.attr_names
|
12
|
+
[
|
13
|
+
'contract',
|
14
|
+
'action_name',
|
15
|
+
'data'
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
def raw_data_bytes
|
20
|
+
[contract, action_name, data.to_s]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iost_sdk/models'
|
4
|
+
|
5
|
+
module IOSTSdk
|
6
|
+
module Models
|
7
|
+
class AmountLimit
|
8
|
+
include Models
|
9
|
+
|
10
|
+
def self.attr_names
|
11
|
+
[
|
12
|
+
'token',
|
13
|
+
'value'
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def raw_data_bytes
|
18
|
+
[token, value.to_s]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iost_sdk/models'
|
4
|
+
require 'iost_sdk/models/transaction'
|
5
|
+
require 'iost_sdk/models/info'
|
6
|
+
|
7
|
+
module IOSTSdk
|
8
|
+
module Models
|
9
|
+
class Block
|
10
|
+
include Models
|
11
|
+
|
12
|
+
def self.attr_names
|
13
|
+
[
|
14
|
+
'hash',
|
15
|
+
'version',
|
16
|
+
'parent_hash',
|
17
|
+
'tx_merkle_hash',
|
18
|
+
'tx_receipt_merkle_hash',
|
19
|
+
'number',
|
20
|
+
'witness',
|
21
|
+
'time',
|
22
|
+
'gas_usage',
|
23
|
+
'tx_count',
|
24
|
+
'info',
|
25
|
+
'transactions'
|
26
|
+
]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|