9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ethereum-contract-abi/encoders/bytes_encoder.rb', line 9
def self.encode(bytes_to_encode, num_bytes = nil)
if bytes_to_encode.methods.include?(:start_with?) && bytes_to_encode.start_with?("0x")
bytes_to_encode = Util.toHexByteString(bytes_to_encode.slice(2, bytes_to_encode.length))
end
unless num_bytes.nil?
raise ArgumentError.new("Too many bytes to encode") unless bytes_to_encode.bytesize <= num_bytes
return self.encode_bytes(bytes_to_encode)
end
num_bytes_encoded = IntEncoder.encode(bytes_to_encode.bytesize)
num_bytes_encoded + self.encode_bytes(bytes_to_encode)
end
|