casper_network 1.0.1 → 1.1.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +490 -89
  3. data/lib/casper_network.rb +28 -10
  4. data/lib/crypto/asymmetric_key.rb +19 -18
  5. data/lib/crypto/ed25519.rb +114 -0
  6. data/lib/crypto/ed25519_key.rb +111 -10
  7. data/lib/crypto/keys.rb +1 -2
  8. data/lib/crypto/keys_util.rb +20 -0
  9. data/lib/entity/auction_state.rb +56 -8
  10. data/lib/entity/bid.rb +1 -1
  11. data/lib/entity/bid_info.rb +1 -1
  12. data/lib/entity/block.rb +39 -0
  13. data/lib/entity/block_body.rb +35 -0
  14. data/lib/entity/block_header.rb +81 -0
  15. data/lib/entity/block_info.rb +56 -0
  16. data/lib/entity/block_proof.rb +24 -0
  17. data/lib/entity/deploy.rb +154 -1
  18. data/lib/entity/deploy_executable.rb +50 -7
  19. data/lib/entity/deploy_executable_item_internal.rb +1 -1
  20. data/lib/entity/deploy_header.rb +17 -0
  21. data/lib/entity/deploy_named_argument.rb +61 -2
  22. data/lib/entity/era_summary.rb +13 -12
  23. data/lib/entity/module_bytes.rb +9 -2
  24. data/lib/entity/status.rb +80 -0
  25. data/lib/entity/stored_value.rb +86 -11
  26. data/lib/entity/transfer.rb +7 -7
  27. data/lib/include.rb +2 -0
  28. data/lib/serialization/cl_value_serializer.rb +69 -12
  29. data/lib/serialization/deploy_serializer.rb +129 -15
  30. data/lib/types/cl_option.rb +9 -1
  31. data/lib/types/cl_public_key.rb +2 -0
  32. data/lib/types/cl_value.rb +8 -0
  33. data/lib/utils/byte_utils.rb +28 -0
  34. data/lib/utils/helpers.rb +10 -0
  35. data/lib/version.rb +1 -1
  36. data/spec/cl_value_serializer_spec.rb +15 -1
  37. data/spec/client_spec.rb +3 -3
  38. data/spec/deploy_executable_spec.rb +90 -0
  39. data/spec/testnet_spec.rb +5 -3
  40. metadata +13 -24
  41. data/lib/crypto/00_asymmetric_key.rb +0 -95
  42. data/lib/crypto/01_ed25519.rb +0 -67
  43. data/lib/crypto/key_pair.rb +0 -40
  44. data/lib/crypto/secp256k1_key.rb +0 -0
  45. data/lib/crypto/test_ed25519_key.rb +0 -44
  46. data/lib/entity/executable_deploy_item.rb +0 -11
  47. data/lib/serialization/test.rb +0 -431
  48. data/lib/types/cl_account_hash.rb +0 -24
  49. data/lib/types/cl_account_hash_type.rb +0 -22
  50. data/lib/utils/utils.rb +0 -2
  51. data/spec/a_spec.rb +0 -697
  52. data/spec/cl_public_spec.rb +0 -169
  53. data/spec/crypto_spec.rb +0 -42
  54. data/spec/deploy_executable_serializer_spec.rb +0 -0
  55. data/spec/deploy_serializer_test_spec.rb +0 -225
  56. data/spec/string_spec.rb +0 -68
@@ -10,11 +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
+ require_relative './crypto/ed25519_key.rb'
19
+ require_relative './crypto/asymmetric_key.rb'
18
20
  module Casper
19
21
  # Interacting with the network
20
22
  class CasperClient
@@ -141,6 +143,8 @@ module Casper
141
143
  status = Timeout::timeout(10) {
142
144
  client = Jimson::Client.new(@url)
143
145
  @node_status = client.info_get_status
146
+ @node_status.deep_symbolize_keys!
147
+ Casper::Entity::Status.new(@node_status)
144
148
  }
145
149
  rescue
146
150
  @rpc_error = Casper::RpcError::ErrorHandle.new
