phantasma 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 83bf85cda436001142acb8223d80acb2d0946a3ebfbad523f540ef0e372f201c
4
+ data.tar.gz: 85b0d08826d43b51100cdb730991938101b34437d753504389c262fa182c3b22
5
+ SHA512:
6
+ metadata.gz: e98803654fe40fef3c0a992d4827b8a0ba704ff26a6dfce519fb454690aaf54ef9eeb78822312e186f02ed4db2455f330b9c0e8b7a736497dd0b51b92dc8e151
7
+ data.tar.gz: 9f2b8078f207b3917fc34a5262c3f54d17adf4a147fc0359f3173e385add057720ce9873968ede62418298a153aece3a1cf80387074fecb3868fc418c5fca28f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Henry Maestu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Phantasma Ruby SDK
2
+ [Phantasma](https://phantasma.io/) - A Smart NFT Carbon Negative Blockchain for Gaming, dApp
3
+
4
+ This gem is community edition of Phantasma Blockchain SDK in Ruby.
5
+
6
+ ## Install
7
+ ```
8
+ gem "phantasma", :git => "https://github.com/MysteriousNothing/phantasma.git"
9
+ # or RubyGems
10
+ gem "phantasma"
11
+ ```
12
+
13
+ #### Test API URL
14
+ https://testnet.phantasma.info
15
+ ## Live API URL
16
+ https://phantasma.gitbook.io/developers/overview/quick-start
17
+
18
+ The Ruby version does not use different classes, we use Ruby metaprogramming.
19
+ This means adding new endpoint means updating `ALLOWED_METHOD` const in [lib/phantasma/API/api.rb](lib/phantasma/API/request.rb)
20
+
21
+ #### Examples how to use API:
22
+ ```
23
+ api = Phantasma::API::Request.new(url: 'https://testnet.phantasma.info')
24
+ api.get_account({account: '1231313'})
25
+ api.get_accounts({accounts: ['1231313']})
26
+ api.get_addresses_by_symbol({symbol: 'SOUL', extended: false})
27
+ api.look_up_name({name: 'SOUL'})
28
+ ```
29
+
30
+ #### Examples how to use RPC call with API:
31
+ ```
32
+ api = Phantasma::API::Request.new(url: 'https://testnet.phantasma.info')
33
+ api.rpc({"jsonrpc": "2.0", "method": "health", "id": "1", "params": [] })
34
+ ```
35
+
36
+ ## Full API documentation is here:
37
+ [docs/api_documentation.md](docs/api_documentation.md)
38
+
39
+ ### Generate documentation after API update:
40
+
41
+ ```
42
+ ruby lib/phantasma/documentation.rb
43
+ ```
44
+
45
+ ## Phantasma Documentation for API Endpoints with responses
46
+ https://testnet.phantasma.info/swagger/index.html
47
+
48
+ ## Helpers
49
+ Find missing or deprecated API endpoints by calling
50
+
51
+ ```
52
+ Phantasma::API.find_missing_endpoints
53
+ Phantasma::API.find_deprecated_endpoints
54
+ ```
55
+
56
+ ## Running tests
57
+
58
+ ```
59
+ # All tests
60
+ rspec spec/
61
+ # Specific
62
+ rspec spec/API/api_spec.rb
63
+ ```
64
+
65
+ ## Todo
66
+ - [ ] Finish tests - 233 examples, 5 failures, 228 passed
67
+
68
+ - [ ] RPC or eRPC(Google RPC, http2)
69
+
70
+ - [ ] Phantasma VM in Ruby
71
+
72
+ - [ ] Add API command line support
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MysteriousNothing/phantasma.
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,556 @@
1
+ ### Account - get_account
2
+ - **Endpoint**: `/api/v1/GetAccount`
3
+ - **Method**: `GET`
4
+ - **Parameters**:
5
+ - `account`: string
6
+ - `extended`: boolean, `default`: true
7
+ - **Ruby Example**:
8
+ ```ruby
9
+ api.get_account({account: 'string', extended: true})
10
+ ```
11
+
12
+ ### Account - get_accounts
13
+ - **Endpoint**: `/api/v1/GetAccounts`
14
+ - **Method**: `GET`
15
+ - **Parameters**:
16
+ - `accounts`: string
17
+ - `extended`: boolean, `default`: true
18
+ - **Ruby Example**:
19
+ ```ruby
20
+ api.get_accounts({accounts: 'string', extended: true})
21
+ ```
22
+
23
+ ### Account - look_up_name
24
+ - **Endpoint**: `/api/v1/LookUpName`
25
+ - **Method**: `GET`
26
+ - **Parameters**:
27
+ - `name`: string
28
+ - **Ruby Example**:
29
+ ```ruby
30
+ api.look_up_name({name: 'string'})
31
+ ```
32
+
33
+ ### Account - get_addresses_by_symbol
34
+ - **Endpoint**: `/api/v1/GetAddressesBySymbol`
35
+ - **Method**: `GET`
36
+ - **Parameters**:
37
+ - `symbol`: string
38
+ - `extended`: boolean, `default`: true
39
+ - **Ruby Example**:
40
+ ```ruby
41
+ api.get_addresses_by_symbol({symbol: 'string', extended: true})
42
+ ```
43
+
44
+ ### Auction - get_auctions_count
45
+ - **Endpoint**: `/api/v1/GetAuctionsCount`
46
+ - **Method**: `GET`
47
+ - **Parameters**:
48
+ - `chainAddressOrName`: string
49
+ - `symbol`: string
50
+ - **Ruby Example**:
51
+ ```ruby
52
+ api.get_auctions_count({chainAddressOrName: 'string', symbol: 'string'})
53
+ ```
54
+
55
+ ### Auction - get_auctions
56
+ - **Endpoint**: `/api/v1/GetAuctions`
57
+ - **Method**: `GET`
58
+ - **Parameters**:
59
+ - `chainAddressOrName`: string
60
+ - `symbol`: string
61
+ - `page`: integer, `default`: 1
62
+ - `pageSize`: integer
63
+ - **Ruby Example**:
64
+ ```ruby
65
+ api.get_auctions({chainAddressOrName: 'string', symbol: 'string', page: 1, pageSize: 'integer'})
66
+ ```
67
+
68
+ ### Auction - get_auction
69
+ - **Endpoint**: `/api/v1/GetAuction`
70
+ - **Method**: `GET`
71
+ - **Parameters**:
72
+ - `chainAddressOrName`: string
73
+ - `symbol`: string
74
+ - `IDtext`: string
75
+ - **Ruby Example**:
76
+ ```ruby
77
+ api.get_auction({chainAddressOrName: 'string', symbol: 'string', IDtext: 'string'})
78
+ ```
79
+
80
+ ### Block - get_block_height
81
+ - **Endpoint**: `/api/v1/GetBlockHeight`
82
+ - **Method**: `GET`
83
+ - **Parameters**:
84
+ - `chainInput`: string
85
+ - **Ruby Example**:
86
+ ```ruby
87
+ api.get_block_height({chainInput: 'string'})
88
+ ```
89
+
90
+ ### Block - get_block_transaction_count_by_hash
91
+ - **Endpoint**: `/api/v1/GetBlockTransactionCountByHash`
92
+ - **Method**: `GET`
93
+ - **Parameters**:
94
+ - `chainAddressOrName`: string
95
+ - `blockHash`: string
96
+ - **Ruby Example**:
97
+ ```ruby
98
+ api.get_block_transaction_count_by_hash({chainAddressOrName: 'string', blockHash: 'string'})
99
+ ```
100
+
101
+ ### Block - get_block_by_hash
102
+ - **Endpoint**: `/api/v1/GetBlockByHash`
103
+ - **Method**: `GET`
104
+ - **Parameters**:
105
+ - `blockHash`: string
106
+ - **Ruby Example**:
107
+ ```ruby
108
+ api.get_block_by_hash({blockHash: 'string'})
109
+ ```
110
+
111
+ ### Block - get_raw_block_by_hash
112
+ - **Endpoint**: `/api/v1/GetRawBlockByHash`
113
+ - **Method**: `GET`
114
+ - **Parameters**:
115
+ - `blockHash`: string
116
+ - **Ruby Example**:
117
+ ```ruby
118
+ api.get_raw_block_by_hash({blockHash: 'string'})
119
+ ```
120
+
121
+ ### Block - get_block_by_height
122
+ - **Endpoint**: `/api/v1/GetBlockByHeight`
123
+ - **Method**: `GET`
124
+ - **Parameters**:
125
+ - `chainInput`: string
126
+ - `height`: string
127
+ - **Ruby Example**:
128
+ ```ruby
129
+ api.get_block_by_height({chainInput: 'string', height: 'string'})
130
+ ```
131
+
132
+ ### Block - get_raw_block_by_height
133
+ - **Endpoint**: `/api/v1/GetRawBlockByHeight`
134
+ - **Method**: `GET`
135
+ - **Parameters**:
136
+ - `chainInput`: string
137
+ - `height`: string
138
+ - **Ruby Example**:
139
+ ```ruby
140
+ api.get_raw_block_by_height({chainInput: 'string', height: 'string'})
141
+ ```
142
+
143
+ ### Block - get_latest_block
144
+ - **Endpoint**: `/api/v1/GetLatestBlock`
145
+ - **Method**: `GET`
146
+ - **Parameters**:
147
+ - `chainInput`: string
148
+ - **Ruby Example**:
149
+ ```ruby
150
+ api.get_latest_block({chainInput: 'string'})
151
+ ```
152
+
153
+ ### Block - get_raw_latest_block
154
+ - **Endpoint**: `/api/v1/GetRawLatestBlock`
155
+ - **Method**: `GET`
156
+ - **Parameters**:
157
+ - `chainInput`: string
158
+ - **Ruby Example**:
159
+ ```ruby
160
+ api.get_raw_latest_block({chainInput: 'string'})
161
+ ```
162
+
163
+ ### Chain - get_chains
164
+ - **Endpoint**: `/api/v1/GetChains`
165
+ - **Method**: `GET`
166
+ - **Parameters**:
167
+ - `extended`: boolean, `default`: true
168
+ - **Ruby Example**:
169
+ ```ruby
170
+ api.get_chains({extended: true})
171
+ ```
172
+
173
+ ### Chain - get_chain
174
+ - **Endpoint**: `/api/v1/GetChain`
175
+ - **Method**: `GET`
176
+ - **Parameters**:
177
+ - `name`: string, `default`: main
178
+ - `extended`: boolean, `default`: true
179
+ - **Ruby Example**:
180
+ ```ruby
181
+ api.get_chain({name: 'main', extended: true})
182
+ ```
183
+
184
+ ### Connection - abci_query
185
+ - **Endpoint**: `/api/v1/abci_query`
186
+ - **Method**: `GET`
187
+ - **Parameters**:
188
+ - `path`: string
189
+ - `data`: string
190
+ - `height`: integer, `default`: 0
191
+ - `prove`: boolean, `default`: false
192
+ - **Ruby Example**:
193
+ ```ruby
194
+ api.abci_query({path: 'string', data: 'string', height: 0, prove: false})
195
+ ```
196
+
197
+ ### Connection - health
198
+ - **Endpoint**: `/api/v1/health`
199
+ - **Method**: `GET`
200
+ - **Parameters**:
201
+ - None
202
+ - **Ruby Example**:
203
+ ```ruby
204
+ api.health
205
+ ```
206
+
207
+ ### Connection - status
208
+ - **Endpoint**: `/api/v1/status`
209
+ - **Method**: `GET`
210
+ - **Parameters**:
211
+ - None
212
+ - **Ruby Example**:
213
+ ```ruby
214
+ api.status
215
+ ```
216
+
217
+ ### Connection - net_info
218
+ - **Endpoint**: `/api/v1/net_info`
219
+ - **Method**: `GET`
220
+ - **Parameters**:
221
+ - None
222
+ - **Ruby Example**:
223
+ ```ruby
224
+ api.net_info
225
+ ```
226
+
227
+ ### Connection - request_block
228
+ - **Endpoint**: `/api/v1/request_block`
229
+ - **Method**: `GET`
230
+ - **Parameters**:
231
+ - `height`: integer, `default`: 0
232
+ - **Ruby Example**:
233
+ ```ruby
234
+ api.request_block({height: 0})
235
+ ```
236
+
237
+ ### Connection - get_validators_settings
238
+ - **Endpoint**: `/api/v1/GetValidatorsSettings`
239
+ - **Method**: `GET`
240
+ - **Parameters**:
241
+ - None
242
+ - **Ruby Example**:
243
+ ```ruby
244
+ api.get_validators_settings
245
+ ```
246
+
247
+ ### Contract - get_contracts
248
+ - **Endpoint**: `/api/v1/GetContracts`
249
+ - **Method**: `GET`
250
+ - **Parameters**:
251
+ - `chainAddressOrName`: string
252
+ - `extended`: boolean, `default`: true
253
+ - **Ruby Example**:
254
+ ```ruby
255
+ api.get_contracts({chainAddressOrName: 'string', extended: true})
256
+ ```
257
+
258
+ ### Contract - get_contract
259
+ - **Endpoint**: `/api/v1/GetContract`
260
+ - **Method**: `GET`
261
+ - **Parameters**:
262
+ - `chainAddressOrName`: string
263
+ - `contractName`: string
264
+ - **Ruby Example**:
265
+ ```ruby
266
+ api.get_contract({chainAddressOrName: 'string', contractName: 'string'})
267
+ ```
268
+
269
+ ### Contract - get_contract_by_address
270
+ - **Endpoint**: `/api/v1/GetContractByAddress`
271
+ - **Method**: `GET`
272
+ - **Parameters**:
273
+ - `chainAddressOrName`: string
274
+ - `contractAddress`: string
275
+ - **Ruby Example**:
276
+ ```ruby
277
+ api.get_contract_by_address({chainAddressOrName: 'string', contractAddress: 'string'})
278
+ ```
279
+
280
+ ### Leaderboard - get_leaderboard
281
+ - **Endpoint**: `/api/v1/GetLeaderboard`
282
+ - **Method**: `GET`
283
+ - **Parameters**:
284
+ - `name`: string
285
+ - **Ruby Example**:
286
+ ```ruby
287
+ api.get_leaderboard({name: 'string'})
288
+ ```
289
+
290
+ ### Nexus - get_nexus
291
+ - **Endpoint**: `/api/v1/GetNexus`
292
+ - **Method**: `GET`
293
+ - **Parameters**:
294
+ - `extended`: boolean, `default`: false
295
+ - **Ruby Example**:
296
+ ```ruby
297
+ api.get_nexus({extended: false})
298
+ ```
299
+
300
+ ### Organization - get_organization
301
+ - **Endpoint**: `/api/v1/GetOrganization`
302
+ - **Method**: `GET`
303
+ - **Parameters**:
304
+ - `id`: string
305
+ - `extended`: boolean, `default`: true
306
+ - **Ruby Example**:
307
+ ```ruby
308
+ api.get_organization({id: 'string', extended: true})
309
+ ```
310
+
311
+ ### Organization - get_organization_by_name
312
+ - **Endpoint**: `/api/v1/GetOrganizationByName`
313
+ - **Method**: `GET`
314
+ - **Parameters**:
315
+ - `name`: string
316
+ - `extended`: boolean, `default`: true
317
+ - **Ruby Example**:
318
+ ```ruby
319
+ api.get_organization_by_name({name: 'string', extended: true})
320
+ ```
321
+
322
+ ### Organization - get_organizations
323
+ - **Endpoint**: `/api/v1/GetOrganizations`
324
+ - **Method**: `GET`
325
+ - **Parameters**:
326
+ - `extended`: boolean, `default`: false
327
+ - **Ruby Example**:
328
+ ```ruby
329
+ api.get_organizations({extended: false})
330
+ ```
331
+
332
+ ### Platform - get_platforms
333
+ - **Endpoint**: `/api/v1/GetPlatforms`
334
+ - **Method**: `GET`
335
+ - **Parameters**:
336
+ - None
337
+ - **Ruby Example**:
338
+ ```ruby
339
+ api.get_platforms
340
+ ```
341
+
342
+ ### Platform - get_platform
343
+ - **Endpoint**: `/api/v1/GetPlatform`
344
+ - **Method**: `GET`
345
+ - **Parameters**:
346
+ - `platform`: string
347
+ - **Ruby Example**:
348
+ ```ruby
349
+ api.get_platform({platform: 'string'})
350
+ ```
351
+
352
+ ### Platform - get_interop
353
+ - **Endpoint**: `/api/v1/GetInterop`
354
+ - **Method**: `GET`
355
+ - **Parameters**:
356
+ - `platform`: string
357
+ - **Ruby Example**:
358
+ ```ruby
359
+ api.get_interop({platform: 'string'})
360
+ ```
361
+
362
+ ### Rpc - rpc
363
+ - **Endpoint**: `/rpc`
364
+ - **Method**: `POST`
365
+ - **Parameters**:
366
+ - None
367
+ - **Ruby Example**:
368
+ ```ruby
369
+ api.rpc
370
+ ```
371
+
372
+ ### Sale - get_latest_sale_hash
373
+ - **Endpoint**: `/api/v1/GetLatestSaleHash`
374
+ - **Method**: `GET`
375
+ - **Parameters**:
376
+ - None
377
+ - **Ruby Example**:
378
+ ```ruby
379
+ api.get_latest_sale_hash
380
+ ```
381
+
382
+ ### Sale - get_sale
383
+ - **Endpoint**: `/api/v1/GetSale`
384
+ - **Method**: `GET`
385
+ - **Parameters**:
386
+ - `hashText`: string
387
+ - **Ruby Example**:
388
+ ```ruby
389
+ api.get_sale({hashText: 'string'})
390
+ ```
391
+
392
+ ### Storage - read_image
393
+ - **Endpoint**: `/api/v1/ReadImage`
394
+ - **Method**: `GET`
395
+ - **Parameters**:
396
+ - `hashText`: string
397
+ - `format`: string, `default`: png
398
+ - **Ruby Example**:
399
+ ```ruby
400
+ api.read_image({hashText: 'string', format: 'png'})
401
+ ```
402
+
403
+ ### Token - get_tokens
404
+ - **Endpoint**: `/api/v1/GetTokens`
405
+ - **Method**: `GET`
406
+ - **Parameters**:
407
+ - `extended`: boolean, `default`: false
408
+ - **Ruby Example**:
409
+ ```ruby
410
+ api.get_tokens({extended: false})
411
+ ```
412
+
413
+ ### Token - get_token
414
+ - **Endpoint**: `/api/v1/GetToken`
415
+ - **Method**: `GET`
416
+ - **Parameters**:
417
+ - `symbol`: string
418
+ - `extended`: boolean
419
+ - **Ruby Example**:
420
+ ```ruby
421
+ api.get_token({symbol: 'string', extended: 'boolean'})
422
+ ```
423
+
424
+ ### Token - get_token_data
425
+ - **Endpoint**: `/api/v1/GetTokenData`
426
+ - **Method**: `GET`
427
+ - **Parameters**:
428
+ - `symbol`: string
429
+ - `IDtext`: string
430
+ - **Ruby Example**:
431
+ ```ruby
432
+ api.get_token_data({symbol: 'string', IDtext: 'string'})
433
+ ```
434
+
435
+ ### Token - get_nft
436
+ - **Endpoint**: `/api/v1/GetNFT`
437
+ - **Method**: `GET`
438
+ - **Parameters**:
439
+ - `symbol`: string
440
+ - `IDtext`: string
441
+ - `extended`: boolean, `default`: false
442
+ - **Ruby Example**:
443
+ ```ruby
444
+ api.get_nft({symbol: 'string', IDtext: 'string', extended: false})
445
+ ```
446
+
447
+ ### Token - get_nfts
448
+ - **Endpoint**: `/api/v1/GetNFTs`
449
+ - **Method**: `GET`
450
+ - **Parameters**:
451
+ - `symbol`: string
452
+ - `IDText`: string
453
+ - `extended`: boolean, `default`: false
454
+ - **Ruby Example**:
455
+ ```ruby
456
+ api.get_nfts({symbol: 'string', IDText: 'string', extended: false})
457
+ ```
458
+
459
+ ### Token - get_token_balance
460
+ - **Endpoint**: `/api/v1/GetTokenBalance`
461
+ - **Method**: `GET`
462
+ - **Parameters**:
463
+ - `account`: string
464
+ - `tokenSymbol`: string
465
+ - `chainInput`: string
466
+ - **Ruby Example**:
467
+ ```ruby
468
+ api.get_token_balance({account: 'string', tokenSymbol: 'string', chainInput: 'string'})
469
+ ```
470
+
471
+ ### Transaction - get_transaction_by_block_hash_and_index
472
+ - **Endpoint**: `/api/v1/GetTransactionByBlockHashAndIndex`
473
+ - **Method**: `GET`
474
+ - **Parameters**:
475
+ - `chainAddressOrName`: string
476
+ - `blockHash`: string
477
+ - `index`: integer
478
+ - **Ruby Example**:
479
+ ```ruby
480
+ api.get_transaction_by_block_hash_and_index({chainAddressOrName: 'string', blockHash: 'string', index: 'integer'})
481
+ ```
482
+
483
+ ### Transaction - get_address_transactions
484
+ - **Endpoint**: `/api/v1/GetAddressTransactions`
485
+ - **Method**: `GET`
486
+ - **Parameters**:
487
+ - `account`: string
488
+ - `page`: integer, `default`: 1
489
+ - `pageSize`: integer, `default`: 99999
490
+ - **Ruby Example**:
491
+ ```ruby
492
+ api.get_address_transactions({account: 'string', page: 1, pageSize: 99999})
493
+ ```
494
+
495
+ ### Transaction - get_address_transaction_count
496
+ - **Endpoint**: `/api/v1/GetAddressTransactionCount`
497
+ - **Method**: `GET`
498
+ - **Parameters**:
499
+ - `account`: string
500
+ - `chainInput`: string, `default`: main
501
+ - **Ruby Example**:
502
+ ```ruby
503
+ api.get_address_transaction_count({account: 'string', chainInput: 'main'})
504
+ ```
505
+
506
+ ### Transaction - send_raw_transaction
507
+ - **Endpoint**: `/api/v1/SendRawTransaction`
508
+ - **Method**: `GET`
509
+ - **Parameters**:
510
+ - `txData`: string
511
+ - **Ruby Example**:
512
+ ```ruby
513
+ api.send_raw_transaction({txData: 'string'})
514
+ ```
515
+
516
+ ### Transaction - invoke_raw_script
517
+ - **Endpoint**: `/api/v1/InvokeRawScript`
518
+ - **Method**: `GET`
519
+ - **Parameters**:
520
+ - `chainInput`: string
521
+ - `scriptData`: string
522
+ - **Ruby Example**:
523
+ ```ruby
524
+ api.invoke_raw_script({chainInput: 'string', scriptData: 'string'})
525
+ ```
526
+
527
+ ### Transaction - get_transaction
528
+ - **Endpoint**: `/api/v1/GetTransaction`
529
+ - **Method**: `GET`
530
+ - **Parameters**:
531
+ - `hashText`: string
532
+ - **Ruby Example**:
533
+ ```ruby
534
+ api.get_transaction({hashText: 'string'})
535
+ ```
536
+
537
+ ### Validator - get_validators
538
+ - **Endpoint**: `/api/v1/GetValidators`
539
+ - **Method**: `GET`
540
+ - **Parameters**:
541
+ - None
542
+ - **Ruby Example**:
543
+ ```ruby
544
+ api.get_validators
545
+ ```
546
+
547
+ ### Validator - get_validator_by_type
548
+ - **Endpoint**: `/api/v1/GetValidators/{type}`
549
+ - **Method**: `GET`
550
+ - **Parameters**:
551
+ - `type`: string
552
+ - **Ruby Example**:
553
+ ```ruby
554
+ api.get_validator_by_type({type: 'string'})
555
+ ```
556
+
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../helpers'
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ module Phantasma
8
+ module API
9
+
10
+ # API endpoints are autogenerated now Phantasma::Helpers.test_api_endpoints
11
+ # Special case is GetValidators/{type} => GetValidatorByType
12
+ ALLOWED_METHODS = %w[GetAccount GetAccounts GetAddressesBySymbol LookUpName GetAuction GetAuctionsCount GetAuctions
13
+ GetBlockByHash GetBlockByHeight GetBlockHeight GetBlockTransactionCountByHash GetLatestBlock GetRawBlockByHash GetRawBlockByHeight
14
+ GetRawLatestBlock GetChains GetChain abci_query GetValidatorsSettings health net_info request_block status GetContractByAddress GetContract GetContracts
15
+ GetLeaderboard GetNexus GetOrganizationByName GetOrganization GetOrganizations GetInterop GetPlatform GetPlatforms rpc
16
+ GetLatestSaleHash GetSale ReadImage GetNFT GetNFTs GetTokenBalance GetTokenData GetToken GetTokens GetAddressTransactionCount
17
+ GetAddressTransactions GetTransactionByBlockHashAndIndex GetTransaction InvokeRawScript SendRawTransaction GetValidators GetValidatorByType].freeze
18
+
19
+ def self.allowed_methods_hash
20
+ hash = {}
21
+ ALLOWED_METHODS.each { |value| hash["#{Phantasma::Helpers.camel_to_snake(value.strip)}"] = "#{value}" }
22
+ hash
23
+ end
24
+
25
+ def self.find_missing_endpoints
26
+ endpoints = (Phantasma::Helpers.test_api_endpoints - ALLOWED_METHODS)
27
+ # Special case, defined as GetValidatorByType int this gem
28
+ endpoints.delete('GetValidators/{type}')
29
+ endpoints
30
+ end
31
+
32
+ def self.find_deprecated_endpoints
33
+ endpoints = []
34
+ test_endpoints = Phantasma::Helpers.test_api_endpoints
35
+ ALLOWED_METHODS.each do |endpoint|
36
+ next if endpoint == 'GetValidatorByType'
37
+ unless test_endpoints.include?(endpoint.to_s)
38
+ endpoints << endpoint
39
+ end
40
+ end
41
+ endpoints
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'api'
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+ require 'openssl'
7
+
8
+ module Phantasma
9
+ module API
10
+ class Request
11
+ attr_accessor :url, :api_version, :debug
12
+
13
+ def initialize(url:, api_version: 'v1', debug: false)
14
+ @url = url
15
+ @api_version = api_version
16
+ @debug = debug
17
+ @allowed_methods_hash = Phantasma::API.allowed_methods_hash
18
+ end
19
+
20
+ def respond_to_missing?(method_name, include_private = false)
21
+ @allowed_methods_hash.include?(method_name.to_s) || super
22
+ end
23
+
24
+ def method_missing(method_name, *args, &block)
25
+ return super(method_name, *args, &block) unless @allowed_methods_hash.include?(method_name.to_s)
26
+ self.class.send(:define_method, method_name) do |*method_args|
27
+ build_request(method_name, method_args)
28
+ end
29
+ self.send(method_name, *args, &block)
30
+ end
31
+
32
+ private
33
+
34
+ def build_request(method_name, method_args)
35
+ uri, get_method = construct_uri(method_name, method_args)
36
+ request = create_request(uri, method_args, get_method)
37
+ response = execute_request(request, uri)
38
+ parse_response(response)
39
+ rescue PhantasmaResponseError => e
40
+ e
41
+ end
42
+
43
+ def construct_uri(method_name, method_args)
44
+ base_uri = "#{@url}/api/#{@api_version}/"
45
+ case method_name.to_s
46
+ when 'get_validator_by_type' && !method_args.empty?
47
+ raise PhantasmaResponseError, 'GetValidator type not specified' if method_args.first[:type].nil?
48
+ [URI("#{base_uri}GetValidators/#{method_args.first[:type]}"), true]
49
+ when 'rpc'
50
+ [URI("#{@url}/#{method_name.to_s}"), false]
51
+ else
52
+ [URI("#{base_uri}#{@allowed_methods_hash[method_name.to_s]}"), true]
53
+ end
54
+ end
55
+
56
+ def create_request(uri, method_args, get_method)
57
+ if get_method
58
+ uri.query = URI.encode_www_form(method_args.first) unless method_args.empty?
59
+ request = Net::HTTP::Get.new(uri)
60
+ else
61
+ request = Net::HTTP::Post.new(uri)
62
+ request.body = JSON.dump(method_args.first)
63
+ end
64
+ request['Content-Type'] = 'application/json'
65
+ request['Accept'] = 'application/json'
66
+ request
67
+ end
68
+
69
+ def execute_request(request, uri)
70
+ http = Net::HTTP.new(uri.host, uri.port)
71
+ if uri.scheme == 'https'
72
+ http.use_ssl = true
73
+ # http.verify_mode = OpenSSL::SSL::VERIFY_NONE
74
+ end
75
+ http.request(request)
76
+ end
77
+
78
+ def parse_response(response)
79
+ if response.is_a?(Net::HTTPSuccess)
80
+ JSON.parse(response.body)
81
+ else
82
+ raise PhantasmaResponseError, "{message: '#{response.message}', body: '#{response.body}', error: '#{response.class}'}"
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,89 @@
1
+ require_relative 'helpers'
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module Phantasma
7
+ class Documentation
8
+ # Based on test swagger json generate documentation
9
+ # https://testnet.phantasma.info/swagger/v1/swagger.json
10
+ SWAGGER_URL = 'https://testnet.phantasma.info/swagger/v1/swagger.json'
11
+
12
+ def self.generate_documentation
13
+ api_data = http_request
14
+ # Start generating the documentation
15
+ File.open(documentation_dir, 'w') do |file|
16
+ api_data['paths'].each do |path, methods|
17
+ methods.each do |method, details|
18
+ endpoint = path.gsub('/api/v1/', '')
19
+ if endpoint == 'GetValidators/{type}'
20
+ # special case
21
+ endpoint = 'GetValidatorByType'
22
+ end
23
+ ruby_method_name = Phantasma::Helpers.camel_to_snake(endpoint.split('/').last)
24
+ parameters = details['parameters'] || []
25
+
26
+ file.puts "### #{details['tags'].first} - #{ruby_method_name}"
27
+ file.puts "- **Endpoint**: `#{path}`"
28
+ file.puts "- **Method**: `#{method.upcase}`"
29
+ file.puts '- **Parameters**:'
30
+ if parameters.empty?
31
+ file.puts ' - None'
32
+ else
33
+ parameters.each do |param|
34
+ if param.dig('schema', 'default').nil?
35
+ file.puts " - `#{param['name']}`: #{param.dig('schema', 'type')}"
36
+ else
37
+ file.puts " - `#{param['name']}`: #{param.dig('schema',
38
+ 'type')}, `default`: #{param.dig('schema', 'default')}"
39
+ end
40
+ end
41
+ end
42
+ file.puts '- **Ruby Example**:'
43
+ file.puts '```ruby'
44
+ if parameters.empty?
45
+ file.puts "api.#{ruby_method_name}"
46
+ else
47
+ file.puts "api.#{ruby_method_name}(#{generate_ruby_hash(parameters) unless parameters.empty?})"
48
+ end
49
+ file.puts '```'
50
+ file.puts ''
51
+ end
52
+ end
53
+ end
54
+
55
+ puts "Documentation generated in #{documentation_dir}"
56
+ end
57
+
58
+ def self.http_request
59
+ url = URI(SWAGGER_URL)
60
+ https = Net::HTTP.new(url.host, url.port)
61
+ https.use_ssl = true
62
+ request = Net::HTTP::Get.new(url)
63
+ response = https.request(request)
64
+ json_data = response.read_body
65
+ JSON.parse(json_data)
66
+ end
67
+
68
+ def self.documentation_dir
69
+ "#{Dir.pwd.gsub('lib/phantasma', 'docs')}/api_documentation.md"
70
+ end
71
+
72
+ def self.generate_ruby_hash(parameters)
73
+ params = parameters.map do |param|
74
+ if param.dig('schema', 'default').nil?
75
+ "#{param['name']}: '#{param.dig('schema', 'type')}'"
76
+ else
77
+ if %w(boolean integer).include?(param.dig('schema', 'type'))
78
+ "#{param['name']}: #{param.dig('schema', 'default')}"
79
+ else
80
+ "#{param['name']}: '#{param.dig('schema', 'default')}'"
81
+ end
82
+ end
83
+ end
84
+ "{#{params.join(', ')}}"
85
+ end
86
+ end
87
+ end
88
+
89
+ Phantasma::Documentation.generate_documentation
@@ -0,0 +1,24 @@
1
+ module Phantasma
2
+ class Helpers
3
+ def self.camel_to_snake(str)
4
+ if str.to_s.match(/NFT/)
5
+ return str.to_s.gsub(/^([A-Z]{1}[a-z]+)([A-Z]+[a-z]?)$/, '\1_\2')
6
+ .tr('-', '_')
7
+ .downcase
8
+ end
9
+ str.to_s.gsub(/::/, '/')
10
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
11
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
12
+ .tr('-', '_')
13
+ .downcase
14
+ end
15
+
16
+ # this is for linux system to check if any new endpoints vs ALLOWED_ENDPOINTS
17
+ def self.test_api_endpoints
18
+ cmd = `curl -v --silent https://testnet.phantasma.info/swagger/v1/swagger.json 2>&1 | grep -oP '(?<=\/api\/v1/)(.+)(?=\".+$)'`
19
+ endpoints = cmd&.gsub(/\n/, ' ').strip.split(' ')
20
+ endpoints&.push('rpc')
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phantasma
4
+ VERSION = "0.1.0"
5
+ end
data/lib/phantasma.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'phantasma/API/request'
4
+ require_relative 'phantasma/helpers'
5
+ require_relative "phantasma/version"
6
+
7
+ module Phantasma
8
+ class Error < StandardError; end
9
+ class PhantasmaResponseError < StandardError; end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phantasma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Phantasma Community
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby Phantasma API library
14
+ email:
15
+ - ''
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - LICENSE.txt
22
+ - README.md
23
+ - Rakefile
24
+ - docs/api_documentation.md
25
+ - lib/phantasma.rb
26
+ - lib/phantasma/API/api.rb
27
+ - lib/phantasma/API/request.rb
28
+ - lib/phantasma/documentation.rb
29
+ - lib/phantasma/helpers.rb
30
+ - lib/phantasma/version.rb
31
+ homepage:
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ source_code_uri: https://github.com/MysteriousNothing/phantasma
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.3.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.0.9
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Community ediction of Phantasma API gem
55
+ test_files: []