test_sdk1 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +1 -0
  3. data/LICENSE +201 -0
  4. data/README.md +147 -0
  5. data/SECURITY.md +12 -0
  6. data/lib/crypto/00_asymmetric_key.rb +95 -0
  7. data/lib/crypto/01_ed25519.rb +67 -0
  8. data/lib/crypto/asymmetric_key.rb +87 -0
  9. data/lib/crypto/ed25519_key.rb +44 -0
  10. data/lib/crypto/key_pair.rb +40 -0
  11. data/lib/crypto/keys.rb +7 -0
  12. data/lib/crypto/secp256k1_key.rb +0 -0
  13. data/lib/crypto/test_ed25519_key.rb +44 -0
  14. data/lib/entity/account.rb +45 -0
  15. data/lib/entity/action_thresholds.rb +25 -0
  16. data/lib/entity/associated_key.rb +24 -0
  17. data/lib/entity/auction_state.rb +36 -0
  18. data/lib/entity/bid.rb +24 -0
  19. data/lib/entity/bid_info.rb +51 -0
  20. data/lib/entity/contract.rb +47 -0
  21. data/lib/entity/contract_package.rb +41 -0
  22. data/lib/entity/contract_version.rb +33 -0
  23. data/lib/entity/delegator.rb +37 -0
  24. data/lib/entity/deploy.rb +44 -0
  25. data/lib/entity/deploy_approval.rb +24 -0
  26. data/lib/entity/deploy_executable.rb +162 -0
  27. data/lib/entity/deploy_executable_item_internal.rb +26 -0
  28. data/lib/entity/deploy_executable_transfer.rb +50 -0
  29. data/lib/entity/deploy_hash.rb +16 -0
  30. data/lib/entity/deploy_header.rb +60 -0
  31. data/lib/entity/deploy_info.rb +44 -0
  32. data/lib/entity/deploy_named_argument.rb +19 -0
  33. data/lib/entity/deploy_transfer.rb +10 -0
  34. data/lib/entity/disabled_version.rb +26 -0
  35. data/lib/entity/era_info.rb +18 -0
  36. data/lib/entity/era_summary.rb +44 -0
  37. data/lib/entity/era_validator.rb +23 -0
  38. data/lib/entity/executable_deploy_item.rb +11 -0
  39. data/lib/entity/group.rb +25 -0
  40. data/lib/entity/module_bytes.rb +50 -0
  41. data/lib/entity/peer.rb +25 -0
  42. data/lib/entity/seigniorage_allocation.rb +18 -0
  43. data/lib/entity/stored_contract_by_hash.rb +50 -0
  44. data/lib/entity/stored_contract_by_name.rb +50 -0
  45. data/lib/entity/stored_value.rb +57 -0
  46. data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
  47. data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
  48. data/lib/entity/transfer.rb +65 -0
  49. data/lib/entity/validator_weight.rb +23 -0
  50. data/lib/entity/vesting_schedule.rb +22 -0
  51. data/lib/include.rb +18 -0
  52. data/lib/rpc/rpc.rb +227 -0
  53. data/lib/rpc/rpc_client.rb +233 -0
  54. data/lib/rpc/rpc_error.rb +79 -0
  55. data/lib/serialization/cl_type_serializer.rb +76 -0
  56. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  57. data/lib/serialization/cl_value_serializer.rb +259 -0
  58. data/lib/serialization/deploy_approval_serializer.rb +15 -0
  59. data/lib/serialization/deploy_executable_serializer.rb +27 -0
  60. data/lib/serialization/deploy_header_serializer.rb +49 -0
  61. data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
  62. data/lib/serialization/deploy_serializer.rb +268 -0
  63. data/lib/serialization/test.rb +431 -0
  64. data/lib/test_sdk1.rb +289 -0
  65. data/lib/types/cl_account_hash.rb +24 -0
  66. data/lib/types/cl_account_hash_type.rb +22 -0
  67. data/lib/types/cl_any.rb +25 -0
  68. data/lib/types/cl_any_type.rb +22 -0
  69. data/lib/types/cl_bool.rb +32 -0
  70. data/lib/types/cl_bool_type.rb +35 -0
  71. data/lib/types/cl_byte_array.rb +25 -0
  72. data/lib/types/cl_byte_array_type.rb +27 -0
  73. data/lib/types/cl_i32.rb +26 -0
  74. data/lib/types/cl_i32_type.rb +26 -0
  75. data/lib/types/cl_i64.rb +26 -0
  76. data/lib/types/cl_i64_type.rb +27 -0
  77. data/lib/types/cl_key.rb +39 -0
  78. data/lib/types/cl_key_type.rb +27 -0
  79. data/lib/types/cl_list.rb +25 -0
  80. data/lib/types/cl_list_type.rb +26 -0
  81. data/lib/types/cl_map.rb +25 -0
  82. data/lib/types/cl_map_type.rb +26 -0
  83. data/lib/types/cl_option.rb +33 -0
  84. data/lib/types/cl_option_type.rb +52 -0
  85. data/lib/types/cl_public_key.rb +152 -0
  86. data/lib/types/cl_public_key_type.rb +26 -0
  87. data/lib/types/cl_result.rb +25 -0
  88. data/lib/types/cl_result_type.rb +26 -0
  89. data/lib/types/cl_string.rb +39 -0
  90. data/lib/types/cl_string_type.rb +32 -0
  91. data/lib/types/cl_tuple.rb +151 -0
  92. data/lib/types/cl_tuple_type.rb +108 -0
  93. data/lib/types/cl_type.rb +94 -0
  94. data/lib/types/cl_type_tag.rb +51 -0
  95. data/lib/types/cl_u128.rb +26 -0
  96. data/lib/types/cl_u128_type.rb +26 -0
  97. data/lib/types/cl_u256.rb +26 -0
  98. data/lib/types/cl_u256_type.rb +26 -0
  99. data/lib/types/cl_u32.rb +26 -0
  100. data/lib/types/cl_u32_type.rb +26 -0
  101. data/lib/types/cl_u512.rb +26 -0
  102. data/lib/types/cl_u512_type.rb +26 -0
  103. data/lib/types/cl_u64.rb +26 -0
  104. data/lib/types/cl_u64_type.rb +27 -0
  105. data/lib/types/cl_u8.rb +26 -0
  106. data/lib/types/cl_u8_type.rb +26 -0
  107. data/lib/types/cl_unit.rb +38 -0
  108. data/lib/types/cl_unit_type.rb +22 -0
  109. data/lib/types/cl_uref.rb +120 -0
  110. data/lib/types/cl_uref_type.rb +46 -0
  111. data/lib/types/cl_value.rb +10 -0
  112. data/lib/types/constants.rb +50 -0
  113. data/lib/types/error.rb +7 -0
  114. data/lib/utils/base_16.rb +18 -0
  115. data/lib/utils/byte_utils.rb +107 -0
  116. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  117. data/lib/utils/hash_utils.rb +19 -0
  118. data/lib/utils/hex_utils.rb +12 -0
  119. data/lib/utils/time_utils.rb +85 -0
  120. data/lib/utils/utils.rb +2 -0
  121. data/lib/version.rb +3 -0
  122. data/spec/a_spec.rb +697 -0
  123. data/spec/byte_utils_spec.rb +72 -0
  124. data/spec/cl_public_spec.rb +169 -0
  125. data/spec/cl_types_spec.rb +715 -0
  126. data/spec/cl_value_serializer_spec.rb +140 -0
  127. data/spec/client_spec.rb +25 -0
  128. data/spec/crypto_spec.rb +42 -0
  129. data/spec/deploy_approval_serializer_spec.rb +26 -0
  130. data/spec/deploy_executable_serializer_spec.rb +0 -0
  131. data/spec/deploy_header_serializer_spec.rb +21 -0
  132. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  133. data/spec/deploy_serializer_spec.rb +77 -0
  134. data/spec/deploy_serializer_test_spec.rb +225 -0
  135. data/spec/mainnet_spec.rb +452 -0
  136. data/spec/spec_helper.rb +100 -0
  137. data/spec/string_spec.rb +68 -0
  138. data/spec/testnet_spec.rb +498 -0
  139. data/spec/time_utils_spec.rb +87 -0
  140. metadata +198 -0
