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.
- checksums.yaml +4 -4
- data/README.md +490 -89
- data/lib/casper_network.rb +28 -10
- data/lib/crypto/asymmetric_key.rb +19 -18
- data/lib/crypto/ed25519.rb +114 -0
- data/lib/crypto/ed25519_key.rb +111 -10
- data/lib/crypto/keys.rb +1 -2
- data/lib/crypto/keys_util.rb +20 -0
- data/lib/entity/auction_state.rb +56 -8
- data/lib/entity/bid.rb +1 -1
- data/lib/entity/bid_info.rb +1 -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/deploy.rb +154 -1
- data/lib/entity/deploy_executable.rb +50 -7
- data/lib/entity/deploy_executable_item_internal.rb +1 -1
- data/lib/entity/deploy_header.rb +17 -0
- data/lib/entity/deploy_named_argument.rb +61 -2
- data/lib/entity/era_summary.rb +13 -12
- data/lib/entity/module_bytes.rb +9 -2
- data/lib/entity/status.rb +80 -0
- data/lib/entity/stored_value.rb +86 -11
- data/lib/entity/transfer.rb +7 -7
- data/lib/include.rb +2 -0
- data/lib/serialization/cl_value_serializer.rb +69 -12
- data/lib/serialization/deploy_serializer.rb +129 -15
- data/lib/types/cl_option.rb +9 -1
- data/lib/types/cl_public_key.rb +2 -0
- data/lib/types/cl_value.rb +8 -0
- data/lib/utils/byte_utils.rb +28 -0
- data/lib/utils/helpers.rb +10 -0
- data/lib/version.rb +1 -1
- data/spec/cl_value_serializer_spec.rb +15 -1
- data/spec/client_spec.rb +3 -3
- data/spec/deploy_executable_spec.rb +90 -0
- data/spec/testnet_spec.rb +5 -3
- metadata +13 -24
- data/lib/crypto/00_asymmetric_key.rb +0 -95
- data/lib/crypto/01_ed25519.rb +0 -67
- data/lib/crypto/key_pair.rb +0 -40
- data/lib/crypto/secp256k1_key.rb +0 -0
- data/lib/crypto/test_ed25519_key.rb +0 -44
- data/lib/entity/executable_deploy_item.rb +0 -11
- data/lib/serialization/test.rb +0 -431
- data/lib/types/cl_account_hash.rb +0 -24
- data/lib/types/cl_account_hash_type.rb +0 -22
- data/lib/utils/utils.rb +0 -2
- data/spec/a_spec.rb +0 -697
- data/spec/cl_public_spec.rb +0 -169
- data/spec/crypto_spec.rb +0 -42
- data/spec/deploy_executable_serializer_spec.rb +0 -0
- data/spec/deploy_serializer_test_spec.rb +0 -225
- data/spec/string_spec.rb +0 -68
@@ -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
|
data/lib/entity/stored_value.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/entity/transfer.rb
CHANGED
@@ -23,32 +23,32 @@ module Casper
|
|
23
23
|
@id = transfer[:id]
|
24
24
|
end
|
25
25
|
|
26
|
-
# @return [String]
|
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]
|
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/include.rb
CHANGED
@@ -7,6 +7,8 @@ Dir[File.join(
|
|
7
7
|
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/rpc/*.rb")].each {|file| require file }
|
8
8
|
Dir[File.join(
|
9
9
|
File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/utils/*.rb")].each {|file| require file }
|
10
|
+
# Dir[File.join(
|
11
|
+
# File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/crypto/*.rb")].each {|file| require file }
|
10
12
|
# path = File.join(
|
11
13
|
# File.dirname(File.dirname(File.absolute_path(__FILE__))),
|
12
14
|
# '/lib/types/cl_bool'
|
@@ -18,20 +18,26 @@ require_relative '../types/cl_uref.rb'
|
|
18
18
|
require_relative '../types/cl_tuple.rb'
|
19
19
|
require_relative '../types/cl_public_key.rb'
|
20
20
|
require_relative '../types/constants.rb'
|
21
|
-
require_relative '
|
21
|
+
require_relative './cl_value_bytes_parsers.rb'
|
22
|
+
require_relative '../utils/byte_utils.rb'
|
22
23
|
|
23
24
|
# Byte serializer for CLValue
|
24
25
|
class CLValueSerializer
|
26
|
+
def to_byte_array(num)
|
27
|
+
result = []
|
28
|
+
begin
|
29
|
+
result << (num & 0xff)
|
30
|
+
num >>= 8
|
31
|
+
end until (num == 0 || num == -1) && (result.last[7] == num[7])
|
32
|
+
# result.reverse
|
33
|
+
result
|
34
|
+
end
|
25
35
|
|
26
36
|
def to_bytes(clvalue)
|
27
37
|
type = clvalue.get_cl_type
|
28
38
|
value = clvalue.get_value
|
29
39
|
tag = CLType::TAGS[type.to_sym]
|
30
|
-
|
31
|
-
# puts value
|
32
|
-
# puts CLType::TAGS[type.to_sym]
|
33
|
-
# puts tag
|
34
|
-
[1].pack("L<*").unpack1("H*")
|
40
|
+
|
35
41
|
serialized = ""
|
36
42
|
if type == "Bool"
|
37
43
|
[1].pack("L<*").unpack1("H*") + [value.to_i].pack("C*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
@@ -50,7 +56,9 @@ class CLValueSerializer
|
|
50
56
|
elsif type == "U256"
|
51
57
|
[8].pack("L<*").unpack1("H*")
|
52
58
|
elsif type == "U512"
|
53
|
-
|
59
|
+
bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))[0...-2]
|
60
|
+
num_of_bytes = bytes.length/2
|
61
|
+
[num_of_bytes+1].pack("L<*").unpack1("H*") + [num_of_bytes].pack("C*").unpack1("H*") + bytes + [tag].pack("C*").unpack1("H*")
|
54
62
|
elsif type == "Unit"
|
55
63
|
[0].pack("L<*").unpack1("H*") + [tag].pack("C*").unpack1("H*")
|
56
64
|
elsif type == "String"
|
@@ -63,7 +71,31 @@ class CLValueSerializer
|
|
63
71
|
size = clvalue.to_bytes(uref).length/2
|
64
72
|
[size].pack("L<*").unpack1("H*") + clvalue.to_bytes(uref) + [tag].pack("C*").unpack1("H*")
|
65
73
|
elsif type == "Option"
|
66
|
-
|
74
|
+
=begin
|
75
|
+
# Solution 1, If we choose
|
76
|
+
# CLOption.new(data, inner_type) = CLOption.new({ "cl_type": inner_type, "bytes": bytes, "parsed": parsed), "U64")
|
77
|
+
inner_type = value[:cl_type]
|
78
|
+
bytes = value[:bytes]
|
79
|
+
parsed = value[:parsed]
|
80
|
+
data = { "cl_type": inner_type, "bytes": bytes, "parsed": parsed}
|
81
|
+
serialize_option_cl_value(data)
|
82
|
+
=end
|
83
|
+
inner_clvalue = value # => CLu64.new(1)
|
84
|
+
inner_value = value.get_value
|
85
|
+
inner_type = value.get_cl_type
|
86
|
+
# or
|
87
|
+
# inner_type = clvalue.get_inner_type
|
88
|
+
|
89
|
+
# puts "inner_clvalue #{inner_clvalue}"
|
90
|
+
inner_type = clvalue.get_inner_type # => or
|
91
|
+
inner_type = value.get_cl_type
|
92
|
+
# puts "inner_type = #{inner_type}"
|
93
|
+
# puts inner_value
|
94
|
+
bytes = Utils::ByteUtils.to_u64(inner_value)
|
95
|
+
bytes = "01" + bytes
|
96
|
+
length = bytes.size/2
|
97
|
+
tag = CLType::TAGS[inner_type.to_sym]
|
98
|
+
[length].pack("L<*").unpack1("H*") + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
67
99
|
elsif type == "List"
|
68
100
|
[0].pack("L<*").unpack1("H*")
|
69
101
|
elsif type == "ByteArray"
|
@@ -78,7 +110,6 @@ class CLValueSerializer
|
|
78
110
|
value1 = clvalue1.get_value
|
79
111
|
tag1 = CLType::TAGS[type1.to_sym]
|
80
112
|
serialized += helper(clvalue.get_value[0]) + [tag].pack("C*").unpack1("H*") + [tag1].pack("C*").unpack1("H*")
|
81
|
-
# [18].pack("C*").unpack1("H*") + cl_type.get_data[0].to_bytes
|
82
113
|
elsif type == "Tuple2"
|
83
114
|
clvalue1 = clvalue.get_value[0]
|
84
115
|
type1 = clvalue1.get_cl_type
|
@@ -134,7 +165,8 @@ class CLValueSerializer
|
|
134
165
|
elsif type == "U8"
|
135
166
|
[1].pack("L<*").unpack1("H*") + [value].pack("C*").unpack1("H*")
|
136
167
|
elsif type == "U32"
|
137
|
-
serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
168
|
+
# serialized += [4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
169
|
+
[4].pack("L<*").unpack1("H*") + [value].pack("L<*").unpack1("H*")
|
138
170
|
elsif type == "U64"
|
139
171
|
[8].pack("L<*").unpack1("H*") + [value].pack("Q<*").unpack1("H*")
|
140
172
|
elsif type == "U128"
|
@@ -142,7 +174,9 @@ class CLValueSerializer
|
|
142
174
|
elsif type == "U256"
|
143
175
|
[8].pack("L<*").unpack1("H*")
|
144
176
|
elsif type == "U512"
|
145
|
-
[
|
177
|
+
bytes = [value].pack("Q<*").unpack1("H*")
|
178
|
+
bytes = bytes[0, 8]
|
179
|
+
[8].pack("Q<*").unpack1("H*")
|
146
180
|
elsif type == "Unit"
|
147
181
|
[9].pack("C*").unpack1("H*")
|
148
182
|
elsif type == "String"
|
@@ -257,4 +291,27 @@ class CLValueSerializer
|
|
257
291
|
"Undefined"
|
258
292
|
end
|
259
293
|
end
|
260
|
-
|
294
|
+
|
295
|
+
def serialize_option_cl_value(data)
|
296
|
+
|
297
|
+
=begin
|
298
|
+
# Solution 1
|
299
|
+
# puts "\nOption:"
|
300
|
+
cl_type = data[:cl_type]
|
301
|
+
bytes = data[:bytes]
|
302
|
+
parsed = data[:parsed]
|
303
|
+
|
304
|
+
if cl_type == "U64"
|
305
|
+
length = bytes.length/2
|
306
|
+
# puts length
|
307
|
+
bytes = bytes[2..]
|
308
|
+
value = Utils::ByteUtils.hex_to_u64_value(bytes)
|
309
|
+
# puts value == 1650706686882
|
310
|
+
clvalue = CLu64.new(value)
|
311
|
+
tag = CLType::TAGS[cl_type.to_sym]
|
312
|
+
# puts "U64: " + [length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
313
|
+
[length].pack("L<*").unpack1("H*") + "01" + bytes + "0d" + [tag].pack("C*").unpack1("H*")
|
314
|
+
end
|
315
|
+
=end
|
316
|
+
end
|
317
|
+
end
|