test_sdk1 1.0.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +478 -89
  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/module_bytes.rb +16 -2
  22. data/lib/entity/status.rb +80 -0
  23. data/lib/entity/stored_value.rb +86 -11
  24. data/lib/entity/transfer.rb +7 -7
  25. data/lib/include.rb +2 -0
  26. data/lib/serialization/cl_value_serializer.rb +69 -12
  27. data/lib/serialization/cl_value_serializer1.rb +314 -0
  28. data/lib/serialization/cl_value_serializer_update.rb +320 -0
  29. data/lib/serialization/deploy_header_serializer.rb +1 -0
  30. data/lib/serialization/deploy_named_arg_serializer.rb +1 -0
  31. data/lib/serialization/deploy_serializer.rb +144 -10
  32. data/lib/serialization/deploy_serializer1.rb +392 -0
  33. data/lib/serialization/deploy_serializer_update.rb +397 -0
  34. data/lib/serialization/test.rb +33 -13
  35. data/lib/test_sdk1.rb +29 -10
  36. data/lib/types/cl_option.rb +8 -2
  37. data/lib/types/cl_public_key.rb +2 -0
  38. data/lib/types/cl_value.rb +8 -0
  39. data/lib/utils/byte_utils.rb +28 -0
  40. data/lib/utils/helpers.rb +10 -0
  41. data/lib/version.rb +1 -1
  42. data/spec/cl_value_serializer_spec.rb +16 -1
  43. data/spec/dene_spec.rb +186 -0
  44. data/spec/deploy_executable_spec.rb +90 -0
  45. data/spec/deploy_executable_test_spec.rb +117 -0
  46. data/spec/deploy_serializer_spec.rb +5 -3
  47. data/spec/deploy_serializer_test_spec.rb +7 -1
  48. data/spec/testnet_spec.rb +3 -1
  49. data/spec/time_utils_spec.rb +3 -0
  50. metadata +20 -5
  51. data/lib/crypto/key_pair.rb +0 -40
  52. data/spec/deploy_executable_serializer_spec.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b89def3f15a842a7ddc8c15b72f04e2cddf49b781fb8d838addcd7854e5dfc4
4
- data.tar.gz: 980521ad36c1ea8acc77e573ff24cd961d3de5f55e12e3a609d2a64b2ec5e074
3
+ metadata.gz: 6845c5cbad03a00aac1310e21090b6a2e6bcff8e797086439d5721fecfd564d0
4
+ data.tar.gz: 0ef9e05f4e649b8dd6acffffdccb747f0bbab8de7e4a705ffe6740ff369a9541
5
5
  SHA512:
