Class: Casper::Entity::DeployNamedArgument
- Inherits:
-
Object
- Object
- Casper::Entity::DeployNamedArgument
- Defined in:
- lib/entity/deploy_named_argument.rb
Overview
Named arguments passed as input in a Deploy item.
Instance Method Summary collapse
- #get_name ⇒ Object
- #get_value ⇒ Object
-
#initialize(name, clvalue) ⇒ DeployNamedArgument
constructor
A new instance of DeployNamedArgument.
-
#to_byte_array(num) ⇒ Array
Byte array containing two's complement.
- #to_hash ⇒ Object
Constructor Details
#initialize(name, clvalue) ⇒ DeployNamedArgument
Returns a new instance of DeployNamedArgument.
6 7 8 9 |
# File 'lib/entity/deploy_named_argument.rb', line 6 def initialize(name, clvalue) @name = name @clvalue = clvalue end |
Instance Method Details
#get_name ⇒ Object
11 12 13 |
# File 'lib/entity/deploy_named_argument.rb', line 11 def get_name @name end |
#get_value ⇒ Object
15 16 17 |
# File 'lib/entity/deploy_named_argument.rb', line 15 def get_value @clvalue end |
#to_byte_array(num) ⇒ Array
Returns byte array containing two's complement.
21 22 23 24 25 26 27 28 29 |
# File 'lib/entity/deploy_named_argument.rb', line 21 def to_byte_array(num) result = [] begin result << (num & 0xff) num >>= 8 end until (num == 0 || num == -1) && (result.last[7] == num[7]) # result.reverse result end |
#to_hash ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/entity/deploy_named_argument.rb', line 33 def to_hash serializer = CLValueSerializer.new value = @clvalue.get_value type = @clvalue.get_cl_type if @name == "amount" bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(value))[0...-2] num_of_bytes = bytes.length/2 [num_of_bytes].pack("C*").unpack1("H*") + bytes [ @name, { "bytes": [num_of_bytes].pack("C*").unpack1("H*") + bytes, "parsed": @clvalue.get_value, "cl_type": @clvalue.get_cl_type } ] elsif @name == "target" && type == "PublicKey" [ @name, { "bytes": @clvalue.to_hex, "parsed": @clvalue.to_hex, "cl_type": @clvalue.get_cl_type } ] elsif @name == "id" data = @clvalue.get_value inner_type = data.get_cl_type inner_value = data.get_value parsed = inner_value bytes = "01" + serializer.only_value(data) [ @name, { "bytes": bytes, "parsed": parsed, "cl_type": { "#{type}": inner_type } } ] end end |