casper_network 0.2.1 → 1.0.0

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 (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -4
  3. data/lib/casper_network.rb +62 -7
  4. data/lib/crypto/00_asymmetric_key.rb +95 -0
  5. data/lib/crypto/01_ed25519.rb +67 -0
  6. data/lib/crypto/asymmetric_key.rb +87 -0
  7. data/lib/crypto/ed25519_key.rb +44 -0
  8. data/lib/crypto/key_pair.rb +40 -0
  9. data/lib/crypto/keys.rb +7 -0
  10. data/lib/crypto/secp256k1_key.rb +0 -0
  11. data/lib/crypto/test_ed25519_key.rb +44 -0
  12. data/lib/entity/account.rb +45 -0
  13. data/lib/entity/action_thresholds.rb +25 -0
  14. data/lib/entity/associated_key.rb +24 -0
  15. data/lib/entity/contract.rb +47 -0
  16. data/lib/entity/contract_package.rb +41 -0
  17. data/lib/entity/contract_version.rb +33 -0
  18. data/lib/entity/deploy_approval.rb +7 -6
  19. data/lib/entity/deploy_executable.rb +154 -1
  20. data/lib/entity/deploy_executable_item_internal.rb +26 -0
  21. data/lib/entity/deploy_executable_transfer.rb +50 -0
  22. data/lib/entity/deploy_header.rb +17 -15
  23. data/lib/entity/deploy_info.rb +44 -0
  24. data/lib/entity/deploy_named_argument.rb +19 -0
  25. data/lib/entity/deploy_transfer.rb +10 -0
  26. data/lib/entity/disabled_version.rb +26 -0
  27. data/lib/entity/era_info.rb +18 -0
  28. data/lib/entity/executable_deploy_item.rb +11 -0
  29. data/lib/entity/group.rb +25 -0
  30. data/lib/entity/module_bytes.rb +50 -0
  31. data/lib/entity/seigniorage_allocation.rb +18 -0
  32. data/lib/entity/stored_contract_by_hash.rb +50 -0
  33. data/lib/entity/stored_contract_by_name.rb +50 -0
  34. data/lib/entity/stored_value.rb +57 -0
  35. data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
  36. data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
  37. data/lib/entity/transfer.rb +65 -0
  38. data/lib/entity/vesting_schedule.rb +22 -0
  39. data/lib/include.rb +18 -0
  40. data/lib/rpc/rpc.rb +227 -0
  41. data/lib/rpc/rpc_client.rb +45 -39
  42. data/lib/serialization/cl_type_serializer.rb +76 -0
  43. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  44. data/lib/serialization/cl_value_serializer.rb +259 -0
  45. data/lib/serialization/deploy_approval_serializer.rb +15 -0
  46. data/lib/serialization/deploy_executable_serializer.rb +26 -0
  47. data/lib/serialization/deploy_header_serializer.rb +49 -0
  48. data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
  49. data/lib/serialization/deploy_serializer.rb +268 -0
  50. data/lib/serialization/test.rb +431 -0
  51. data/lib/types/cl_account_hash.rb +24 -0
  52. data/lib/types/cl_account_hash_type.rb +22 -0
  53. data/lib/types/cl_any.rb +25 -0
  54. data/lib/types/cl_any_type.rb +22 -0
  55. data/lib/types/cl_bool.rb +32 -0
  56. data/lib/types/cl_bool_type.rb +35 -0
  57. data/lib/types/cl_byte_array.rb +25 -0
  58. data/lib/types/cl_byte_array_type.rb +27 -0
  59. data/lib/types/cl_i32.rb +26 -0
  60. data/lib/types/cl_i32_type.rb +26 -0
  61. data/lib/types/cl_i64.rb +26 -0
  62. data/lib/types/cl_i64_type.rb +27 -0
  63. data/lib/types/cl_key.rb +39 -0
  64. data/lib/types/cl_key_type.rb +27 -0
  65. data/lib/types/cl_list.rb +25 -0
  66. data/lib/types/cl_list_type.rb +26 -0
  67. data/lib/types/cl_map.rb +25 -0
  68. data/lib/types/cl_map_type.rb +26 -0
  69. data/lib/types/cl_option.rb +33 -0
  70. data/lib/types/cl_option_type.rb +52 -0
  71. data/lib/types/cl_public_key.rb +152 -0
  72. data/lib/types/cl_public_key_type.rb +26 -0
  73. data/lib/types/cl_result.rb +25 -0
  74. data/lib/types/cl_result_type.rb +26 -0
  75. data/lib/types/cl_string.rb +39 -0
  76. data/lib/types/cl_string_type.rb +32 -0
  77. data/lib/types/cl_tuple.rb +151 -0
  78. data/lib/types/cl_tuple_type.rb +108 -0
  79. data/lib/types/cl_type.rb +94 -0
  80. data/lib/types/cl_type_tag.rb +51 -0
  81. data/lib/types/cl_u128.rb +26 -0
  82. data/lib/types/cl_u128_type.rb +26 -0
  83. data/lib/types/cl_u256.rb +26 -0
  84. data/lib/types/cl_u256_type.rb +26 -0
  85. data/lib/types/cl_u32.rb +26 -0
  86. data/lib/types/cl_u32_type.rb +26 -0
  87. data/lib/types/cl_u512.rb +26 -0
  88. data/lib/types/cl_u512_type.rb +26 -0
  89. data/lib/types/cl_u64.rb +26 -0
  90. data/lib/types/cl_u64_type.rb +27 -0
  91. data/lib/types/cl_u8.rb +26 -0
  92. data/lib/types/cl_u8_type.rb +26 -0
  93. data/lib/types/cl_unit.rb +38 -0
  94. data/lib/types/cl_unit_type.rb +22 -0
  95. data/lib/types/cl_uref.rb +119 -0
  96. data/lib/types/cl_uref_type.rb +46 -0
  97. data/lib/types/cl_value.rb +10 -0
  98. data/lib/types/constants.rb +50 -0
  99. data/lib/types/error.rb +7 -0
  100. data/lib/utils/base_16.rb +18 -0
  101. data/lib/utils/byte_utils.rb +107 -0
  102. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  103. data/lib/utils/hash_utils.rb +19 -0
  104. data/lib/utils/hex_utils.rb +12 -0
  105. data/lib/utils/time_utils.rb +85 -0
  106. data/lib/utils/utils.rb +2 -0
  107. data/lib/version.rb +3 -0
  108. data/spec/a_spec.rb +697 -0
  109. data/spec/byte_utils_spec.rb +72 -0
  110. data/spec/cl_public_spec.rb +169 -0
  111. data/spec/cl_types_spec.rb +715 -0
  112. data/spec/cl_value_serializer_spec.rb +140 -0
  113. data/spec/client_spec.rb +20 -20
  114. data/spec/crypto_spec.rb +42 -0
  115. data/spec/deploy_approval_serializer_spec.rb +26 -0
  116. data/spec/deploy_executable_serializer_spec.rb +0 -0
  117. data/spec/deploy_header_serializer_spec.rb +21 -0
  118. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  119. data/spec/deploy_serializer_spec.rb +77 -0
  120. data/spec/deploy_serializer_test_spec.rb +225 -0
  121. data/spec/mainnet_spec.rb +8 -8
  122. data/spec/string_spec.rb +68 -0
  123. data/spec/testnet_spec.rb +11 -11
  124. data/spec/time_utils_spec.rb +87 -0
  125. metadata +130 -2
@@ -0,0 +1,50 @@
1
+ require_relative './deploy_executable_item_internal.rb'
2
+
3
+ module Casper
4
+ module Entity
5
+ class StoredContractByHash < DeployExecutableItemInternal
6
+
7
+ # @param [String] hash
8
+ # @param [String] entry_point
9
+ # @param [Array<Array<DeployNamedArgument>>] args
10
+ def initialize(hash, entry_point, args)
11
+ @tag = 1
12
+ @hash = hash
13
+ @entry_point = entry_point
14
+ @args = args
15
+ end
16
+
17
+ def get_tag
18
+ @tag
19
+ end
20
+
21
+ def get_hash
22
+ @hash
23
+ end
24
+
25
+ def get_entry_point
26
+ @entry_point
27
+ end
28
+
29
+ def get_args
30
+ @args
31
+ end
32
+
33
+ def to_bytes
34
+ serializer = DeployNamedArgSerializer.new
35
+ num_of_args = @args.length
36
+ bytes = Utils::ByteUtils.to_u8(@tag)
37
+ bytes += @hash
38
+ bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@entry_point)
39
+ bytes += Utils::ByteUtils.to_u32(num_of_args)
40
+ @args.each do |arg|
41
+ arg.each do |item|
42
+ bytes += serializer.to_bytes(item)
43
+ end
44
+ end
45
+ Utils::ByteUtils.hex_to_byte_array(bytes)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require_relative './deploy_executable_item_internal.rb'
2
+
3
+ module Casper
4
+ module Entity
5
+ class StoredContractByName < DeployExecutableItemInternal
6
+
7
+ # @param [String] name
8
+ # @param [String] entry_point
9
+ # @param [Array<Array<DeployNamedArgument>>] args
10
+ def initialize(name, entry_point, args)
11
+ @tag = 2
12
+ @name = name
13
+ @entry_point = entry_point
14
+ @args = args
15
+ end
16
+
17
+ def get_tag
18
+ @tag
19
+ end
20
+
21
+ def get_name
22
+ @name
23
+ end
24
+
25
+ def get_entry_point
26
+ @entry_point
27
+ end
28
+
29
+ def get_args
30
+ @args
31
+ end
32
+
33
+
34
+ def to_bytes
35
+ serializer = DeployNamedArgSerializer.new
36
+ num_of_args = @args.length
37
+ bytes = Utils::ByteUtils.to_u8(@tag)
38
+ bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@name)
39
+ bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@entry_point)
40
+ bytes += Utils::ByteUtils.to_u32(num_of_args)
41
+ @args.each do |arg|
42
+ arg.each do |item|
43
+ bytes += serializer.to_bytes(item)
44
+ end
45
+ end
46
+ Utils::ByteUtils.hex_to_byte_array(bytes)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,57 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # A class that represents a value stored in global state.
5
+ class StoredValue
6
+
7
+ def initialize(cl_value, account, contract, contract_package, transfer, deploy_info, era_info, bid, withdraw)
8
+ @cl_value = cl_value
9
+ @account = account
10
+ @contract = contract
11
+ @contract_package = contract_package
12
+ @transfer = transfer
13
+ @deploy_info = deploy_info
14
+ @era_info = era_info
15
+ @bid = bid
16
+ @withdraw = withdraw
17
+ end
18
+
19
+ def get_cl_value
20
+ @cl_value
21
+ end
22
+
23
+ def get_account
24
+ @account
25
+ end
26
+
27
+ def get_contract
28
+ @contract
29
+ end
30
+
31
+ def get_contract_package
32
+ @contract_package
33
+ end
34
+
35
+ def get_transfer
36
+ @transfer
37
+ end
38
+
39
+ def get_deploy_info
40
+ @deploy_info
41
+ end
42
+
43
+ def get_era_info
44
+ @era_info
45
+ end
46
+
47
+ def get_bid
48
+ @bid
49
+ end
50
+
51
+ def get_withdraw
52
+ @withdraw
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,61 @@
1
+ require_relative './deploy_executable_item_internal.rb'
2
+
3
+ module Casper
4
+ module Entity
5
+ class StoredVersionedContractByHash < DeployExecutableItemInternal
6
+
7
+ # @param [String] hash
8
+ # @param [Integer] version
9
+ # @param [String] entry_point
10
+ # @param [Array<Array<DeployNamedArgument>>] args
11
+ def initialize(hash, version, entry_point, args)
12
+ @tag = 3
13
+ @hash = hash
14
+ @version = version
15
+ @entry_point = entry_point
16
+ @args = args
17
+ end
18
+
19
+ def get_tag
20
+ @tag
21
+ end
22
+
23
+ def get_hash
24
+ @hash
25
+ end
26
+
27
+ def get_version
28
+ @version
29
+ end
30
+
31
+ def get_entry_point
32
+ @entry_point
33
+ end
34
+
35
+ def get_args
36
+ @args
37
+ end
38
+
39
+ def to_bytes
40
+ serializer = DeployNamedArgSerializer.new
41
+ num_of_args = @args.length
42
+ bytes = Utils::ByteUtils.to_u8(@tag)
43
+ bytes += @hash
44
+ if @version == nil
45
+ bytes += Utils::ByteUtils.to_u8(0)
46
+ else
47
+ bytes += Utils::ByteUtils.to_u8(1)
48
+ end
49
+ bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@entry_point)
50
+ bytes += Utils::ByteUtils.to_u32(num_of_args)
51
+ @args.each do |arg|
52
+ arg.each do |item|
53
+ bytes += serializer.to_bytes(item)
54
+ end
55
+ end
56
+ Utils::ByteUtils.hex_to_byte_array(bytes)
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,61 @@
1
+ require_relative './deploy_executable_item_internal.rb'
2
+
3
+ module Casper
4
+ module Entity
5
+ class StoredVersionedContractByName < DeployExecutableItemInternal
6
+
7
+ # @param [String] name
8
+ # @param [Integer] version
9
+ # @param [String] entry_point
10
+ # @param [Array<Array<DeployNamedArgument>>] args
11
+ def initialize(name, version, entry_point, args)
12
+ @tag = 4
13
+ @name = name
14
+ @version = version
15
+ @entry_point = entry_point
16
+ @args = args
17
+ end
18
+
19
+ def get_tag
20
+ @tag
21
+ end
22
+
23
+ def get_name
24
+ @name
25
+ end
26
+
27
+ def get_version
28
+ @version
29
+ end
30
+
31
+ def get_entry_point
32
+ @entry_point
33
+ end
34
+
35
+ def get_args
36
+ @args
37
+ end
38
+
39
+ def to_bytes
40
+ serializer = DeployNamedArgSerializer.new
41
+ num_of_args = @args.length
42
+ bytes = Utils::ByteUtils.to_u8(@tag)
43
+ bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@name)
44
+ if @version == nil
45
+ bytes += Utils::ByteUtils.to_u8(0)
46
+ else
47
+ bytes += Utils::ByteUtils.to_u8(1)
48
+ end
49
+ bytes += CLValueBytesParsers::CLStringBytesParser.to_bytes(@entry_point)
50
+ bytes += Utils::ByteUtils.to_u32(num_of_args)
51
+ @args.each do |arg|
52
+ arg.each do |item|
53
+ bytes += serializer.to_bytes(item)
54
+ end
55
+ end
56
+ Utils::ByteUtils.hex_to_byte_array(bytes)
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,65 @@
1
+ module Casper
2
+ module Entity
3
+ class Transfer
4
+
5
+ # @param [Hash] transfer
6
+ # @option transfer [String] :deploy_hash
7
+ # @option transfer [String] :from
8
+ # @option transfer [String] :to
9
+ # @option transfer [String] :source
10
+ # @option transfer [String] :target
11
+ # @option transfer [String] :amount
12
+ # @option transfer [String] :gas
13
+ # @option transfer [Integer] :id
14
+ def initialize(transfer = {})
15
+ @deploy_hash = transfer[:deploy_hash]
16
+ @from = transfer[:from]
17
+ @to = transfer[:to]
18
+ @source = transfer[:source]
19
+ @target = transfer[:target]
20
+ @amount = transfer[:amount]
21
+ @gas = transfer[:gas]
22
+ @id = transfer[:id]
23
+ end
24
+
25
+ # @return [String] deploy_hash
26
+ def get_deploy_hash
27
+ @deploy_hash
28
+ end
29
+
30
+ # @return [String] from
31
+ def get_from
32
+ @from
33
+ end
34
+
35
+ # @return [String] to
36
+ def get_to
37
+ @to
38
+ end
39
+
40
+ # @return [String] source
41
+ def get_source
42
+ @source
43
+ end
44
+
45
+ # @return [String] target
46
+ def get_target
47
+ @target
48
+ end
49
+
50
+ # @return [String] amount
51
+ def get_amount
52
+ @amount
53
+ end
54
+
55
+ # @return [String] gas
56
+ def get_gas
57
+ @gas
58
+ end
59
+ # @return [Integer] id
60
+ def get_id
61
+ @id
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,22 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # Vesting schedule for a genesis validator.
5
+ class VestingSchedule
6
+
7
+ def initialize(vesting_schedule = {})
8
+ @initial_release_timestamp_millis = vesting_schedule[:initial_release_timestamp_millis]
9
+ @locked_amounts = vesting_schedule[:locked_amounts]
10
+ end
11
+
12
+ def get_initial_release_timestamp_millis
13
+ @initial_release_timestamp_millis
14
+ end
15
+
16
+ def get_locked_amounts
17
+ @locked_amounts
18
+ end
19
+
20
+ end
21
+ end
22
+ end
data/lib/include.rb ADDED
@@ -0,0 +1,18 @@
1
+ # Dir["./types/*.rb"].each {|file| require file }
2
+ Dir[File.join(
3
+ File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/types/*.rb")].each {|file| require file }
4
+ Dir[File.join(
5
+ File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/entity/*.rb")].each {|file| require file }
6
+ Dir[File.join(
7
+ File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/rpc/*.rb")].each {|file| require file }
8
+ Dir[File.join(
9
+ File.dirname(File.dirname(File.absolute_path(__FILE__))), "/lib/utils/*.rb")].each {|file| require file }
10
+ # path = File.join(
11
+ # File.dirname(File.dirname(File.absolute_path(__FILE__))),
12
+ # '/lib/types/cl_bool'
13
+ # )
14
+ # puts path
15
+ # require path
16
+ # require_relative "./types/cl_bool.rb"
17
+ # require_relative "./types/cl_string.rb"
18
+
data/lib/rpc/rpc.rb ADDED
@@ -0,0 +1,227 @@
1
+ # casper_network.rb
2
+ require 'jimson'
3
+ require 'json'
4
+ require 'rdoc/rdoc'
5
+ require "ipaddress"
6
+ require 'resolv'
7
+ require 'rest-client'
8
+ require 'active_support/core_ext/hash/keys'
9
+ require 'timeout'
10
+ require_relative '../entity/peer.rb'
11
+ module Casper
12
+ # Class for interacting with the network via RPC
13
+ class RpcClient
14
+ attr_accessor :ip_address, :port, :url, :state_root_hash
15
+
16
+ # Constructor
17
+ # @param [String] ip_address
18
+ def initialize(ip_address)
19
+ @ip_address = ip_address
20
+ @url = "http://" + @ip_address + ":7777/rpc"
21
+ @state_root_hash = ""
22
+ @peer_array = []
23
+ @block_hash = ""
24
+ @deploy = {}
25
+ @node_status = {}
26
+ @block_transfers = []
27
+ @block_info = {}
28
+ @era_summary = {}
29
+ @balance_value = ""
30
+ @auction_state = {}
31
+
32
+ @peers = []
33
+ end
34
+
35
+ # @return [Array<Hash>] peers array
36
+ def info_get_peers
37
+ begin
38
+ status = Timeout::timeout(20) {
39
+ client = Jimson::Client.new(@url)
40
+ response = client.info_get_peers
41
+ response.deep_symbolize_keys!
42
+ @peer_array = response[:peers]
43
+ @peer_array.map { |item| @peers << Casper::Entity::Peer.new(item) }
44
+ # @peers[0].get_node_id
45
+ # @peers[0].get_node_id
46
+ # @peers[0].get_address
47
+ @peer_array
48
+ }
49
+ rescue Timeout::Error
50
+ 'Timeout expired to retrieve peers!'
51
+ end
52
+ end
53
+
54
+ # @return [String] state_root_hash value
55
+ def chain_get_StateRootHash(block_hash = "")
56
+ begin
57
+ status = Timeout::timeout(10) {
58
+ client = Jimson::Client.new(@url)
59
+ result = client.chain_get_state_root_hash
60
+ @state_root_hash = result["state_root_hash"]
61
+ }
62
+ rescue
63
+ 'Timeout expired to retrieve state_root_hash value!'
64
+ end
65
+ end
66
+
67
+ # Get information about a single deploy by hash.
68
+ # @param [String] deploy_hash
69
+ # @return [Hash] Deploy
70
+ def info_get_deploy(deploy_hash)
71
+ begin
72
+ status = Timeout::timeout(20) {
73
+ if (deploy_hash == "" || deploy_hash == nil)
74
+ return "Server error -32602: Invalid params"
75
+ end
76
+ client = Jimson::Client.new(@url)
77
+ response = client.info_get_deploy({"deploy_hash"=> deploy_hash })
78
+ @deploy = response["deploy"]
79
+ # @deploy.keys.each do |key|
80
+ # @deploy[(key.to_sym rescue key) || key] = @deploy.delete(key)
81
+ # end
82
+ @deploy
83
+ }
84
+ rescue
85
+ 'Timeout expired to retrieve Deploy!'
86
+ end
87
+ end
88
+
89
+
90
+ # Receive node status information
91
+ # @return node_status
92
+ def info_get_status
93
+ begin
94
+ status = Timeout::timeout(10) {
95
+ client = Jimson::Client.new(@url)
96
+ @node_status = client.info_get_status
97
+ }
98
+ rescue
99
+ 'Timeout expired to retrieve node status information'
100
+ end
101
+ end
102
+
103
+ # @param [String] block_hash
104
+ # @return [Array<Hash>] block_transfers
105
+ def chain_get_block_transfers(block_hash = "")
106
+ begin
107
+ status = Timeout::timeout(5) {
108
+ client = Jimson::Client.new(@url)
109
+ response = client.chain_get_block_transfers({
110
+ "block_identifier" => {"Hash" => block_hash}
111
+ })
112
+ @block_transfers = response["transfers"]
113
+ @block_transfers
114
+ }
115
+ rescue
116
+ 'Timeout expired to retrieve block_transfers'
117
+ end
118
+ end
119
+
120
+ # @param [String] block_hash
121
+ # @return [Hash] block_info
122
+ def chain_get_block(block_hash)
123
+ begin
124
+ state = Timeout::timeout(10) {
125
+ client = Jimson::Client.new(@url)
126
+ result = client.chain_get_block({"block_identifier" => {"Hash" => block_hash}})
127
+ @block_info = result["block"]
128
+ if (!@block_info.empty?() && @block_info["hash"] != block_hash)
129
+ raise("Returned block does not have a matching hash.")
130
+ else
131
+ @block_info
132
+ end
133
+ }
134
+ rescue
135
+ 'Timeout expired to retrieve block_info'
136
+ end
137
+ end
138
+
139
+ # @param [String] block_hash
140
+ # @return [Hash] era_summary
141
+ def chain_get_eraInfo_by_SwitchBlock(block_hash)
142
+ begin
143
+ state = Timeout::timeout(60) {
144
+ client = Jimson::Client.new(@url)
145
+ response = client.chain_get_era_info_by_switch_block("block_identifier" => {"Hash" => block_hash})
146
+ @era_summary = response["era_summary"]
147
+ @era_summary
148
+ }
149
+ rescue
150
+ 'Timeout expired to retrieve era_summary'
151
+ end
152
+ end
153
+
154
+ # @param [String] state_root_hash
155
+ # @param [String] key
156
+ # @param [Array] path
157
+ def state_get_item(state_root_hash, key, path)
158
+ begin
159
+ state = Timeout::timeout(20) {
160
+ client = Jimson::Client.new(@url)
161
+ response = client.state_get_item({
162
+ "state_root_hash" => state_root_hash,
163
+ "key" => key,
164
+ "path" => path
165
+ })
166
+ @stored_value = response["stored_value"]
167
+ @stored_value
168
+ }
169
+ rescue
170
+ 'Timeout expired to retrieve stored_value'
171
+ end
172
+ end
173
+
174
+ # @param [String] state_root_hash
175
+ # @param [String] item_key
176
+ # @param [String] uref
177
+ def state_get_dictionary_item(state_root_hash, item_key, uref)
178
+ begin
179
+ state = Timeout::timeout(5) {
180
+ client = Jimson::Client.new(@url)
181
+ response = client.state_get_dictionary_item({
182
+ "state_root_hash" => state_root_hash,
183
+ "dictionary_identifier" => {'URef' =>
184
+ {'seed_uref' => uref, 'dictionary_item_key' => item_key} }})
185
+ @stored_value = response["stored_value"]
186
+ @stored_value
187
+ }
188
+ rescue
189
+ 'Timeout expired to retrieve stored_value'
190
+ end
191
+ end
192
+
193
+ # @param [String] state_root_hash
194
+ # @param [String] balance_uref
195
+ def state_get_balance(state_root_hash, balance_uref)
196
+ begin
197
+ state = Timeout::timeout(5) {
198
+ client = Jimson::Client.new(@url)
199
+ response = client.state_get_balance({
200
+ "state_root_hash" => state_root_hash,
201
+ "purse_uref" => balance_uref
202
+ })
203
+ @balance_value = response["balance_value"]
204
+ @balance_value
205
+ }
206
+ rescue
207
+ 'Timeout expired to retrieve balance_value'
208
+ end
209
+ end
210
+
211
+ # Returns current auction system contract information.
212
+ # @return [Hash] auction_state
213
+ def state_get_AuctionInfo
214
+ begin
215
+ state = Timeout::timeout(50) {
216
+ client = Jimson::Client.new(@url)
217
+ response = client.state_get_auction_info
218
+ @auction_state = response['auction_state']
219
+ @auction_state
220
+ }
221
+ rescue
222
+ 'Timeout expired to retrieve auction_state information!'
223
+ end
224
+ end
225
+ end
226
+ end
227
+