casper_network 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79a82b8fd4b57919a7bfe74dcd42f79fcdcac5a89a68722ee5d9d0cc4f621f76
4
- data.tar.gz: 4c77091a8448de28de05cf8af7b19e32bd21f6e7dc2916f8e91c1def1738db7d
3
+ metadata.gz: 3446db6dad9ec70e0ad842479120abfe4cb919a7c65be7af300da5473a6e342f
4
+ data.tar.gz: d101cdc5acccc2ea222fb41a36baf819499cea70faaad98c8cbeb35a7955a833
5
5
  SHA512:
6
- metadata.gz: e884413451fb3e760745245319570d2a299c276c0885042c170821e535aaec7eeed65772e68c6c444f63674ba60d4d2ee2933a99dd8512b0b0975909faada95c
7
- data.tar.gz: e01d429e70bf95b5a2e3197de1fec5a935a7507adb553bf52cf773d862a919f090c0e6654744aa5d4b7aae1f0915d3a6595f79b7951d6ab8f43236ccbd27ea94
6
+ metadata.gz: eb48b8c657010cfd2327c2d6ce1b060b29742084a0df40b682b03819f958c0c4c25aacc31c7049a5f749ad97aa92b53318274ae9cca98e3774d15c4e8db03ba7
7
+ data.tar.gz: 5e14e5e989ff7078464ff63caafccf41c38bd3fc4c0b378a2119da76a92481c06783f4a34a5e578baed18568086935398ffbe1555ee7889c140e0d25a5f551fa
data/README.md CHANGED
@@ -42,28 +42,24 @@ gem build casper_network.gemspec
42
42
  # Install RSpec
43
43
  gem install rspec
44
44
  # Run the test
45
- rspec spec/testnet_spec.rb
46
- rspec spec/mainnet_spec.rb
45
+ bundle exec rspec
46
+ # To see the test results in detail
47
+ bundle exec rspec -fd
47
48
  ```
48
49
 
49
- ## Testnet Tests
50
+ ## How run each test file individually
50
51
  ```bash
51
52
  git checkout main
52
53
  # Run the test
53
- rspec spec/testnet_spec.rb
54
+ rspec spec/file_name.rb
54
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
55
60
  rspec -fd spec/testnet_spec.rb
56
- # Test for cltypes
57
- rspec -fd spec/cl_types_spec.rb
58
61
  ```
59
62
 
60
- ## Mainnet Tests
61
- ```bash
62
- # Run the test
63
- rspec spec/mainnet_spec.rb
64
- # To see the test results in detail
65
- rspec -fd spec/mainnet_spec.rb
66
- ```
67
63
 
68
64
  ## How to generate docs
69
65
  ```bash
