test_sdk1 1.0.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +495 -76
  3. data/lib/crypto/asymmetric_key.rb +19 -18
  4. data/lib/crypto/ed25519_key.rb +99 -10
  5. data/lib/crypto/keys.rb +1 -2
  6. data/lib/crypto/keys_util.rb +20 -0
  7. data/lib/entity/auction_state.rb +56 -8
  8. data/lib/entity/bid.rb +1 -1
  9. data/lib/entity/bid_info.rb +1 -1
  10. data/lib/entity/block.rb +39 -0
  11. data/lib/entity/block_body.rb +35 -0
  12. data/lib/entity/block_header.rb +81 -0
  13. data/lib/entity/block_info.rb +56 -0
  14. data/lib/entity/block_proof.rb +24 -0
  15. data/lib/entity/deploy.rb +154 -1
  16. data/lib/entity/deploy_executable.rb +108 -6
  17. data/lib/entity/deploy_executable_item_internal.rb +1 -1
  18. data/lib/entity/deploy_header.rb +17 -0
  19. data/lib/entity/deploy_named_argument.rb +69 -2
  20. data/lib/entity/era_summary.rb +13 -12
  21. data/lib/entity/group.rb +1 -1
  22. data/lib/entity/module_bytes.rb +16 -2
  23. data/lib/entity/status.rb +80 -0
  24. data/lib/entity/stored_contract_by_name.rb +2 -1
  25. data/lib/entity/stored_value.rb +86 -11
  26. data/lib/entity/stored_versioned_contract_by_hash.rb +2 -1
  27. data/lib/entity/stored_versioned_contract_by_name.rb +1 -1
  28. data/lib/entity/transfer.rb +7 -7
  29. data/lib/include.rb +2 -0
  30. data/lib/rpc/rpc_client.rb +1 -2
  31. data/lib/serialization/cl_type_serializer.rb +1 -0
  32. data/lib/serialization/cl_value_serializer.rb +70 -12
  33. data/lib/serialization/cl_value_serializer1.rb +314 -0
  34. data/lib/serialization/cl_value_serializer_update.rb +320 -0
  35. data/lib/serialization/deploy_approval_serializer.rb +1 -0
  36. data/lib/serialization/deploy_executable_serializer.rb +1 -1
  37. data/lib/serialization/deploy_header_serializer.rb +2 -1
  38. data/lib/serialization/deploy_named_arg_serializer.rb +2 -0
  39. data/lib/serialization/deploy_serializer.rb +145 -10
  40. data/lib/serialization/deploy_serializer1.rb +392 -0
  41. data/lib/serialization/deploy_serializer_update.rb +397 -0
  42. data/lib/serialization/test.rb +33 -13
  43. data/lib/test_sdk1.rb +30 -13
  44. data/lib/types/cl_option.rb +8 -2
  45. data/lib/types/cl_public_key.rb +2 -0
  46. data/lib/types/cl_type.rb +1 -0
  47. data/lib/types/cl_value.rb +8 -0
  48. data/lib/utils/byte_utils.rb +28 -0
  49. data/lib/utils/helpers.rb +10 -0
  50. data/lib/version.rb +1 -1
  51. data/spec/cl_value_serializer_spec.rb +16 -1
  52. data/spec/client_spec.rb +20 -20
  53. data/spec/dene_spec.rb +186 -0
  54. data/spec/deploy_executable_spec.rb +90 -0
  55. data/spec/deploy_executable_test_spec.rb +117 -0
  56. data/spec/deploy_serializer_spec.rb +5 -3
  57. data/spec/deploy_serializer_test_spec.rb +7 -1
  58. data/spec/testnet_spec.rb +3 -1
  59. data/spec/time_utils_spec.rb +3 -0
  60. metadata +20 -5
  61. data/lib/crypto/key_pair.rb +0 -40
  62. data/spec/deploy_executable_serializer_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc912ab6a40cae5e4fb436cd53e64f9d8e312ef47d538dd2bb9aa82e31b12a39
4
- data.tar.gz: a560cc02719b199ce0ee21921aadcfbf1d6def7a5d92326de4bdf9539b9ff7fd
3
+ metadata.gz: 19df95113627970cd416e5bd602df39ec2d0791714803544df62302b6f0f490b
4
+ data.tar.gz: bedf1c745ccdaca73523d2c93885f3a15a6136adb8ed3ff01a8d3caa4afa7e38
5
5
  SHA512:
6
- metadata.gz: c26c3679268634a2f6859367b5caa1281589dcc01fbaeb189b7fda3d6ad710fd86d9d7329fdbb371eda4bbc032bd799cea3063f66d6739df2ce422539ee77763
7
- data.tar.gz: 359258d4d8bd9e817eda41ddc86644a618f897c0e412d18f14474934ea899e8694aaaa168b15ec8d44c326253edd8a75241c623769ff105e0c7a0898b65a5c1d
6
+ metadata.gz: da16ea0326db013e89e67e62903b7be37fb2fb6d91108e0045e4fb88f19f32fed30c1ec6d2b3d7ae9a36ec5125535100271acd8eec3e183a3e7fcf4fe25f7f3d
7
+ data.tar.gz: cf129cf4821b1f60a2b0a86f8751565ebe463736c92b1479f9f114cdb0e9fd01dced89510ac325c57db59e0581adb53e67bc6afa7ac311fa8be9848f56aa613d
data/README.md CHANGED
@@ -47,6 +47,20 @@ bundle exec rspec
47
47
  bundle exec rspec -fd
48
48
  ```
49
49
 
50
+ ## How run each test file individually
51
+ ```bash
52
+ git checkout main
53
+ # Run the test
54
+ rspec spec/file_name.rb
55
+ # To see the test results in detail
56
+ rspec -fd spec/file_name.rb
57
+ # Example:
58
+ rspec spec/testnet_spec.rb
59
+ # To see results in details
60
+ rspec -fd spec/testnet_spec.rb
61
+ ```
62
+
63
+
50
64
  ## How to generate docs
51
65
  ```bash
52
66
  gem install yard
