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: [], network: nil) ⇒ Transfer
constructor
A new instance of Transfer.
-
#to_hash ⇒ Object
attributes must be CAMEL CASE for NIS params.
- #version ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(recipient, amount, message = '', mosaics: [], network: nil) ⇒ Transfer
Returns a new instance of Transfer.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nem/transaction/transfer.rb', line 16 def initialize(recipient, amount, = '', mosaics: [], network: nil) @amount = amount @recipient = recipient = .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) 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 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
29 30 31 |
# File 'lib/nem/transaction/transfer.rb', line 29 def .bytesize > 0 end |
#has_mosaics? ⇒ Boolean
33 34 35 |
# File 'lib/nem/transaction/transfer.rb', line 33 def has_mosaics? @mosaics.size > 0 end |
#to_hash ⇒ Object
attributes must be CAMEL CASE for NIS params
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nem/transaction/transfer.rb', line 42 def to_hash tmp = { amount: amount * 1_000_000, recipient: recipient, message: .to_hash } unless mosaics.empty? tmp[:mosaics] = mosaics.map do |moa| { mosaicId: { namespaceId: moa.mosaic_id.namespace_id, name: moa.mosaic_id.name, }, quantity: moa.amount } end end tmp end |
#version ⇒ Object
37 38 39 |
# File 'lib/nem/transaction/transfer.rb', line 37 def version network(hex: true) + (has_mosaics? ? 2 : 1) end |