@@ -74,7 +70,269 @@ yardoc lib/**/*.rb lib/*.rb - README.md LICENSE CONTRIBUTING.md SECURITY.md
74
70
  yardoc --help
75
71
  ```
76
72
 
73
+ ## Documentation:
74
+ ### Casper-Ruby-Sdk RPC
75
+ * [info_get_peers](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#info_get_peers)
76
+ * [chain_get_StateRootHash](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-state_root_hash)
77
+ * [info_get_deploy](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-deploy)
78
+ * [info_get_status](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-status)
79
+ * [chain_get_block_transfers](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-block-transfers)
80
+ * [chain_get_block](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-block-by-hash)
81
+ * [chain_get_eraInfo_by_SwitchBlock](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-era-summary-by-switch-block-hash)
82
+ * [state_get_item](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get--state-item)
83
+ * [state_get_dictionary_item](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-dictionary-item)
84
+ * [state_get_balance](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-account-balance)
85
+ * [state_get_AuctionInfo](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#get-auction-state)
86
+ * [put_deploy](https://github.com/saitgulmez/casper-ruby-sdk/blob/main/docs/rpc.md#put-deploy)
87
+
88
+
77
89
  ## Usage examples
90
+
91
+ ## Include 'casper_network' gem into the source file
92
+
93
+ ```ruby
94
+ require 'casper_network'
95
+ ```
96
+ ## Create a Client
97
+
98
+ Pass the node ip address to constructor
99
+
100
+ ```ruby
101
+ node_ip_address = "5.9.23.55" # IP is taken from "testnet"
102
+ client = Casper::CasperClient.new(node_ip_address)
103
+ ```
104
+ ## RPC Calls
105
+
106
+ ### Get network peers list
107
+
108
+ Retrieves the list of connected peers.
109
+
110
+ ```ruby
111
+ peers = client.info_get_peers
112
+ # Retrieve to the first peer object
113
+ peer = peers[0]
114
+ # Retrieve to info of the first peer object
115
+ node_id = peer[0].get_node_id
116
+ address = peer[0].get_address
117
+ ```
118
+
119
+ ### Get State Root Hash
120
+
121
+ Retrieves the state root hash String.
122
+
123
+ ```ruby
124
+ state_root_hash = client.chain_get_StateRootHash
125
+ ```
126
+
127
+ ### Get Deploy
128
+
129
+ Retrieves a Deploy object from the network.
130
+
131
+ call parameters :
132
+ - deploy hash
133
+
134
+ ```ruby
135
+ deploy_hash = "0806cc477a5282574bc5302d7598cd33a09875704c5fef9264d984535c945e31"
136
+ deploy = client.info_get_deploy(deploy_hash)
137
+ # Deploy members
138
+ hash = Casper::Entity::DeployHash.new(deploy.get_hash)
139
+ header = Casper::Entity::DeployHeader.new(deploy.get_header)
140
+ payment = deploy.get_payment
141
+ session = deploy.get_session
142
+ ```
143
+
144
+ ### Get Node Status
145
+
146
+ Retrieves the current status of the node.
147
+
148
+ ```ruby
149
+ node_status = client.info_get_status
150
+ # Examples of retrieving and printing the members of node status
151
+ puts node_status.get_api_version
152
+ puts node_status.get_chainspec_name
153
+ puts node_status.get_starting_state_root_hash
154
+ puts node_status.get_peers
155
+ puts node_status.get_last_added_block_info
156
+ puts node_status.get_our_public_signing_key
157
+ puts node_status.get_round_length
158
+ puts node_status.get_next_upgrade
159
+ puts node_status.get_build_version
160
+ puts node_status.get_uptime
161
+ ```
162
+
163
+ ### Get BlockTransfers
164
+
165
+ Retrieve all transfers for a Block from the network
166
+
167
+ ```ruby
168
+ # block_Hash taken from Testnet
169
+ block_hash = "ff2ad232c3efc22a385fce44df844fc696e904ce8ba78599a576aa68c76889c4"
170
+ transfers = client.chain_get_block_transfers(block_hash)
171
+ # Examples of accessing and printing the members of each transfer object
172
+ transfers.each do |transfer|
173
+ puts transfer.get_deploy_hash
174
+ puts transfer.get_from
175
+ puts transfer.get_to
176
+ puts transfer.get_source
177
+ puts transfer.get_target
178
+ puts transfer.get_amount
179
+ puts transfer.get_gas
180
+ puts transfer.get_id
181
+ end
182
+ ```
183
+
184
+ ### Get Block
185
+
186
+ Retrieve a Block object from the network
187
+
188
+ ```ruby
189
+ block_hash = "ff2ad232c3efc22a385fce44df844fc696e904ce8ba78599a576aa68c76889c4"
190
+ block = client.chain_get_block(block_hash)
191
+ puts block # => It is an instance of Block
192
+ # To retrieve BlockHeader object
193
+ block_header = block.get_header
194
+ puts block_header
195
+ # To access and print members of the block_header object (block_header is an instance of BlockHeader )
196
+ puts block_header.get_parent_hash
197
+ puts block_header.get_state_root_hash
198
+ puts block_header.get_body_hash
199
+ puts block_header.get_random_bit
200
+ puts block_header.get_accumulated_seed
201
+ puts block_header.get_era_end
202
+ puts block_header.get_timestamp
203
+ puts block_header.get_era_id
204
+ puts block_header.get_height
205
+ puts block_header.get_protocol_version
206
+
207
+ # To retrieve BlockBody object
208
+ block_body = block.get_body
209
+ # To access and print members of the block_body object (block_body is an instance of BlockBody )
210
+ puts block_body
211
+ puts block_body.get_proposer
212
+ puts block_body.get_deploy_hashes
213
+ puts block_body.get_transfer_hashes
214
+
215
+ # To retrieve an array of BlockProof objects
216
+ proofs = block.get_proofs
217
+ # To access and print members of the block_proof objects (block_proof is an instance of BlockProof )
218
+ puts proofs
219
+ # To access and print each proof object and its members
220
+ i = 0
221
+ proofs.each do |proof|
222
+ puts "proofs[#{i}]: #{proof}"
223
+ puts "public_key: " + proof.get_public_key
224
+ puts "signature: " + proof.get_signature
225
+ i += 1
226
+ end
227
+ ```
228
+
229
+ ### Get EraInfo By Switch Block
230
+
231
+ Retrieves an EraSummury object.
232
+
233
+ ```ruby
234
+ block_hash = "d2077716e5b8796723c5720237239720f54e6ada54e3357f2c4896f2a51a6d8f"
235
+ era_summary = client.chain_get_eraInfo_by_SwitchBlock(block_hash)
236
+ puts era_summary # => It is an instance of EraSummary
237
+ puts era_summary.get_block_hash
238
+ puts era_summary.get_era_id
239
+ puts era_summary.get_stored_value # => Retrieve and print the instance of StoredValue
240
+ puts era_summary.get_stored_value.get_stored_value
241
+ puts era_summary.get_state_root_hash
242
+ puts era_summary.get_merkle_proof
243
+ ```
244
+
245
+ ### Get StateItem
246
+
247
+ Retrieves a StoredValue object.
248
+
249
+ ```ruby
250
+ node_ip_address = "65.108.78.120" # => Taken from the Mainnet
251
+ client = Casper::CasperClient.new(node_ip_address)
252
+ # Retrieve the stored_value object which is an instance of StoredValue
253
+ stored_value = client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
254
+ puts stored_value # => #<Casper::Entity::StoredValue:0x0000000003767a48>
255
+ puts stored_value.get_key # => Bid
256
+ puts stored_value.get_bid # => Retrieve and print Bid object related data
257
+ # or
258
+ puts stored_value.get_stored_value # => Retrieve and print Bid object related data
259
+ ```
260
+
261
+ ### Get DictionaryItem
262
+
263
+ Retrieves a CLValue object.
264
+
265
+ ```ruby
266
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
267
+ client = Casper::CasperClient.new(node_ip_address)
268
+ state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
269
+ item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
270
+ uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
271
+ # Retrieve folowing data from the network and convert it into its proper CLValue
272
+ # {"CLValue"=>{"cl_type"=>"String", "bytes"=>"1a00000068747470733a2f2f636173706572636f6d6d756e6974792e696f", "parsed"=>"https://caspercommunity.io"}}
273
+ stored_value = client.state_get_dictionary_item(state_root_hash, item_key, uref)
274
+ puts stored_value # => #<CLString:0x0000000002b3c8e0>
275
+ puts stored_value.get_cl_type # => String
276
+ puts stored_value.get_value # => https://caspercommunity.io
277
+ puts CLValueBytesParsers::CLStringBytesParser.to_bytes(stored_value.get_value) # => 1a00000068747470733a2f2f636173706572636f6d6d756e6974792e696f
278
+ ```
279
+
280
+ ### Get Balance
281
+
282
+ Retrieves the balances(in motes) of an account
283
+
284
+ Parameters :
285
+
286
+ - state root hash
287
+ - account uref hash
288
+
289
+ ```ruby
290
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
291
+ client = Casper::CasperClient.new(node_ip_address)
292
+ state_root_hash = "610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5"
293
+ uref = "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007"
294
+ balance = client.state_get_balance(state_root_hash, uref)
295
+ puts balance # => 29269647684075 (current balance 9/24/2022)
296
+ ```
297
+
298
+ ### Get current auction state
299
+
300
+ Retrieves an AutionState object.
301
+
302
+ call parameters :
303
+ - block hash
304
+
305
+ ```ruby
306
+ # block_Hash taken from MainNet
307
+ block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
308
+ node_ip_address = "65.108.78.120" # => Taken from Mainnet
309
+ client = Casper::CasperClient.new(node_ip_address)
310
+ auction = client.state_get_AuctionInfo
311
+ # Retrieve and print an instance of AuctionState entity
312
+ puts auction # => #<Casper::Entity::AuctionState:0x0000000003306bc0>
313
+ # Retrieve and print state root hash as a String value
314
+ puts auction.get_state_root_hash # => "6448b55f1dd7c9ad337f4fd4c77586d7ae30da146e0b340932aba7e7efa9cbcb"
315
+ # Retrieve and print block height as an Integer value
316
+ puts auction.get_block_height # => 1128800
317
+ # Retrieve and print an array of instances of EraValidor entity
318
+ puts auction.get_era_validators # => [#<Casper::Entity::EraValidator:0x0000000002b69980>, #<Casper::Entity::EraValidator:0x0000000002b68940>]
319
+ # Retrieve and print an array of instances of Bid entity
320
+ puts auction.get_bids # => [#<Casper::Entity::Bid:0x000000000430bcf0>, #<Casper::Entity::Bid:0x000000000430b6d8>....]
321
+
322
+ # Retrieve and print an instance of BidInfo, which is also the member of bid object
323
+ bids = auction.get_bids
324
+ bid = bids[0] # => #<Casper::Entity::Bid:0x0000000003773dc0>
325
+ bid_info = bid.get_bid_info # => #<Casper::Entity::BidInfo:0x00000000042cffc0>
326
+ # Retrieve and print an array of delegator objects, which are instance of Delegator entity
327
+ delegators = bid_info.get_delegators
328
+ puts delegators # => [#<Casper::Entity::Delegator:0x000000000396c550>, #<Casper::Entity::Delegator:0x000000000396c500>.....]
329
+ # How to access members of one of the above delegator instances
330
+ # For instance, access to stake amount at first delegator
331
+ delegator = delegators[0]
332
+ stake_amount = delegator.get_staked_amount # => 27871095039894
333
+ ```
334
+
335
+
78
336
  ### Get 5 peer IP addresses randomly
79
337
  ```ruby
80
338
  require 'casper_network'
@@ -157,9 +415,9 @@ end
157
415
 
158
416
 
159
417
  ## TODO
160
- - [ ] Ruby version of CLType primitives
161
- - [ ] Ruby version for Casper domain-specific objects
162
- - [ ] Serialization of Casper domain-specific objects
418
+ - [x] Ruby version of CLType primitives
419
+ - [x] Ruby version for Casper domain-specific objects
420
+ - [x] Serialization of Casper domain-specific objects
163
421
  - [ ] ED25519/SECP256K1 key pairs Wrappers implemented
164
422
  - [ ] PutDeploy call implemented and tested
165
- - [ ] SDK calls will return Casper domain-specific objects
423
+ - [x] SDK calls will return Casper domain-specific objects
@@ -10,7 +10,7 @@ require 'net/http'
10
10
  # require "./rpc/rpc.rb"
11
11
  require_relative './rpc/rpc_error.rb'
12
12
  require_relative './rpc/rpc_client.rb'
13
-
13
+ require_relative './serialization/deploy_serializer.rb'
14
14
  # Dir["./entity/*.rb"].each {|file| require file }
15
15
  # Dir["./serialization/*.rb"].each {|file| require file }
16
16
  # Dir["./types/*.rb"].each {|file| require file }
@@ -141,6 +141,8 @@ module Casper
141
141
  status = Timeout::timeout(10) {
142
142
  client = Jimson::Client.new(@url)
143
143
  @node_status = client.info_get_status
144
+ @node_status.deep_symbolize_keys!
145
+ Casper::Entity::Status.new(@node_status)
144
146
  }
145
147
  rescue
146
148
  @rpc_error = Casper::RpcError::ErrorHandle.new
@@ -176,7 +178,8 @@ module Casper
176
178
  if (!@block_info.empty?() && @block_info["hash"] != block_hash)
177
179
  raise("Returned block does not have a matching hash.")
178
180
  else
179
- @block_info
181
+ @block_info.deep_symbolize_keys!
182
+ Casper::Entity::Block.new(@block_info[:hash], @block_info[:header], @block_info[:body], @block_info[:proofs])
180
183
  end
181
184
  }
182
185
  rescue
@@ -196,7 +199,8 @@ module Casper
196
199
  if @era_summary == nil
197
200
  Casper::RpcError::InvalidParameter.error
198
201
  else
199
- @era_summary
202
+ @era_summary.deep_symbolize_keys!
203
+ Casper::Entity::EraSummary.new(@era_summary)
200
204
  end
201
205
  }
202
206
  rescue
@@ -217,7 +221,8 @@ module Casper
217
221
  "path" => path
218
222
  })
219
223
  @stored_value = response["stored_value"]
220
- @stored_value
224
+ @stored_value.deep_symbolize_keys!
225
+ Casper::Entity::StoredValue.new(@stored_value)
221
226
  }
222
227
  rescue
223
228
  Casper::RpcError::InvalidParameter.error
@@ -236,7 +241,10 @@ module Casper
236
241
  "dictionary_identifier" => {'URef' =>
237
242
  {'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
238
243
  @stored_value = response["stored_value"]
239
- @stored_value
244
+ @stored_value.deep_symbolize_keys!
245
+ # cl_type = @stored_value[:CLValue][:cl_type]
246
+ # bytes = @stored_value[:CLValue][:bytes]
247
+ DeploySerializer.new().build_cl_value(@stored_value[:CLValue])
240
248
  }
241
249
  rescue
242
250
  Casper::RpcError::InvalidParameter.error
@@ -263,13 +271,19 @@ module Casper
263
271
 
264
272
  # Returns current auction system contract information.
265
273
  # @return [Hash] auction_state
266
- def state_get_AuctionInfo
274
+ def state_get_AuctionInfo(block_hash = "")
267
275
  begin
268
276
  state = Timeout::timeout(50) {
269
277
  client = Jimson::Client.new(@url)
270
278
  response = client.state_get_auction_info
271
279
  @auction_state = response['auction_state']
280
+ @auction_state.deep_symbolize_keys!
281
+ state_root_hash = @auction_state[:state_root_hash]
282
+ block_height = @auction_state[:block_height]
283
+ era_validators = @auction_state[:era_validators]
272
284
  @auction_state
285
+ bids = @auction_state[:bids]
286
+ Casper::Entity::AuctionState.new(state_root_hash, block_height, era_validators, bids)
273
287
  }
274
288
  rescue
275
289
  @rpc_error = Casper::RpcError::ErrorHandle.new
@@ -277,6 +291,7 @@ module Casper
277
291
  end
278
292
  end
279
293
 
294
+ # @param [Deploy] deploy
280
295
  def put_deploy(deploy)
281
296
  client = Jimson::Client.new(url)
282
297
  response = client.account_put_deploy(deploy)
@@ -4,33 +4,81 @@ module Casper
4
4
  class AuctionState
5
5
  # @param [String] state_root_hash
6
6
  # @param [Integer] block_height
7
- # @param [Array] era_validators
8
- # @param [Array] bids
7
+ # @param [Array<Hash>] era_validators
8
+ # @option era_validators [Integer] :era_id
9
+ # @option era_validators [Array<Hash>] :validator_weights
10
+ # @param [Array<Hash>] bids
9
11
  def initialize(state_root_hash, block_height, era_validators, bids)
10
12
  @state_root_hash = state_root_hash
11
13
  @block_height = block_height
12
- @era_validators = era_validators
14
+
15
+ @era_validators = []
16
+ era_validators.each do |era_validator|
17
+ @validators_weights = []
18
+ era_validator[:validator_weights].each do |validator_weight|
19
+ @validators_weights << Casper::Entity::ValidatorWeight.new(validator_weight[:public_key], validator_weight[:weight])
20
+ end
21
+ @era_validators << Casper::Entity::EraValidator.new(era_validator[:era_id], @validators_weights)
22
+ @validators_weights = []
23
+ # puts Casper::Entity::EraValidator.new(era_validator[:era_id], @validators_weights).get_era_id
24
+ # puts Casper::Entity::EraValidator.new(era_validator[:era_id], @validators_weights).get_validator_weights
25
+ end
26
+
27
+ # @era_validators.each do |era_validator|
28
+ # puts era_validator.get_validator_weights[0].get_era_id
29
+ # puts era_validator.get_validator_weights[0].get_weight
30
+ # end
31
+
13
32
  @bids = bids
33
+ @bids_list = []
34
+
35
+ bids.each do |bid|
36
+ bid_info = bid[:bid]
37
+ @delegators_list = []
38
+ delegators = bid_info[:delegators]
39
+
40
+ delegators.each do |delegator|
41
+ @delegators_list << Casper::Entity::Delegator.new(
42
+ delegator[:public_key],
43
+ delegator[:staked_amount],
44
+ delegator[:bonding_purse],
45
+ delegator[:delegatee]
46
+ )
47
+ # puts delegator
48
+ # puts delegator[:public_key]
49
+ end
50
+
51
+ bid_info = Casper::Entity::BidInfo.new(
52
+ bid_info[:bonding_purse],
53
+ bid_info[:staked_amount],
54
+ bid_info[:delegation_rate],
55
+ bid_info[:vesting_schedule],
56
+ # bid_info[:delegators],
57
+ @delegators_list,
58
+ bid_info[:inactive]
59
+ )
60
+ @bids_list << Casper::Entity::Bid.new(bid[:public_key], bid_info)
61
+ end
14
62
  end
15
63
 
16
- # @return [String] returns state root hash as a String
64
+ # @return [String] state root hash as a String
17
65
  def get_state_root_hash
18
66
  @state_root_hash
19
67
  end
20
68
 
21
- # @return [Integer] returns block height as an Integer
69
+ # @return [Integer] block height as an Integer
22
70
  def get_block_height
23
71
  @block_height
24
72
  end
25
73
 
26
- # @return [Array<Hash>] returns array of hashes
74
+ # @return [Array<EraValidator>] array of EraValidator
27
75
  def get_era_validators
28
76
  @era_validators
29
77
  end
30
78
 
31
- # @return [Array<Hash>] returns array of hashes
79
+ # @return [Array<Bid>] array of Bid
32
80
  def get_bids
33
- @bids
81
+ @bids_list
34
82
  end
35
83
  end
36
84
  end
data/lib/entity/bid.rb CHANGED
@@ -7,7 +7,7 @@ module Casper
7
7
  # @param [BidInfo] bid_info
8
8
  def initialize(public_key, bid_info)
9
9
  @public_key = public_key
10
- @BidInfo = bid_info
10
+ @bid_info = bid_info
11
11
 
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ module Casper
7
7
  # @param [String] staked_amount
8
8
  # @param [Integer] delegation_rate
9
9
  # @param [VestingSchedule] vesting_schedule
10
- # @param [Hash<Delegator>] delegators
10
+ # @param [Array<Delegator>] delegators
11
11
  # @param [Boolean] inactive
12
12
  def initialize(bonding_purse, staked_amount, delegation_rate, vesting_schedule, delegators, inactive)
13
13
  @bonding_purse = bonding_purse
@@ -0,0 +1,39 @@
1
+ module Casper
2
+ module Entity
3
+ # Block
4
+ class Block
5
+
6
+ # @param [String] hash
7
+ # @param [Hash] header
8
+ # @param [Hash] body
9
+ # @param [Array<Hash>] proofs
10
+ def initialize(hash, header = {}, body = {}, proofs = [])
11
+ @hash = hash
12
+ @header = Casper::Entity::BlockHeader.new(header)
13
+ @body = Casper::Entity::BlockBody.new(body)
14
+ @proofs = []
15
+ proofs.each { |proof| @proofs << Casper::Entity::BlockProof.new(proof) }
16
+ end
17
+
18
+ # @return [String] block hash
19
+ def get_hash
20
+ @hash
21
+ end
22
+
23
+ # @return [BlockHeader] block header
24
+ def get_header
25
+ @header
26
+ end
27
+
28
+ # @return [BlockBody] block body
29
+ def get_body
30
+ @body
31
+ end
32
+
33
+ # @return [Array<BlockProof>] list of proofs for this block
34
+ def get_proofs
35
+ @proofs
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ module Casper
2
+ module Entity
3
+ # BlockBody entity
4
+ class BlockBody
5
+
6
+ # @param [Hash] body
7
+ # @option [String] :proposer
8
+ # @option [Array] :deploy_hashes
9
+ # @option [Array] :transfer_hashes
10
+ def initialize(body = {})
11
+ @proposer = body[:proposer]
12
+ @deploy_hashes = body[:deploy_hashes]
13
+ @transfer_hashes = body[:transfer_hashes]
14
+ end
15
+
16
+ # @return [String] a hex-encoded cryptographic public key,
17
+ # including the algorithm tag prefix.
18
+ def get_proposer
19
+ @proposer
20
+ end
21
+
22
+ # @return [Array] hex-encoded Deploy hashes.
23
+ def get_deploy_hashes
24
+ @deploy_hashes
25
+ end
26
+
27
+ # @return [Array] a vector of hex-encoded hashes
28
+ # identifying Transfers included in this block.
29
+ def get_transfer_hashes
30
+ @transfer_hashes
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,81 @@
1
+ module Casper
2
+ module Entity
3
+ # BlockHeader
4
+ class BlockHeader
5
+
6
+ # @param [Hash] header
7
+ # @option header [String] :parent_hash
8
+ # @option header [String] :state_root_hash
9
+ # @option header [String] :parent_hash
10
+ # @option header [String] :body_hash
11
+ # @option header [Boolean] :random_bit
12
+ # @option header [String] :accumulated_seed
13
+ # @option header [String] :era_end
14
+ # @option header [Integer] :timestamp
15
+ # @option header [Integer] :era_id
16
+ # @option header [Integer] :height
17
+ def initialize(header = {})
18
+ @parent_hash = header[:parent_hash]
19
+ @state_root_hash = header[:state_root_hash]
20
+ @body_hash = header[:body_hash]
21
+ @random_bit = header[:random_bit]
22
+ @accumulated_seed = header[:accumulated_seed]
23
+ @era_end = header[:era_end]
24
+ @timestamp = header[:timestamp]
25
+ @era_id = header[:era_id]
26
+ @height = header[:height]
27
+ @protocol_version = header[:protocol_version]
28
+ end
29
+
30
+ # @return [String] parent_hash
31
+ def get_parent_hash
32
+ @parent_hash
33
+ end
34
+
35
+ # @return [String] state_root_hash
36
+ def get_state_root_hash
37
+ @state_root_hash
38
+ end
39
+
40
+ # @return [String] body_hash
41
+ def get_body_hash
42
+ @body_hash
43
+ end
44
+
45
+ # @return [Boolean] random_bit
46
+ def get_random_bit
47
+ @random_bit
48
+ end
49
+
50
+ # @return [String] accumulated_seed
51
+ def get_accumulated_seed
52
+ @accumulated_seed
53
+ end
54
+
55
+ # @return [String] era_end
56
+ def get_era_end
57
+ @era_end
58
+ end
59
+
60
+ # @return [Integer] timestamp
61
+ def get_timestamp
62
+ @timestamp
63
+ end
64
+
65
+ # @return [Integer] era_id
66
+ def get_era_id
67
+ @era_id
68
+ end
69
+
70
+ # @return [Integer] height
71
+ def get_height
72
+ @height
73
+ end
74
+
75
+ # @return [String] protocol_version
76
+ def get_protocol_version
77
+ @protocol_version
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,56 @@
1
+ module Casper
2
+ module Entity
3
+ # BlockInfo class entity
4
+ class BlockInfo
5
+
6
+ # @param [Hash] last_added_block_info
7
+ # @option last_added_block_info [String] :hash
8
+ # @option last_added_block_info [String] :timestamp
9
+ # @option last_added_block_info [Integer] :era_id
10
+ # @option last_added_block_info [Integer] :height
11
+ # @option last_added_block_info [String] :state_root_hash
12
+ # @option last_added_block_info [String] :creator
13
+ def initialize(last_added_block_info = {})
14
+ @hash = last_added_block_info[:hash]
15
+ @timestamp = last_added_block_info[:timestamp]
16
+ @era_id = last_added_block_info[:era_id]
17
+ @height = last_added_block_info[:height]
18
+ @state_root_hash = last_added_block_info[:state_root_hash]
19
+ @creator = last_added_block_info[:creator]
20
+ end
21
+
22
+ # @return [String] a cryptographic hash identifying a Block.
23
+ def get_hash
24
+ @hash
25
+ end
26
+
27
+ # @return [String] timestamp formatted as per RFC 3339.
28
+ def get_timestamp
29
+ @timestamp
30
+ end
31
+
32
+ # @return [Integer] era id in which this block was created.
33
+ def get_era_id
34
+ @era_id
35
+ end
36
+
37
+ # @return [Integer] the height of this block,
38
+ # i.e., the number of ancestors.
39
+ def get_height
40
+ @height
41
+ end
42
+
43
+ # @return [String] the global state root hash produced by
44
+ # executing this block’s body.
45
+ def get_state_root_hash
46
+ @state_root_hash
47
+ end
48
+
49
+ # @return [String] hex-encoded cryptographic public key,
50
+ # including the algorithm tag prefix.
51
+ def get_creator
52
+ @creator
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,24 @@
1
+ module Casper
2
+ module Entity
3
+ # BlockProof
4
+ class BlockProof
5
+ # @param [Hash] proof
6
+ # @option proof [String] :public_key
7
+ # @option proof [String] :signature
8
+ def initialize(proof = {})
9
+ @public_key = proof[:public_key]
10
+ @signature = proof[:signature]
11
+ end
12
+
13
+ # @return [String] public_key
14
+ def get_public_key
15
+ @public_key
16
+ end
17
+
18
+ # @return [String] signature
19
+ def get_signature
20
+ @signature
21
+ end
22
+ end
23
+ end
24
+ end
@@ -3,17 +3,18 @@ module Casper
3
3
  # The summary of an era.
4
4
  class EraSummary
5
5
 
6
- # @param [String] block_hash_
7
- # @param [Integer] era_id_
8
- # @param [StoredValue] stored_value_
9
- # @param [String] state_root_hash_
10
- # @param [String] merkle_proof_
11
- def initialize(block_hash_, era_id_, stored_value_, state_root_hash_, merkle_proof_)
12
- @block_hash = block_hash_
13
- @era_id = era_id_
14
- @stored_value = stored_value_
15
- @state_root_hash = state_root_hash_
16
- @merkle_proof = merkle_proof_
6
+ # @param [Hash] era_summary
7
+ # @option era_summary [String] :block_hash
8
+ # @option era_summary [Integer] :era_id
9
+ # @option era_summary [Hash] :stored_value
10
+ # @option era_summary [String] :state_root_hash
11
+ # @option era_summary [String] :merkle_proof
12
+ def initialize(era_summary = {})
13
+ @block_hash = era_summary[:block_hash]
14
+ @era_id = era_summary[:era_id]
15
+ @stored_value = Casper::Entity::StoredValue.new(era_summary[:stored_value])
16
+ @state_root_hash = era_summary[:state_root_hash]
17
+ @merkle_proof = era_summary[:merkle_proof]
17
18
  end
18
19
 
19
20
  # @return [String] block_hash
@@ -26,7 +27,7 @@ module Casper
26
27
  @era_id
27
28
  end
28
29
 
29
- # @return [StoredValue] StoredValue
30
+ # @return [Hash] StoredValue
30
31
  def get_stored_value
31
32
  @stored_value
32
33
  end
@@ -0,0 +1,80 @@
1
+ module Casper
2
+ module Entity
3
+ class Status
4
+ # @param [Hash] status
5
+ # @option status [String] :api_version
6
+ # @option status [String] :chainspec_name
7
+ # @option status [String] :starting_state_root_hash
8
+ # @option status [Array<Hash>] :peers
9
+ # @option status [Hash] :last_added_block_info
10
+ # @option status [String] :our_public_signing_key
11
+ # @option status [Integer] :round_length
12
+ # @option status [String] :next_upgrade
13
+ # @option status [String] :build_version
14
+ # @option status [String] :uptime
15
+ def initialize(status = {})
16
+ @api_version = status[:api_version]
17
+ @chainspec_name = status[:chainspec_name]
18
+ @starting_state_root_hash = status[:starting_state_root_hash]
19
+ @peers = []
20
+ status[:peers].map { |peer| @peers << Casper::Entity::Peer.new(peer)}
21
+ @last_added_block_info = status[:last_added_block_info]
22
+ @our_public_signing_key = status[:our_public_signing_key]
23
+ @round_length = status[:round_length]
24
+ @next_upgrade = status[:next_upgrade]
25
+ @build_version = status[:build_version]
26
+ @uptime = status[:uptime]
27
+ end
28
+
29
+ # @return [String] the RPC API version.
30
+ def get_api_version
31
+ @api_version
32
+ end
33
+
34
+ # @return [String] the chainspec name.
35
+ def get_chainspec_name
36
+ @chainspec_name
37
+ end
38
+
39
+ # @return [String] the state root hash used at the start of the current sessio
40
+ def get_starting_state_root_hash
41
+ @starting_state_root_hash
42
+ end
43
+
44
+ # @return [Array<Peer>] the node ID and network address of each connected peer.
45
+ def get_peers
46
+ @peers
47
+ end
48
+
49
+ # @return [Hash] the minimal info of the last block from the linear chain.
50
+ def get_last_added_block_info
51
+ @last_added_block_info
52
+ end
53
+
54
+ # @return [String] Our public signing key.
55
+ def get_our_public_signing_key
56
+ @our_public_signing_key
57
+ end
58
+
59
+ # @return [Integer] the next round length if this node is a validator.
60
+ def get_round_length
61
+ @round_length
62
+ end
63
+
64
+ # @return [String] information about the next scheduled upgrade.
65
+ def get_next_upgrade
66
+ @next_upgrade
67
+ end
68
+
69
+ # @return [String] the compiled node version.
70
+ def get_build_version
71
+ @build_version
72
+ end
73
+
74
+ # @return [String] the time that passed since the node has started.
75
+ def get_uptime
76
+ @uptime
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,57 +1,132 @@
1
+
1
2
  module Casper
2
3
  module Entity
3
4
 
4
5
  # A class that represents a value stored in global state.
5
6
  class StoredValue
6
7
 
7
- def initialize(cl_value, account, contract, contract_package, transfer, deploy_info, era_info, bid, withdraw)
8
- @cl_value = cl_value
9
- @account = account
10
- @contract = contract
11
- @contract_package = contract_package
12
- @transfer = transfer
13
- @deploy_info = deploy_info
14
- @era_info = era_info
15
- @bid = bid
16
- @withdraw = withdraw
8
+ # @param [Hash] stored_value
9
+ # @option stored_value [CLValue] :CLValue
10
+ # @option stored_value [Account] :Account
11
+ # @option stored_value [String] :ContractWasm
12
+ # @option stored_value [Contract] :Contract
13
+ # @option stored_value [ContractPackage] :ContractPackage
14
+ # @option stored_value [Transfer] :Transfer
15
+ # @option stored_value [DeployInfo] :DeployInfo
16
+ # @option stored_value [EraInfo] :EraInfo
17
+ # @option stored_value [Bid] :Bid
18
+ # @option stored_value [Array] :Withdraw
19
+ def initialize(stored_value = {})
20
+ @stored_value = stored_value
21
+ @cl_value = nil
22
+ @account = nil
23
+ @contract_wasm = nil
24
+ @contract = nil
25
+ @contract_package = nil
26
+ @transfer = nil
27
+ @deploy_info = nil
28
+ @era_info = nil
29
+ @bid = nil
30
+ @withdraw = nil
31
+ @key = nil
32
+ if stored_value.has_key?(:CLValue)
33
+ @cl_value = stored_value[:CLValue]
34
+ @key = :CLValue
35
+ end
36
+ if stored_value.has_key?(:Account)
37
+ @account = stored_value[:Account]
38
+ @key = :Account
39
+ end
40
+ if stored_value.has_key?(:ContractWasm)
41
+ @contract_wasm = stored_value[:ContractWasm]
42
+ @key = :ContractWasm
43
+ end
44
+ if stored_value.has_key?(:Contract)
45
+ @contract = stored_value[:Contract]
46
+ @key = :Contract
47
+ end
48
+ if stored_value.has_key?(:ContractPackage)
49
+ @contract_package = stored_value[:ContractPackage]
50
+ @key = :ContractPackage
51
+ end
52
+ if stored_value.has_key?(:Transfer)
53
+ @transfer = stored_value[:Transfer]
54
+ @key = :Transfer
55
+ end
56
+ if stored_value.has_key?(:DeployInfo)
57
+ @transfer = stored_value[:DeployInfo]
58
+ @key = :Deploy
59
+ end
60
+ if stored_value.has_key?(:EraInfo)
61
+ @era_info = stored_value[:EraInfo]
62
+ @key = :EraInfo
63
+ end
64
+ if stored_value.has_key?(:Bid)
65
+ @bid = stored_value[:Bid]
66
+ @key = :Bid
67
+ end
68
+ if stored_value.has_key?(:Withdraw)
69
+ @withdraw = stored_value[:Withdraw]
70
+ @key = :Withdraw
71
+ end
17
72
  end
18
73
 
74
+ # @return [CLValue] a CasperLabs value.
19
75
  def get_cl_value
20
76
  @cl_value
21
77
  end
22
78
 
79
+ # @return [Account] an account.
23
80
  def get_account
24
81
  @account
25
82
  end
26
83
 
84
+ # @return [String] a contract’s Wasm
27
85
  def get_contract
28
86
  @contract
29
87
  end
30
-
88
+
89
+ # @return [Contract] methods and type signatures supported by a contract.
90
+ def get_contract
91
+ @contract
92
+ end
93
+ # @return [ContractPackage] contract definition, metadata, and security container.
31
94
  def get_contract_package
32
95
  @contract_package
33
96
  end
34
97
 
98
+ # @return [Transfer] record of a transfer
35
99
  def get_transfer
36
100
  @transfer
37
101
  end
38
102
 
103
+ # @return [DeployInfo] record of a deploy
39
104
  def get_deploy_info
40
105
  @deploy_info
41
106
  end
42
107
 
108
+ # @return [EraInfo] auction metadata
43
109
  def get_era_info
44
110
  @era_info
45
111
  end
46
112
 
113
+ # @return [Bid] a bid
47
114
  def get_bid
48
115
  @bid
49
116
  end
50
117
 
118
+ # @return [Array] a withdraw
51
119
  def get_withdraw
52
120
  @withdraw
53
121
  end
54
122
 
123
+ def get_stored_value
124
+ @stored_value[@key]
125
+ end
126
+
127
+ def get_key
128
+ @key
129
+ end
55
130
  end
56
131
  end
57
132
  end
@@ -23,32 +23,32 @@ module Casper
23
23
  @id = transfer[:id]
24
24
  end
25
25
 
26
- # @return [String] deploy_hash
26
+ # @return [String] deploy that created the transfer
27
27
  def get_deploy_hash
28
28
  @deploy_hash
29
29
  end
30
30
 
31
- # @return [String] from
31
+ # @return [String] account from which transfer was executed
32
32
  def get_from
33
33
  @from
34
34
  end
35
35
 
36
- # @return [String] to
36
+ # @return [String] account to which funds are transferred
37
37
  def get_to
38
38
  @to
39
39
  end
40
40
 
41
- # @return [String] source
41
+ # @return [String] tource purse
42
42
  def get_source
43
43
  @source
44
44
  end
45
45
 
46
- # @return [String] target
46
+ # @return [String] target purse
47
47
  def get_target
48
48
  @target
49
49
  end
50
50
 
51
- # @return [String] amount
51
+ # @return [String] transfer amount
52
52
  def get_amount
53
53
  @amount
54
54
  end
@@ -57,7 +57,7 @@ module Casper
57
57
  def get_gas
58
58
  @gas
59
59
  end
60
- # @return [Integer] id
60
+ # @return [Integer] user-defined id
61
61
  def get_id
62
62
  @id
63
63
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CasperNetworkSDK
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # client_spec.rb
2
- require './lib/casper_network.rb'
2
+ require './lib/rpc/rpc_client.rb'
3
3
 
4
- describe CasperClient do
5
- client1 = CasperClient.new("185.246.84.43")
4
+ describe Casper::RpcClient do
5
+ client1 = Casper::RpcClient.new("185.246.84.43")
6
6
  # Test info_get_peers()
7
7
  describe "#info_get_peers" do
8
8
  it "returns peers array." do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casper_network
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Sait Gülmez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-20 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem enables developers to interact with the Casper Network.
14
14
  email: cenggulmez.65@gmail.com
@@ -35,6 +35,11 @@ files:
35
35
  - lib/entity/auction_state.rb
36
36
  - lib/entity/bid.rb
37
37
  - lib/entity/bid_info.rb
38
+ - lib/entity/block.rb
39
+ - lib/entity/block_body.rb
40
+ - lib/entity/block_header.rb
41
+ - lib/entity/block_info.rb
42
+ - lib/entity/block_proof.rb
38
43
  - lib/entity/contract.rb
39
44
  - lib/entity/contract_package.rb
40
45
  - lib/entity/contract_version.rb
@@ -58,6 +63,7 @@ files:
58
63
  - lib/entity/module_bytes.rb
59
64
  - lib/entity/peer.rb
60
65
  - lib/entity/seigniorage_allocation.rb
66
+ - lib/entity/status.rb
61
67
  - lib/entity/stored_contract_by_hash.rb
62
68
  - lib/entity/stored_contract_by_name.rb
63
69
  - lib/entity/stored_value.rb