class Nis::Request::PrepareAnnounce

@attr [Nis::Struct::Transaction] transaction @attr [Nis::Keypair] keypair @see nemproject.github.io/#requestPrepareAnnounce

Constants

DEADLINE

Attributes

keypair[RW]
transaction[RW]

Public Class Methods

new(transaction, keypair) click to toggle source
# File lib/nis/request/prepare_announce.rb, line 12
def initialize(transaction, keypair)
  @keypair = keypair
  @transaction = transaction
end

Public Instance Methods

to_hash() click to toggle source

@return [Hash] Attribute and value pairs

# File lib/nis/request/prepare_announce.rb, line 18
def to_hash
  entity = @transaction.clone

  entity.amount *= 1_000_000 if entity.respond_to?(:amount)

  if entity.respond_to?(:other_trans)
    other_trans(entity)
  end

  entity.tap do |tx|
    tx.timeStamp = Nis::Util.timestamp
    tx.deadline = Nis::Util.deadline(DEADLINE)
    tx.version = Nis::Util.parse_version(tx.network, version(tx))
    tx.signer = @keypair.public
  end

  entity_hash = entity.to_hash
  if entity.respond_to?(:has_mosaics?) && !entity.has_mosaics?
    entity_hash.delete(:mosaics)
  end

  if entity.respond_to?(:other_trans) && !entity.other_trans.has_mosaics?
    entity_hash[:otherTrans].delete(:mosaics)
  end

  { transaction: entity_hash,
    privateKey: @keypair.private }
end

Private Instance Methods

other_trans(transaction) click to toggle source
# File lib/nis/request/prepare_announce.rb, line 49
def other_trans(transaction)
  transaction.other_trans.tap do |tx|
    tx.amount *= 1_000_000 if tx.respond_to?(:amount)

    tx.timeStamp = Nis::Util.timestamp
    tx.deadline = Nis::Util.deadline(DEADLINE)
    tx.version = Nis::Util.parse_version(tx.network, version(tx))

    # multisig transfer
    tx.signer = transaction.signer
  end
end
version(transaction) click to toggle source
# File lib/nis/request/prepare_announce.rb, line 62
def version(transaction)
  transaction.respond_to?(:has_mosaics?) && transaction.has_mosaics? ? 2 : 1
end