radiator 0.4.4 → 0.4.8.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +90 -6
- data/Rakefile +50 -20
- data/lib/radiator.rb +7 -1
- data/lib/radiator/api.rb +105 -14
- data/lib/radiator/bridge.rb +34 -0
- data/lib/radiator/chain_config.rb +9 -2
- data/lib/radiator/database_api.rb +1 -1
- data/lib/radiator/follow_api.rb +1 -1
- data/lib/radiator/market_history_api.rb +1 -1
- data/lib/radiator/operation.rb +3 -2
- data/lib/radiator/operation_types.rb +43 -27
- data/lib/radiator/ssc/base_steem_smart_contract_rpc.rb +147 -0
- data/lib/radiator/ssc/blockchain.rb +57 -0
- data/lib/radiator/ssc/contracts.rb +88 -0
- data/lib/radiator/ssc/stream.rb +62 -0
- data/lib/radiator/stream.rb +15 -6
- data/lib/radiator/transaction.rb +41 -1
- data/lib/radiator/type/amount.rb +26 -50
- data/lib/radiator/type/beneficiaries.rb +8 -1
- data/lib/radiator/type/price.rb +2 -2
- data/lib/radiator/version.rb +1 -1
- data/radiator.gemspec +15 -12
- data/test/fixtures/empty.json +1 -0
- data/test/fixtures/error.json +29 -0
- data/test/fixtures/follow_api_get_followers.json +1 -0
- data/test/fixtures/get_account.json +165 -0
- data/test/fixtures/get_account_count.json +1 -0
- data/test/fixtures/get_account_references.json +1 -0
- data/test/fixtures/get_block.json +193 -0
- data/test/fixtures/get_dynamic_global_properties.json +32 -0
- data/test/fixtures/get_feed_history.json +684 -0
- data/test/fixtures/get_hardfork_version.json +1 -0
- data/test/fixtures/get_key_references.json +14 -0
- data/test/fixtures/get_stats_for_time.json +57 -0
- data/test/fixtures/get_vesting_delegation.json +936 -0
- data/test/fixtures/golos_get_dynamic_global_properties.json +32 -0
- data/test/fixtures/market_history_api_get_market_history_buckets.json +1 -0
- data/test/fixtures/market_history_api_get_order_book.json +109 -0
- data/test/fixtures/market_history_api_get_recent_trades.json +55 -0
- data/test/fixtures/market_history_api_get_ticker.json +11 -0
- data/test/fixtures/market_history_api_get_volume.json +1 -0
- data/test/fixtures/null.json +1 -0
- data/test/fixtures/vcr_cassettes/account_by_key_api_all_methods.yml +525 -0
- data/test/fixtures/vcr_cassettes/account_by_key_api_jsonrpc.yml +52 -0
- data/test/fixtures/vcr_cassettes/all_methods.yml +18155 -0
- data/test/fixtures/vcr_cassettes/api_all_methods.yml +13254 -0
- data/test/fixtures/vcr_cassettes/base_per_debt.yml +4946 -0
- data/test/fixtures/vcr_cassettes/base_per_mvest.yml +3969 -0
- data/test/fixtures/vcr_cassettes/block_time.yml +3322 -0
- data/test/fixtures/vcr_cassettes/broadcast_transaction.yml +1186 -0
- data/test/fixtures/vcr_cassettes/condenser_all_all_methods.yml +13297 -0
- data/test/fixtures/vcr_cassettes/expiration_initialize.yml +3428 -0
- data/test/fixtures/vcr_cassettes/find_account.yml +3681 -0
- data/test/fixtures/vcr_cassettes/find_block.yml +3589 -0
- data/test/fixtures/vcr_cassettes/find_comment.yml +11464 -0
- data/test/fixtures/vcr_cassettes/follow_api_jsonrpc.yml +52 -0
- data/test/fixtures/vcr_cassettes/get_account_count.yml +575 -0
- data/test/fixtures/vcr_cassettes/get_account_references.yml +608 -0
- data/test/fixtures/vcr_cassettes/get_accounts.yml +674 -0
- data/test/fixtures/vcr_cassettes/get_accounts_no_argument.yml +608 -0
- data/test/fixtures/vcr_cassettes/get_dynamic_global_properties.yml +661 -0
- data/test/fixtures/vcr_cassettes/get_feed_history.yml +1106 -0
- data/test/fixtures/vcr_cassettes/get_hardfork_version.yml +577 -0
- data/test/fixtures/vcr_cassettes/get_key_references.yml +987 -0
- data/test/fixtures/vcr_cassettes/get_market_history.yml +1043 -0
- data/test/fixtures/vcr_cassettes/get_market_history_buckets.yml +1043 -0
- data/test/fixtures/vcr_cassettes/get_order_book.yml +1091 -0
- data/test/fixtures/vcr_cassettes/get_recent_trades.yml +1043 -0
- data/test/fixtures/vcr_cassettes/get_ticker.yml +1047 -0
- data/test/fixtures/vcr_cassettes/get_trade_history.yml +1049 -0
- data/test/fixtures/vcr_cassettes/get_vesting_delegations.yml +523 -0
- data/test/fixtures/vcr_cassettes/get_volume.yml +1051 -0
- data/test/fixtures/vcr_cassettes/get_witness_by_account.yml +575 -0
- data/test/fixtures/vcr_cassettes/look_up_witnesses.yml +523 -0
- data/test/fixtures/vcr_cassettes/market_history_api_all_methods.yml +4373 -0
- data/test/fixtures/vcr_cassettes/network_broadcast_api_all_methods.yml +1288 -0
- data/test/fixtures/vcr_cassettes/properties.yml +3627 -0
- data/test/fixtures/vcr_cassettes/recover_transaction.yml +1099 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info.yml +92 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_block_info_invalid.yml +90 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_latest_block_info.yml +91 -0
- data/test/fixtures/vcr_cassettes/ssc_blockchain_transaction_info.yml +92 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_contract.yml +366 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_find.yml +91 -0
- data/test/fixtures/vcr_cassettes/ssc_contracts_find_one.yml +89 -0
- data/test/fixtures/vcr_cassettes/stream_jsonrpc.yml +8253 -0
- data/test/fixtures/vcr_cassettes/transaction_expiration_initialize_nil.yml +3176 -0
- data/test/fixtures/vcr_cassettes/transaction_jsonrpc.yml +151 -0
- data/test/fixtures/vcr_cassettes/unknown_chain_id.yml +3343 -0
- data/test/fixtures/vcr_cassettes/valid_chains.yml +3124 -0
- data/test/radiator/account_by_key_api_test.rb +46 -0
- data/test/radiator/api_test.rb +135 -0
- data/test/radiator/chain_stats_api_test.rb +49 -0
- data/test/radiator/chain_test.rb +153 -0
- data/test/radiator/condenser_api_test.rb +48 -0
- data/test/radiator/follow_api_test.rb +48 -0
- data/test/radiator/market_history_api_test.rb +100 -0
- data/test/radiator/network_broadcast_api_test.rb +48 -0
- data/test/radiator/operation_test.rb +117 -0
- data/test/radiator/ssc/blockchain_test.rb +58 -0
- data/test/radiator/ssc/contracts_test.rb +65 -0
- data/test/radiator/stream_test.rb +48 -0
- data/test/radiator/tag_api_test.rb +40 -0
- data/test/radiator/transaction_test.rb +755 -0
- data/test/test_helper.rb +66 -0
- metadata +206 -73
- data/.codeclimate.yml +0 -19
- data/.gitignore +0 -52
- data/.travis.yml +0 -23
- data/gource.sh +0 -8
- data/images/Anthony Martin.png +0 -0
- data/images/Marvin Hofmann.jpg +0 -0
- data/images/Marvin Hofmann.png +0 -0
- data/lib/steem.rb +0 -17
@@ -0,0 +1,34 @@
|
|
1
|
+
module Radiator
|
2
|
+
class Bridge < Api
|
3
|
+
def method_names
|
4
|
+
@method_names ||= [
|
5
|
+
:normalize_post,
|
6
|
+
:get_post_header,
|
7
|
+
:get_discussion,
|
8
|
+
:get_post,
|
9
|
+
:get_account_posts,
|
10
|
+
:get_ranked_posts,
|
11
|
+
:get_profile,
|
12
|
+
:get_trending_topics,
|
13
|
+
:get_relationship_between_accounts,
|
14
|
+
:post_notifications,
|
15
|
+
:account_notifications,
|
16
|
+
:unread_notifications,
|
17
|
+
:get_payout_stats,
|
18
|
+
:get_community,
|
19
|
+
:get_community_context,
|
20
|
+
:list_communities,
|
21
|
+
:list_pop_communities,
|
22
|
+
:list_community_roles,
|
23
|
+
:list_subscribers,
|
24
|
+
:list_all_subscriptions
|
25
|
+
].freeze
|
26
|
+
end
|
27
|
+
|
28
|
+
def api_name
|
29
|
+
:bridge
|
30
|
+
end
|
31
|
+
|
32
|
+
def healthy?(_); true; end
|
33
|
+
end
|
34
|
+
end
|
@@ -10,6 +10,13 @@ module Radiator
|
|
10
10
|
NETWORKS_STEEM_VEST_ASSET = 'VESTS'
|
11
11
|
NETWORKS_STEEM_DEFAULT_NODE = 'https://api.steemit.com'
|
12
12
|
|
13
|
+
NETWORKS_HIVE_CHAIN_ID = 'beeab0de00000000000000000000000000000000000000000000000000000000'
|
14
|
+
NETWORKS_HIVE_ADDRESS_PREFIX = 'STM'
|
15
|
+
NETWORKS_HIVE_CORE_ASSET = 'HIVE'
|
16
|
+
NETWORKS_HIVE_DEBT_ASSET = 'HBD'
|
17
|
+
NETWORKS_HIVE_VEST_ASSET = 'VESTS'
|
18
|
+
NETWORKS_HIVE_DEFAULT_NODE = 'https://api.openhive.network'
|
19
|
+
|
13
20
|
NETWORKS_TEST_CHAIN_ID = '18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e'
|
14
21
|
NETWORKS_TEST_ADDRESS_PREFIX = 'TST'
|
15
22
|
NETWORKS_TEST_CORE_ASSET = 'CORE'
|
@@ -17,6 +24,6 @@ module Radiator
|
|
17
24
|
NETWORKS_TEST_VEST_ASSET = 'CESTS'
|
18
25
|
NETWORKS_TEST_DEFAULT_NODE = 'https://test.steem.ws'
|
19
26
|
|
20
|
-
NETWORK_CHAIN_IDS = [NETWORKS_STEEM_CHAIN_ID, NETWORKS_TEST_CHAIN_ID]
|
27
|
+
NETWORK_CHAIN_IDS = [NETWORKS_STEEM_CHAIN_ID, NETWORKS_HIVE_CHAIN_ID, NETWORKS_TEST_CHAIN_ID]
|
21
28
|
end
|
22
|
-
end
|
29
|
+
end
|
data/lib/radiator/follow_api.rb
CHANGED
data/lib/radiator/operation.rb
CHANGED
@@ -5,11 +5,12 @@ module Radiator
|
|
5
5
|
include Utils
|
6
6
|
|
7
7
|
def initialize(options = {})
|
8
|
+
chain = options.delete(:chain) || :steem
|
8
9
|
opt = options.dup
|
9
10
|
@type = opt.delete(:type)
|
10
11
|
|
11
12
|
opt.each do |k, v|
|
12
|
-
instance_variable_set("@#{k}", type(@type, k, v))
|
13
|
+
instance_variable_set("@#{k}", type(chain, @type, k, v))
|
13
14
|
end
|
14
15
|
|
15
16
|
@use_condenser_namespace = if options.keys.include? :use_condenser_namespace
|
@@ -61,7 +62,7 @@ module Radiator
|
|
61
62
|
|
62
63
|
params[p] = case v
|
63
64
|
when Radiator::Type::Beneficiaries then [[0, v.to_h]]
|
64
|
-
when
|
65
|
+
when Hive::Type::Amount, Steem::Type::Amount
|
65
66
|
if use_condenser_namespace?
|
66
67
|
v.to_s
|
67
68
|
else
|
@@ -4,18 +4,18 @@ module Radiator
|
|
4
4
|
module OperationTypes
|
5
5
|
TYPES = {
|
6
6
|
transfer: {
|
7
|
-
amount: Type::Amount
|
7
|
+
amount: Hive::Type::Amount
|
8
8
|
},
|
9
9
|
transfer_to_vesting: {
|
10
|
-
amount: Type::Amount
|
10
|
+
amount: Hive::Type::Amount
|
11
11
|
},
|
12
12
|
withdraw_vesting: {
|
13
|
-
vesting_shares: Type::Amount
|
13
|
+
vesting_shares: Hive::Type::Amount
|
14
14
|
},
|
15
15
|
limit_order_create: {
|
16
16
|
orderid: Type::Uint32,
|
17
|
-
amount_to_sell: Type::Amount,
|
18
|
-
min_to_receive: Type::Amount,
|
17
|
+
amount_to_sell: Hive::Type::Amount,
|
18
|
+
min_to_receive: Hive::Type::Amount,
|
19
19
|
expiration: Type::PointInTime
|
20
20
|
},
|
21
21
|
limit_order_cancel: {
|
@@ -26,10 +26,10 @@ module Radiator
|
|
26
26
|
},
|
27
27
|
convert: {
|
28
28
|
requestid: Type::Uint32,
|
29
|
-
amount: Type::Amount
|
29
|
+
amount: Hive::Type::Amount
|
30
30
|
},
|
31
31
|
account_create: {
|
32
|
-
fee: Type::Amount,
|
32
|
+
fee: Hive::Type::Amount,
|
33
33
|
owner: Type::Permission,
|
34
34
|
active: Type::Permission,
|
35
35
|
posting: Type::Permission,
|
@@ -51,7 +51,7 @@ module Radiator
|
|
51
51
|
id: Type::Uint16
|
52
52
|
},
|
53
53
|
comment_options: {
|
54
|
-
max_accepted_payout: Type::Amount,
|
54
|
+
max_accepted_payout: Hive::Type::Amount,
|
55
55
|
allow_replies: Type::Future
|
56
56
|
},
|
57
57
|
set_withdraw_vesting_route: {
|
@@ -59,7 +59,7 @@ module Radiator
|
|
59
59
|
},
|
60
60
|
limit_order_create2: {
|
61
61
|
orderid: Type::Uint32,
|
62
|
-
amount_to_sell: Type::Amount,
|
62
|
+
amount_to_sell: Hive::Type::Amount,
|
63
63
|
exchange_rate: Type::Price,
|
64
64
|
expiration: Type::PointInTime
|
65
65
|
},
|
@@ -71,10 +71,12 @@ module Radiator
|
|
71
71
|
recent_owner_Permission: Type::Permission
|
72
72
|
},
|
73
73
|
escrow_transfer: {
|
74
|
-
sbd_amount: Type::Amount,
|
75
|
-
|
74
|
+
sbd_amount: Steem::Type::Amount,
|
75
|
+
hbd_amount: Hive::Type::Amount,
|
76
|
+
steem_amount: Steem::Type::Amount,
|
77
|
+
hive_amount: Hive::Type::Amount,
|
76
78
|
escrow_id: Type::Uint32,
|
77
|
-
fee: Type::Amount,
|
79
|
+
fee: Hive::Type::Amount,
|
78
80
|
ratification_deadline: Type::PointInTime,
|
79
81
|
escrow_expiration: Type::PointInTime
|
80
82
|
},
|
@@ -83,40 +85,46 @@ module Radiator
|
|
83
85
|
},
|
84
86
|
escrow_release: {
|
85
87
|
escrow_id: Type::Uint32,
|
86
|
-
sbd_amount: Type::Amount,
|
87
|
-
|
88
|
+
sbd_amount: Steem::Type::Amount,
|
89
|
+
hbd_amount: Hive::Type::Amount,
|
90
|
+
steem_amount: Steem::Type::Amount,
|
91
|
+
hive_amount: Hive::Type::Amount
|
88
92
|
},
|
89
93
|
escrow_approve: {
|
90
94
|
escrow_id: Type::Uint32
|
91
95
|
},
|
92
96
|
transfer_to_savings: {
|
93
|
-
amount: Type::Amount
|
97
|
+
amount: Hive::Type::Amount
|
94
98
|
},
|
95
99
|
transfer_from_savings: {
|
96
100
|
request_id: Type::Uint32,
|
97
|
-
amount: Type::Amount
|
101
|
+
amount: Hive::Type::Amount
|
98
102
|
},
|
99
103
|
cancel_transfer_from_savings: {
|
100
104
|
request_id: Type::Uint32
|
101
105
|
},
|
102
106
|
reset_account: {
|
103
|
-
new_owner_permission: Type::Amount
|
107
|
+
new_owner_permission: Hive::Type::Amount
|
104
108
|
},
|
105
109
|
set_reset_account: {
|
106
|
-
reward_steem: Type::Amount,
|
107
|
-
|
108
|
-
|
110
|
+
reward_steem: Steem::Type::Amount,
|
111
|
+
reward_hive: Hive::Type::Amount,
|
112
|
+
reward_sbd: Steem::Type::Amount,
|
113
|
+
reward_hbd: Hive::Type::Amount,
|
114
|
+
reward_vests: Hive::Type::Amount
|
109
115
|
},
|
110
116
|
claim_reward_balance: {
|
111
|
-
reward_steem: Type::Amount,
|
112
|
-
|
113
|
-
|
117
|
+
reward_steem: Steem::Type::Amount,
|
118
|
+
reward_hive: Hive::Type::Amount,
|
119
|
+
reward_sbd: Steem::Type::Amount,
|
120
|
+
reward_hbd: Hive::Type::Amount,
|
121
|
+
reward_vests: Hive::Type::Amount
|
114
122
|
},
|
115
123
|
delegate_vesting_shares: {
|
116
|
-
vesting_shares: Type::Amount
|
124
|
+
vesting_shares: Hive::Type::Amount
|
117
125
|
},
|
118
126
|
claim_account: {
|
119
|
-
fee: Type::Amount
|
127
|
+
fee: Hive::Type::Amount
|
120
128
|
},
|
121
129
|
witness_update: {
|
122
130
|
block_signing_key: Type::PublicKey,
|
@@ -127,13 +135,21 @@ module Radiator
|
|
127
135
|
}
|
128
136
|
}
|
129
137
|
|
130
|
-
def type(key, param, value)
|
138
|
+
def type(chain, key, param, value)
|
131
139
|
return if value.nil?
|
132
140
|
|
133
141
|
t = TYPES[key] or return value
|
134
142
|
p = t[param] or return value
|
135
143
|
|
136
|
-
p
|
144
|
+
if p == Hive::Type::Amount
|
145
|
+
case chain
|
146
|
+
when :steem then Steem::Type::Amount.new(value)
|
147
|
+
else
|
148
|
+
p.new(value)
|
149
|
+
end
|
150
|
+
else
|
151
|
+
p.new(value)
|
152
|
+
end
|
137
153
|
end
|
138
154
|
end
|
139
155
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Radiator
|
2
|
+
module SSC
|
3
|
+
class BaseSteemSmartContractRPC
|
4
|
+
# @private
|
5
|
+
POST_HEADERS = {
|
6
|
+
'Content-Type' => 'application/json',
|
7
|
+
'User-Agent' => Radiator::AGENT_ID
|
8
|
+
}
|
9
|
+
|
10
|
+
MAX_BACKOFF = 60.0
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@root_url = options[:root_url] || 'https://api.steem-engine.com/rpc'
|
14
|
+
|
15
|
+
@self_hashie_logger = false
|
16
|
+
@hashie_logger = if options[:hashie_logger].nil?
|
17
|
+
@self_hashie_logger = true
|
18
|
+
Logger.new(nil)
|
19
|
+
else
|
20
|
+
options[:hashie_logger]
|
21
|
+
end
|
22
|
+
|
23
|
+
unless @hashie_logger.respond_to? :warn
|
24
|
+
@hashie_logger = Logger.new(@hashie_logger)
|
25
|
+
end
|
26
|
+
|
27
|
+
@reuse_ssl_sessions = if options.keys.include? :reuse_ssl_sessions
|
28
|
+
options[:reuse_ssl_sessions]
|
29
|
+
else
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
@persist = if options[:persist].nil?
|
34
|
+
true
|
35
|
+
else
|
36
|
+
options[:persist]
|
37
|
+
end
|
38
|
+
|
39
|
+
if defined? Net::HTTP::Persistent::DEFAULT_POOL_SIZE
|
40
|
+
@pool_size = options[:pool_size] || Net::HTTP::Persistent::DEFAULT_POOL_SIZE
|
41
|
+
end
|
42
|
+
|
43
|
+
Hashie.logger = @hashie_logger
|
44
|
+
@uri = nil
|
45
|
+
@http_id = nil
|
46
|
+
@http = nil
|
47
|
+
@max_requests = options[:max_requests] || 30
|
48
|
+
end
|
49
|
+
|
50
|
+
# Stops the persistant http connections.
|
51
|
+
#
|
52
|
+
def shutdown
|
53
|
+
@uri = nil
|
54
|
+
@http_id = nil
|
55
|
+
@http = nil
|
56
|
+
end
|
57
|
+
protected
|
58
|
+
def rpc_id
|
59
|
+
@rpc_id ||= 0
|
60
|
+
@rpc_id = @rpc_id + 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def uri
|
64
|
+
@uri ||= URI.parse(@url)
|
65
|
+
end
|
66
|
+
|
67
|
+
def http_id
|
68
|
+
@http_id ||= "radiator-#{Radiator::VERSION}-ssc-blockchain-#{SecureRandom.uuid}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def http
|
72
|
+
@http ||= if persist?
|
73
|
+
if defined? Net::HTTP::Persistent::DEFAULT_POOL_SIZE
|
74
|
+
Net::HTTP::Persistent.new(name: http_id, pool_size: @pool_size).tap do |http|
|
75
|
+
http.keep_alive = 30
|
76
|
+
http.idle_timeout = 10
|
77
|
+
http.max_requests = @max_requests
|
78
|
+
http.retry_change_requests = true if defined? http.retry_change_requests
|
79
|
+
http.reuse_ssl_sessions = @reuse_ssl_sessions
|
80
|
+
end
|
81
|
+
else
|
82
|
+
# net-http-persistent < 3.0
|
83
|
+
Net::HTTP::Persistent.new(http_id) do |http|
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
http.use_ssl = uri.scheme == 'https'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
else
|
89
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
90
|
+
http.use_ssl = uri.scheme == 'https'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def post_request
|
96
|
+
Net::HTTP::Post.new uri.request_uri, POST_HEADERS
|
97
|
+
end
|
98
|
+
|
99
|
+
def request(options)
|
100
|
+
request = post_request
|
101
|
+
skip_health_check = options.delete(:skip_health_check)
|
102
|
+
request.body = JSON[options.merge(jsonrpc: '2.0', id: rpc_id)]
|
103
|
+
|
104
|
+
unless skip_health_check
|
105
|
+
unless healthy?
|
106
|
+
@backoff ||= 0.1
|
107
|
+
|
108
|
+
backoff = @backoff
|
109
|
+
|
110
|
+
if !!backoff
|
111
|
+
raise "Too many failures on #{url}" if backoff >= MAX_BACKOFF
|
112
|
+
|
113
|
+
backoff *= backoff
|
114
|
+
@backoff = backoff
|
115
|
+
sleep backoff
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
@backoff = nil
|
120
|
+
end
|
121
|
+
|
122
|
+
response = case http
|
123
|
+
when Net::HTTP::Persistent then http.request(uri, request)
|
124
|
+
when Net::HTTP then http.request(request)
|
125
|
+
else; raise ApiError, "Unsuppored scheme: #{http.inspect}"
|
126
|
+
end
|
127
|
+
|
128
|
+
response = Hashie::Mash.new(JSON[response.body])
|
129
|
+
|
130
|
+
if !!(error = response.error)
|
131
|
+
raise ApiError, "Error #{error.code}: #{error.message}"
|
132
|
+
end
|
133
|
+
|
134
|
+
response.result
|
135
|
+
end
|
136
|
+
|
137
|
+
def healthy?
|
138
|
+
warn("Health check not defined for: #{uri}")
|
139
|
+
true
|
140
|
+
end
|
141
|
+
|
142
|
+
def persist?
|
143
|
+
!!@persist
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Radiator
|
2
|
+
module SSC
|
3
|
+
# The "blockchain" endpoint
|
4
|
+
#
|
5
|
+
# See: https://github.com/harpagon210/steemsmartcontracts/wiki/JSON-RPC-server#1-the-blockchain-endpoint-httplocalhost5000blockchain
|
6
|
+
class Blockchain < BaseSteemSmartContractRPC
|
7
|
+
# @param options [::Hash] The attributes
|
8
|
+
# @option options [String] :url Specify the full node end-point. Default: https://api.steem-engine.com/rpc/blockchain
|
9
|
+
def initialize(options = {})
|
10
|
+
super
|
11
|
+
@url = options[:url] || "#{@root_url}/blockchain"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Example using the defaults, backed by Steem Engine:
|
15
|
+
#
|
16
|
+
# rpc = Radiator::SSC::Blockchain.new
|
17
|
+
# rpc.latest_block_info
|
18
|
+
#
|
19
|
+
# @return the latest block of the sidechain
|
20
|
+
def latest_block_info
|
21
|
+
request(method: 'getLatestBlockInfo')
|
22
|
+
end
|
23
|
+
|
24
|
+
# Example using the defaults, backed by Steem Engine:
|
25
|
+
#
|
26
|
+
# rpc = Radiator::SSC::Blockchain.new
|
27
|
+
# rpc.block_info(1)
|
28
|
+
#
|
29
|
+
# @param [Integer] block_num
|
30
|
+
# @return the block with the specified block number of the sidechain
|
31
|
+
def block_info(block_num)
|
32
|
+
request(method: 'getBlockInfo', params: {blockNumber: block_num})
|
33
|
+
end
|
34
|
+
|
35
|
+
# Example using the defaults, backed by Steem Engine:
|
36
|
+
#
|
37
|
+
# rpc = Radiator::SSC::Blockchain.new
|
38
|
+
# rpc.transaction_info('9d288aab2eb66064dc0d4492cb281512386e2293')
|
39
|
+
#
|
40
|
+
# @param [String] trx_id
|
41
|
+
# @return the specified transaction info of the sidechain
|
42
|
+
def transaction_info(trx_id)
|
43
|
+
request(method: 'getTransactionInfo', params: {txid: trx_id})
|
44
|
+
end
|
45
|
+
protected
|
46
|
+
def healthy?
|
47
|
+
begin
|
48
|
+
request(method: 'getBlockInfo', params: {blockNumber: -1}, skip_health_check: true).nil?
|
49
|
+
rescue => e
|
50
|
+
warn("Health check for #{uri.inspect} failed: #{e.inspect}")
|
51
|
+
|
52
|
+
!!shutdown
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|