Module: Nis::Util::Serializer
- Defined in:
- lib/nis/util/serializer.rb
Class Method Summary collapse
- .serialize_common(entity) ⇒ Object
- .serialize_multisig_transfer(entity) ⇒ Object
-
.serialize_transaction(entity) ⇒ Array
Serialize a transaction object.
- .serialize_transfer(entity) ⇒ Object
Class Method Details
.serialize_common(entity) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nis/util/serializer.rb', line 15 def self.serialize_common(entity) a = [] a += serialize_int(entity[:type]) a += serialize_int(entity[:version]) a += serialize_int(entity[:timeStamp]) temp = hex2ua(entity[:signer]) a += serialize_int(temp.size) a += temp a += serialize_long(entity[:fee].to_i) a += serialize_int(entity[:deadline]) a end |
.serialize_multisig_transfer(entity) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nis/util/serializer.rb', line 30 def self.serialize_multisig_transfer(entity) a = [] # Common transaction part a += serialize_common(entity) # Transfer transaction part tx = serialize_transfer(entity[:otherTrans]) a += serialize_int(tx.size) a += tx a end |
.serialize_transaction(entity) ⇒ Array
Serialize a transaction object
6 7 8 9 10 11 12 13 |
# File 'lib/nis/util/serializer.rb', line 6 def self.serialize_transaction(entity) method = case entity[:type] when 257 then method(:serialize_transfer) when 4100 then method(:serialize_multisig_transfer) else raise "Not implemented entity type: #{entity[:type]}" end method.call(entity) end |
.serialize_transfer(entity) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nis/util/serializer.rb', line 43 def self.serialize_transfer(entity) a = [] # Common transaction part a += serialize_common(entity) # Transfer transaction part temp = serialize_safe_string(entity[:recipient]) a += temp a += serialize_long(entity[:amount]) temp = hex2ua(entity[:message][:payload]) if temp.size == 0 a += [0,0,0,0] else a += serialize_int(temp.size + 8) a += serialize_int(entity[:message][:type]) a += serialize_int(temp.size) a += temp end a end |