Class: Nem::Transaction::Transfer
- Defined in:
- lib/nem/transaction/transfer.rb
Overview
Constant Summary collapse
- TYPE =
257 (transfer transaction)
0x0101
Constants inherited from Base
Instance Attribute Summary collapse
-
#amount ⇒ Integer
The current value of amount.
-
#message ⇒ Nem::Model::Message
The current value of message.
-
#mosaics ⇒ Array <Nem::Model::MosaicId>
The current value of mosaics.
-
#recipient ⇒ String
The current value of recipient.
Attributes inherited from Base
#deadline, #fee, #signature, #signer, #timestamp, #type
Instance Method Summary collapse
- #has_message? ⇒ Boolean
- #has_mosaics? ⇒ Boolean
-
#initialize(recipient, amount, message = '', mosaics: [], timestamp: nil, deadline: nil, network: nil) ⇒ Transfer
constructor
A new instance of Transfer.
-
#to_hash ⇒ Hash
attributes must be CAMEL CASE for NIS params Mosaics need to be sorted by fqn.
- #version ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(recipient, amount, message = '', mosaics: [], timestamp: nil, deadline: nil, network: nil) ⇒ Transfer
Returns a new instance of Transfer.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nem/transaction/transfer.rb', line 16 def initialize(recipient, amount, = '', mosaics: [], timestamp: nil, deadline: nil, network: nil) @amount = amount @recipient = recipient @message = .is_a?(Nem::Model::Message) ? : Nem::Model::Message.new(.to_s) @mosaics = mosaics @network = network || Nem.default_network @type = TYPE @fee = Nem::Fee::Transfer.new(self) @timestamp = || Time.now @deadline = deadline || Time.now + Nem.default_deadline end |
Instance Attribute Details
#amount ⇒ Integer
Returns the current value of amount.
11 12 13 |
# File 'lib/nem/transaction/transfer.rb', line 11 def amount @amount end |
#message ⇒ Nem::Model::Message
Returns the current value of message.
11 12 13 |
# File 'lib/nem/transaction/transfer.rb', line 11 def @message end |
#mosaics ⇒ Array <Nem::Model::MosaicId>
Returns the current value of mosaics.
11 12 13 |
# File 'lib/nem/transaction/transfer.rb', line 11 def mosaics @mosaics end |
#recipient ⇒ String
Returns the current value of recipient.
11 12 13 |
# File 'lib/nem/transaction/transfer.rb', line 11 def recipient @recipient end |
Instance Method Details
#has_message? ⇒ Boolean
32 33 34 |
# File 'lib/nem/transaction/transfer.rb', line 32 def .bytesize > 0 end |
#has_mosaics? ⇒ Boolean
37 38 39 |
# File 'lib/nem/transaction/transfer.rb', line 37 def has_mosaics? mosaics.size > 0 end |
#to_hash ⇒ Hash
attributes must be CAMEL CASE for NIS params Mosaics need to be sorted by fqn. if not it will occur FAILURE_SIGNATURE_NOT_VERIFIABLE
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nem/transaction/transfer.rb', line 49 def to_hash tmp = { amount: (amount * 1_000_000).to_i, recipient: recipient, message: .to_hash } unless mosaics.empty? tmp[:mosaics] = mosaics .sort_by { |mo| mo.fqn } .map do |moa| { mosaicId: { namespaceId: moa.mosaic_id.namespace_id, name: moa.mosaic_id.name, }, quantity: moa.amount } end end tmp end |
#version ⇒ Object
41 42 43 |
# File 'lib/nem/transaction/transfer.rb', line 41 def version network(hex: true) + (has_mosaics? ? 2 : 1) end |