Class: Nis::Request::PrepareAnnounce

Inherits:
Object
  • Object
show all
Includes:
Mixin::Struct
Defined in:
lib/nis/request/prepare_announce.rb

Overview

Constant Summary collapse

DEADLINE =
3600

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Struct

#[], #to_json

Constructor Details

#initialize(transaction, keypair) ⇒ PrepareAnnounce

Returns a new instance of PrepareAnnounce.



12
13
14
15
# File 'lib/nis/request/prepare_announce.rb', line 12

def initialize(transaction, keypair)
  @keypair = keypair
  @transaction = transaction
end

Instance Attribute Details

#keypairNis::Keypair

Returns the current value of keypair.

Returns:



5
6
7
# File 'lib/nis/request/prepare_announce.rb', line 5

def keypair
  @keypair
end

#transactionNis::Struct::Transaction

Returns the current value of transaction.

Returns:



5
6
7
# File 'lib/nis/request/prepare_announce.rb', line 5

def transaction
  @transaction
end

Instance Method Details

#to_hashHash

Returns Attribute and value pairs.

Returns:

  • (Hash)

    Attribute and value pairs



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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