@@ -176,7 +180,8 @@ module Casper
176
180
  if (!@block_info.empty?() && @block_info["hash"] != block_hash)
177
181
  raise("Returned block does not have a matching hash.")
178
182
  else
179
- @block_info
183
+ @block_info.deep_symbolize_keys!
184
+ Casper::Entity::Block.new(@block_info[:hash], @block_info[:header], @block_info[:body], @block_info[:proofs])
180
185
  end
181
186
  }
182
187
  rescue
@@ -196,7 +201,8 @@ module Casper
196
201
  if @era_summary == nil
197
202
  Casper::RpcError::InvalidParameter.error
198
203
  else
199
- @era_summary
204
+ @era_summary.deep_symbolize_keys!
205
+ Casper::Entity::EraSummary.new(@era_summary)
200
206
  end
201
207
  }
202
208
  rescue
@@ -217,7 +223,8 @@ module Casper
217
223
  "path" => path
218
224
  })
219
225
  @stored_value = response["stored_value"]
220
- @stored_value
226
+ @stored_value.deep_symbolize_keys!
227
+ Casper::Entity::StoredValue.new(@stored_value)
221
228
  }
222
229
  rescue
223
230
  Casper::RpcError::InvalidParameter.error
@@ -236,7 +243,10 @@ module Casper
236
243
  "dictionary_identifier" => {'URef' =>
237
244
  {'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
238
245
  @stored_value = response["stored_value"]
239
- @stored_value
246
+ @stored_value.deep_symbolize_keys!
247
+ # cl_type = @stored_value[:CLValue][:cl_type]
248
+ # bytes = @stored_value[:CLValue][:bytes]
249
+ DeploySerializer.new().build_cl_value(@stored_value[:CLValue])
240
250
  }
241
251
  rescue
242
252
  Casper::RpcError::InvalidParameter.error
@@ -263,13 +273,19 @@ module Casper
263
273
 
264
274
  # Returns current auction system contract information.
265
275
  # @return [Hash] auction_state
266
- def state_get_AuctionInfo
276
+ def state_get_AuctionInfo(block_hash = "")
267
277
  begin
268
278
  state = Timeout::timeout(50) {
269
279
  client = Jimson::Client.new(@url)
270
280
  response = client.state_get_auction_info
271
281
  @auction_state = response['auction_state']
272
- @auction_state
282
+ @auction_state.deep_symbolize_keys!
283
+ state_root_hash = @auction_state[:state_root_hash]
284
+ block_height = @auction_state[:block_height]
285
+ era_validators = @auction_state[:era_validators]
286
+
287
+ bids = @auction_state[:bids]
288
+ Casper::Entity::AuctionState.new(state_root_hash, block_height, era_validators, bids)
273
289
  }
274
290
  rescue
275
291
  @rpc_error = Casper::RpcError::ErrorHandle.new
@@ -277,10 +293,12 @@ module Casper
277
293
  end
278
294
  end
279
295
 
296
+ # @param [Deploy] deploy
280
297
  def put_deploy(deploy)
281
- client = Jimson::Client.new(url)
282
- response = client.account_put_deploy(deploy)
283
- response['deploy_hash']
298
+ client = Jimson::Client.new(@url)
299
+ response = client.account_put_deploy({
300
+ "deploy" => deploy
301
+ })
284
302
  end
285
303
 
286
304
  end
@@ -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)
@@ -0,0 +1,114 @@
1
+ require 'ed25519'
2
+ require 'blake2b'
3
+ require 'chilkat'
4
+ signing_key = Ed25519::SigningKey.generate
5
+ # puts "signing_key:\t #{signing_key}"
6
+ # puts "seed:\t #{signing_key.seed}"
7
+ # puts "keypair:\t #{signing_key.keypair}"
8
+ # puts "verify_key:\t #{signing_key.verify_key}"
9
+ # serialized_deploy_to_hash = "dc7edd3dde249343bc379564724b3e30116d8d84702a589513728f2e09bcd167"
10
+ # signature = Ed25519.provider.sign("MC4CAQAwBQYDK2VwBCIEIKf7pd4LhteUsRPmagsm7by7YWZVM+thD/fWoP+QDZO7", serialized_deploy_to_hash)
11
+
12
+ # key = Blake2b::Key.none
13
+ # signature = "01" + Blake2b.hex(signature, key, 64)
14
+ # puts signature
15
+ # message = "hello"
16
+ # signature = signing_key.sign(message)
17
+ # puts "signature:\t #{signature}"
18
+
19
+ # verify_key = signing_key.verify_key
20
+ # puts "verify_key:\t #{verify_key}"
21
+
22
+ # check_validity_of_signature = verify_key.verify(signature, message)
23
+ # puts "check_validity_of_signature:\t #{check_validity_of_signature}"
24
+
25
+ # # Serializing Keys
26
+ # signature_key_bytes = signing_key.to_bytes
27
+ # puts "signature_key_bytes:\t #{signature_key_bytes}"
28
+ # verify_key_bytes = verify_key.to_bytes
29
+ # puts "verify_key_bytes:\t #{verify_key_bytes}"
30
+
31
+ # signing_key = Ed25519::SigningKey.new(signature_key_bytes)
32
+ # puts "signing_key:\t #{signing_key}"
33
+ # verify_key = Ed25519::VerifyKey.new(verify_key_bytes)
34
+ # puts "verify_key:\t #{verify_key}
35
+
36
+
37
+ #************************************************************************************************************
38
+
39
+
40
+ # Load an Ed25519 key
41
+ privKey = Chilkat::CkPrivateKey.new()
42
+
43
+ # Load an Ed25519 key from an unencrypted PEM file (no password required).
44
+ success = privKey.LoadAnyFormatFile("#{Dir.home}/Downloads/ed25519_secret_key.pem","")
45
+ if (success == false)
46
+ print privKey.lastErrorText() + "\n";
47
+ exit
48
+ end
49
+
50
+ # The key type should be "ed25519" to indicate an Ed25519 key.
51
+ print "key type = " + privKey.keyType() + "\n";
52
+ # key type = ed25519
53
+
54
+ # # What is the size of the private key in bits? (should always be 256 bits for Ed25519)
55
+ print "size in bits = " + privKey.get_BitLength().to_s() + "\n";
56
+ # size in bits = 256
57
+
58
+ # # Get the private and public key parts in raw hex format:
59
+ sbPubKeyHex = Chilkat::CkStringBuilder.new()
60
+ privKeyHex = privKey.getRawHex(sbPubKeyHex)
61
+
62
+ # # We should have a 32-byte private key (a 64 character hex string).
63
+ print "private key = " + privKeyHex + "\n";
64
+ # private key = a7fba5de0b86d794b113e66a0b26edbcbb61665533eb610ff7d6a0ff900d93bb
65
+
66
+ # # We should have a 32-byte public key (a 64 character hex string).
67
+ print "public key = " + sbPubKeyHex.getAsString() + "\n";
68
+ # public key = ccee19366eaf03487cb81197ae8edcb1b47f214cee00d6597380096b9f8463c1
69
+
70
+
71
+
72
+ # This example assumes the Chilkat API to have been previously unlocked.
73
+ # See Global Unlock Sample for sample code.
74
+
75
+ privKeyHex = "a7fba5de0b86d794b113e66a0b26edbcbb61665533eb610ff7d6a0ff900d93bb"
76
+ pubKeyHex = "ccee19366eaf03487cb81197ae8edcb1b47f214cee00d6597380096b9f8463c1"
77
+
78
+ privKey = Chilkat::CkPrivateKey.new()
79
+ # This example shows only one way of loading an Ed25519 private key.
80
+ # Chilkat can load other formats (JWK, PEM, ASN.1 DER, etc.)
81
+ # You may do so by calling LoadAnyFormat or LoadAnyFormatFile.
82
+ success = privKey.LoadEd25519(privKeyHex,pubKeyHex)
83
+ if (success == false)
84
+ print privKey.lastErrorText() + "\n";
85
+ exit
86
+ end
87
+
88
+ # The data to be signed...
89
+ bd = Chilkat::CkBinData.new()
90
+ deploy_hash = "633435d9660122917fd5b4de16b7f495959cd832b9ef293486c6893dc694ec26"
91
+ bd.AppendString(deploy_hash,"utf-8")
92
+ eddsa = Chilkat::CkEdDSA.new()
93
+ hexSig = eddsa.signBdENC(bd,"hexlower",privKey)
94
+
95
+ print "signature = " + "01" + hexSig + "\n";
96
+
97
+ # The expected output is: 016d49ac6138e556c9174c9c8e0d512bbb4697bbe3e96a28d8c1be83ea05c3a5945b6b87e4c974ae04e6cbcbac78bbbce672648444e269bdf30d27686fa03a440e
98
+
99
+ # # Verify the signature..
100
+ pubKey = Chilkat::CkPublicKey.new()
101
+ success = pubKey.LoadEd25519(pubKeyHex)
102
+ if (success == false)
103
+ print pubKey.lastErrorText() + "\n";
104
+ exit
105
+ end
106
+ puts pubKey
107
+ bVerified = eddsa.VerifyBdENC(bd,hexSig,"hexlower",pubKey)
108
+ if (bVerified == false)
109
+ print eddsa.lastErrorText() + "\n";
110
+ print "Failed to verify the signature." + "\n";
111
+ exit
112
+ end
113
+
114
+ print "The Ed25519 signature is verified!" + "\n";
@@ -1,23 +1,129 @@
1
1
  require 'openssl'
