test_sdk1 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +1 -0
- data/LICENSE +201 -0
- data/README.md +147 -0
- data/SECURITY.md +12 -0
- data/lib/crypto/00_asymmetric_key.rb +95 -0
- data/lib/crypto/01_ed25519.rb +67 -0
- data/lib/crypto/asymmetric_key.rb +87 -0
- data/lib/crypto/ed25519_key.rb +44 -0
- data/lib/crypto/key_pair.rb +40 -0
- data/lib/crypto/keys.rb +7 -0
- data/lib/crypto/secp256k1_key.rb +0 -0
- data/lib/crypto/test_ed25519_key.rb +44 -0
- data/lib/entity/account.rb +45 -0
- data/lib/entity/action_thresholds.rb +25 -0
- data/lib/entity/associated_key.rb +24 -0
- data/lib/entity/auction_state.rb +36 -0
- data/lib/entity/bid.rb +24 -0
- data/lib/entity/bid_info.rb +51 -0
- data/lib/entity/contract.rb +47 -0
- data/lib/entity/contract_package.rb +41 -0
- data/lib/entity/contract_version.rb +33 -0
- data/lib/entity/delegator.rb +37 -0
- data/lib/entity/deploy.rb +44 -0
- data/lib/entity/deploy_approval.rb +24 -0
- data/lib/entity/deploy_executable.rb +162 -0
- data/lib/entity/deploy_executable_item_internal.rb +26 -0
- data/lib/entity/deploy_executable_transfer.rb +50 -0
- data/lib/entity/deploy_hash.rb +16 -0
- data/lib/entity/deploy_header.rb +60 -0
- data/lib/entity/deploy_info.rb +44 -0
- data/lib/entity/deploy_named_argument.rb +19 -0
- data/lib/entity/deploy_transfer.rb +10 -0
- data/lib/entity/disabled_version.rb +26 -0
- data/lib/entity/era_info.rb +18 -0
- data/lib/entity/era_summary.rb +44 -0
- data/lib/entity/era_validator.rb +23 -0
- data/lib/entity/executable_deploy_item.rb +11 -0
- data/lib/entity/group.rb +25 -0
- data/lib/entity/module_bytes.rb +50 -0
- data/lib/entity/peer.rb +25 -0
- data/lib/entity/seigniorage_allocation.rb +18 -0
- data/lib/entity/stored_contract_by_hash.rb +50 -0
- data/lib/entity/stored_contract_by_name.rb +50 -0
- data/lib/entity/stored_value.rb +57 -0
- data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
- data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
- data/lib/entity/transfer.rb +65 -0
- data/lib/entity/validator_weight.rb +23 -0
- data/lib/entity/vesting_schedule.rb +22 -0
- data/lib/include.rb +18 -0
- data/lib/rpc/rpc.rb +227 -0
- data/lib/rpc/rpc_client.rb +233 -0
- data/lib/rpc/rpc_error.rb +79 -0
- data/lib/serialization/cl_type_serializer.rb +76 -0
- data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
- data/lib/serialization/cl_value_serializer.rb +259 -0
- data/lib/serialization/deploy_approval_serializer.rb +15 -0
- data/lib/serialization/deploy_executable_serializer.rb +27 -0
- data/lib/serialization/deploy_header_serializer.rb +49 -0
- data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
- data/lib/serialization/deploy_serializer.rb +268 -0
- data/lib/serialization/test.rb +431 -0
- data/lib/test_sdk1.rb +289 -0
- data/lib/types/cl_account_hash.rb +24 -0
- data/lib/types/cl_account_hash_type.rb +22 -0
- data/lib/types/cl_any.rb +25 -0
- data/lib/types/cl_any_type.rb +22 -0
- data/lib/types/cl_bool.rb +32 -0
- data/lib/types/cl_bool_type.rb +35 -0
- data/lib/types/cl_byte_array.rb +25 -0
- data/lib/types/cl_byte_array_type.rb +27 -0
- data/lib/types/cl_i32.rb +26 -0
- data/lib/types/cl_i32_type.rb +26 -0
- data/lib/types/cl_i64.rb +26 -0
- data/lib/types/cl_i64_type.rb +27 -0
- data/lib/types/cl_key.rb +39 -0
- data/lib/types/cl_key_type.rb +27 -0
- data/lib/types/cl_list.rb +25 -0
- data/lib/types/cl_list_type.rb +26 -0
- data/lib/types/cl_map.rb +25 -0
- data/lib/types/cl_map_type.rb +26 -0
- data/lib/types/cl_option.rb +33 -0
- data/lib/types/cl_option_type.rb +52 -0
- data/lib/types/cl_public_key.rb +152 -0
- data/lib/types/cl_public_key_type.rb +26 -0
- data/lib/types/cl_result.rb +25 -0
- data/lib/types/cl_result_type.rb +26 -0
- data/lib/types/cl_string.rb +39 -0
- data/lib/types/cl_string_type.rb +32 -0
- data/lib/types/cl_tuple.rb +151 -0
- data/lib/types/cl_tuple_type.rb +108 -0
- data/lib/types/cl_type.rb +94 -0
- data/lib/types/cl_type_tag.rb +51 -0
- data/lib/types/cl_u128.rb +26 -0
- data/lib/types/cl_u128_type.rb +26 -0
- data/lib/types/cl_u256.rb +26 -0
- data/lib/types/cl_u256_type.rb +26 -0
- data/lib/types/cl_u32.rb +26 -0
- data/lib/types/cl_u32_type.rb +26 -0
- data/lib/types/cl_u512.rb +26 -0
- data/lib/types/cl_u512_type.rb +26 -0
- data/lib/types/cl_u64.rb +26 -0
- data/lib/types/cl_u64_type.rb +27 -0
- data/lib/types/cl_u8.rb +26 -0
- data/lib/types/cl_u8_type.rb +26 -0
- data/lib/types/cl_unit.rb +38 -0
- data/lib/types/cl_unit_type.rb +22 -0
- data/lib/types/cl_uref.rb +120 -0
- data/lib/types/cl_uref_type.rb +46 -0
- data/lib/types/cl_value.rb +10 -0
- data/lib/types/constants.rb +50 -0
- data/lib/types/error.rb +7 -0
- data/lib/utils/base_16.rb +18 -0
- data/lib/utils/byte_utils.rb +107 -0
- data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
- data/lib/utils/hash_utils.rb +19 -0
- data/lib/utils/hex_utils.rb +12 -0
- data/lib/utils/time_utils.rb +85 -0
- data/lib/utils/utils.rb +2 -0
- data/lib/version.rb +3 -0
- data/spec/a_spec.rb +697 -0
- data/spec/byte_utils_spec.rb +72 -0
- data/spec/cl_public_spec.rb +169 -0
- data/spec/cl_types_spec.rb +715 -0
- data/spec/cl_value_serializer_spec.rb +140 -0
- data/spec/client_spec.rb +25 -0
- data/spec/crypto_spec.rb +42 -0
- data/spec/deploy_approval_serializer_spec.rb +26 -0
- data/spec/deploy_executable_serializer_spec.rb +0 -0
- data/spec/deploy_header_serializer_spec.rb +21 -0
- data/spec/deploy_named_arg_serializer_spec.rb +49 -0
- data/spec/deploy_serializer_spec.rb +77 -0
- data/spec/deploy_serializer_test_spec.rb +225 -0
- data/spec/mainnet_spec.rb +452 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/string_spec.rb +68 -0
- data/spec/testnet_spec.rb +498 -0
- data/spec/time_utils_spec.rb +87 -0
- metadata +198 -0
@@ -0,0 +1,431 @@
|
|
1
|
+
require_relative '../types/cl_bool.rb'
|
2
|
+
require_relative '../types/cl_i32.rb'
|
3
|
+
require_relative '../types/cl_i64.rb'
|
4
|
+
require_relative '../types/cl_u8.rb'
|
5
|
+
require_relative '../types/cl_u32.rb'
|
6
|
+
require_relative '../types/cl_u64.rb'
|
7
|
+
require_relative '../types/cl_string.rb'
|
8
|
+
# require_relative '../types/cl_key.rb'
|
9
|
+
require_relative '../types/cl_uref.rb'
|
10
|
+
require_relative '../types/cl_tuple.rb'
|
11
|
+
require_relative '../types/cl_public_key.rb'
|
12
|
+
require_relative './cl_type_serializer.rb'
|
13
|
+
require_relative './cl_value_serializer.rb'
|
14
|
+
require_relative '../entity/deploy_named_argument.rb'
|
15
|
+
require_relative './deploy_named_arg_serializer.rb'
|
16
|
+
require_relative '../entity/deploy_executable_item_internal.rb'
|
17
|
+
require_relative '../entity/deploy_executable.rb'
|
18
|
+
require_relative '../entity/stored_contract_by_hash.rb'
|
19
|
+
require_relative '../entity/stored_contract_by_name.rb'
|
20
|
+
require_relative '../entity/stored_versioned_contract_by_hash.rb'
|
21
|
+
require_relative '../entity/stored_versioned_contract_by_name.rb'
|
22
|
+
require_relative './deploy_executable_serializer.rb'
|
23
|
+
require_relative '../entity/deploy.rb'
|
24
|
+
require_relative '../entity/deploy_hash.rb'
|
25
|
+
require_relative '../entity/deploy_header.rb'
|
26
|
+
require_relative '../entity/deploy_approval.rb'
|
27
|
+
require_relative '../entity/deploy_info.rb'
|
28
|
+
require_relative '../entity/deploy.rb'
|
29
|
+
require_relative './deploy_serializer.rb'
|
30
|
+
require 'blake2b'
|
31
|
+
|
32
|
+
# *************************** CLValueSerializer::Start *****************************************************#
|
33
|
+
|
34
|
+
# arg = Casper::Entity::DeployNamedArgument.new("casper-testnet", CLBool.new(true))
|
35
|
+
# arg = Casper::Entity::DeployNamedArgument.new("casper-testnet", CLString.new("Hello, Casper!"))
|
36
|
+
arg = Casper::Entity::DeployNamedArgument.new("casper-testnet", CLString.new("Hello, World!"))
|
37
|
+
deploy_named_arg_serializer = DeployNamedArgSerializer.new
|
38
|
+
serializer = CLValueSerializer.new
|
39
|
+
|
40
|
+
# puts deploy_named_arg_serializer.to_bytes(arg)
|
41
|
+
# puts serializer.to_bytes(CLString.new("Hello, Casper!"))
|
42
|
+
# clvalue = CLBool.new(true)
|
43
|
+
# puts serializer.to_bytes(clvalue)
|
44
|
+
|
45
|
+
# clvalue = CLi32.new(-10)
|
46
|
+
# puts serializer.to_bytes(clvalue)
|
47
|
+
|
48
|
+
# clvalue = CLi64.new(-16)
|
49
|
+
# puts serializer.to_bytes(clvalue)
|
50
|
+
|
51
|
+
clvalue = CLu8.new(0x07)
|
52
|
+
# puts serializer.to_bytes(clvalue)
|
53
|
+
clvalue = CLu32.new(2.pow(32) - 1)
|
54
|
+
clvalue = CLu64.new(2.pow(64) - 1)
|
55
|
+
|
56
|
+
pub_key_hex_ed25519 = "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1"
|
57
|
+
pub_raw_ed25519 = [10, 245, 169, 67, 186, 205, 42, 142, 145, 121, 46, 180, 233, 162,
|
58
|
+
94, 50, 213, 54, 171, 16, 51, 114, 245, 127, 137, 235, 202, 223, 197, 152, 32, 209 ]
|
59
|
+
clvalue = CLPublicKey.new(pub_raw_ed25519, CLPublicKeyTag[:ED25519])
|
60
|
+
# puts serializer.to_bytes(clvalue)
|
61
|
+
|
62
|
+
clvalue = CLString.new("Hello, Casper!")
|
63
|
+
# puts serializer.to_bytes(clvalue)
|
64
|
+
|
65
|
+
uref = "uref-000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f-007"
|
66
|
+
clvalue = CLURef.new(uref)
|
67
|
+
# puts CLURef.parse_uref_address(uref)
|
68
|
+
# puts clvalue.to_bytes(uref)
|
69
|
+
# puts serializer.to_bytes(clvalue)
|
70
|
+
|
71
|
+
# u32 = CLu32.new(17)
|
72
|
+
# clvalue = CLTuple1.new([u32])
|
73
|
+
str = CLString.new("ABCDE")
|
74
|
+
clvalue = CLTuple1.new([str])
|
75
|
+
# puts clvalue.get_value.class # => Array
|
76
|
+
# puts clvalue.get_value[0].get_value
|
77
|
+
# puts serializer.to_bytes(clvalue)
|
78
|
+
|
79
|
+
u32_1 = CLu32.new(17)
|
80
|
+
u32_2 = CLu32.new(127)
|
81
|
+
clvalue = CLTuple2.new([u32_1, u32_2])
|
82
|
+
clvalue = CLTuple2.new([u32_2, str])
|
83
|
+
# clval1 = clvalue.get_value[0]
|
84
|
+
# puts serializer.to_bytes(clval1)
|
85
|
+
# clval2 = clvalue.get_value[1]
|
86
|
+
# puts serializer.to_bytes(clval2)
|
87
|
+
# puts serializer.to_bytes(clvalue)
|
88
|
+
|
89
|
+
# clvalue = CLTuple2.new([u32_1, u32_2])
|
90
|
+
# puts clvalue.get_size
|
91
|
+
# puts serializer.tuple_values_length(clvalue)
|
92
|
+
|
93
|
+
clvalue = CLTuple3.new([u32_1, u32_2, u32_1])
|
94
|
+
clvalue = CLTuple3.new([u32_2, str, u32_2])
|
95
|
+
# puts clvalue.get_cl_type
|
96
|
+
# puts serializer.to_bytes(clvalue)
|
97
|
+
|
98
|
+
|
99
|
+
clvalue = CLOption.new(CLBool.new(false))
|
100
|
+
|
101
|
+
# puts clvalue.get_cl_type
|
102
|
+
|
103
|
+
temp = CLType.new(false)
|
104
|
+
# p temp.get_cl_type_tag(:Bool)
|
105
|
+
# p temp.get_cl_type_tag(:Option)
|
106
|
+
# p temp.get_tags
|
107
|
+
|
108
|
+
opt_type = CLOptionType.new( CLBoolType.new())
|
109
|
+
# p opt_type
|
110
|
+
# p opt_type.to_string
|
111
|
+
# p opt_type.get_inner_type
|
112
|
+
# p opt_type.to_json
|
113
|
+
# p opt_type.to_bytes
|
114
|
+
|
115
|
+
cl_opt = CLOption.new(CLBool.new(true))
|
116
|
+
# p cl_opt.get_value
|
117
|
+
# p cl_opt.get_cl_type
|
118
|
+
|
119
|
+
|
120
|
+
# serializer = CLValueSerializer.new
|
121
|
+
# puts serializer.to_bytes(cloption1)
|
122
|
+
|
123
|
+
|
124
|
+
# *************************** CLValueSerializer::End *****************************************************#
|
125
|
+
|
126
|
+
|
127
|
+
# StoredContractByName: {
|
128
|
+
# "name": "casper-example",
|
129
|
+
# "entry_point": "example-entry-point",
|
130
|
+
# "args": [
|
131
|
+
# [
|
132
|
+
# "quantity",
|
133
|
+
# {
|
134
|
+
# "cl_type": "I32",
|
135
|
+
# "bytes": "e8030000",
|
136
|
+
# "parsed": 1000
|
137
|
+
# }
|
138
|
+
# ]
|
139
|
+
# ]
|
140
|
+
# }
|
141
|
+
|
142
|
+
#********************** DeployExecutableItemInternal ************************************************************
|
143
|
+
deploy_executable_item_internal = Casper::Entity::DeployExecutableItemInternal.new()
|
144
|
+
deploy_executable_item_internal.set_arg(Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000)))
|
145
|
+
deploy_executable_item_internal.set_arg(Casper::Entity::DeployNamedArgument.new("amount", CLi32.new(1000)))
|
146
|
+
# puts deploy_executable_item_internal.set_arg(Casper::Entity::DeployNamedArgument.new("amount", CLi32.new(1000)))[1][1].get_value
|
147
|
+
# puts deploy_executable_item_internal.args[0][0].get_name
|
148
|
+
# puts deploy_executable_item_internal.args[0][0].get_value.get_value
|
149
|
+
# puts deploy_executable_item_internal.args[1][0].get_name
|
150
|
+
# puts deploy_executable_item_internal.args[1][0].get_value.get_value
|
151
|
+
|
152
|
+
|
153
|
+
# 0) ********************** ModuleBytes ************************************************************
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
# 1) *************** StoredContractByHash ***************************** Done!
|
159
|
+
arg1 = Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000))
|
160
|
+
args = []
|
161
|
+
args.push([arg1])
|
162
|
+
stored_contract_by_hash = Casper::Entity::StoredContractByHash.new("c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa4", "pclphXwfYmCmdITj8hnh", args)
|
163
|
+
# puts stored_contract_by_hash.to_bytes
|
164
|
+
|
165
|
+
byte_array = stored_contract_by_hash.to_bytes
|
166
|
+
# puts byte_array.inspect
|
167
|
+
# puts Utils::ByteUtils.byte_array_to_hex(byte_array)
|
168
|
+
|
169
|
+
|
170
|
+
# 2) *************** StoredContractByName ***************************** Done!
|
171
|
+
arg1 = Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000))
|
172
|
+
args = []
|
173
|
+
args.push([arg1])
|
174
|
+
stored_contract_by_name = Casper::Entity::StoredContractByName.new("casper-example", "example-entry-point", args)
|
175
|
+
byte_array = stored_contract_by_name.to_bytes
|
176
|
+
# puts byte_array
|
177
|
+
# puts Utils::ByteUtils.byte_array_to_hex(byte_array)
|
178
|
+
|
179
|
+
|
180
|
+
# 3) *************** StoredVersionedContractByHash ***************************** # Done! (entry_point is not serialized in scala example but it is serialized in documentation)
|
181
|
+
arg1 = Casper::Entity::DeployNamedArgument.new("test", CLString.new("Hello, World!"))
|
182
|
+
args = []
|
183
|
+
args.push([arg1])
|
184
|
+
stored_versioned_contract_by_hash = Casper::Entity::StoredVersionedContractByHash.new("b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423",nil, "PsLz5c7JsqT8BK8ll0kF", args)
|
185
|
+
byte_array = stored_versioned_contract_by_hash.to_bytes
|
186
|
+
# puts byte_array.inspect
|
187
|
+
# puts Utils::ByteUtils.byte_array_to_hex(byte_array)
|
188
|
+
|
189
|
+
|
190
|
+
# 4) *************** StoredVersionedContractByName ***************************** # Done! (entry_point is not serialized in scala example but it is serialized in documentation)
|
191
|
+
arg1 = Casper::Entity::DeployNamedArgument.new("test", CLString.new("Hello, World!"))
|
192
|
+
args = []
|
193
|
+
args.push([arg1])
|
194
|
+
stored_versioned_contract_by_hash = Casper::Entity::StoredVersionedContractByName.new("test-contract",nil, "PsLz5c7JsqT8BK8ll0kF", args)
|
195
|
+
byte_array = stored_versioned_contract_by_hash.to_bytes
|
196
|
+
# puts byte_array.inspect
|
197
|
+
# puts Utils::ByteUtils.byte_array_to_hex(byte_array)
|
198
|
+
|
199
|
+
|
200
|
+
# 5) *************** DeployExecutableTransfer *****************************
|
201
|
+
arg1 = Casper::Entity::DeployNamedArgument.new("amount", CLi32.new(1000))
|
202
|
+
args = []
|
203
|
+
args.push([arg1])
|
204
|
+
deploy_transfer = Casper::Entity::DeployExecutableTransfer.new(args)
|
205
|
+
byte_array = deploy_transfer.to_bytes
|
206
|
+
# puts byte_array.inspect
|
207
|
+
# puts Utils::ByteUtils.byte_array_to_hex(byte_array)
|
208
|
+
|
209
|
+
# puts Utils::ByteUtils.byte_array_to_hex(byte_array)
|
210
|
+
# puts deploy_transfer.get_args[0][0].get_name
|
211
|
+
# puts deploy_transfer.get_args[0][0].get_value.get_value
|
212
|
+
# puts deploy_transfer.get_args[0][0].get_value.get_cl_type
|
213
|
+
|
214
|
+
|
215
|
+
#********************** DeployExecutable ************************************************************
|
216
|
+
deploy_executable = Casper::Entity::DeployExecutable.new
|
217
|
+
|
218
|
+
# ***** @module_bytes.set_arg(arg) # => Add arg and return args
|
219
|
+
# args = deploy_executable.standard_payment(1000)
|
220
|
+
# puts args
|
221
|
+
# puts args[0][0].get_name
|
222
|
+
# puts args[0][0].get_value
|
223
|
+
|
224
|
+
# Return ModuleBytes object
|
225
|
+
# module_bytes = deploy_executable.standard_payment(1000)
|
226
|
+
# puts module_bytes.class
|
227
|
+
# puts module_bytes.get_args[0][0].get_name
|
228
|
+
# puts module_bytes.get_args[0][0].get_value.get_value
|
229
|
+
# puts module_bytes.get_args[0][0].get_value.get_cl_type
|
230
|
+
|
231
|
+
# puts module_bytes.module_bytes
|
232
|
+
account_key = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
|
233
|
+
public_key = CLPublicKey.from_hex(account_key)
|
234
|
+
source_purse = "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1"
|
235
|
+
transfer = deploy_executable.new_transfer(1, 1000, CLPublicKey.from_hex(account_key), CLPublicKey.from_hex(source_purse))
|
236
|
+
|
237
|
+
args = transfer.get_args
|
238
|
+
# puts args[0][0].get_name
|
239
|
+
# puts args[0][0].get_value
|
240
|
+
# puts args[1][0].get_name
|
241
|
+
# puts args[1][0].get_value
|
242
|
+
# puts args[2][0].get_name
|
243
|
+
# puts args[2][0].get_value
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
#********************** DeployExecutableSerializer ************************************************************
|
248
|
+
deploy_executable.set_stored_contract_by_hash(stored_contract_by_hash)
|
249
|
+
deploy_executable.set_stored_contract_by_name(stored_contract_by_name)
|
250
|
+
# puts deploy_executable.get_stored_contract_by_name
|
251
|
+
# puts deploy_executable.stored_contract_by_name
|
252
|
+
# puts deploy_executable.to_bytes
|
253
|
+
deploy_executable_serializer = DeployExecutableSerializer.new
|
254
|
+
executable_item = deploy_executable_serializer.to_bytes(deploy_executable)
|
255
|
+
# puts executable_item
|
256
|
+
# puts Utils::ByteUtils.byte_array_to_hex(executable_item)
|
257
|
+
|
258
|
+
h1 = {
|
259
|
+
"hash": "01da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187",
|
260
|
+
"header": {
|
261
|
+
"account": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
|
262
|
+
"timestamp": "2020-11-17T00:39:24.072Z",
|
263
|
+
"ttl": "1h",
|
264
|
+
"gas_price": 1,
|
265
|
+
"body_hash": "4811966d37fe5674a8af4001884ea0d9042d1c06668da0c963769c3a01ebd08f",
|
266
|
+
"dependencies": [
|
267
|
+
"0101010101010101010101010101010101010101010101010101010101010101"
|
268
|
+
],
|
269
|
+
"chain_name": "casper-example"
|
270
|
+
},
|
271
|
+
"payment": {
|
272
|
+
"StoredContractByName": {
|
273
|
+
"name": "casper-example",
|
274
|
+
"entry_point": "example-entry-point",
|
275
|
+
"args": [
|
276
|
+
[
|
277
|
+
"quantity",
|
278
|
+
{
|
279
|
+
"cl_type": "I32",
|
280
|
+
"bytes": "e8030000",
|
281
|
+
"parsed": 1000
|
282
|
+
}
|
283
|
+
]
|
284
|
+
]
|
285
|
+
}
|
286
|
+
# "ModuleBytes": {
|
287
|
+
# "args": [
|
288
|
+
# [
|
289
|
+
# "amount",
|
290
|
+
# {
|
291
|
+
# "bytes": "e8030000",
|
292
|
+
# "parsed": "1000",
|
293
|
+
# "cl_type": "I32"
|
294
|
+
# }
|
295
|
+
# ]
|
296
|
+
# ],
|
297
|
+
# "module_bytes": "sdsdssadsds"
|
298
|
+
# }
|
299
|
+
},
|
300
|
+
"session": {
|
301
|
+
"Transfer": {
|
302
|
+
"args": [
|
303
|
+
[
|
304
|
+
"amount",
|
305
|
+
{
|
306
|
+
"cl_type": "I32",
|
307
|
+
"bytes": "e8030000",
|
308
|
+
"parsed": 1000
|
309
|
+
}
|
310
|
+
]
|
311
|
+
]
|
312
|
+
}
|
313
|
+
# "ModuleBytes": {
|
314
|
+
# "args": [
|
315
|
+
# [
|
316
|
+
# "amount",
|
317
|
+
# {
|
318
|
+
# "bytes": "e8030000",
|
319
|
+
# "parsed": "1000",
|
320
|
+
# "cl_type": "I32"
|
321
|
+
# }
|
322
|
+
# ]
|
323
|
+
# ],
|
324
|
+
# "module_bytes": "sdsdssadsds"
|
325
|
+
# }
|
326
|
+
},
|
327
|
+
"approvals": [
|
328
|
+
{
|
329
|
+
"signer": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
|
330
|
+
"signature": "012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08"
|
331
|
+
}
|
332
|
+
]
|
333
|
+
}
|
334
|
+
deploy = Casper::Entity::Deploy.new(h1[:hash], h1[:header], h1[:payment], h1[:session], h1[:approvals])
|
335
|
+
deploy_hash = Casper::Entity::DeployHash.new(deploy.get_hash)
|
336
|
+
header = Casper::Entity::DeployHeader.new(deploy.get_header)
|
337
|
+
payment = deploy.get_payment
|
338
|
+
key = payment.keys[0]
|
339
|
+
# puts key == :StoredContractByName
|
340
|
+
if key == :StoredContractByName
|
341
|
+
name = payment[:StoredContractByName][:name]
|
342
|
+
entry_point = payment[:StoredContractByName][:entry_point]
|
343
|
+
args = payment[:StoredContractByName][:args]
|
344
|
+
# deploy_named_arg
|
345
|
+
executable_payment = Casper::Entity::StoredContractByName.new(name, entry_point, args)
|
346
|
+
# puts executable_payment.get_args
|
347
|
+
end
|
348
|
+
# payment = StoredContractByName.new()
|
349
|
+
session = deploy.get_session
|
350
|
+
deploy_executable_payment = Casper::Entity::DeployExecutable.new
|
351
|
+
deploy_executable_session = Casper::Entity::DeployExecutable.new
|
352
|
+
|
353
|
+
deploy_serializer = DeploySerializer.new
|
354
|
+
# puts deploy_serializer.to_bytes(deploy)
|
355
|
+
|
356
|
+
# h = {"cl_type": "Bool", "bytes": "01", "parsed": ""}
|
357
|
+
# h = {"cl_type": "I32", "bytes": "e0ffffff", "parsed": ""} # => parsed = -32
|
358
|
+
# h = {"cl_type": "I64", "bytes": "c0ffffffffffffff", "parsed": ""} # => parsed = -64
|
359
|
+
# h = {"cl_type": "U8", "bytes": "08", "parsed": ""} # => parsed = 8
|
360
|
+
# h = {"cl_type": "U32", "bytes": "20000000", "parsed": ""} # => parsed = 32
|
361
|
+
# h = {"cl_type": "U64", "bytes": "4000000000000000", "parsed": ""} # => parsed = 64
|
362
|
+
# h = {"cl_type": "String", "bytes": "0b0000006361737065722d74657374", "parsed": ""} # => parsed = "casper-test"
|
363
|
+
h = {"cl_type": "Unit", "bytes": "", "parsed": ""} # => parsed = "casper-test"
|
364
|
+
h = {"cl_type": "URef", "bytes": "21000000000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f07", "parsed": ""}
|
365
|
+
# => parsed = "uref-000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f-007"
|
366
|
+
h = {"cl_type": "PublicKey", "bytes": "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1", "parsed": ""}
|
367
|
+
# puts deploy_serializer.build_cl_value(h).to_hex
|
368
|
+
# puts deploy_serializer.build_cl_value(h)
|
369
|
+
|
370
|
+
|
371
|
+
deploy_bytes_array = deploy_serializer.to_bytes(deploy)
|
372
|
+
deploy_hex = Utils::ByteUtils.byte_array_to_hex(deploy_bytes_array)
|
373
|
+
# puts Blake2b.hex(deploy_hex)
|
374
|
+
|
375
|
+
input = "abc"
|
376
|
+
key = Blake2b::Key.none
|
377
|
+
out_len = 32
|
378
|
+
|
379
|
+
# puts Blake2b.hex(input)
|
380
|
+
# puts Blake2b.hex(input, key)
|
381
|
+
# puts Blake2b.hex(input, key, 32) # => Create a hash of 32 bytes length
|
382
|
+
# # puts Blake2b.hex(input, key, 64) # => create a hash of 64 bytes length
|
383
|
+
# bytes = Blake2b.bytes(input)
|
384
|
+
# puts bytes.inspect
|
385
|
+
# puts bytes.pack("C*").unpack("H*") # => Convert bytes to hex (hash version)
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
key = "01ccee19366eaf03487cb81197ae8edcb1b47f214cee00d6597380096b9f8463c1"
|
390
|
+
|
391
|
+
|
392
|
+
# puts Blake2b.hex(deploy_hex)
|
393
|
+
require 'openssl'
|
394
|
+
|
395
|
+
# k = OpenSSL::PKey::RSA.new(File.read("/home/mehmet/Documents/ed25519_secret_key.pem"))
|
396
|
+
# puts k.private?
|
397
|
+
require "ssh_data"
|
398
|
+
require "ed25519"
|
399
|
+
|
400
|
+
key_data = File.read("#{Dir.home}/.ssh/id_ed25519")
|
401
|
+
key = SSHData::PrivateKey.parse_openssh(key_data)
|
402
|
+
#=> <SSHData::PrivateKey::ED25519>
|
403
|
+
# puts key[0][0]
|
404
|
+
SSHData::PrivateKey::ED25519.generate
|
405
|
+
#=> raises SSHData::AlgorithmError
|
406
|
+
|
407
|
+
|
408
|
+
SSHData::PrivateKey::ED25519.generate
|
409
|
+
#=> <SSHData::PrivateKey::ED25519>
|
410
|
+
|
411
|
+
# OpenSSL::PKey::RSA.new File.read("#{Dir.home}/.ssh/id_rsa")
|
412
|
+
# cert = OpenSSL::X509::Certificate.new("#{Dir.home}/Document/ed25519_secret_key.pem")
|
413
|
+
|
414
|
+
# file = File.open("#{Dir.home}/Document/ed25519_secret_key.pem")
|
415
|
+
# file = File.open("#{Dir.home}/Desktop/casper-ruby-sdk/lib/serialization/test.txt")
|
416
|
+
# file_data = file.read
|
417
|
+
# puts file_data
|
418
|
+
# puts "/home/mehmet/Document/hetzner.txt"
|
419
|
+
# puts "#{Dir.home}"
|
420
|
+
require 'json'
|
421
|
+
path = File.join(
|
422
|
+
File.dirname(File.dirname(File.absolute_path(__FILE__))),
|
423
|
+
'serialization/ed25519.pem'
|
424
|
+
)
|
425
|
+
puts path
|
426
|
+
|
427
|
+
file = File.open(path)
|
428
|
+
puts file
|
429
|
+
file_data = file.readlines.map(&:chomp)
|
430
|
+
puts file_data.inspect
|
431
|
+
file.close
|