6
- metadata.gz: 15907f268c7f6e4fb4f30ca4bb42518c545d8c01f6803db931381ac76a22c360771a788e435062d862302ba3b4e7da320f2a0069dba9c984b2cbe4bad7907757
7
- data.tar.gz: fce9046fe2e0f2978f949b8c2ae09585a5936225b50137a622f48f0c87ac101c1b92d11bb4b89d90030e89ed3d6d4ea51794a21908bbb8061c7c486be4f106fd
6
+ metadata.gz: a9780e76722ff64de3f36c618a6cd617cedb608791ed14b0e2911ff3d9e95ae60d144764bf5bce510428329973eab4f81cd65b858900e14011db40c2a50a6f52
7
+ data.tar.gz: 2540a2b8a4ebcce73cb25ac9c405d4cff4c108d4bbc38acef41c332e2a130b432287f11783038b673c18acf1e91a7ffdf8581913212ffecc2ed12beffc45478f
data/README.md CHANGED
@@ -70,108 +70,497 @@ yardoc lib/**/*.rb lib/*.rb - README.md LICENSE CONTRIBUTING.md SECURITY.md
70
70
  yardoc --help
71
71
  ```
72
72
 
73
- ## Documentation:
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
+
74
87
  ### Casper-Ruby-Sdk RPC
75
- * [info_get_peers](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#info_get_peers)
76
- * [chain_get_StateRootHash](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-state_root_hash)
77
- * [info_get_deploy](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-deploy)
78
- * [info_get_status](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-status)
79
- * [chain_get_block_transfers](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-block-transfers)
80
- * [chain_get_block](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-block-by-hash)
81
- * [chain_get_eraInfo_by_SwitchBlock](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-era-summary-by-switch-block-hash)
82
- * [state_get_item](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get--state-item)
83
- * [state_get_dictionary_item](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-dictionary-item)
84
- * [state_get_balance](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-account-balance)
85
- * [state_get_AuctionInfo](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#get-auction-state)
86
- * [put_deploy](https://github.com/saitgulmez/testing/blob/main/docs/rpc.md#put-deploy)
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)
87
100
 
88
101
 
89
102
  ## Usage examples
90
- ### Get 5 peer IP addresses randomly
103
+
104
+ ## Include 'casper_network' gem into the source file
105
+
91
106
  ```ruby
92
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
141
+
142
+ Retrieves a Deploy object from the network.
143
+
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
93
158
 
94
- # In order to interact with casper network we should give a valid ip address to the constructor
159
+ Retrieves the current status of the node.
95
160
 
96
- # if it does not work, please choose another node ip address from the Testnet
97
- # IP is taken from "Testnet"
98
- node_ip_address = "85.114.132.129"
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
99
181
  # block_Hash taken from Testnet
100
- block_hash = "71e19e2e9629c716dc9578066cfeceace559d32fe51b08245ddd4d218f8c18da"
101
- # deploy_Hash taken from Testnet
102
- deploy_hash = "d3e0a1bd85ee74916e096cf4b18df391ada414d0915aeb865eff0ba75f04c3d8"
103
- 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"
104
282
  item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
105
- uref = "uref-9199d08ff4ca4d52cd7a05ba0d2694204b7ebff963fec1c216f81bf654e0e59f-007"
106
- 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
107
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
312
+
313
+ Retrieves an AutionState object.
108
314
 
109
- # Uncomment following lines to test on Mainnet
110
- # if it does not work, please choose another node ip address from the Mainnet
111
- # IP is taken from "Mainnet"
112
- # node_ip_address = "65.108.78.12"
315
+ call parameters :
316
+ - block hash
317
+
318
+ ```ruby
113
319
  # block_Hash taken from MainNet
114
- # block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
115
- # # deploy_Hash taken from MainNet
116
- # deploy_hash = "52a40996a88523c475c12e5370ff90b0ae4ec051cfaa57cd048c136b1a83319d"
117
- # state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
118
- # item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
119
- # uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
120
- # switch_block_hash = "4696285db1ca6572f425cada612257f85a58a6a4034c09846afe360ba40e5df0"
121
-
122
- if (IPAddress.valid? node_ip_address)
123
- client = Casper::CasperClient.new(node_ip_address)
124
- peers = client.info_get_peers.sample(5)
125
- puts "node_id and address of five randomly selected 5 peers:"
126
- puts peers
127
-
128
- # Store ip addresses of these peers into an array
129
- ips = []
130
- peers.select do |item|
131
- ip = item["address"]
132
- ips << ip[0, ip.index(':')]
133
- end
134
-
135
- clients = []
136
- puts "Randomly selected 5 peers ip addresses:"
137
- ips.each do |ip_address|
138
- # Create a client object for each iteration
139
- puts ip_address
140
- client = CasperClient.new(ip_address)
141
- clients.push(client)
142
- end
143
-
144
-
145
- clients.each do |client|
146
- puts client.info_get_peers
147
- puts client.chain_get_StateRootHash(block_hash)
148
- puts client.chain_get_StateRootHash
149
- puts client.info_get_deploy(deploy_hash)
150
- puts client.info_get_status
151
- puts client.chain_get_block_transfers(block_hash)
152
- puts client.chain_get_block_transfers
153
- puts client.chain_get_block(block_hash)
154
- puts client.chain_get_eraInfo_by_SwitchBlock(switch_block_hash)
155
- puts client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
156
- puts client.state_get_dictionary_item(state_root_hash, item_key, uref)
157
- state_root_hash = "610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5"
158
- uref = "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007"
159
- puts client.state_get_balance(state_root_hash, uref)
160
- puts client.state_get_AuctionInfo
161
-
162
- end
163
- else
164
- puts "Invalid IP address"
165
- 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
166
346
  ```
167
- - [Testnet](https://testnet.cspr.live/tools/peers), [Mainnet](https://cspr.live/tools/peers)
168
- - [doc](https://www.rubydoc.info/gems/casper_network/0.2.1)
169
347
 
170
348
 
171
- ## TODO
172
- - [ ] Ruby version of CLType primitives
173
- - [ ] Ruby version for Casper domain-specific objects
174
- - [ ] Serialization of Casper domain-specific objects
175
- - [ ] ED25519/SECP256K1 key pairs Wrappers implemented
176
- - [ ] PutDeploy call implemented and tested
177
- - [ ] SDK calls will return Casper domain-specific objects
349
+ ### Example
350
+ ```bash
351
+ # example.rb
352
+ # how to execute example.rb
353
+ $ ruby example.rb
354
+ ```
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>....]
554
+
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)