2
2
  require 'ed25519'
3
- require_relative './asymmetric_key.rb'
3
+ require 'blake2b'
4
+ require 'chilkat'
5
+
6
+ # CLPublicKeyTag = {
7
+ # ED25519: 1,
8
+ # SECP256K1: 2
9
+ # }
4
10
 
5
11
  # ED25519 private key length in bytes
6
12
  PRIVATE_KEY_LENGTH = 32
7
13
 
8
- class Ed25519Key < AsymmetricKey
14
+ class Ed25519Key
15
+ # attr_reader :public_key, :private_key, :signature_algorithm
16
+ attr_accessor :public_key_hex, :signature_algorithm, :privKey, :private_key_hex
17
+ # attr_reader :private_key_hex, :privKey
18
+ include Utils::HashUtils
19
+
20
+ def initialize()
21
+ # file_path = "#{Dir.home}/ed25519_secret_key.pem"
22
+ @file_path = "#{Dir.home}/ed25519_secret_key.pem"
23
+ @privKey = Chilkat::CkPrivateKey.new()
24
+
25
+ # This loads an Ed25519 key from an unencrypted PEM file (no password required).
26
+ success = @privKey.LoadAnyFormatFile(@file_path,"")
27
+ if (success == false)
28
+ print @privKey.lastErrorText() + "\n";
29
+ exit
30
+ end
31
+
32
+ @signature_algorithm = @privKey.keyType()
33
+
34
+ # 32-byte (256-bit)
35
+ @private_key_bit_length = @privKey.get_BitLength
36
+
37
+ # Get the private and public key parts in raw hex format
38
+ sbPubKeyHex = Chilkat::CkStringBuilder.new()
39
+
40
+ @private_key_hex = @privKey.getRawHex(sbPubKeyHex)
41
+
42
+ @public_key_hex = sbPubKeyHex.getAsString()
43
+
44
+ success = @privKey.LoadEd25519(@private_key_hex, @public_key_hex)
45
+ if (success == false)
46
+ print @privKey.lastErrorText() + "\n";
47
+ exit
48
+ end
49
+ end
50
+
51
+ def get_public_key
52
+ raise ArgumentError, "Expected a 64 character hex String" unless @public_key_hex.length == 64
53
+ return "01" + @public_key_hex
54
+ end
55
+
56
+ def get_private_key
57
+ raise ArgumentError, "Expected a 64 character hex String" unless @private_key_hex.length == 64
58
+ return @private_key_hex
59
+ end
60
+
61
+ # @return [String] an encoded string, as specified by the encoding argument.
62
+ def get_private_key_base_encoded_format(encoding)
63
+ # encoding can be "base64"
64
+ privKey.getPkcs1ENC(encoding)
65
+ end
66
+
67
+ def sign(message)
68
+ success = @privKey.LoadEd25519(@private_key_hex, @public_key_hex)
69
+ if (success == false)
70
+ print @privKey.lastErrorText() + "\n";
71
+ exit
72
+ end
73
+ @message = message
74
+ # @message = Utils::ByteUtils.hex_to_byte_array(@message)
75
+
76
+
77
+ byteData = Chilkat::CkByteData.new()
78
+ byteData.appendEncoded(@message, "hex");
79
+
80
+ @bd = Chilkat::CkBinData.new()
81
+ @bd.AppendBinary(byteData)
82
+
83
+ @signer = Chilkat::CkEdDSA.new()
84
+ @signature = @signer.signBdENC(@bd, "hexlower", @privKey)
85
+ if @signature_algorithm == "ed25519"
86
+ @prefix = "0#{CLPublicKeyTag[:ED25519]}"
87
+ @signature = @prefix + @signature
88
+ end
89
+ @signature
90
+ end
91
+
92
+ # Verify the signature
93
+ def verify(signature, message)
94
+ pubKey = Chilkat::CkPublicKey.new()
95
+ success = pubKey.LoadEd25519(@public_key_hex)
96
+ if (success == false)
97
+ print pubKey.lastErrorText() + "\n";
98
+ exit
99
+ end
100
+ # Remove prefix "01"
101
+ signature = signature[2...]
102
+ verified = @signer.VerifyBdENC(@bd, signature, "hex", pubKey);
103
+ if (verified == false)
104
+ print @signer.lastErrorText() + "\n";
105
+ print "Failed to verify the signature." + "\n";
106
+ exit
107
+ end
108
+ return true
9
109
 