@@ -0,0 +1,40 @@
1
+ require 'ed25519'
2
+
3
+
4
+ signing_key = Ed25519::SigningKey.generate
5
+ puts "signing_key:\t #{signing_key}"
6
+
7
+ message = "hello"
8
+ signature = signing_key.sign(message)
9
+ puts "signature:\t #{signature}"
10
+
11
+ verify_key = signing_key.verify_key
12
+ puts "verify_key:\t #{verify_key}"
13
+
14
+ check_validity_of_signature = verify_key.verify(signature, message)
15
+ puts "check_validity_of_signature:\t #{check_validity_of_signature}"
16
+
17
+ # Serializing Keys
18
+ signature_key_bytes = signing_key.to_bytes
19
+ puts "signature_key_bytes:\t #{signature_key_bytes}"
20
+ verify_key_bytes = verify_key.to_bytes
21
+ puts "verify_key_bytes:\t #{verify_key_bytes}"
22
+
23
+ signing_key = Ed25519::SigningKey.new(signature_key_bytes)
24
+ puts "signing_key:\t #{signing_key}"
25
+ verify_key = Ed25519::VerifyKey.new(verify_key_bytes)
26
+ puts "verify_key:\t #{verify_key}"
27
+
28
+
29
+ require "ssh_data"
30
+
31
+ # key_data = File.read("/home/mehmet/Desktop/casper-ruby-sdk/lib/crypto/id_ed25519")
32
+ # key = SSHData::PrivateKey.parse_openssh(key_data)
33
+ #=> <SSHData::PrivateKey::ED25519>
34
+
35
+ # SSHData::PrivateKey::ED25519.generate
36
+ #=> raises SSHData::AlgorithmError
37
+
38
+
39
+ # SSHData::PrivateKey::ED25519.generate
40
+ #=> <SSHData::PrivateKey::ED25519>
@@ -0,0 +1,7 @@
1
+
2
+ SignatureAlgorithm = {
3
+ Ed25519: 'ed25519',
4
+ Secp256K1: 'secp256k1'
5
+ }
6
+
7
+
File without changes
@@ -0,0 +1,44 @@
1
+ require 'openssl'
2
+ require 'ed25519'
3
+ require_relative './asymmetric_key.rb'
4
+
5
+ # SignatureAlgorithm = {
6
+ # Ed25519: 'ed25519',
7
+ # Secp256K1: 'secp256k1'
8
+ # }
9
+ public_key = [
10
+ 72, 211, 174, 85, 36, 108, 106, 103,
11
+ 8, 124, 245, 68, 60, 206, 180, 170,
12
+ 17, 175, 158, 175, 142, 32, 64, 61,
13
+ 195, 38, 169, 191, 55, 231, 249, 39
14
+ ]
15
+
16
+ private_key = [
17
+ 236, 126, 0, 243, 8, 76, 9, 186, 180, 175, 7,
18
+ 155, 21, 92, 86, 47, 12, 70, 89, 171, 48, 87,
19
+ 37, 172, 174, 34, 140, 219, 24, 190, 42, 192, 72,
20
+ 211, 174, 85, 36, 108, 106, 103, 8, 124, 245, 68,
21
+ 60, 206, 180, 170, 17, 175, 158, 175, 142, 32, 64,
22
+ 61, 195, 38, 169, 191, 55, 231, 249, 39
23
+ ]
24
+ class Ed25519Key < AsymmetricKey
25
+
26
+ def initialize(public_key, private_key)
27
+ # super(keypair.public_key, keypair.secret_key, SignatureAlgorithm[:Ed25519])
28
+ super(public_key, private_key, SignatureAlgorithm[:Ed25519])
29
+ end
30
+
31
+ # Generate the account_hex for the Ed25519 public key
32
+ #
33
+ # @param [Array] public_key
34
+ # @return [String]
35
+ def account_hex(public_key)
36
+ '01' + Utils::Base16.encode16(public_key)
37
+ end
38
+ end
39
+
40
+ ed25519 = Ed25519Key.new(public_key, private_key)
41
+
42
+ puts ed25519.account_hash(public_key)
43
+ puts ed25519.get_signature_algorithm
44
+ puts ed25519.get_public_key
@@ -0,0 +1,45 @@
1
+ module Casper
2
+ module Entity
3
+ # An Account is a structure that represents a user on a Casper Network.
4
+ class Account
5
+
6
+ # @param [CLAccountHash] account_hash
7
+ # @param [Array] named_keys
8
+ # @param [CLUref] main_purse The account's main purse URef
9
+ # @param [Array] associated_keys
10
+ # @param [Array<ActionThresHolds>] action_thresholds
11
+ def initialize(account_hash, named_keys, main_purse, associated_keys, action_thresholds)
12
+ @account_hash = account_hash
13
+ @named_keys = named_keys
14
+ @main_purse = main_purse
15
+ @associated_keys = associated_keys
16
+ @action_thresholds = action_thresholds
17
+ end
18
+
19
+ # @return [CLAccountHash]
20
+ def get_account_hash
21
+ @account_hash
22
+ end
23
+
24
+ # @return [Array]
25
+ def get_named_keys
26
+ @named_keys
27
+ end
28
+
29
+ # @return [CLUref]
30
+ def get_main_purse
31
+ @main_purse
32
+ end
33
+
34
+ # @return [Array<AssociatedKey>]
35
+ def get_associated_keys
36
+ @associated_keys
37
+ end
38
+
39
+ # @return [ActionThresHolds]
40
+ def get_action_thresholds
41
+ @action_thresholds
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # @note The minimum weight thresholds that have to be met when executing an action of a certain type.
5
+ class ActionThresholds
6
+
7
+ # @param [Integer] deployment Threshold required to perform deployment actions.
8
+ # @param [Integer] key_management Threshold required to perform key management actions.
9
+ def initialize(deployment, key_management)
10
+ @deployment = deployment
11
+ @key_management = key_management
12
+ end
13
+
14
+ # @return [Integer] deployment
15
+ def get_deployment
16
+ @deployment
17
+ end
18
+
19
+ # @return [Integer] key_management
20
+ def get_key_management
21
+ @key_management
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Casper
2
+ module Entity
3
+ # A key granted limited permissions to an Account, for purposes such as multisig.
4
+ class AssociatedKey
5
+
6
+ # @param [CLAccountHash] account_hash
7
+ # @param [Integer] weight
8
+ def initialize(account_hash, weight)
9
+ @account_hash = account_hash
10
+ @weight = weight
11
+ end
12
+
13
+ # @return [CLAccountHash] account hash of associated key
14
+ def get_account_hash
15
+ @account_hash
16
+ end
17
+
18
+ # @return [Integer] weight of an associated key.
19
+ def get_weight
20
+ @weight
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ module Casper
2
+ module Entity
3
+ class AuctionState
4
+ # @param [String] state_root_hash
5
+ # @param [Integer] block_height
6
+ # @param [Array] era_validators
7
+ # @param [Array] bids
8
+ def initialize(state_root_hash, block_height, era_validators, bids)
9
+ @state_root_hash = state_root_hash
10
+ @block_height = block_height
11
+ @era_validators = era_validators
12
+ @bids = bids
13
+ end
14
+
15
+ # @return [String] returns state root hash as a String
16
+ def get_state_root_hash
17
+ @state_root_hash
18
+ end
19
+
20
+ # @return [Integer] returns block height as an Integer
21
+ def get_block_height
22
+ @block_height
23
+ end
24
+
25
+ # @return [Array<Hash>] returns array of hashes
26
+ def get_era_validators
27
+ @era_validators
28
+ end
29
+
30
+ # @return [Array<Hash>] returns array of hashes
31
+ def get_bids
32
+ @bids
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/entity/bid.rb ADDED
@@ -0,0 +1,24 @@
1
+ module Casper
2
+ module Entity
3
+ class Bid
4
+
5
+ # @param [String] public_key
6
+ # @param [BidInfo] bid_info
7
+ def initialize(public_key, bid_info)
8
+ @public_key = public_key
9
+ @BidInfo = bid_info
10
+
11
+ end
12
+
13
+ # @return [String] public_key
14
+ def get_public_key
15
+ @public_key
16
+ end
17
+
18
+ # @return [BidInfo] bid_info
19
+ def get_bid_info
20
+ @bid_info
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ module Casper
2
+ module Entity
3
+ class BidInfo
4
+
5
+ # @param [String] bonding_purse
6
+ # @param [String] staked_amount
7
+ # @param [Integer] delegation_rate
8
+ # @param [VestingSchedule] vesting_schedule
9
+ # @param [Hash<Delegator>] delegators
10
+ # @param [Boolean] inactive
11
+ def initialize(bonding_purse, staked_amount, delegation_rate, vesting_schedule, delegators, inactive)
12
+ @bonding_purse = bonding_purse
13
+ @staked_amount = staked_amount
14
+ @delegation_rate = delegation_rate
15
+ @vesting_schedule = vesting_schedule
16
+ @delegators = delegators
17
+ @inactive = inactive
18
+ end
19
+
20
+ # @return [String] bonding_purse
21
+ def get_bonding_purse
22
+ @bonding_purse
23
+ end
24
+
25
+ # @return [String] staked_amount
26
+ def get_staked_amount
27
+ @staked_amount
28
+ end
29
+
30
+ # @return [Integer] delegation_rate
31
+ def get_delegation_rate
32
+ @delegation_rate
33
+ end
34
+
35
+ # @return [VestingSchedule] vesting_schedule
36
+ def get_vesting_schedule
37
+ @vesting_schedule
38
+ end
39
+
40
+ # @return [Delegator] delegators
41
+ def get_delegators
42
+ @delegators
43
+ end
44
+
45
+ # @return [true, false] inactive
46
+ def get_inactive
47
+ @inactive
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # Contract entity class
5
+ class Contract
6
+
7
+ # @param [String] contract_package_hash
8
+ # @param [String] contract_wasm_hash
9
+ # @param [Array] entry_points
10
+ # @param [Array] named_keys
11
+ # @param [String] protocol_version
12
+ def initialize(contract_package_hash, contract_wasm_hash, named_keys, entry_points, protocol_version)
13
+ @contract_package_hash = contract_package_hash
14
+ @contract_wasm_hash = contract_wasm_hash
15
+ @entry_points = entry_points
16
+ @named_keys = named_keys
17
+ @protocol_version = protocol_version
18
+ end
19
+
20
+ # @return [String] contract_package_hash
21
+ def get_contract_package_hash
22
+ @contract_package_hash
23
+ end
24
+
25
+ # @return [String] contract_wasm_hash
26
+ def get_contract_wasm_hash
27
+ @contract_wasm_hash
28
+ end
29
+
30
+ # @return [Array] entry_points
31
+ def get_entry_points
32
+ @entry_points
33
+ end
34
+
35
+ # @return [Array] named_keys
36
+ def get_named_keys
37
+ @named_keys
38
+ end
39
+
40
+ # @return [String] protocol_version
41
+ def get_protocol_version
42
+ @protocol_version
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # Contract definition, metadata and security container.
5
+ class ContractPackage
6
+
7
+ # @param [CLURef] access_key
8
+ # @param [ContractVersion] versions
9
+ # @param [DisabledVersion] disabled_versions
10
+ # @param [Group] groups
11
+ def initialize(access_key, versions, disabled_versions, groups)
12
+ @access_key = access_key
13
+ @versions = versions
14
+ @disabled_versions = disabled_versions
15
+ @groups = groups
16
+ end
17
+
18
+ # @return [CLURef] access_key
19
+ def get_access_key
20
+ @access_key
21
+ end
22
+
23
+ # @return [ContractVersion] versions
24
+ def get_versions
25
+ @versions
26
+ end
27
+
28
+ # @return [DisabledVersion] versions
29
+ def get_disabled_versions
30
+ @disabled_versions
31
+ end
32
+
33
+ # @return [Group] groups
34
+ def get_groups
35
+ @groups
36
+ end
37
+
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ module Casper
2
+ module Entity
3
+
4
+ # The version of the contract.
5
+ class ContractVersion
6
+
7
+ # @param [Integer] protocol_version_major
8
+ # @param [Integer] contract_version
9
+ # @param [String] contract_hash
10
+ def initialize(protocol_version_major, contract_version, contract_hash)
11
+ @protocol_version_major = protocol_version_major
12
+ @contract_version = contract_version
13
+ @contract_hash = contract_hash
14
+ end
15
+
16
+ # @return [Integer] protocol_version_major
17
+ def get_protocol_version_major
18
+ @protocol_version_major
19
+ end
20
+
21
+ # @return [Integer] contract_version
22
+ def get_contract_version
23
+ @contract_version
24
+ end
25
+
26
+ # @return [String] contract_hash
27
+ def get_contract_hash
28
+ @contract_hash
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ module Casper
2
+ module Entity
3
+ class Delegator
4
+
5
+ # @param [String] public_key
6
+ # @param [String] staked_amount
7
+ # @param [String] bonding_purse
8
+ # @param [String] delegatee
9
+ def initialize(public_key, staked_amount, bonding_purse, delegatee)
10
+ @public_key = public_key
11
+ @staked_amount = staked_amount
12
+ @bonding_purse = bonding_purse
13
+ @delegatee = delegatee
14
+ end
15
+
16
+ # @return [String] public_key
17
+ def get_public_key
18
+ @public_key
19
+ end
20
+
21
+ # @return [String] staked_amount
22
+ def get_staked_amount
23
+ @staked_amount
24
+ end
25
+
26
+ # @return [String] bonding_purse
27
+ def get_bonding_purse
28
+ @bonding_purse
29
+ end
30
+
31
+ # @return [String] delegatee
32
+ def get_delegatee
33
+ @delegatee
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ module Casper
2
+ module Entity
3
+ class Deploy
4
+
5
+ # @param [String] hash
6
+ # @param [DeployHeader] header
7
+ # @param [DeployExecutable] payment
8
+ # @param [DeployExecutable] session
9
+ # @param [DeployApproval] approvals
10
+ def initialize(hash, header, payment, session, approvals)
11
+ @hash = hash
12
+ @header = header
13
+ @payment = payment
14
+ @session = session
15
+ @approvals = approvals
16
+ end
17
+
18
+ # @return [String] hash
19
+ def get_hash
20
+ @hash
21
+ end
22
+
23
+ # @return [DeployHeader] header
24
+ def get_header
25
+ @header
26
+ end
27
+
28
+ # @return [DeployExecutable] payment
29
+ def get_payment
30
+ @payment
31
+ end
32
+
33
+ # @return [DeployExecutable] session
34
+ def get_session
35
+ @session
36
+ end
37
+
38
+ # @return [DeployApproval] approvals
39
+ def get_approvals
40
+ @approvals
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ module Casper
2
+ module Entity
3
+ class DeployApproval
4
+
5
+ # @param [Hash] approval
6
+ # @option approval [String] :signer
7
+ # @option approval [String] :signature
8
+ def initialize(approval = {})
9
+ @signer = approval[:signer]
10
+ @signature = approval[:signature]
11
+ end
12
+
13
+ # @return [String] signer
14
+ def get_signer
15
+ @signer
16
+ end
17
+
18
+ # return [String] signature
19
+ def get_signature
20
+ @signature
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,162 @@
1
+ require_relative './deploy_named_argument.rb'
2
+ require_relative './module_bytes.rb'
3
+ require_relative './deploy_executable_transfer.rb'
4
+
5
+ module Casper
6
+ module Entity
7
+ class DeployExecutable
8
+ attr_accessor :module_bytes, :transfer, :stored_contract_by_hash, :stored_contract_by_name,
9
+ :stored_versioned_contract_by_hash, :stored_versioned_contract_by_name
10
+ def initialize
11
+ @module_bytes = nil
12
+ @stored_contract_by_hash = nil
13
+ @stored_contract_by_name = nil
14
+ @stored_versioned_contract_by_hash = nil
15
+ @stored_versioned_contract_by_name = nil
16
+ @transfer = nil
17
+ end
18
+
19
+ def standard_payment(payment_amount)
20
+ @module_bytes = ModuleBytes.new("", [])
21
+ arg = DeployNamedArgument.new("amount", CLu512.new(payment_amount))
22
+ @module_bytes.set_arg(arg) # => Add arg and return args
23
+ @module_bytes
24
+ end
25
+
26
+ # @param [Integer] id
27
+ # @param [Integer] amount
28
+ # @param [CLURef | CLPublicKey] target
29
+ # @param [CLURef | CLPublicKey] source_purse
30
+ # @return [DeployExecutable]
31
+ def new_transfer(id, amount, target, source_purse = nil)
32
+ if target.instance_of? CLURef
33
+ @target = target
34
+ elsif target.instance_of? CLPublicKey
35
+ @target = target.to_account_hash_byte_array
36
+ else
37
+ raise ArgumentError.new("Please specify target")
38
+ end
39
+ arg1 = DeployNamedArgument.new("amount", CLu512.new(amount))
40
+ # arg2 = DeployNamedArgument.new("target", @target)
41
+ @transfer = DeployExecutableTransfer.new([])
42
+ # @transfer.set_arg(DeployNamedArgument.new("target", @target))
43
+ # @transfer.set_arg(arg1)
44
+ # @transfer.set_arg(arg2)
45
+ # @transfer
46
+
47
+ if source_purse != nil
48
+ @transfer.set_arg(DeployNamedArgument.new("source", source_purse))
49
+ # @transfer
50
+ end
51
+ @transfer.set_arg(DeployNamedArgument.new("target", @target))
52
+ @transfer.set_arg(DeployNamedArgument.new("id", CLu64.new(id)))
53
+ @transfer
54
+ end
55
+
56
+ def set_module_bytes(module_bytes)
57
+ @module_bytes = module_bytes
58
+ end
59
+
60
+ # @return [ModuleBytes] module_bytes
61
+ def get_module_bytes
62
+ @module_bytes
63
+ end
64
+
65
+ # @return [Boolean]
66
+ def module_bytes?
67
+ @module_bytes != nil
68
+ end
69
+
70
+ # @param [DeployExecutableTransfer] transfer
71
+ def set_transfer(transfer)
72
+ @transfer = transfer
73
+ end
74
+
75
+ def get_transfer
76
+ @transfer
77
+ end
78
+
79
+ # @return [Boolean]
80
+ def transfer?
81
+ @transfer != nil
82
+ end
83
+
84
+ # @param [StoredContractByHash] stored_contract_by_hash
85
+ def set_stored_contract_by_hash(stored_contract_by_hash)
86
+ @stored_contract_by_hash = stored_contract_by_hash
87
+ end
88
+
89
+ def get_stored_contract_by_hash
90
+ @stored_contract_by_hash
91
+ end
92
+
93
+ # @return [Boolean]
94
+ def stored_contract_by_hash?
95
+ @stored_contract_by_hash != nil
96
+ end
97
+
98
+ # @param [StoredContractByName] stored_contract_by_name
99
+ def set_stored_contract_by_name(stored_contract_by_name)
100
+ @stored_contract_by_name = stored_contract_by_name
101
+ end
102
+
103
+ def get_stored_contract_by_name
104
+ @stored_contract_by_name
105
+ end
106
+
107
+ # @return [Boolean]
108
+ def stored_contract_by_name?
109
+ @stored_contract_by_name != nil
110
+ end
111
+
112
+ # @param [StoredVersionedContractByHash] stored_versioned_contract_by_hash
113
+ def set_stored_versioned_contract_by_hash(stored_versioned_contract_by_hash)
114
+ @stored_versioned_contract_by_hash = stored_versioned_contract_by_hash
115
+ end
116
+
117
+ def get_stored_versioned_contract_by_hash
118
+ @stored_versioned_contract_by_hash
119
+ end
120
+
121
+ # @return [Boolean]
122
+ def stored_versioned_contract_by_hash?
123
+ @stored_versioned_contract_by_hash != nil
124
+ end
125
+
126
+ # @param [StoredVersionedContractByName] stored_versioned_contract_by_name
127
+ def set_stored_versioned_contract_by_name(stored_versioned_contract_by_name)
128
+ @stored_versioned_contract_by_name = stored_versioned_contract_by_name
129
+ end
130
+
131
+ def get_stored_versioned_contract_by_name
132
+ @stored_versioned_contract_by_name
133
+ end
134
+
135
+ # @return [Boolean]
136
+ def stored_versioned_contract_by_name?
137
+ @stored_versioned_contract_by_name != nil
138
+ end
139
+
140
+ def to_bytes
141
+ if module_bytes?
142
+ @module_bytes.to_bytes
143
+ elsif stored_contract_by_name?
144
+ @stored_contract_by_name.to_bytes
145
+ elsif stored_contract_by_hash?
146
+ @stored_contract_by_hash.to_bytes
147
+ elsif stored_contract_by_name?
148
+ @stored_contract_by_name.to_bytes
149
+ elsif stored_versioned_contract_by_hash?
150
+ @stored_versioned_contract_by_hash.to_bytes
151
+ elsif stored_versioned_contract_by_name?
152
+ @stored_versioned_contract_by_name.to_bytes
153
+ elsif stored_versioned_contract_by_hash?
154
+ @stored_versioned_contract_by_hash.to_bytes
155
+ elsif transfer?
156
+ @transfer.to_bytes
157
+ end
158
+ raise "failed to serialize ExecutableDeployItemJsonWrapper"
159
+ end
160
+ end
161
+ end
162
+ end