crea-ruby 0.0.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 +7 -0
- data/.gitignore +55 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +234 -0
- data/Rakefile +332 -0
- data/crea-ruby.gemspec +39 -0
- data/gource.sh +6 -0
- data/lib/crea.rb +85 -0
- data/lib/crea/api.rb +208 -0
- data/lib/crea/base_error.rb +218 -0
- data/lib/crea/block_api.rb +78 -0
- data/lib/crea/broadcast.rb +1334 -0
- data/lib/crea/chain_config.rb +36 -0
- data/lib/crea/formatter.rb +14 -0
- data/lib/crea/jsonrpc.rb +108 -0
- data/lib/crea/marshal.rb +231 -0
- data/lib/crea/mixins/jsonable.rb +37 -0
- data/lib/crea/mixins/retriable.rb +58 -0
- data/lib/crea/mixins/serializable.rb +45 -0
- data/lib/crea/operation.rb +141 -0
- data/lib/crea/operation/account_create.rb +10 -0
- data/lib/crea/operation/account_create_with_delegation.rb +12 -0
- data/lib/crea/operation/account_update.rb +8 -0
- data/lib/crea/operation/account_witness_proxy.rb +4 -0
- data/lib/crea/operation/account_witness_vote.rb +5 -0
- data/lib/crea/operation/cancel_transfer_from_savings.rb +4 -0
- data/lib/crea/operation/challenge_authority.rb +5 -0
- data/lib/crea/operation/change_recovery_account.rb +5 -0
- data/lib/crea/operation/claim_account.rb +5 -0
- data/lib/crea/operation/claim_reward_balance.rb +6 -0
- data/lib/crea/operation/comment.rb +9 -0
- data/lib/crea/operation/comment_options.rb +10 -0
- data/lib/crea/operation/convert.rb +5 -0
- data/lib/crea/operation/create_claimed_account.rb +10 -0
- data/lib/crea/operation/custom.rb +5 -0
- data/lib/crea/operation/custom_binary.rb +8 -0
- data/lib/crea/operation/custom_json.rb +6 -0
- data/lib/crea/operation/decline_voting_rights.rb +4 -0
- data/lib/crea/operation/delegate_vesting_shares.rb +5 -0
- data/lib/crea/operation/delete_comment.rb +4 -0
- data/lib/crea/operation/escrow_approve.rb +8 -0
- data/lib/crea/operation/escrow_dispute.rb +7 -0
- data/lib/crea/operation/escrow_release.rb +10 -0
- data/lib/crea/operation/escrow_transfer.rb +12 -0
- data/lib/crea/operation/feed_publish.rb +4 -0
- data/lib/crea/operation/limit_order_cancel.rb +4 -0
- data/lib/crea/operation/limit_order_create.rb +8 -0
- data/lib/crea/operation/limit_order_create2.rb +8 -0
- data/lib/crea/operation/prove_authority.rb +4 -0
- data/lib/crea/operation/recover_account.rb +6 -0
- data/lib/crea/operation/report_over_production.rb +5 -0
- data/lib/crea/operation/request_account_recovery.rb +6 -0
- data/lib/crea/operation/reset_account.rb +5 -0
- data/lib/crea/operation/set_reset_account.rb +5 -0
- data/lib/crea/operation/set_withdraw_vesting_route.rb +6 -0
- data/lib/crea/operation/transfer.rb +6 -0
- data/lib/crea/operation/transfer_from_savings.rb +7 -0
- data/lib/crea/operation/transfer_to_savings.rb +6 -0
- data/lib/crea/operation/transfer_to_vesting.rb +5 -0
- data/lib/crea/operation/vote.rb +6 -0
- data/lib/crea/operation/withdraw_vesting.rb +4 -0
- data/lib/crea/operation/witness_set_properties.rb +5 -0
- data/lib/crea/operation/witness_update.rb +7 -0
- data/lib/crea/rpc/base_client.rb +179 -0
- data/lib/crea/rpc/http_client.rb +143 -0
- data/lib/crea/rpc/thread_safe_http_client.rb +35 -0
- data/lib/crea/stream.rb +385 -0
- data/lib/crea/transaction.rb +96 -0
- data/lib/crea/transaction_builder.rb +393 -0
- data/lib/crea/type/amount.rb +107 -0
- data/lib/crea/type/base_type.rb +10 -0
- data/lib/crea/utils.rb +17 -0
- data/lib/crea/version.rb +4 -0
- metadata +478 -0
data/crea-ruby.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'crea/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'crea-ruby'
|
8
|
+
spec.version = Crea::VERSION
|
9
|
+
spec.authors = ['Creativechain FDN']
|
10
|
+
spec.email = ['info@creativechain.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Crea Ruby Client}
|
13
|
+
spec.description = %q{Client for accessing the Crea blockchain.}
|
14
|
+
spec.homepage = 'https://github.com/creativechain/crea-ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
|
21
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.0'
|
22
|
+
spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
|
23
|
+
spec.add_development_dependency 'minitest-line', '~> 0.6', '>= 0.6.4'
|
24
|
+
spec.add_development_dependency 'minitest-proveit', '~> 1.0', '>= 1.0.0'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 3.3', '>= 3.3.0'
|
26
|
+
spec.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
|
27
|
+
spec.add_development_dependency 'vcr', '~> 4.0', '>= 4.0.0'
|
28
|
+
spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.12'
|
29
|
+
spec.add_development_dependency 'pry', '~> 0.11', '>= 0.11.3'
|
30
|
+
spec.add_development_dependency 'awesome_print', '~> 1.8', '>= 1.8.0'
|
31
|
+
|
32
|
+
spec.add_dependency 'json', '~> 2.1', '>= 2.1.0'
|
33
|
+
spec.add_dependency 'logging', '~> 2.2', '>= 2.2.0'
|
34
|
+
spec.add_dependency 'hashie', '~> 3.5', '>= 3.5.7'
|
35
|
+
spec.add_dependency 'bitcoin-ruby', '~> 0.0', '>= 0.0.18'
|
36
|
+
spec.add_dependency 'ffi', '~> 1.9', '>= 1.9.23'
|
37
|
+
spec.add_dependency 'bindata', '~> 2.4', '>= 2.4.4'
|
38
|
+
spec.add_dependency 'base58', '~> 0.2', '>= 0.2.3'
|
39
|
+
end
|
data/gource.sh
ADDED
data/lib/crea.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'json' unless defined?(JSON)
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
require 'hashie'
|
6
|
+
require 'crea/version'
|
7
|
+
require 'crea/utils'
|
8
|
+
require 'crea/base_error'
|
9
|
+
require 'crea/mixins/serializable'
|
10
|
+
require 'crea/mixins/jsonable'
|
11
|
+
require 'crea/mixins/retriable'
|
12
|
+
require 'crea/chain_config'
|
13
|
+
require 'crea/type/base_type'
|
14
|
+
require 'crea/type/amount'
|
15
|
+
require 'crea/operation'
|
16
|
+
require 'crea/operation/account_create.rb'
|
17
|
+
require 'crea/operation/account_create_with_delegation.rb'
|
18
|
+
require 'crea/operation/account_update.rb'
|
19
|
+
require 'crea/operation/account_witness_proxy.rb'
|
20
|
+
require 'crea/operation/account_witness_vote.rb'
|
21
|
+
require 'crea/operation/cancel_transfer_from_savings.rb'
|
22
|
+
require 'crea/operation/challenge_authority.rb'
|
23
|
+
require 'crea/operation/change_recovery_account.rb'
|
24
|
+
require 'crea/operation/claim_account.rb'
|
25
|
+
require 'crea/operation/claim_reward_balance.rb'
|
26
|
+
require 'crea/operation/comment.rb'
|
27
|
+
require 'crea/operation/comment_options.rb'
|
28
|
+
require 'crea/operation/convert.rb'
|
29
|
+
require 'crea/operation/create_claimed_account.rb'
|
30
|
+
require 'crea/operation/custom.rb'
|
31
|
+
require 'crea/operation/custom_binary.rb'
|
32
|
+
require 'crea/operation/custom_json.rb'
|
33
|
+
require 'crea/operation/decline_voting_rights.rb'
|
34
|
+
require 'crea/operation/delegate_vesting_shares.rb'
|
35
|
+
require 'crea/operation/delete_comment.rb'
|
36
|
+
require 'crea/operation/escrow_approve.rb'
|
37
|
+
require 'crea/operation/escrow_dispute.rb'
|
38
|
+
require 'crea/operation/escrow_release.rb'
|
39
|
+
require 'crea/operation/escrow_transfer.rb'
|
40
|
+
require 'crea/operation/feed_publish.rb'
|
41
|
+
require 'crea/operation/limit_order_cancel.rb'
|
42
|
+
require 'crea/operation/limit_order_create.rb'
|
43
|
+
require 'crea/operation/limit_order_create2.rb'
|
44
|
+
require 'crea/operation/prove_authority.rb'
|
45
|
+
require 'crea/operation/recover_account.rb'
|
46
|
+
require 'crea/operation/report_over_production.rb'
|
47
|
+
require 'crea/operation/request_account_recovery.rb'
|
48
|
+
require 'crea/operation/reset_account.rb'
|
49
|
+
require 'crea/operation/set_reset_account.rb'
|
50
|
+
require 'crea/operation/set_withdraw_vesting_route.rb'
|
51
|
+
require 'crea/operation/transfer.rb'
|
52
|
+
require 'crea/operation/transfer_from_savings.rb'
|
53
|
+
require 'crea/operation/transfer_to_savings.rb'
|
54
|
+
require 'crea/operation/transfer_to_vesting.rb'
|
55
|
+
require 'crea/operation/vote.rb'
|
56
|
+
require 'crea/operation/withdraw_vesting.rb'
|
57
|
+
require 'crea/operation/witness_update.rb'
|
58
|
+
require 'crea/operation/witness_set_properties.rb'
|
59
|
+
require 'crea/marshal'
|
60
|
+
require 'crea/transaction'
|
61
|
+
require 'crea/transaction_builder'
|
62
|
+
require 'crea/rpc/base_client'
|
63
|
+
require 'crea/rpc/http_client'
|
64
|
+
require 'crea/rpc/thread_safe_http_client'
|
65
|
+
require 'crea/api'
|
66
|
+
require 'crea/jsonrpc'
|
67
|
+
require 'crea/block_api'
|
68
|
+
require 'crea/formatter'
|
69
|
+
require 'crea/broadcast'
|
70
|
+
require 'crea/stream'
|
71
|
+
|
72
|
+
module Crea
|
73
|
+
def self.api_classes
|
74
|
+
@api_classes ||= {}
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.const_missing(api_name)
|
78
|
+
api = api_classes[api_name]
|
79
|
+
api ||= Api.clone(freeze: true) rescue Api.clone
|
80
|
+
api.api_name = api_name
|
81
|
+
api_classes[api_name] = api
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Hashie.logger = Logger.new(ENV['HASHIE_LOGGER'])
|
data/lib/crea/api.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
module Crea
|
2
|
+
# This ruby API works with
|
3
|
+
# {https://github.com/creary/crea/releases cread-0.19.10} and other AppBase
|
4
|
+
# compatible upstreams. To access different API namespaces, use the
|
5
|
+
# following:
|
6
|
+
#
|
7
|
+
# api = Crea::Api.new
|
8
|
+
# api.get_dynamic_global_properties
|
9
|
+
#
|
10
|
+
# The above example will make an instance that can access the
|
11
|
+
# {https://developers.crea.io/apidefinitions/condenser-api condenser_api}
|
12
|
+
# namespace. Alternatively, you may also create a direct instances with its
|
13
|
+
# full name, if you prefer:
|
14
|
+
#
|
15
|
+
# api = Crea::CondenserApi.new
|
16
|
+
# api.get_dynamic_global_properties
|
17
|
+
#
|
18
|
+
# If you know the name of another API that is supported by the remote node,
|
19
|
+
# you can create an instance to that instead, for example:
|
20
|
+
#
|
21
|
+
# api = Crea::MarketHistoryApi.new
|
22
|
+
# api.get_volume
|
23
|
+
#
|
24
|
+
# All known API by namespace:
|
25
|
+
#
|
26
|
+
# * {AccountByKeyApi}
|
27
|
+
# * {AccountHistoryApi}
|
28
|
+
# * {BlockApi}
|
29
|
+
# * {DatabaseApi}
|
30
|
+
# * {FollowApi}
|
31
|
+
# * {Jsonrpc}
|
32
|
+
# * {MarketHistoryApi}
|
33
|
+
# * {NetworkBroadcastApi}
|
34
|
+
# * {TagsApi}
|
35
|
+
# * {WitnessApi}
|
36
|
+
#
|
37
|
+
# Also see: {https://developers.crea.io/apidefinitions/ Complete API Definitions}
|
38
|
+
class Api
|
39
|
+
attr_accessor :chain, :methods, :rpc_client
|
40
|
+
|
41
|
+
# Use this for debugging naive thread handler.
|
42
|
+
# DEFAULT_RPC_CLIENT_CLASS = RPC::HttpClient
|
43
|
+
DEFAULT_RPC_CLIENT_CLASS = RPC::ThreadSafeHttpClient
|
44
|
+
|
45
|
+
def self.api_name=(api_name)
|
46
|
+
@api_name = api_name.to_s.
|
47
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
48
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
49
|
+
tr('-', '_').downcase.to_sym
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.api_name
|
53
|
+
@api_name
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.api_class_name
|
57
|
+
@api_name.to_s.split('_').map(&:capitalize).join
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.jsonrpc=(jsonrpc, url = nil)
|
61
|
+
@jsonrpc ||= {}
|
62
|
+
@jsonrpc[url || jsonrpc.rpc_client.uri.to_s] = jsonrpc
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.jsonrpc(url = nil)
|
66
|
+
if @jsonrpc.size < 2 && url.nil?
|
67
|
+
@jsonrpc.values.first
|
68
|
+
else
|
69
|
+
@jsonrpc[url]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Override this if you want to just use your own client. Otherwise, inject
|
74
|
+
# the default using:
|
75
|
+
#
|
76
|
+
# Crea::Api.register default_rpc_client_class: MyClient
|
77
|
+
def self.default_rpc_client_class
|
78
|
+
if !!@injected_dependencies && !!@injected_dependencies[:default_rpc_client_class]
|
79
|
+
@injected_dependencies[:default_rpc_client_class]
|
80
|
+
else
|
81
|
+
DEFAULT_RPC_CLIENT_CLASS
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Used for dependency injection. Currently, the only key supported is:
|
86
|
+
#
|
87
|
+
# `default_rpc_client_class`
|
88
|
+
def self.register(register)
|
89
|
+
@injected_dependencies ||= {}
|
90
|
+
@injected_dependencies = @injected_dependencies.merge register
|
91
|
+
end
|
92
|
+
|
93
|
+
def initialize(options = {})
|
94
|
+
@chain = options[:chain] || :crea
|
95
|
+
@error_pipe = options[:error_pipe] || STDERR
|
96
|
+
@api_name = self.class.api_name ||= :condenser_api
|
97
|
+
|
98
|
+
@rpc_client = if !!options[:rpc_client]
|
99
|
+
options[:rpc_client]
|
100
|
+
else
|
101
|
+
rpc_client_class = self.class.default_rpc_client_class
|
102
|
+
rpc_client_class.new(options.merge(api_name: @api_name))
|
103
|
+
end
|
104
|
+
|
105
|
+
if @api_name == :jsonrpc
|
106
|
+
Api::jsonrpc = self
|
107
|
+
else
|
108
|
+
# Note, we have to wait until initialize to check this because we don't
|
109
|
+
# have access to instance options until now.
|
110
|
+
|
111
|
+
Api::jsonrpc = Jsonrpc.new(options)
|
112
|
+
@methods = Api::jsonrpc(rpc_client.uri.to_s).get_api_methods
|
113
|
+
|
114
|
+
unless !!@methods[@api_name]
|
115
|
+
raise UnknownApiError, "#{@api_name} (known APIs: #{@methods.keys.join(' ')})"
|
116
|
+
end
|
117
|
+
|
118
|
+
@methods = @methods[@api_name]
|
119
|
+
end
|
120
|
+
|
121
|
+
@try_count = 0
|
122
|
+
end
|
123
|
+
|
124
|
+
def inspect
|
125
|
+
properties = %w(chain methods).map do |prop|
|
126
|
+
if !!(v = instance_variable_get("@#{prop}"))
|
127
|
+
case v
|
128
|
+
when Array then "@#{prop}=<#{v.size} #{v.size == 1 ? 'element' : 'elements'}>"
|
129
|
+
else; "@#{prop}=#{v}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end.compact.join(', ')
|
133
|
+
|
134
|
+
"#<#{self.class.api_class_name} [#{properties}]>"
|
135
|
+
end
|
136
|
+
private
|
137
|
+
# @private
|
138
|
+
def args_keys_to_s(rpc_method_name)
|
139
|
+
args = signature(rpc_method_name).args
|
140
|
+
args_keys = JSON[args.to_json]
|
141
|
+
end
|
142
|
+
|
143
|
+
# @private
|
144
|
+
def signature(rpc_method_name)
|
145
|
+
url = rpc_client.uri.to_s
|
146
|
+
|
147
|
+
@@signatures ||= {}
|
148
|
+
@@signatures[url] ||= {}
|
149
|
+
@@signatures[url][rpc_method_name] ||= Api::jsonrpc(url).get_signature(method: rpc_method_name).result
|
150
|
+
end
|
151
|
+
|
152
|
+
# @private
|
153
|
+
def respond_to_missing?(m, include_private = false)
|
154
|
+
methods.nil? ? false : methods.include?(m.to_sym)
|
155
|
+
end
|
156
|
+
|
157
|
+
# @private
|
158
|
+
def method_missing(m, *args, &block)
|
159
|
+
super unless respond_to_missing?(m)
|
160
|
+
|
161
|
+
rpc_method_name = "#{@api_name}.#{m}"
|
162
|
+
rpc_args = case @api_name
|
163
|
+
when :condenser_api then args
|
164
|
+
when :jsonrpc then args.first
|
165
|
+
else
|
166
|
+
expected_args = signature(rpc_method_name).args || []
|
167
|
+
expected_args_key_string = if expected_args.size > 0
|
168
|
+
" (#{args_keys_to_s(rpc_method_name)})"
|
169
|
+
end
|
170
|
+
expected_args_size = expected_args.size
|
171
|
+
|
172
|
+
begin
|
173
|
+
args = args.first.to_h
|
174
|
+
args_size = args.size
|
175
|
+
|
176
|
+
# Some argument are optional, but if the arguments passed are greater
|
177
|
+
# than the expected arguments size, we can warn.
|
178
|
+
if args_size > expected_args_size
|
179
|
+
@error_pipe.puts "Warning #{rpc_method_name} expects arguments: #{expected_args_size}, got: #{args_size}"
|
180
|
+
end
|
181
|
+
rescue NoMethodError => e
|
182
|
+
error = Crea::ArgumentError.new("#{rpc_method_name} expects arguments: #{expected_args_size}", e)
|
183
|
+
raise error
|
184
|
+
rescue => e
|
185
|
+
raise UnknownError.new("#{rpc_method_name} unknown error.", e)
|
186
|
+
end
|
187
|
+
|
188
|
+
args
|
189
|
+
end
|
190
|
+
|
191
|
+
response = rpc_client.rpc_execute(@api_name, m, rpc_args)
|
192
|
+
|
193
|
+
if !!block
|
194
|
+
case response
|
195
|
+
when Hashie::Mash then yield response.result, response.error, response.id
|
196
|
+
when Hashie::Array
|
197
|
+
response.each do |r|
|
198
|
+
r = Hashie::Mash.new(r)
|
199
|
+
yield r.result, r.error, r.id
|
200
|
+
end
|
201
|
+
else; yield response
|
202
|
+
end
|
203
|
+
else
|
204
|
+
return response
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
module Crea
|
2
|
+
class BaseError < StandardError
|
3
|
+
def initialize(error = nil, cause = nil)
|
4
|
+
@error = error
|
5
|
+
@cause = cause
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
detail = {}
|
10
|
+
detail[:error] = @error if !!@error
|
11
|
+
detail[:cause] = @cause if !!@cause
|
12
|
+
|
13
|
+
JSON[detail] rescue detail.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.build_error(error, context)
|
17
|
+
if error.message == 'Unable to acquire database lock'
|
18
|
+
raise Crea::RemoteDatabaseLockError, error.message, build_backtrace(error)
|
19
|
+
end
|
20
|
+
|
21
|
+
if error.message.include? 'Internal Error'
|
22
|
+
raise Crea::RemoteNodeError, error.message, build_backtrace(error)
|
23
|
+
end
|
24
|
+
|
25
|
+
if error.message.include? 'Server error'
|
26
|
+
raise Crea::RemoteNodeError, error.message, build_backtrace(error)
|
27
|
+
end
|
28
|
+
|
29
|
+
if error.message.include? 'plugin not enabled'
|
30
|
+
raise Crea::PluginNotEnabledError, error.message, build_backtrace(error)
|
31
|
+
end
|
32
|
+
|
33
|
+
if error.message.include? 'argument'
|
34
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
35
|
+
end
|
36
|
+
|
37
|
+
if error.message.include? 'Invalid params'
|
38
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
39
|
+
end
|
40
|
+
|
41
|
+
if error.message.start_with? 'Bad Cast:'
|
42
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
43
|
+
end
|
44
|
+
|
45
|
+
if error.message.include? 'prefix_len'
|
46
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
47
|
+
end
|
48
|
+
|
49
|
+
if error.message.include? 'Parse Error'
|
50
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
51
|
+
end
|
52
|
+
|
53
|
+
if error.message.include? 'unknown key'
|
54
|
+
raise Crea::ArgumentError, "#{context}: #{error.message} (or content has been deleted)", build_backtrace(error)
|
55
|
+
end
|
56
|
+
|
57
|
+
if error.message.include? 'Comment is not in account\'s comments'
|
58
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
59
|
+
end
|
60
|
+
|
61
|
+
if error.message.include? 'Could not find comment'
|
62
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
63
|
+
end
|
64
|
+
|
65
|
+
if error.message.include? 'unable to convert ISO-formatted string to fc::time_point_sec'
|
66
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
67
|
+
end
|
68
|
+
|
69
|
+
if error.message.include? 'Input data have to treated as object.'
|
70
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
71
|
+
end
|
72
|
+
|
73
|
+
if error.message.include? 'base.amount > share_type(0)'
|
74
|
+
raise Crea::ArgumentError, "#{context}: #{error.message}", build_backtrace(error)
|
75
|
+
end
|
76
|
+
|
77
|
+
if error.message.include? 'blk->transactions.size() > itr->trx_in_block'
|
78
|
+
raise Crea::VirtualOperationsNotAllowedError, "#{context}: #{error.message}", build_backtrace(error)
|
79
|
+
end
|
80
|
+
|
81
|
+
if error.message.include? 'A transaction must have at least one operation'
|
82
|
+
raise Crea::EmptyTransactionError, "#{context}: #{error.message}", build_backtrace(error)
|
83
|
+
end
|
84
|
+
|
85
|
+
if error.message.include? 'transaction expiration exception'
|
86
|
+
raise Crea::TransactionExpiredError, "#{context}: #{error.message}", build_backtrace(error)
|
87
|
+
end
|
88
|
+
|
89
|
+
if error.message.include? 'Duplicate transaction check failed'
|
90
|
+
raise Crea::DuplicateTransactionError, "#{context}: #{error.message}", build_backtrace(error)
|
91
|
+
end
|
92
|
+
|
93
|
+
if error.message.include? 'signature is not canonical'
|
94
|
+
raise Crea::NonCanonicalSignatureError, "#{context}: #{error.message}", build_backtrace(error)
|
95
|
+
end
|
96
|
+
|
97
|
+
if error.message.include? 'attempting to push a block that is too old'
|
98
|
+
raise Crea::BlockTooOldError, "#{context}: #{error.message}", build_backtrace(error)
|
99
|
+
end
|
100
|
+
|
101
|
+
if error.message.include? 'irrelevant signature'
|
102
|
+
raise Crea::IrrelevantSignatureError, "#{context}: #{error.message}", build_backtrace(error)
|
103
|
+
end
|
104
|
+
|
105
|
+
if error.message.include? 'missing required posting authority'
|
106
|
+
raise Crea::MissingPostingAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
|
107
|
+
end
|
108
|
+
|
109
|
+
if error.message.include? 'missing required active authority'
|
110
|
+
raise Crea::MissingActiveAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
|
111
|
+
end
|
112
|
+
|
113
|
+
if error.message.include? 'missing required owner authority'
|
114
|
+
raise Crea::MissingOwnerAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
|
115
|
+
end
|
116
|
+
|
117
|
+
if error.message.include? 'missing required other authority'
|
118
|
+
raise Crea::MissingOtherAuthorityError, "#{context}: #{error.message}", build_backtrace(error)
|
119
|
+
end
|
120
|
+
|
121
|
+
if error.message.include? 'Upstream response error'
|
122
|
+
raise Crea::UpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
|
123
|
+
end
|
124
|
+
|
125
|
+
if error.message.include? 'Bad or missing upstream response'
|
126
|
+
raise Crea::BadOrMissingUpstreamResponseError, "#{context}: #{error.message}", build_backtrace(error)
|
127
|
+
end
|
128
|
+
|
129
|
+
if error.message.include? 'operator has disabled operation indexing by transaction_id'
|
130
|
+
raise Crea::TransactionIndexDisabledError, "#{context}: #{error.message}", build_backtrace(error)
|
131
|
+
end
|
132
|
+
|
133
|
+
if error.message.include? 'is_valid_account_name'
|
134
|
+
raise Crea::InvalidAccountError, "#{context}: #{error.message}", build_backtrace(error)
|
135
|
+
end
|
136
|
+
|
137
|
+
if error.message.include?('Method') && error.message.include?(' does not exist.')
|
138
|
+
raise Crea::UnknownMethodError, "#{context}: #{error.message}", build_backtrace(error)
|
139
|
+
end
|
140
|
+
|
141
|
+
if error.message.include? 'Invalid operation name'
|
142
|
+
raise Crea::UnknownOperationError, "#{context}: #{error.message}", build_backtrace(error)
|
143
|
+
end
|
144
|
+
|
145
|
+
if error.message =~ /Invalid object name: .+_operation/
|
146
|
+
raise Crea::UnknownOperationError, "#{context}: #{error.message}", build_backtrace(error)
|
147
|
+
end
|
148
|
+
|
149
|
+
if error.message.include? 'Author not found'
|
150
|
+
raise Crea::AuthorNotFoundError, "#{context}: #{error.message}", build_backtrace(error)
|
151
|
+
end
|
152
|
+
|
153
|
+
if error.message.include? ' != fc::time_point_sec::maximum()'
|
154
|
+
raise Crea::ReachedMaximumTimeError, "#{context}: #{error.message}", build_backtrace(error)
|
155
|
+
end
|
156
|
+
|
157
|
+
if error.message.include? 'Cannot transfer a negative amount (aka: stealing)'
|
158
|
+
raise Crea::TheftError, "#{context}: #{error.message}", build_backtrace(error)
|
159
|
+
end
|
160
|
+
|
161
|
+
if error.message.include? 'Must transfer a nonzero amount'
|
162
|
+
raise Crea::NonZeroRequiredError, "#{context}: #{error.message}", build_backtrace(error)
|
163
|
+
end
|
164
|
+
|
165
|
+
if error.message.include? 'is_asset_type'
|
166
|
+
raise Crea::UnexpectedAssetError, "#{context}: #{error.message}", build_backtrace(error)
|
167
|
+
end
|
168
|
+
|
169
|
+
puts JSON.pretty_generate(error) if ENV['DEBUG']
|
170
|
+
raise UnknownError, "#{context}: #{error.message}", build_backtrace(error)
|
171
|
+
end
|
172
|
+
private
|
173
|
+
def self.build_backtrace(error)
|
174
|
+
backtrace = Thread.current.backtrace.reject{ |line| line =~ /base_error/ }
|
175
|
+
JSON.pretty_generate(error) + "\n" + backtrace.join("\n")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
class DeserializationError < BaseError; end
|
180
|
+
class SerializationMismatchError < BaseError; end
|
181
|
+
class UnsupportedChainError < BaseError; end
|
182
|
+
class ArgumentError < BaseError; end
|
183
|
+
class TypeError < BaseError; end
|
184
|
+
class EmptyTransactionError < ArgumentError; end
|
185
|
+
class InvalidAccountError < ArgumentError; end
|
186
|
+
class AuthorNotFoundError < ArgumentError; end
|
187
|
+
class ReachedMaximumTimeError < ArgumentError; end
|
188
|
+
class VirtualOperationsNotAllowedError < ArgumentError; end
|
189
|
+
class TheftError < ArgumentError; end
|
190
|
+
class NonZeroRequiredError < ArgumentError; end
|
191
|
+
class UnexpectedAssetError < ArgumentError; end
|
192
|
+
class TransactionExpiredError < BaseError; end
|
193
|
+
class DuplicateTransactionError < TransactionExpiredError; end
|
194
|
+
class NonCanonicalSignatureError < TransactionExpiredError; end
|
195
|
+
class BlockTooOldError < BaseError; end
|
196
|
+
class IrrelevantSignatureError < BaseError; end
|
197
|
+
class MissingAuthorityError < BaseError; end
|
198
|
+
class MissingPostingAuthorityError < MissingAuthorityError; end
|
199
|
+
class MissingActiveAuthorityError < MissingAuthorityError; end
|
200
|
+
class MissingOwnerAuthorityError < MissingAuthorityError; end
|
201
|
+
class MissingOtherAuthorityError < MissingAuthorityError; end
|
202
|
+
class IncorrectRequestIdError < BaseError; end
|
203
|
+
class IncorrectResponseIdError < BaseError; end
|
204
|
+
class RemoteNodeError < BaseError; end
|
205
|
+
class UpstreamResponseError < RemoteNodeError; end
|
206
|
+
class RemoteDatabaseLockError < UpstreamResponseError; end
|
207
|
+
class PluginNotEnabledError < UpstreamResponseError; end
|
208
|
+
class BadOrMissingUpstreamResponseError < UpstreamResponseError; end
|
209
|
+
class TransactionIndexDisabledError < BaseError; end
|
210
|
+
class NotAppBaseError < BaseError; end
|
211
|
+
class UnknownApiError < BaseError; end
|
212
|
+
class UnknownMethodError < BaseError; end
|
213
|
+
class UnknownOperationError < BaseError; end
|
214
|
+
class JsonRpcBatchMaximumSizeExceededError < BaseError; end
|
215
|
+
class TooManyTimeoutsError < BaseError; end
|
216
|
+
class TooManyRetriesError < BaseError; end
|
217
|
+
class UnknownError < BaseError; end
|
218
|
+
end
|