@@ -56,92 +70,497 @@ yardoc lib/**/*.rb lib/*.rb - README.md LICENSE CONTRIBUTING.md SECURITY.md
56
70
  yardoc --help
57
71
  ```
58
72
 
73
+ ## Documentation
74
+
75
+ The SDK documentation can be found [here](https://www.rubydoc.info/gems/casper_network/1.0.2) in detail.
76
+
77
+ ### Serialization
78
+ Casper provides a custom implementation to serialize data structures used by the Casper node to their byte representation.
79
+ More information on this custom implementation can be found [here](https://caspernetwork.readthedocs.io/en/latest/implementation/serialization-standard.html).
80
+
81
+ * [Serialization](https://github.com/saitgulmez/testing/blob/main/docs/serialization.md#serialization)
82
+ * [Examples](https://github.com/saitgulmez/testing/blob/main/docs/serialization.md#examples)
83
+
84
+ ### Key Management
85
+ * [CLPublicKey](https://github.com/saitgulmez/testing/blob/main/docs/keys.md#public-keys)
86
+
87
+ ### Casper-Ruby-Sdk RPC
88
+ * [info_get_peers](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#info_get_peers)
89
+ * [chain_get_StateRootHash](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-state_root_hash)
90
+ * [info_get_deploy](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-deploy)
91
+ * [info_get_status](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-status)
92
+ * [chain_get_block_transfers](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-block-transfers)
93
+ * [chain_get_block](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-block-by-hash)
94
+ * [chain_get_eraInfo_by_SwitchBlock](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-era-summary-by-switch-block-hash)
95
+ * [state_get_item](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get--state-item)
96
+ * [state_get_dictionary_item](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-dictionary-item)
97
+ * [state_get_balance](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-account-balance)
98
+ * [state_get_AuctionInfo](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-auction-state)
99
+ * [put_deploy](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#put-deploy)
100
+
101
+
59
102
  ## Usage examples
60
- ### Get 5 peer IP addresses randomly
103
+
104
+ ## Include 'casper_network' gem into the source file
105
+
61
106
  ```ruby
62
107
  require 'casper_network'
108
+ ```
109
+ ## Create a Client
110
+
111
+ Pass the node ip address to constructor
112
+
113
+ ```ruby
114
+ node_ip_address = "5.9.23.55" # IP is taken from "testnet"
115
+ client = Casper::CasperClient.new(node_ip_address)
116
+ ```
117
+ ## RPC Calls
118
+
119
+ ### Get network peers list
120
+
121
+ Retrieves the list of connected peers.
122
+
123
+ ```ruby
124
+ peers = client.info_get_peers
125
+ # Retrieve to the first peer object
126
+ peer = peers[0]
127
+ # Retrieve to info of the first peer object
128
+ node_id = peer[0].get_node_id
129
+ address = peer[0].get_address
130
+ ```
131
+
132
+ ### Get State Root Hash
133
+
134
+ Retrieves the state root hash String.
135
+
136
+ ```ruby
137
+ state_root_hash = client.chain_get_StateRootHash
138
+ ```
139
+
140
+ ### Get Deploy
63
141
 
64
- # In order to interact with casper network we should give a valid ip address to the constructor
142
+ Retrieves a Deploy object from the network.
65
143
 
66
- # if it does not work, please choose another node ip address from the Testnet
67
- # IP is taken from "Testnet"
68
- node_ip_address = "85.114.132.129"
144
+ call parameters :
145
+ - deploy hash
146
+
147
+ ```ruby
148
+ deploy_hash = "0806cc477a5282574bc5302d7598cd33a09875704c5fef9264d984535c945e31"
149
+ deploy = client.info_get_deploy(deploy_hash)
150
+ # Deploy members
151
+ hash = Casper::Entity::DeployHash.new(deploy.get_hash)
152
+ header = Casper::Entity::DeployHeader.new(deploy.get_header)
153
+ payment = deploy.get_payment
154
+ session = deploy.get_session
155
+ ```
156
+
157
+ ### Get Node Status
158
+
159
+ Retrieves the current status of the node.
160
+
161
+ ```ruby
162
+ node_status = client.info_get_status
163
+ # Examples of retrieving and printing the members of node status
164
+ puts node_status.get_api_version
165
+ puts node_status.get_chainspec_name
166
+ puts node_status.get_starting_state_root_hash
167
+ puts node_status.get_peers
168
+ puts node_status.get_last_added_block_info
169
+ puts node_status.get_our_public_signing_key
170
+ puts node_status.get_round_length
171
+ puts node_status.get_next_upgrade
172
+ puts node_status.get_build_version
173
+ puts node_status.get_uptime
174
+ ```
175
+
176
+ ### Get BlockTransfers
177
+
178
+ Retrieve all transfers for a Block from the network
179
+
180
+ ```ruby
69
181
  # block_Hash taken from Testnet
70
- block_hash = "71e19e2e9629c716dc9578066cfeceace559d32fe51b08245ddd4d218f8c18da"
71
- # deploy_Hash taken from Testnet
72
- deploy_hash = "d3e0a1bd85ee74916e096cf4b18df391ada414d0915aeb865eff0ba75f04c3d8"
73
- state_root_hash = "2a62440a1e1e57bff71344aac8a7de169f6dd08d29cffe83b2fb5d6648971855"
182
+ block_hash = "ff2ad232c3efc22a385fce44df844fc696e904ce8ba78599a576aa68c76889c4"
183
+ transfers = client.chain_get_block_transfers(block_hash)
184
+ # Examples of accessing and printing the members of each transfer object
185
+ transfers.each do |transfer|
186
+ puts transfer.get_deploy_hash
187
+ puts transfer.get_from
188
+ puts transfer.get_to
189
+ puts transfer.get_source
190
+ puts transfer.get_target
191
+ puts transfer.get_amount
192
+ puts transfer.get_gas
193
+ puts transfer.get_id
194
+ end
195
+ ```
196
+
197
+ ### Get Block
198
+
199
+ Retrieve a Block object from the network
200
+
201
+ ```ruby
202
+ block_hash = "ff2ad232c3efc22a385fce44df844fc696e904ce8ba78599a576aa68c76889c4"
203
+ block = client.chain_get_block(block_hash)
204
+ puts block # => It is an instance of Block
205
+ # To retrieve BlockHeader object
206
+ block_header = block.get_header
207
+ puts block_header
208
+ # To access and print members of the block_header object (block_header is an instance of BlockHeader )
209
+ puts block_header.get_parent_hash
210
+ puts block_header.get_state_root_hash
211
+ puts block_header.get_body_hash
212
+ puts block_header.get_random_bit
213
+ puts block_header.get_accumulated_seed
214
+ puts block_header.get_era_end
215
+ puts block_header.get_timestamp
216
+ puts block_header.get_era_id
217
+ puts block_header.get_height
218
+ puts block_header.get_protocol_version
219
+
220
+ # To retrieve BlockBody object
221
+ block_body = block.get_body
222
+ # To access and print members of the block_body object (block_body is an instance of BlockBody )
223
+ puts block_body
224
+ puts block_body.get_proposer
225
+ puts block_body.get_deploy_hashes
226
+ puts block_body.get_transfer_hashes
227
+
228
+ # To retrieve an array of BlockProof objects
229
+ proofs = block.get_proofs
230
+ # To access and print members of the block_proof objects (block_proof is an instance of BlockProof )
231
+ puts proofs
232
+ # To access and print each proof object and its members
233
+ i = 0
234
+ proofs.each do |proof|
235
+ puts "proofs[#{i}]: #{proof}"
236
+ puts "public_key: " + proof.get_public_key
237
+ puts "signature: " + proof.get_signature
238
+ i += 1
239
+ end
240
+ ```
241
+
242
+ ### Get EraInfo By Switch Block
243
+
244
+ Retrieves an EraSummury object.
245
+
246
+ ```ruby
247
+ block_hash = "d2077716e5b8796723c5720237239720f54e6ada54e3357f2c4896f2a51a6d8f"
248
+ era_summary = client.chain_get_eraInfo_by_SwitchBlock(block_hash)
249
+ puts era_summary # => It is an instance of EraSummary
250
+ puts era_summary.get_block_hash
251
+ puts era_summary.get_era_id
252
+ puts era_summary.get_stored_value # => Retrieve and print the instance of StoredValue
253
+ puts era_summary.get_stored_value.get_stored_value
254
+ puts era_summary.get_state_root_hash
255
+ puts era_summary.get_merkle_proof
256
+ ```
257
+
258
+ ### Get StateItem
259
+
260
+ Retrieves a StoredValue object.
261
+
262
+ ```ruby
263
+ node_ip_address = "65.108.78.120" # => Taken from the Mainnet
264
+ client = Casper::CasperClient.new(node_ip_address)
265
+ # Retrieve the stored_value object which is an instance of StoredValue
266
+ stored_value = client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
267
+ puts stored_value # => #<Casper::Entity::StoredValue:0x0000000003767a48>
268
+ puts stored_value.get_key # => Bid
269
+ puts stored_value.get_bid # => Retrieve and print Bid object related data
270
+ # or
271
+ puts stored_value.get_stored_value # => Retrieve and print Bid object related data
272
+ ```
273
+
274
+ ### Get DictionaryItem
275
+
276
+ Retrieves a CLValue object.
277
+
278
+ ```ruby
279
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
280
+ client = Casper::CasperClient.new(node_ip_address)
281
+ state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
74
282
  item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
75
- uref = "uref-9199d08ff4ca4d52cd7a05ba0d2694204b7ebff963fec1c216f81bf654e0e59f-007"
76
- switch_block_hash = "9e30104581a492f5c6faad4cdfb098311e3bf0e93897ebbfb47c3df62f5e6375"
283
+ uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
284
+ # Retrieve folowing data from the network and convert it into its proper CLValue
285
+ # {"CLValue"=>{"cl_type"=>"String", "bytes"=>"1a00000068747470733a2f2f636173706572636f6d6d756e6974792e696f", "parsed"=>"https://caspercommunity.io"}}
286
+ stored_value = client.state_get_dictionary_item(state_root_hash, item_key, uref)
287
+ puts stored_value # => #<CLString:0x0000000002b3c8e0>
288
+ puts stored_value.get_cl_type # => String
289
+ puts stored_value.get_value # => https://caspercommunity.io
290
+ puts CLValueBytesParsers::CLStringBytesParser.to_bytes(stored_value.get_value) # => 1a00000068747470733a2f2f636173706572636f6d6d756e6974792e696f
291
+ ```
292
+
293
+ ### Get Balance
294
+
295
+ Retrieves the balances(in motes) of an account
296
+
297
+ Parameters :
298
+
299
+ - state root hash
300
+ - account uref hash
301
+
302
+ ```ruby
303
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
304
+ client = Casper::CasperClient.new(node_ip_address)
305
+ state_root_hash = "610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5"
306
+ uref = "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007"
307
+ balance = client.state_get_balance(state_root_hash, uref)
308
+ puts balance # => 29269647684075 (current balance 9/24/2022)
309
+ ```
310
+
311
+ ### Get current auction state
77
312
 
313
+ Retrieves an AutionState object.
78
314
 
79
- # Uncomment following lines to test on Mainnet
80
- # if it does not work, please choose another node ip address from the Mainnet
81
- # IP is taken from "Mainnet"
82
- # node_ip_address = "65.108.78.12"
315
+ call parameters :
316
+ - block hash
317
+
318
+ ```ruby
83
319
  # block_Hash taken from MainNet
84
- # block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
85
- # # deploy_Hash taken from MainNet
86
- # deploy_hash = "52a40996a88523c475c12e5370ff90b0ae4ec051cfaa57cd048c136b1a83319d"
87
- # state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
88
- # item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
89
- # uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
90
- # switch_block_hash = "4696285db1ca6572f425cada612257f85a58a6a4034c09846afe360ba40e5df0"
91
-
92
- if (IPAddress.valid? node_ip_address)
93
- client = Casper::CasperClient.new(node_ip_address)
94
- peers = client.info_get_peers.sample(5)
95
- puts "node_id and address of five randomly selected 5 peers:"
96
- puts peers
97
-
98
- # Store ip addresses of these peers into an array
99
- ips = []
100
- peers.select do |item|
101
- ip = item["address"]
102
- ips << ip[0, ip.index(':')]
103
- end
104
-
105
- clients = []
106
- puts "Randomly selected 5 peers ip addresses:"
107
- ips.each do |ip_address|
108
- # Create a client object for each iteration
109
- puts ip_address
110
- client = CasperClient.new(ip_address)
111
- clients.push(client)
112
- end
113
-
114
-
115
- clients.each do |client|
116
- puts client.info_get_peers
117
- puts client.chain_get_StateRootHash(block_hash)
118
- puts client.chain_get_StateRootHash
119
- puts client.info_get_deploy(deploy_hash)
120
- puts client.info_get_status
121
- puts client.chain_get_block_transfers(block_hash)
122
- puts client.chain_get_block_transfers
123
- puts client.chain_get_block(block_hash)
124
- puts client.chain_get_eraInfo_by_SwitchBlock(switch_block_hash)
125
- puts client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
126
- puts client.state_get_dictionary_item(state_root_hash, item_key, uref)
127
- state_root_hash = "610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5"
128
- uref = "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007"
129
- puts client.state_get_balance(state_root_hash, uref)
130
- puts client.state_get_AuctionInfo
131
-
132
- end
133
- else
134
- puts "Invalid IP address"
135
- end
320
+ block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
321
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
322
+ client = Casper::CasperClient.new(node_ip_address)
323
+ auction = client.state_get_AuctionInfo
324
+ # Retrieve and print an instance of AuctionState entity
325
+ puts auction # => #<Casper::Entity::AuctionState:0x0000000003306bc0>
326
+ # Retrieve and print state root hash as a String value
327
+ puts auction.get_state_root_hash # => "6448b55f1dd7c9ad337f4fd4c77586d7ae30da146e0b340932aba7e7efa9cbcb"
328
+ # Retrieve and print block height as an Integer value
329
+ puts auction.get_block_height # => 1128800
330
+ # Retrieve and print an array of instances of EraValidor entity
331
+ puts auction.get_era_validators # => [#<Casper::Entity::EraValidator:0x0000000002b69980>, #<Casper::Entity::EraValidator:0x0000000002b68940>]
332
+ # Retrieve and print an array of instances of Bid entity
333
+ puts auction.get_bids # => [#<Casper::Entity::Bid:0x000000000430bcf0>, #<Casper::Entity::Bid:0x000000000430b6d8>....]
334
+
335
+ # Retrieve and print an instance of BidInfo, which is also the member of bid object
336
+ bids = auction.get_bids
337
+ bid = bids[0] # => #<Casper::Entity::Bid:0x0000000003773dc0>
338
+ bid_info = bid.get_bid_info # => #<Casper::Entity::BidInfo:0x00000000042cffc0>
339
+ # Retrieve and print an array of delegator objects, which are instance of Delegator entity
340
+ delegators = bid_info.get_delegators
341
+ puts delegators # => [#<Casper::Entity::Delegator:0x000000000396c550>, #<Casper::Entity::Delegator:0x000000000396c500>.....]
342
+ # How to access members of one of the above delegator instances
343
+ # For instance, access to stake amount at first delegator
344
+ delegator = delegators[0]
345
+ stake_amount = delegator.get_staked_amount # => 27871095039894
346
+ ```
347
+
348
+
349
+ ### Example
350
+ ```bash
351
+ # example.rb
352
+ # how to execute example.rb
353
+ $ ruby example.rb
136
354
  ```
137
- - [Testnet](https://testnet.cspr.live/tools/peers), [Mainnet](https://cspr.live/tools/peers)
138
- - [doc](https://www.rubydoc.info/gems/casper_network/0.2.1)
139
355
 
356
+ ```ruby
357
+ # example.rb
358
+ require 'casper_network'
359
+ # Class-Object Level
360
+ # Casper::CasperClient
361
+ node_ip_address = "5.9.23.55" # IP is taken from "testnet"
362
+ client = Casper::CasperClient.new(node_ip_address)
363
+
364
+ #********** info_get_peers *********************************#
365
+
366
+ # Uncomment following lines to see the outputs
367
+ # puts client.info_get_peers
368
+ # puts client.info_get_peers[0].get_node_id
369
+ # puts client.info_get_peers[0].get_address
370
+
371
+
372
+ #********** chain_get_StateRootHash *********************************#
373
+ # Uncomment following line to see the outputs
374
+ # puts client.chain_get_StateRootHash
375
+
376
+
377
+ #********** info_get_deploy(deploy_hash) *********************************#
378
+ deploy_hash = "0806cc477a5282574bc5302d7598cd33a09875704c5fef9264d984535c945e31"
379
+ deploy = client.info_get_deploy(deploy_hash)
380
+ # Uncomment following lines to see the outputs
381
+ # puts deploy
382
+ # hash = Casper::Entity::DeployHash.new(deploy.get_hash)
383
+ # puts hash
384
+ # header = Casper::Entity::DeployHeader.new(deploy.get_header)
385
+ # puts header
386
+ # payment = deploy.get_payment
387
+ # puts payment
388
+ # session = deploy.get_session
389
+ # puts session
390
+
391
+ # approvals = []
392
+ # num_of_approvals = deploy.get_approvals.size
393
+ # num_of_approvals.times do |i|
394
+ # approvals.push(Casper::Entity::DeployApproval.new(deploy.get_approvals[i]))
395
+ # end
396
+ # puts approvals[0].get_signer
397
+ # puts hash, header, payment, session, approvals
398
+
399
+ #********** info_get_status *********************************#
400
+ node_status = client.info_get_status
401
+ # Uncomment following lines to see the outputs
402
+ # puts node_status
403
+ # puts node_status.get_api_version
404
+ # puts node_status.get_chainspec_name
405
+ # puts node_status.get_starting_state_root_hash
406
+ # puts node_status.get_peers
407
+ # puts node_status.get_last_added_block_info
408
+ # puts node_status.get_our_public_signing_key
409
+ # puts node_status.get_round_length
410
+ # puts node_status.get_next_upgrade
411
+ # puts node_status.get_build_version
412
+ # puts node_status.get_uptime
413
+
414
+ #********** chain_get_block_transfers(block_hash = "") *********************************#
415
+ # block_Hash taken from Testnet
416
+ block_hash = "ff2ad232c3efc22a385fce44df844fc696e904ce8ba78599a576aa68c76889c4"
417
+ transfers = client.chain_get_block_transfers(block_hash)
418
+ # Uncomment following lines to see the outputs
419
+ # puts transfers
420
+ # transfers.each do |transfer|
421
+ # puts transfer.get_deploy_hash
422
+ # puts transfer.get_from
423
+ # puts transfer.get_to
424
+ # puts transfer.get_source
425
+ # puts transfer.get_target
426
+ # puts transfer.get_amount
427
+ # puts transfer.get_gas
428
+ # puts transfer.get_id
429
+ # end
430
+
431
+
432
+
433
+ #********** chain_get_block(block_hash) *********************************#
434
+ block_hash = "ff2ad232c3efc22a385fce44df844fc696e904ce8ba78599a576aa68c76889c4"
435
+ block = client.chain_get_block(block_hash)
436
+ # Uncomment following lines to see the outputs
437
+ # puts block
438
+ # To retrieve BlockHeader object
439
+ # block_header = block.get_header
440
+ # puts block_header
441
+ # To access and print members of the block_header object (block_header is an instance of BlockHeader )
442
+ # puts block_header.get_parent_hash
443
+ # puts block_header.get_state_root_hash
444
+ # puts block_header.get_body_hash
445
+ # puts block_header.get_random_bit
446
+ # puts block_header.get_accumulated_seed
447
+ # puts block_header.get_era_end
448
+ # puts block_header.get_timestamp
449
+ # puts block_header.get_era_id
450
+ # puts block_header.get_height
451
+ # puts block_header.get_protocol_version
452
+
453
+ # To retrieve BlockBody object
454
+ # block_body = block.get_body
455
+ # To access and print members of the block_body object (block_body is an instance of BlockBody )
456
+ # puts block_body
457
+ # puts block_body.get_proposer
458
+ # puts block_body.get_deploy_hashes
459
+ # puts block_body.get_transfer_hashes
460
+
461
+ # To retrieve an array of BlockProof objects
462
+ # proofs = block.get_proofs
463
+ # To access and print members of the block_proof objects (block_proof is an instance of BlockProof )
464
+ # puts proofs
465
+ # To access and print each proof object and its members
466
+ # i = 0
467
+ # proofs.each do |proof|
468
+ # puts "proofs[#{i}]: #{proof}"
469
+ # puts "public_key: " + proof.get_public_key
470
+ # puts "signature: " + proof.get_signature
471
+ # i += 1
472
+ # end
473
+
474
+
475
+
476
+ #********** chain_get_eraInfo_by_SwitchBlock(block_hash) *********************************#
477
+ block_hash = "d2077716e5b8796723c5720237239720f54e6ada54e3357f2c4896f2a51a6d8f"
478
+ era_summary = client.chain_get_eraInfo_by_SwitchBlock(block_hash)
479
+ # Uncomment following lines to see the outputs
480
+ # puts era_summary
481
+ # puts era_summary.get_block_hash
482
+ # puts era_summary.get_era_id
483
+ # puts era_summary.get_stored_value
484
+ # puts era_summary.get_stored_value.get_stored_value
485
+ # puts era_summary.get_state_root_hash
486
+ # puts era_summary.get_merkle_proof
487
+ # era_summary.map { |k, v| puts "#{k}" }
488
+ #
489
+
490
+
491
+
492
+ #********** state_get_item(state_root_hash, key, path) *********************************#
493
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
494
+ client = Casper::CasperClient.new(node_ip_address)
495
+ # Retrieve the stored_value object which is an instance of StoredValue
496
+ # Uncomment following lines to see the outputs
497
+ stored_value = client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
498
+ # puts stored_value # => #<Casper::Entity::StoredValue:0x0000000003767a48>
499
+ # puts stored_value.get_key # => Bid
500
+ # puts stored_value.get_bid # => Retrieve and print Bid object related data
501
+ # # or
502
+ # puts stored_value.get_stored_value # => Retrieve and print Bid object related data
503
+
504
+
505
+
506
+
507
+ #********** state_get_dictionary_item(state_root_hash, item_key, uref) *********************************#
508
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
509
+ client = Casper::CasperClient.new(node_ip_address)
510
+ state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
511
+ item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
512
+ uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
513
+ # # Retrieve folowing data from the network and convert it into its proper CLValue
514
+ # # {"CLValue"=>{"cl_type"=>"String", "bytes"=>"1a00000068747470733a2f2f636173706572636f6d6d756e6974792e696f", "parsed"=>"https://caspercommunity.io"}}
515
+
516
+ # Uncomment following lines to see the outputs
517
+ # stored_value = client.state_get_dictionary_item(state_root_hash, item_key, uref)
518
+ # puts stored_value # => #<CLString:0x0000000002b3c8e0>
519
+ # puts stored_value.get_cl_type # => String
520
+ # puts stored_value.get_value # => https://caspercommunity.io
521
+ # puts CLValueBytesParsers::CLStringBytesParser.to_bytes(stored_value.get_value) # => 1a00000068747470733a2f2f636173706572636f6d6d756e6974792e696f
522
+
523
+
524
+
525
+ #********** state_get_balance(state_root_hash, balance_uref) *********************************#
526
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
527
+ client = Casper::CasperClient.new(node_ip_address)
528
+ state_root_hash = "610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5"
529
+ uref = "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007"
530
+
531
+ # Uncomment following lines to see the outputs
532
+ # balance = client.state_get_balance(state_root_hash, uref)
533
+ # puts balance # => 29269647684075 (current balance 9/24/2022)
534
+
535
+
536
+ #********** state_get_AuctionInfo *********************************#
537
+ # block_Hash taken from MainNet
538
+ block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
539
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
540
+ client = Casper::CasperClient.new(node_ip_address)
541
+
542
+ # Uncomment following lines to see the outputs
543
+ # auction = client.state_get_AuctionInfo
544
+ # Retrieve and print an instance of AuctionState entity
545
+ # puts auction # => #<Casper::Entity::AuctionState:0x0000000003306bc0>
546
+ # Retrieve and print state root hash as a String value
547
+ # puts auction.get_state_root_hash # => "6448b55f1dd7c9ad337f4fd4c77586d7ae30da146e0b340932aba7e7efa9cbcb"
548
+ # Retrieve and print block height as an Integer value
549
+ # puts auction.get_block_height # => 1128800
550
+ # Retrieve and print an array of instances of EraValidor entity
551
+ # puts auction.get_era_validators # => [#<Casper::Entity::EraValidator:0x0000000002b69980>, #<Casper::Entity::EraValidator:0x0000000002b68940>]
552
+ # Retrieve and print an array of instances of Bid entity
553
+ # puts auction.get_bids # => [#<Casper::Entity::Bid:0x000000000430bcf0>, #<Casper::Entity::Bid:0x000000000430b6d8>....]
140
554
 
141
- ## TODO
142
- - [x] Ruby version of CLType primitives
143
- - [x] Ruby version for Casper domain-specific objects
144
- - [x] Serialization of Casper domain-specific objects
145
- - [ ] ED25519/SECP256K1 key pairs Wrappers implemented
146
- - [ ] PutDeploy call implemented and tested
147
- - [x] SDK calls will return Casper domain-specific objects
555
+ # Retrieve and print an instance of BidInfo, which is also the member of bid object
556
+ # bids = auction.get_bids
557
+ # bid = bids[0] # => #<Casper::Entity::Bid:0x0000000003773dc0>
558
+ # bid_info = bid.get_bid_info # => #<Casper::Entity::BidInfo:0x00000000042cffc0>
559
+ # Retrieve and print an array of delegator objects, which are instance of Delegator entity
560
+ # delegators = bid_info.get_delegators
561
+ # puts delegators # => [#<Casper::Entity::Delegator:0x000000000396c550>, #<Casper::Entity::Delegator:0x000000000396c500>.....]
562
+ # How to access members of one of the above delegator instances
563
+ # For instance, access to stake amount at first delegator
564
+ # delegator = delegators[0]
565
+ # stake_amount = delegator.get_staked_amount # => 27871095039894
566
+ ```
@@ -3,15 +3,15 @@ require_relative '../types/cl_public_key.rb'
3
3
  require_relative '../utils/hex_utils.rb'
4
4
  require_relative '../utils/hash_utils.rb'
5
5
 
6
- CLPublicKeyTag = {
7
- ED25519: 1,
8
- SECP256K1: 2
9
- }
6
+ # CLPublicKeyTag = {
7
+ # ED25519: 1,
8
+ # SECP256K1: 2
9
+ # }
10
10
 
11
- SignatureAlgorithm = {
12
- Ed25519: 'ed25519',
13
- Secp256K1: 'secp256k1'
14
- }
11
+ # SignatureAlgorithm = {
12
+ # Ed25519: 'ed25519',
13
+ # Secp256K1: 'secp256k1'
14
+ # }
15
15
 
16
16
  class AsymmetricKey
17
17
  attr_reader :public_key, :private_key, :signature_algorithm
@@ -19,7 +19,8 @@ class AsymmetricKey
19
19
  # @param [CLPublicKey] public_key
20
20
  # @param [Array] private_key
21
21
  # @param [SignatureAlgorithm] signature_algorithm
22
- def initialize(public_key, private_key, signature_algorithm)
22
+ def initialize(public_key = CLPublicKey.new([204, 238, 25, 54, 110, 175, 3, 72, 124, 184, 17, 151, 174, 142, 220,
23
+ 177, 180, 127, 33, 76, 238, 0, 214, 89, 115, 128, 9, 107, 159, 132, 99, 193], 1), private_key = nil, signature_algorithm = nil)
23
24
  @public_key = public_key
24
25
  @private_key = private_key
25
26
  @signature_algorithm = signature_algorithm
@@ -49,15 +50,15 @@ class AsymmetricKey
49
50
  end
50
51
 
51
52
  # @return [Array<Integer>]
52
- def account_hash
53
- @tag = @public_key.get_cl_public_key_tag
54
- key_name = CLPublicKeyTag.key(@tag).to_s
55
- prefix = key_name.downcase.unpack("C*") + [0]
56
- bytes = prefix + @public_key.get_value
57
- result_array = Utils::HashUtils.byte_hash(bytes)
58
- @public_key.get_value.length == 0 ? [] : result_array
59
- #*** @public_key.to_account_hash_byte_array
60
- end
53
+ # def account_hash
54
+ # @tag = @public_key.get_cl_public_key_tag
55
+ # key_name = CLPublicKeyTag.key(@tag).to_s
56
+ # prefix = key_name.downcase.unpack("C*") + [0]
57
+ # bytes = prefix + @public_key.get_value
58
+ # result_array = Utils::HashUtils.byte_hash(bytes)
59
+ # @public_key.get_value.length == 0 ? [] : result_array
60
+ # #*** @public_key.to_account_hash_byte_array
61
+ # end
61
62
 
62
63
  # @param [String] path_to_private_key
63
64
  def create_from_private_key_file(path_to_private_key)