lbd_sdk 0.1.0
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/.github/workflows/pull-request.yml +20 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +6 -0
- data/.vscode/settings.json +6 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +162 -0
- data/Rakefile +8 -0
- data/bin/console +23 -0
- data/bin/setup +8 -0
- data/lbd_sdk.gemspec +34 -0
- data/lib/lbd_sdk/client.rb +852 -0
- data/lib/lbd_sdk/http_client.rb +56 -0
- data/lib/lbd_sdk/request_body_flattener.rb +33 -0
- data/lib/lbd_sdk/request_param_flattener.rb +9 -0
- data/lib/lbd_sdk/signature_generator.rb +36 -0
- data/lib/lbd_sdk/version.rb +5 -0
- data/lib/lbd_sdk.rb +8 -0
- metadata +68 -0
@@ -0,0 +1,852 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
require 'net/http'
|
5
|
+
require 'openssl'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module LbdSdk
|
9
|
+
# Client for the LINE Blockchain API
|
10
|
+
#
|
11
|
+
# @client ||= LbdSdk::Client.new do |config|
|
12
|
+
# config.endpoint = 'https://test-api.blockchain.line.me/'
|
13
|
+
# config.api_key = 'your_api_key'
|
14
|
+
# config.api_secret_key = 'your_secret_key'
|
15
|
+
# end
|
16
|
+
class Client
|
17
|
+
attr_accessor :endpoint, :api_key, :api_secret_key
|
18
|
+
|
19
|
+
DEFAULT_ENDPOINT = 'https://test-api.blockchain.line.me/'
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
options.each do |key, value|
|
23
|
+
instance_variable_set("@#{key}", value)
|
24
|
+
end
|
25
|
+
yield(self) if block_given?
|
26
|
+
|
27
|
+
@endpoint ||= DEFAULT_ENDPOINT
|
28
|
+
end
|
29
|
+
|
30
|
+
def time
|
31
|
+
get('/v1/time')
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_detail(user_id)
|
35
|
+
get("/v1/users/#{user_id}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_transactions(user_id, query_params = {})
|
39
|
+
get("/v1/users/#{user_id}/transactions", query_params: transaction_page_request(query_params))
|
40
|
+
end
|
41
|
+
|
42
|
+
def base_coin_balance_of_user(user_id)
|
43
|
+
get("/v1/users/#{user_id}/base-coin")
|
44
|
+
end
|
45
|
+
|
46
|
+
def service_token_balances_of_user(user_id, query_params = {})
|
47
|
+
get("/v1/users/#{user_id}/service-tokens", query_params: page_request(query_params))
|
48
|
+
end
|
49
|
+
|
50
|
+
def service_token_balance_of_user(user_id, contract_id)
|
51
|
+
get("/v1/users/#{user_id}/service-tokens/#{contract_id}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def fungible_token_balances_of_user(user_id, contractId, query_params = {})
|
55
|
+
get("/v1/users/#{user_id}/item-tokens/#{contractId}/fungibles", query_params: page_request(query_params))
|
56
|
+
end
|
57
|
+
|
58
|
+
def fungible_token_balance_of_user(user_id, contractId, token_type)
|
59
|
+
get("/v1/users/#{user_id}/item-tokens/#{contractId}/fungibles/#{token_type}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def non_fungible_token_balances_of_user(user_id, contractId, query_params = {})
|
63
|
+
get("/v1/users/#{user_id}/item-tokens/#{contractId}/non-fungibles", query_params: page_request(query_params))
|
64
|
+
end
|
65
|
+
|
66
|
+
def non_fungible_token_balances_by_type_of_user(user_id, contractId, token_type, query_params = {})
|
67
|
+
get("/v1/users/#{user_id}/item-tokens/#{contractId}/non-fungibles/#{token_type}", query_params: page_request(query_params))
|
68
|
+
end
|
69
|
+
|
70
|
+
def non_fungible_token_balance_of_user(user_id, contractId, token_type, token_index)
|
71
|
+
get("/v1/users/#{user_id}/item-tokens/#{contractId}/non-fungibles/#{token_type}/#{token_index}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def retrieve_session_token_status(request_session_token)
|
75
|
+
get("/v1/user-requests/#{request_session_token}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def issue_session_token_for_base_coin_transfer(user_id, request_type, payload = {})
|
79
|
+
post("/v1/users/#{user_id}/base-coin/request-transfer", query_params: {requestType: request_type}, payload: issue_transfer_session_token_request(payload))
|
80
|
+
end
|
81
|
+
|
82
|
+
def issue_session_token_for_service_token_transfer(user_id, contract_id, request_type, payload = {})
|
83
|
+
post("/v1/users/#{user_id}/service-tokens/#{contract_id}/request-transfer", query_params: {requestType: request_type}, payload: issue_transfer_session_token_request(payload))
|
84
|
+
end
|
85
|
+
|
86
|
+
def issue_service_token_proxy_request(user_id, contract_id, request_type, payload = {})
|
87
|
+
post("/v1/users/#{user_id}/service-tokens/#{contract_id}/request-proxy", query_params: {requestType: request_type}, payload: user_proxy_request(payload))
|
88
|
+
end
|
89
|
+
|
90
|
+
def issue_item_token_proxy_request(user_id, contract_id, request_type, payload = {})
|
91
|
+
post("/v1/users/#{user_id}/item-tokens/#{contract_id}/request-proxy", query_params: {requestType: request_type}, payload: user_proxy_request(payload))
|
92
|
+
end
|
93
|
+
|
94
|
+
def commit_proxy_request(request_session_token)
|
95
|
+
post("/v1/user-requests/#{request_session_token}/commit")
|
96
|
+
end
|
97
|
+
|
98
|
+
def transfer_service_token_of_user(user_id, contract_id, payload = {})
|
99
|
+
post("/v1/users/#{user_id}/service-tokens/#{contract_id}/transfer", payload: transfer_service_token_proxy_request(payload))
|
100
|
+
end
|
101
|
+
|
102
|
+
def transfer_fungible_token_of_user(user_id, contract_id, token_type, payload = {})
|
103
|
+
post("/v1/users/#{user_id}/item-tokens/#{contract_id}/fungibles/#{token_type}/transfer", payload: transfer_fungible_token_proxy_request(payload))
|
104
|
+
end
|
105
|
+
|
106
|
+
def transfer_non_fungible_token_of_user(user_id, contract_id, token_type, token_index, payload = {})
|
107
|
+
post("/v1/users/#{user_id}/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/transfer", payload: transfer_non_fungible_token_proxy_request(payload))
|
108
|
+
end
|
109
|
+
|
110
|
+
def batch_transfer_non_fungible_token_of_user(user_id, contract_id, payload = {})
|
111
|
+
post("/v1/users/#{user_id}/item-tokens/#{contract_id}/non-fungibles/batch-transfer", payload: batch_transfer_non_fungible_token_proxy_request(payload))
|
112
|
+
end
|
113
|
+
|
114
|
+
def service_token_proxy_status_of_user(user_id, contract_id)
|
115
|
+
get("/v1/users/#{user_id}/service-tokens/#{contract_id}/proxy")
|
116
|
+
end
|
117
|
+
|
118
|
+
def item_token_proxy_status_of_user(user_id, contract_id)
|
119
|
+
get("/v1/users/#{user_id}/item-tokens/#{contract_id}/proxy")
|
120
|
+
end
|
121
|
+
|
122
|
+
def wallets()
|
123
|
+
get('/v1/wallets')
|
124
|
+
end
|
125
|
+
|
126
|
+
def wallet_detail(wallet_address)
|
127
|
+
get("/v1/wallets/#{wallet_address}")
|
128
|
+
end
|
129
|
+
|
130
|
+
def wallet_transactions(wallet_address, query_params = {})
|
131
|
+
get("/v1/wallets/#{wallet_address}/transactions", query_params: transaction_page_request(query_params))
|
132
|
+
end
|
133
|
+
|
134
|
+
def base_coin_balance_of_wallet(wallet_address)
|
135
|
+
get("/v1/wallets/#{wallet_address}/base-coin")
|
136
|
+
end
|
137
|
+
|
138
|
+
def service_token_balances_of_wallet(wallet_address, query_params = {})
|
139
|
+
get("/v1/wallets/#{wallet_address}/service-tokens", query_params: page_request(query_params))
|
140
|
+
end
|
141
|
+
|
142
|
+
def service_token_balance_of_wallet(wallet_address, contract_id)
|
143
|
+
get("/v1/wallets/#{wallet_address}/service-tokens/#{contract_id}")
|
144
|
+
end
|
145
|
+
|
146
|
+
def fungible_token_balances_of_wallet(wallet_address, contract_id, query_params = {})
|
147
|
+
get("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/fungibles", query_params: page_request(query_params))
|
148
|
+
end
|
149
|
+
|
150
|
+
def fungible_token_balance_of_wallet(wallet_address, contract_id, token_type)
|
151
|
+
get("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/fungibles/#{token_type}")
|
152
|
+
end
|
153
|
+
|
154
|
+
def non_fungible_token_balances_of_wallet(wallet_address, contract_id, query_params = {})
|
155
|
+
get("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/non-fungibles", query_params: page_request(query_params))
|
156
|
+
end
|
157
|
+
|
158
|
+
def non_fungible_token_balances_by_type_of_wallet(wallet_address, contract_id, token_type, query_params = {})
|
159
|
+
get("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/non-fungibles/#{token_type}", query_params: page_request(query_params))
|
160
|
+
end
|
161
|
+
|
162
|
+
def non_fungible_token_balance_of_wallet(wallet_address, contract_id, token_type, token_index)
|
163
|
+
get("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}")
|
164
|
+
end
|
165
|
+
|
166
|
+
def transfer_base_coin_of_wallet(wallet_address, payload = {})
|
167
|
+
post("/v1/wallets/#{wallet_address}/base-coin/transfer", payload: transfer_base_coin_request(payload))
|
168
|
+
end
|
169
|
+
|
170
|
+
def transfer_service_token_of_wallet(wallet_address, contract_id, payload = {})
|
171
|
+
post("/v1/wallets/#{wallet_address}/service-tokens/#{contract_id}/transfer", payload: transfer_service_token_request(payload))
|
172
|
+
end
|
173
|
+
|
174
|
+
def transfer_fungible_token_of_wallet(wallet_address, contract_id, token_type, payload = {})
|
175
|
+
post("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/fungibles/#{token_type}/transfer", payload: transfer_fungible_token_request(payload))
|
176
|
+
end
|
177
|
+
|
178
|
+
def transfer_non_fungible_token_of_wallet(wallet_address, contract_id, token_type, token_index, payload = {})
|
179
|
+
post("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/transfer", payload: transfer_non_fungible_token_request(payload))
|
180
|
+
end
|
181
|
+
|
182
|
+
def batch_transfer_non_fungible_token_of_wallet(wallet_address, contract_id, payload = {})
|
183
|
+
post("/v1/wallets/#{wallet_address}/item-tokens/#{contract_id}/non-fungibles/batch-transfer", payload: batch_transfer_non_fungible_token_request(payload))
|
184
|
+
end
|
185
|
+
|
186
|
+
def service_detail(service_id)
|
187
|
+
get("/v1/services/#{service_id}")
|
188
|
+
end
|
189
|
+
|
190
|
+
def service_tokens()
|
191
|
+
get('/v1/service-tokens')
|
192
|
+
end
|
193
|
+
|
194
|
+
def service_token_detail(contract_id)
|
195
|
+
get("/v1/service-tokens/#{contract_id}")
|
196
|
+
end
|
197
|
+
|
198
|
+
def update_service_token(contract_id, payload = {})
|
199
|
+
put("/v1/service-tokens/#{contract_id}", payload: update_service_token_request(payload))
|
200
|
+
end
|
201
|
+
|
202
|
+
def mint_service_token(contract_id, payload = {})
|
203
|
+
post("/v1/service-tokens/#{contract_id}/mint", payload: mint_service_token_request(payload))
|
204
|
+
end
|
205
|
+
|
206
|
+
def burn_from_service_token(contract_id, payload = {})
|
207
|
+
post("/v1/service-tokens/#{contract_id}/burn-from", payload: burn_from_service_token_request(payload))
|
208
|
+
end
|
209
|
+
|
210
|
+
def service_token_holders(contract_id, query_params = {})
|
211
|
+
get("/v1/service-tokens/#{contract_id}/holders", query_params: page_request(query_params))
|
212
|
+
end
|
213
|
+
|
214
|
+
def item_token(contract_id)
|
215
|
+
get("/v1/item-tokens/#{contract_id}")
|
216
|
+
end
|
217
|
+
|
218
|
+
def fungible_tokens(contract_id, query_params = {})
|
219
|
+
get("/v1/item-tokens/#{contract_id}/fungibles", query_params: page_request(query_params))
|
220
|
+
end
|
221
|
+
|
222
|
+
def create_fungible_token(contract_id, payload = {})
|
223
|
+
post("/v1/item-tokens/#{contract_id}/fungibles", payload: fungible_token_create_update_request(payload))
|
224
|
+
end
|
225
|
+
|
226
|
+
def mint_fungible_token(contract_id, token_type, payload = {})
|
227
|
+
post("/v1/item-tokens/#{contract_id}/fungibles/#{token_type}/mint", payload: fungible_token_mint_request(payload))
|
228
|
+
end
|
229
|
+
|
230
|
+
def burn_fungible_token(contract_id, token_type, payload = {})
|
231
|
+
post("/v1/item-tokens/#{contract_id}/fungibles/#{token_type}/burn", payload: fungible_token_burn_request(payload))
|
232
|
+
end
|
233
|
+
|
234
|
+
def fungible_token(contract_id, token_type)
|
235
|
+
get("/v1/item-tokens/#{contract_id}/fungibles/#{token_type}")
|
236
|
+
end
|
237
|
+
|
238
|
+
def update_fungible_token(contract_id, token_type, payload = {})
|
239
|
+
put("/v1/item-tokens/#{contract_id}/fungibles/#{token_type}", payload: fungible_token_create_update_request(payload))
|
240
|
+
end
|
241
|
+
|
242
|
+
def fungible_token_holders(contract_id, token_type, query_params = {})
|
243
|
+
get("/v1/item-tokens/#{contract_id}/fungibles/#{token_type}/holders", query_params: page_request(query_params))
|
244
|
+
end
|
245
|
+
|
246
|
+
def non_fungible_tokens(contract_id, query_params = {})
|
247
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles", query_params: page_request(query_params))
|
248
|
+
end
|
249
|
+
|
250
|
+
def non_fungible_token_type(contract_id, token_type, query_params = {})
|
251
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}", query_params: page_request(query_params))
|
252
|
+
end
|
253
|
+
|
254
|
+
def create_non_fungible_token(contract_id, payload = {})
|
255
|
+
post("/v1/item-tokens/#{contract_id}/non-fungibles", payload: non_fungible_token_create_update_request(payload))
|
256
|
+
end
|
257
|
+
|
258
|
+
def mint_non_fungible_token(contract_id, token_type, payload = {})
|
259
|
+
post("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/mint", payload: non_fungible_token_mint_request(payload))
|
260
|
+
end
|
261
|
+
|
262
|
+
def multi_mint_non_fungible_token(contract_id, payload = {})
|
263
|
+
post("/v1/item-tokens/#{contract_id}/non-fungibles/multi-mint", payload: non_fungible_token_multi_mint_request(payload))
|
264
|
+
end
|
265
|
+
|
266
|
+
def multi_mint_non_fungible_token_for_multi_recipients(contract_id, payload = {})
|
267
|
+
warn('Not Implemented yet')
|
268
|
+
post("/v1/item-tokens/#{contract_id}/non-fungibles/multi-recipients/multi-mint", payload: non_fungible_token_multi_mint_multi_recipients_request(payload))
|
269
|
+
end
|
270
|
+
|
271
|
+
def burn_non_fungible_token(contract_id, token_type, token_index, payload = {})
|
272
|
+
post("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/burn", payload: non_fungible_token_burn_request(payload))
|
273
|
+
end
|
274
|
+
|
275
|
+
def non_fungible_token(contract_id, token_type, token_index)
|
276
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}")
|
277
|
+
end
|
278
|
+
|
279
|
+
def update_non_fungible_token_type(contract_id, token_type, payload = {})
|
280
|
+
put("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}", payload: non_fungible_token_create_update_request(payload))
|
281
|
+
end
|
282
|
+
|
283
|
+
def update_non_fungible_token(contract_id, token_type, token_index, payload = {})
|
284
|
+
put("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}", payload: non_fungible_token_create_update_request(payload))
|
285
|
+
end
|
286
|
+
|
287
|
+
def non_fungible_token_type_holders(contract_id, token_type, query_params = {})
|
288
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/holders", query_params: page_request(query_params))
|
289
|
+
end
|
290
|
+
|
291
|
+
def non_fungible_token_holder(contract_id, token_type, token_index)
|
292
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/holder")
|
293
|
+
end
|
294
|
+
|
295
|
+
def attach_non_fungible_token(contract_id, token_type, token_index, payload = {})
|
296
|
+
post("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/parent", payload: non_fungible_token_attach_request(payload))
|
297
|
+
end
|
298
|
+
|
299
|
+
def detach_non_fungible_token(contract_id, token_type, token_index, payload = {})
|
300
|
+
delete("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/parent", payload: non_fungible_token_detach_request(payload))
|
301
|
+
end
|
302
|
+
|
303
|
+
def children_of_non_fungible_token(contract_id, token_type, token_index, query_params = {})
|
304
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/children", query_params: page_request(query_params))
|
305
|
+
end
|
306
|
+
|
307
|
+
def parent_of_non_fungible_token(contract_id, token_type, token_index)
|
308
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/parent")
|
309
|
+
end
|
310
|
+
|
311
|
+
def root_of_non_fungible_token(contract_id, token_type, token_index)
|
312
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/#{token_type}/#{token_index}/root")
|
313
|
+
end
|
314
|
+
|
315
|
+
def fungible_token_media_resources_update_status(contract_id, request_id)
|
316
|
+
get("/v1/item-tokens/#{contract_id}/fungibles/icon/#{request_id}/status")
|
317
|
+
end
|
318
|
+
|
319
|
+
def update_fungible_token_media_resources(contract_id, token_types)
|
320
|
+
put("/v1/item-tokens/#{contract_id}/fungibles/icon", payload: fungible_token_media_resources_request(token_types))
|
321
|
+
end
|
322
|
+
|
323
|
+
def non_fungible_token_media_resources_update_status(contract_id, request_id)
|
324
|
+
get("/v1/item-tokens/#{contract_id}/non-fungibles/icon/#{request_id}/status")
|
325
|
+
end
|
326
|
+
|
327
|
+
def update_non_fungible_token_media_resources(contract_id, token_ids)
|
328
|
+
put("/v1/item-tokens/#{contract_id}/non-fungibles/icon", payload: non_fungible_token_media_resources_request(token_ids))
|
329
|
+
end
|
330
|
+
|
331
|
+
def memos(tx_hash)
|
332
|
+
get("/v1/memos/#{tx_hash}")
|
333
|
+
end
|
334
|
+
|
335
|
+
def create_memo(payload = {})
|
336
|
+
post('/v1/memos', payload: memo_request(payload))
|
337
|
+
end
|
338
|
+
|
339
|
+
def transaction_result(tx_hash)
|
340
|
+
get("/v1/transactions/#{tx_hash}")
|
341
|
+
end
|
342
|
+
|
343
|
+
def httpclient
|
344
|
+
HTTPClient.new
|
345
|
+
end
|
346
|
+
|
347
|
+
def get(endpoint_path, query_params: {})
|
348
|
+
headers = request_headers(endpoint_path: endpoint_path, method: 'GET', query_params: query_params)
|
349
|
+
query_params = RequestParamFlattener.new.flatten(query_params)
|
350
|
+
if query_params.empty?
|
351
|
+
httpclient.get("#{@endpoint}#{endpoint_path}", headers)
|
352
|
+
else
|
353
|
+
httpclient.get("#{@endpoint}#{endpoint_path}?#{query_params}", headers)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def post(endpoint_path, query_params: {}, payload: {})
|
358
|
+
headers = request_headers(endpoint_path: endpoint_path, method: 'POST', query_params: query_params, payload: payload)
|
359
|
+
query_params = RequestParamFlattener.new.flatten(query_params)
|
360
|
+
if query_params.empty?
|
361
|
+
httpclient.post("#{@endpoint}#{endpoint_path}", payload.to_json, headers)
|
362
|
+
else
|
363
|
+
httpclient.post("#{@endpoint}#{endpoint_path}?#{query_params}", payload.to_json, headers)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def put(endpoint_path, payload: {})
|
368
|
+
headers = request_headers(endpoint_path: endpoint_path, method: 'PUT', payload: payload)
|
369
|
+
httpclient.put("#{@endpoint}#{endpoint_path}", payload.to_json, headers)
|
370
|
+
end
|
371
|
+
|
372
|
+
def delete(endpoint_path, payload: {})
|
373
|
+
headers = request_headers(endpoint_path: endpoint_path, method: 'DELETE', payload: payload)
|
374
|
+
httpclient.delete("#{@endpoint}#{endpoint_path}", payload.to_json, headers)
|
375
|
+
end
|
376
|
+
|
377
|
+
def request_headers(endpoint_path:, method:, query_params: {}, payload: {})
|
378
|
+
nonce = rand(10_000_000..99_999_999)
|
379
|
+
timestamp = (Time.now.utc.to_f * 1000).round
|
380
|
+
method = method.to_s.upcase
|
381
|
+
{
|
382
|
+
'service-api-key': @api_key,
|
383
|
+
'Content-Type': 'application/json',
|
384
|
+
Nonce: "#{nonce}",
|
385
|
+
Timestamp: "#{timestamp}",
|
386
|
+
Signature: SignatureGenerator.new.generate(
|
387
|
+
secret: @api_secret_key,
|
388
|
+
method: method,
|
389
|
+
endpoint_path: endpoint_path,
|
390
|
+
timestamp: timestamp,
|
391
|
+
nonce: nonce,
|
392
|
+
query_params: query_params,
|
393
|
+
body: payload,
|
394
|
+
),
|
395
|
+
}
|
396
|
+
end
|
397
|
+
|
398
|
+
def page_request(options)
|
399
|
+
{
|
400
|
+
limit: options[:limit] || 10,
|
401
|
+
page: options[:page] || 1,
|
402
|
+
orderBy: options[:order_by] || 'desc',
|
403
|
+
}
|
404
|
+
end
|
405
|
+
|
406
|
+
def transaction_page_request(options)
|
407
|
+
params = {
|
408
|
+
limit: options[:limit] || 10,
|
409
|
+
page: options[:page] || 1,
|
410
|
+
orderBy: options[:order_by] || 'desc',
|
411
|
+
}
|
412
|
+
if !options[:before].nil?
|
413
|
+
params[:before] = options[:before]
|
414
|
+
end
|
415
|
+
if !options[:after].nil?
|
416
|
+
params[:after] = options[:after]
|
417
|
+
end
|
418
|
+
if !options[:msgType].nil?
|
419
|
+
params[:msgType] = options[:msgType]
|
420
|
+
end
|
421
|
+
params
|
422
|
+
end
|
423
|
+
|
424
|
+
def update_service_token_request(options)
|
425
|
+
params = {
|
426
|
+
ownerAddress: options[:owner_address],
|
427
|
+
ownerSecret: options[:owner_secret],
|
428
|
+
}
|
429
|
+
if !options[:name].nil?
|
430
|
+
params[:name] = options[:name]
|
431
|
+
end
|
432
|
+
if !options[:meta].nil?
|
433
|
+
params[:meta] = options[:meta]
|
434
|
+
end
|
435
|
+
params
|
436
|
+
end
|
437
|
+
|
438
|
+
def mint_service_token_request(options)
|
439
|
+
params = {
|
440
|
+
ownerAddress: options[:owner_address],
|
441
|
+
ownerSecret: options[:owner_secret],
|
442
|
+
amount: options[:amount].to_s,
|
443
|
+
}
|
444
|
+
if !options[:to_user_id].nil?
|
445
|
+
params[:toUserId] = options[:to_user_id]
|
446
|
+
elsif !options[:to_address].nil?
|
447
|
+
params[:toAddress] = options[:to_address]
|
448
|
+
end
|
449
|
+
params
|
450
|
+
end
|
451
|
+
|
452
|
+
def burn_from_service_token_request(options)
|
453
|
+
params = {
|
454
|
+
ownerAddress: options[:owner_address],
|
455
|
+
ownerSecret: options[:owner_secret],
|
456
|
+
amount: options[:amount].to_s,
|
457
|
+
}
|
458
|
+
if !options[:from_user_id].nil?
|
459
|
+
params[:fromUserId] = options[:from_user_id]
|
460
|
+
elsif !options[:from_address].nil?
|
461
|
+
params[:fromAddress] = options[:from_address]
|
462
|
+
end
|
463
|
+
params
|
464
|
+
end
|
465
|
+
|
466
|
+
def user_proxy_request(options)
|
467
|
+
{
|
468
|
+
ownerAddress: options[:owner_address],
|
469
|
+
landingUri: options[:landing_uri],
|
470
|
+
}
|
471
|
+
end
|
472
|
+
|
473
|
+
def issue_transfer_session_token_request(options)
|
474
|
+
params = {
|
475
|
+
amount: options[:amount].to_s,
|
476
|
+
landingUri: options[:landing_uri],
|
477
|
+
}
|
478
|
+
|
479
|
+
if params[:amount].to_i <= 0
|
480
|
+
raise ArgumentError, 'Invalid amount - $amount is less than zero '
|
481
|
+
end
|
482
|
+
|
483
|
+
if !options[:to_user_id].nil?
|
484
|
+
params[:toUserId] = options[:to_user_id]
|
485
|
+
elsif !options[:to_address].nil?
|
486
|
+
params[:toAddress] = options[:to_address]
|
487
|
+
end
|
488
|
+
params
|
489
|
+
end
|
490
|
+
|
491
|
+
def transfer_service_token_proxy_request(options)
|
492
|
+
params = {
|
493
|
+
ownerAddress: options[:owner_address],
|
494
|
+
ownerSecret: options[:owner_secret],
|
495
|
+
amount: options[:amount].to_s,
|
496
|
+
}
|
497
|
+
if !options[:to_user_id].nil?
|
498
|
+
params[:toUserId] = options[:to_user_id]
|
499
|
+
elsif !options[:to_address].nil?
|
500
|
+
params[:toAddress] = options[:to_address]
|
501
|
+
end
|
502
|
+
params
|
503
|
+
end
|
504
|
+
|
505
|
+
def transfer_fungible_token_proxy_request(options)
|
506
|
+
params = {
|
507
|
+
ownerAddress: options[:owner_address],
|
508
|
+
ownerSecret: options[:owner_secret],
|
509
|
+
amount: options[:amount].to_s,
|
510
|
+
}
|
511
|
+
if !options[:to_user_id].nil?
|
512
|
+
params[:toUserId] = options[:to_user_id]
|
513
|
+
elsif !options[:to_address].nil?
|
514
|
+
params[:toAddress] = options[:to_address]
|
515
|
+
end
|
516
|
+
params
|
517
|
+
end
|
518
|
+
|
519
|
+
def transfer_non_fungible_token_proxy_request(options)
|
520
|
+
params = {
|
521
|
+
ownerAddress: options[:owner_address],
|
522
|
+
ownerSecret: options[:owner_secret],
|
523
|
+
}
|
524
|
+
if !options[:to_user_id].nil?
|
525
|
+
params[:toUserId] = options[:to_user_id]
|
526
|
+
elsif !options[:to_address].nil?
|
527
|
+
params[:toAddress] = options[:to_address]
|
528
|
+
end
|
529
|
+
params
|
530
|
+
end
|
531
|
+
|
532
|
+
def batch_transfer_non_fungible_token_proxy_request(options)
|
533
|
+
params = {
|
534
|
+
ownerAddress: options[:owner_address],
|
535
|
+
ownerSecret: options[:owner_secret],
|
536
|
+
}
|
537
|
+
|
538
|
+
if !options[:transfer_list].nil? &&
|
539
|
+
options[:transfer_list].is_a?(Array) && !options[:transfer_list].empty?
|
540
|
+
params[:transferList] = options[:transfer_list].map do |option|
|
541
|
+
{
|
542
|
+
tokenId: option[:token_id] || option[:tokenId],
|
543
|
+
}
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
if !options[:to_user_id].nil?
|
548
|
+
params[:toUserId] = options[:to_user_id]
|
549
|
+
elsif !options[:to_address].nil?
|
550
|
+
params[:toAddress] = options[:to_address]
|
551
|
+
end
|
552
|
+
params
|
553
|
+
end
|
554
|
+
|
555
|
+
def transfer_base_coin_request(options)
|
556
|
+
params = {
|
557
|
+
walletSecret: options[:wallet_secret],
|
558
|
+
amount: options[:amount].to_s,
|
559
|
+
}
|
560
|
+
if !options[:to_user_id].nil?
|
561
|
+
params[:toUserId] = options[:to_user_id]
|
562
|
+
elsif !options[:to_address].nil?
|
563
|
+
params[:toAddress] = options[:to_address]
|
564
|
+
end
|
565
|
+
params
|
566
|
+
end
|
567
|
+
|
568
|
+
def transfer_service_token_request(options)
|
569
|
+
params = {
|
570
|
+
walletSecret: options[:wallet_secret],
|
571
|
+
amount: options[:amount].to_s,
|
572
|
+
}
|
573
|
+
if !options[:to_user_id].nil?
|
574
|
+
params[:toUserId] = options[:to_user_id]
|
575
|
+
elsif !options[:to_address].nil?
|
576
|
+
params[:toAddress] = options[:to_address]
|
577
|
+
end
|
578
|
+
params
|
579
|
+
end
|
580
|
+
|
581
|
+
def transfer_fungible_token_request(options)
|
582
|
+
params = {
|
583
|
+
walletSecret: options[:wallet_secret],
|
584
|
+
amount: options[:amount].to_s,
|
585
|
+
}
|
586
|
+
if !options[:to_user_id].nil?
|
587
|
+
params[:toUserId] = options[:to_user_id]
|
588
|
+
elsif !options[:to_address].nil?
|
589
|
+
params[:toAddress] = options[:to_address]
|
590
|
+
end
|
591
|
+
params
|
592
|
+
end
|
593
|
+
|
594
|
+
def transfer_non_fungible_token_request(options)
|
595
|
+
params = {
|
596
|
+
walletSecret: options[:wallet_secret],
|
597
|
+
}
|
598
|
+
if !options[:to_user_id].nil?
|
599
|
+
params[:toUserId] = options[:to_user_id]
|
600
|
+
elsif !options[:to_address].nil?
|
601
|
+
params[:toAddress] = options[:to_address]
|
602
|
+
end
|
603
|
+
params
|
604
|
+
end
|
605
|
+
|
606
|
+
def batch_transfer_non_fungible_token_request(options)
|
607
|
+
params = {
|
608
|
+
walletSecret: options[:wallet_secret],
|
609
|
+
}
|
610
|
+
|
611
|
+
if !options[:transfer_list].nil? &&
|
612
|
+
options[:transfer_list].is_a?(Array) && !options[:transfer_list].empty?
|
613
|
+
params[:transferList] = options[:transfer_list].map do |option|
|
614
|
+
{
|
615
|
+
tokenId: option[:token_id] || option[:tokenId],
|
616
|
+
}
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
if !options[:to_user_id].nil?
|
621
|
+
params[:toUserId] = options[:to_user_id]
|
622
|
+
elsif !options[:to_address].nil?
|
623
|
+
params[:toAddress] = options[:to_address]
|
624
|
+
end
|
625
|
+
params
|
626
|
+
end
|
627
|
+
|
628
|
+
def fungible_token_create_update_request(options)
|
629
|
+
params = {
|
630
|
+
ownerAddress: options[:owner_address],
|
631
|
+
ownerSecret: options[:owner_secret],
|
632
|
+
}
|
633
|
+
if !options[:name].nil?
|
634
|
+
params[:name] = options[:name]
|
635
|
+
end
|
636
|
+
if !options[:meta].nil?
|
637
|
+
params[:meta] = options[:meta]
|
638
|
+
end
|
639
|
+
params
|
640
|
+
end
|
641
|
+
|
642
|
+
def non_fungible_token_create_update_request(options)
|
643
|
+
params = {
|
644
|
+
ownerAddress: options[:owner_address],
|
645
|
+
ownerSecret: options[:owner_secret],
|
646
|
+
}
|
647
|
+
if !options[:name].nil?
|
648
|
+
params[:name] = options[:name]
|
649
|
+
end
|
650
|
+
if !options[:meta].nil?
|
651
|
+
params[:meta] = options[:meta]
|
652
|
+
end
|
653
|
+
params
|
654
|
+
end
|
655
|
+
|
656
|
+
def non_fungible_token_attach_request(options)
|
657
|
+
params = {
|
658
|
+
parentTokenId: options[:parent_token_id],
|
659
|
+
serviceWalletAddress: options[:service_wallet_address],
|
660
|
+
serviceWalletSecret: options[:service_wallet_secret],
|
661
|
+
}
|
662
|
+
if !options[:token_holder_address].nil?
|
663
|
+
params[:tokenHolderAddress] = options[:token_holder_address]
|
664
|
+
elsif !options[:token_holder_user_id].nil?
|
665
|
+
params[:tokenHolderUserId] = options[:token_holder_user_id]
|
666
|
+
else
|
667
|
+
raise ArgumentError, 'token_holder_address or token_holder_user_id, one of them is required'
|
668
|
+
end
|
669
|
+
params
|
670
|
+
end
|
671
|
+
|
672
|
+
def non_fungible_token_detach_request(options)
|
673
|
+
params = {
|
674
|
+
serviceWalletAddress: options[:service_wallet_address],
|
675
|
+
serviceWalletSecret: options[:service_wallet_secret],
|
676
|
+
}
|
677
|
+
if !options[:token_holder_address].nil?
|
678
|
+
params[:tokenHolderAddress] = options[:token_holder_address]
|
679
|
+
elsif !options[:token_holder_user_id].nil?
|
680
|
+
params[:tokenHolderUserId] = options[:token_holder_user_id]
|
681
|
+
else
|
682
|
+
raise ArgumentError, 'token_holder_address or token_holder_user_id, one of them is required'
|
683
|
+
end
|
684
|
+
params
|
685
|
+
end
|
686
|
+
|
687
|
+
def fungible_token_mint_request(options)
|
688
|
+
params = {
|
689
|
+
ownerAddress: options[:owner_address],
|
690
|
+
ownerSecret: options[:owner_secret],
|
691
|
+
amount: options[:amount].to_s,
|
692
|
+
}
|
693
|
+
if !options[:to_user_id].nil?
|
694
|
+
params[:toUserId] = options[:to_user_id]
|
695
|
+
elsif !options[:to_address].nil?
|
696
|
+
params[:toAddress] = options[:to_address]
|
697
|
+
end
|
698
|
+
params
|
699
|
+
end
|
700
|
+
|
701
|
+
def fungible_token_burn_request(options)
|
702
|
+
params = {
|
703
|
+
ownerAddress: options[:owner_address],
|
704
|
+
ownerSecret: options[:owner_secret],
|
705
|
+
amount: options[:amount].to_s,
|
706
|
+
}
|
707
|
+
if !options[:from_user_id].nil?
|
708
|
+
params[:fromUserId] = options[:from_user_id]
|
709
|
+
elsif !options[:from_address].nil?
|
710
|
+
params[:fromAddress] = options[:from_address]
|
711
|
+
end
|
712
|
+
params
|
713
|
+
end
|
714
|
+
|
715
|
+
def non_fungible_token_mint_request(options)
|
716
|
+
params = {
|
717
|
+
ownerAddress: options[:owner_address],
|
718
|
+
ownerSecret: options[:owner_secret],
|
719
|
+
name: options[:name],
|
720
|
+
}
|
721
|
+
|
722
|
+
if !options[:meta].nil?
|
723
|
+
params[:meta] = options[:meta]
|
724
|
+
end
|
725
|
+
|
726
|
+
if !options[:to_user_id].nil?
|
727
|
+
params[:toUserId] = options[:to_user_id]
|
728
|
+
elsif !options[:to_address].nil?
|
729
|
+
params[:toAddress] = options[:to_address]
|
730
|
+
end
|
731
|
+
params
|
732
|
+
end
|
733
|
+
|
734
|
+
def non_fungible_token_multi_mint_request(options)
|
735
|
+
params = {
|
736
|
+
ownerAddress: options[:owner_address],
|
737
|
+
ownerSecret: options[:owner_secret],
|
738
|
+
mintList: options[:mint_list],
|
739
|
+
}
|
740
|
+
|
741
|
+
if !options[:mint_list].nil? && options[:mint_list].is_a?(Array) && !options[:mint_list].empty?
|
742
|
+
params[:mintList] = options[:mint_list].map do |option|
|
743
|
+
inner_params = {
|
744
|
+
tokenType: option[:token_type],
|
745
|
+
name: option[:name],
|
746
|
+
}
|
747
|
+
|
748
|
+
if !option[:meta].nil?
|
749
|
+
inner_params[:meta] = option[:meta]
|
750
|
+
end
|
751
|
+
|
752
|
+
inner_params
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
if !options[:to_user_id].nil?
|
757
|
+
params[:toUserId] = options[:to_user_id]
|
758
|
+
elsif !options[:to_address].nil?
|
759
|
+
params[:toAddress] = options[:to_address]
|
760
|
+
end
|
761
|
+
|
762
|
+
params
|
763
|
+
end
|
764
|
+
|
765
|
+
def non_fungible_token_multi_mint_multi_recipients_request(options)
|
766
|
+
params = {
|
767
|
+
ownerAddress: options[:owner_address],
|
768
|
+
ownerSecret: options[:owner_secret],
|
769
|
+
mintList: options[:mint_list],
|
770
|
+
}
|
771
|
+
|
772
|
+
if !options[:mint_list].nil? && options[:mint_list].is_a?(Array) && !options[:mint_list].empty?
|
773
|
+
params[:mintList] = options[:mint_list].map do |option|
|
774
|
+
inner_params = {
|
775
|
+
tokenType: option[:token_type],
|
776
|
+
name: option[:name],
|
777
|
+
}
|
778
|
+
|
779
|
+
if !option[:meta].nil?
|
780
|
+
inner_params[:meta] = option[:meta]
|
781
|
+
end
|
782
|
+
|
783
|
+
if !option[:to_user_id].nil?
|
784
|
+
inner_params[:toUserId] = option[:to_user_id]
|
785
|
+
elsif !option[:to_address].nil?
|
786
|
+
inner_params[:toAddress] = option[:to_address]
|
787
|
+
end
|
788
|
+
|
789
|
+
inner_params
|
790
|
+
end
|
791
|
+
end
|
792
|
+
|
793
|
+
params
|
794
|
+
end
|
795
|
+
|
796
|
+
def non_fungible_token_burn_request(options)
|
797
|
+
params = {
|
798
|
+
ownerAddress: options[:owner_address],
|
799
|
+
ownerSecret: options[:owner_secret],
|
800
|
+
}
|
801
|
+
if !options[:from_user_id].nil?
|
802
|
+
params[:fromUserId] = options[:from_user_id]
|
803
|
+
elsif !options[:from_address].nil?
|
804
|
+
params[:fromAddress] = options[:from_address]
|
805
|
+
end
|
806
|
+
params
|
807
|
+
end
|
808
|
+
|
809
|
+
def fungible_token_media_resources_request(options)
|
810
|
+
params = {
|
811
|
+
updateList: options[:update_list],
|
812
|
+
}
|
813
|
+
|
814
|
+
if !options[:update_list].nil? &&
|
815
|
+
options[:update_list].is_a?(Array) && !options[:update_list].empty?
|
816
|
+
params[:updateList] = options[:update_list].map do |option|
|
817
|
+
{
|
818
|
+
tokenType: option[:token_type] || option[:tokenType],
|
819
|
+
}
|
820
|
+
end
|
821
|
+
end
|
822
|
+
|
823
|
+
params
|
824
|
+
end
|
825
|
+
|
826
|
+
def non_fungible_token_media_resources_request(options)
|
827
|
+
params = {
|
828
|
+
updateList: options[:update_list],
|
829
|
+
}
|
830
|
+
|
831
|
+
if !options[:update_list].nil? &&
|
832
|
+
options[:update_list].is_a?(Array) && !options[:update_list].empty?
|
833
|
+
params[:updateList] = options[:update_list].map do |option|
|
834
|
+
{
|
835
|
+
tokenType: option[:token_type] || option[:tokenType],
|
836
|
+
tokenIndex: option[:token_index] || option[:tokenIndex],
|
837
|
+
}
|
838
|
+
end
|
839
|
+
end
|
840
|
+
|
841
|
+
params
|
842
|
+
end
|
843
|
+
|
844
|
+
def memo_request(options)
|
845
|
+
{
|
846
|
+
walletAddress: options[:wallet_address],
|
847
|
+
walletSecret: options[:wallet_secret],
|
848
|
+
memo: options[:memo],
|
849
|
+
}
|
850
|
+
end
|
851
|
+
end
|
852
|
+
end
|