10
- def initialize(public_key, private_key)
11
- super(public_key, private_key, SignatureAlgorithm[:Ed25519])
12
110
  end
13
111
 
112
+ def public_key
113
+ if @signature_algorithm == "ed25519" && @private_key_hex.length == 64
114
+ prefix = "01"
115
+ @public_key = prefix + @public_key_hex
116
+ end
117
+ end
118
+
119
+
14
120
  # @param [Array] public_key
15
121
  # @return [String]
16
122
  # def self.account_hex(public_key)
17
123
  # '01' + Utils::Base16.encode16(public_key)
18
124
  # end
19
125
 
20
-
126
+ # @param [String] private_key_path
21
127
  def create_from_private_key_file(private_key_path)
22
128
 
23
129
  end
@@ -28,11 +134,6 @@ class Ed25519Key < AsymmetricKey
28
134
  def export_private_key_in_pem
29
135
  end
30
136
 
31
- def sign(msg)
32
- end
33
-
34
- def verify(signature, msg)
35
- end
36
137
 
37
138
  def private_to_public_key(private_key)
38
139
  end
data/lib/crypto/keys.rb CHANGED
@@ -1,5 +1,4 @@
1
-
2
- SignatureAlgorithm = {
1
+ SignatureAlgorithm = {
3
2
  Ed25519: 'ed25519',
4
3
  Secp256K1: 'secp256k1'
5
4
  }
@@ -0,0 +1,20 @@
1
+
2
+ module Utils
3
+ module KeysUtil
4
+ extend self
5
+
6
+ # @return Uint8Array
7
+ def read_base64_with_pem(content)
8
+
9
+ end
10
+
11
+ def to_pem(tag, content)
12
+ "-----BEGIN #{tag}-----\n" +
13
+ "#{content}\n" +
14
+ "-----END #{tag}-----\n"
15
+ end
16
+
17
+
18
+
19
+ end
20
+ end
@@ -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