casper_network 1.0.0 → 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 +4 -4
- data/README.md +275 -17
- data/lib/casper_network.rb +22 -8
- data/lib/crypto/00_asymmetric_key.rb +1 -1
- data/lib/crypto/asymmetric_key.rb +1 -1
- data/lib/entity/account.rb +1 -1
- data/lib/entity/action_thresholds.rb +2 -2
- data/lib/entity/associated_key.rb +1 -1
- data/lib/entity/auction_state.rb +57 -8
- data/lib/entity/bid.rb +2 -1
- data/lib/entity/bid_info.rb +2 -1
- data/lib/entity/block.rb +39 -0
- data/lib/entity/block_body.rb +35 -0
- data/lib/entity/block_header.rb +81 -0
- data/lib/entity/block_info.rb +56 -0
- data/lib/entity/block_proof.rb +24 -0
- data/lib/entity/contract.rb +1 -1
- data/lib/entity/delegator.rb +1 -0
- data/lib/entity/deploy.rb +1 -0
- data/lib/entity/deploy_approval.rb +1 -0
- data/lib/entity/deploy_executable.rb +4 -3
- data/lib/entity/deploy_executable_item_internal.rb +1 -0
- data/lib/entity/deploy_executable_transfer.rb +1 -0
- data/lib/entity/deploy_hash.rb +1 -0
- data/lib/entity/deploy_header.rb +1 -0
- data/lib/entity/deploy_info.rb +1 -0
- data/lib/entity/deploy_named_argument.rb +1 -0
- data/lib/entity/deploy_transfer.rb +1 -0
- data/lib/entity/era_summary.rb +14 -12
- data/lib/entity/era_validator.rb +1 -0
- data/lib/entity/executable_deploy_item.rb +1 -1
- data/lib/entity/group.rb +2 -2
- data/lib/entity/module_bytes.rb +1 -0
- data/lib/entity/peer.rb +1 -0
- data/lib/entity/status.rb +80 -0
- data/lib/entity/stored_contract_by_hash.rb +1 -0
- data/lib/entity/stored_contract_by_name.rb +2 -0
- data/lib/entity/stored_value.rb +86 -11
- data/lib/entity/stored_versioned_contract_by_hash.rb +2 -0
- data/lib/entity/stored_versioned_contract_by_name.rb +2 -0
- data/lib/entity/transfer.rb +8 -7
- data/lib/entity/validator_weight.rb +1 -0
- data/lib/rpc/rpc_client.rb +1 -1
- data/lib/rpc/rpc_error.rb +1 -0
- data/lib/serialization/cl_type_serializer.rb +1 -0
- data/lib/serialization/cl_value_bytes_parsers.rb +1 -1
- data/lib/serialization/cl_value_serializer.rb +1 -0
- data/lib/serialization/deploy_approval_serializer.rb +1 -0
- data/lib/serialization/deploy_executable_serializer.rb +3 -2
- data/lib/serialization/deploy_header_serializer.rb +2 -2
- data/lib/serialization/deploy_named_arg_serializer.rb +1 -0
- data/lib/serialization/deploy_serializer.rb +1 -0
- data/lib/types/cl_type.rb +5 -3
- data/lib/types/cl_uref.rb +2 -1
- data/lib/types/cl_value.rb +1 -0
- data/lib/utils/byte_utils.rb +3 -3
- data/lib/version.rb +1 -1
- data/spec/client_spec.rb +20 -20
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3446db6dad9ec70e0ad842479120abfe4cb919a7c65be7af300da5473a6e342f
|
4
|
+
data.tar.gz: d101cdc5acccc2ea222fb41a36baf819499cea70faaad98c8cbeb35a7955a833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
46
|
-
|
45
|
+
bundle exec rspec
|
46
|
+
# To see the test results in detail
|
47
|
+
bundle exec rspec -fd
|
47
48
|
```
|
48
49
|
|
49
|
-
##
|
50
|
+
## How run each test file individually
|
50
51
|
```bash
|
51
52
|
git checkout main
|
52
53
|
# Run the test
|
53
|
-
rspec spec/
|
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
|
-
- [
|
161
|
-
- [
|
162
|
-
- [
|
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
|
-
- [
|
423
|
+
- [x] SDK calls will return Casper domain-specific objects
|
data/lib/casper_network.rb
CHANGED
@@ -10,14 +10,13 @@ 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 }
|
17
17
|
require_relative './include.rb'
|
18
|
-
# Class for interacting with the network via RPC
|
19
|
-
# puts "Hello"
|
20
18
|
module Casper
|
19
|
+
# Interacting with the network
|
21
20
|
class CasperClient
|
22
21
|
attr_accessor :ip_address, :port, :url, :state_root_hash
|
23
22
|
|
@@ -142,6 +141,8 @@ module Casper
|
|
142
141
|
status = Timeout::timeout(10) {
|
143
142
|
client = Jimson::Client.new(@url)
|
144
143
|
@node_status = client.info_get_status
|
144
|
+
@node_status.deep_symbolize_keys!
|
145
|
+
Casper::Entity::Status.new(@node_status)
|
145
146
|
}
|
146
147
|
rescue
|
147
148
|
@rpc_error = Casper::RpcError::ErrorHandle.new
|
@@ -177,7 +178,8 @@ module Casper
|
|
177
178
|
if (!@block_info.empty?() && @block_info["hash"] != block_hash)
|
178
179
|
raise("Returned block does not have a matching hash.")
|
179
180
|
else
|
180
|
-
@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])
|
181
183
|
end
|
182
184
|
}
|
183
185
|
rescue
|
@@ -197,7 +199,8 @@ module Casper
|
|
197
199
|
if @era_summary == nil
|
198
200
|
Casper::RpcError::InvalidParameter.error
|
199
201
|
else
|
200
|
-
@era_summary
|
202
|
+
@era_summary.deep_symbolize_keys!
|
203
|
+
Casper::Entity::EraSummary.new(@era_summary)
|
201
204
|
end
|
202
205
|
}
|
203
206
|
rescue
|
@@ -218,7 +221,8 @@ module Casper
|
|
218
221
|
"path" => path
|
219
222
|
})
|
220
223
|
@stored_value = response["stored_value"]
|
221
|
-
@stored_value
|
224
|
+
@stored_value.deep_symbolize_keys!
|
225
|
+
Casper::Entity::StoredValue.new(@stored_value)
|
222
226
|
}
|
223
227
|
rescue
|
224
228
|
Casper::RpcError::InvalidParameter.error
|
@@ -237,7 +241,10 @@ module Casper
|
|
237
241
|
"dictionary_identifier" => {'URef' =>
|
238
242
|
{'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
|
239
243
|
@stored_value = response["stored_value"]
|
240
|
-
@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])
|
241
248
|
}
|
242
249
|
rescue
|
243
250
|
Casper::RpcError::InvalidParameter.error
|
@@ -264,13 +271,19 @@ module Casper
|
|
264
271
|
|
265
272
|
# Returns current auction system contract information.
|
266
273
|
# @return [Hash] auction_state
|
267
|
-
def state_get_AuctionInfo
|
274
|
+
def state_get_AuctionInfo(block_hash = "")
|
268
275
|
begin
|
269
276
|
state = Timeout::timeout(50) {
|
270
277
|
client = Jimson::Client.new(@url)
|
271
278
|
response = client.state_get_auction_info
|
272
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]
|
273
284
|
@auction_state
|
285
|
+
bids = @auction_state[:bids]
|
286
|
+
Casper::Entity::AuctionState.new(state_root_hash, block_height, era_validators, bids)
|
274
287
|
}
|
275
288
|
rescue
|
276
289
|
@rpc_error = Casper::RpcError::ErrorHandle.new
|
@@ -278,6 +291,7 @@ module Casper
|
|
278
291
|
end
|
279
292
|
end
|
280
293
|
|
294
|
+
# @param [Deploy] deploy
|
281
295
|
def put_deploy(deploy)
|
282
296
|
client = Jimson::Client.new(url)
|
283
297
|
response = client.account_put_deploy(deploy)
|
@@ -56,7 +56,7 @@ class AsymmetricKey
|
|
56
56
|
bytes = prefix + @public_key.get_value
|
57
57
|
result_array = Utils::HashUtils.byte_hash(bytes)
|
58
58
|
@public_key.get_value.length == 0 ? [] : result_array
|
59
|
-
|
59
|
+
#** @public_key.to_account_hash_byte_array
|
60
60
|
end
|
61
61
|
|
62
62
|
# @param [String] path_to_private_key
|
@@ -56,7 +56,7 @@ class AsymmetricKey
|
|
56
56
|
bytes = prefix + @public_key.get_value
|
57
57
|
result_array = Utils::HashUtils.byte_hash(bytes)
|
58
58
|
@public_key.get_value.length == 0 ? [] : result_array
|
59
|
-
|
59
|
+
#*** @public_key.to_account_hash_byte_array
|
60
60
|
end
|
61
61
|
|
62
62
|
# @param [String] path_to_private_key
|
data/lib/entity/account.rb
CHANGED
@@ -5,7 +5,7 @@ module Casper
|
|
5
5
|
|
6
6
|
# @param [CLAccountHash] account_hash
|
7
7
|
# @param [Array] named_keys
|
8
|
-
# @param [CLUref] main_purse
|
8
|
+
# @param [CLUref] main_purse The account's main purse URef
|
9
9
|
# @param [Array] associated_keys
|
10
10
|
# @param [Array<ActionThresHolds>] action_thresholds
|
11
11
|
def initialize(account_hash, named_keys, main_purse, associated_keys, action_thresholds)
|
@@ -4,8 +4,8 @@ module Casper
|
|
4
4
|
# @note The minimum weight thresholds that have to be met when executing an action of a certain type.
|
5
5
|
class ActionThresholds
|
6
6
|
|
7
|
-
# @param [Integer] deployment
|
8
|
-
# @param [Integer] key_management
|
7
|
+
# @param [Integer] deployment Threshold required to perform deployment actions.
|
8
|
+
# @param [Integer] key_management Threshold required to perform key management actions.
|
9
9
|
def initialize(deployment, key_management)
|
10
10
|
@deployment = deployment
|
11
11
|
@key_management = key_management
|
data/lib/entity/auction_state.rb
CHANGED
@@ -1,35 +1,84 @@
|
|
1
1
|
module Casper
|
2
2
|
module Entity
|
3
|
+
# Data structure summarizing auction contract data.
|
3
4
|
class AuctionState
|
4
5
|
# @param [String] state_root_hash
|
5
6
|
# @param [Integer] block_height
|
6
|
-
# @param [Array] era_validators
|
7
|
-
# @
|
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
|
8
11
|
def initialize(state_root_hash, block_height, era_validators, bids)
|
9
12
|
@state_root_hash = state_root_hash
|
10
13
|
@block_height = block_height
|
11
|
-
|
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
|
+
|
12
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
|
13
62
|
end
|
14
63
|
|
15
|
-
# @return [String]
|
64
|
+
# @return [String] state root hash as a String
|
16
65
|
def get_state_root_hash
|
17
66
|
@state_root_hash
|
18
67
|
end
|
19
68
|
|
20
|
-
# @return [Integer]
|
69
|
+
# @return [Integer] block height as an Integer
|
21
70
|
def get_block_height
|
22
71
|
@block_height
|
23
72
|
end
|
24
73
|
|
25
|
-
# @return [Array<
|
74
|
+
# @return [Array<EraValidator>] array of EraValidator
|
26
75
|
def get_era_validators
|
27
76
|
@era_validators
|
28
77
|
end
|
29
78
|
|
30
|
-
# @return [Array<
|
79
|
+
# @return [Array<Bid>] array of Bid
|
31
80
|
def get_bids
|
32
|
-
@
|
81
|
+
@bids_list
|
33
82
|
end
|
34
83
|
end
|
35
84
|
end
|
data/lib/entity/bid.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Casper
|
2
2
|
module Entity
|
3
|
+
# An entry in the validator map.
|
3
4
|
class Bid
|
4
5
|
|
5
6
|
# @param [String] public_key
|
6
7
|
# @param [BidInfo] bid_info
|
7
8
|
def initialize(public_key, bid_info)
|
8
9
|
@public_key = public_key
|
9
|
-
@
|
10
|
+
@bid_info = bid_info
|
10
11
|
|
11
12
|
end
|
12
13
|
|
data/lib/entity/bid_info.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Casper
|
2
2
|
module Entity
|
3
|
+
# BidInfo
|
3
4
|
class BidInfo
|
4
5
|
|
5
6
|
# @param [String] bonding_purse
|
6
7
|
# @param [String] staked_amount
|
7
8
|
# @param [Integer] delegation_rate
|
8
9
|
# @param [VestingSchedule] vesting_schedule
|
9
|
-
# @param [
|
10
|
+
# @param [Array<Delegator>] delegators
|
10
11
|
# @param [Boolean] inactive
|
11
12
|
def initialize(bonding_purse, staked_amount, delegation_rate, vesting_schedule, delegators, inactive)
|
12
13
|
@bonding_purse = bonding_purse
|
data/lib/entity/block.rb
ADDED
@@ -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
|