Class: Nis::Request::Announce

Inherits:
Object
  • Object
show all
Includes:
Mixin::Struct
Defined in:
lib/nis/request/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) ⇒ Announce

Returns a new instance of Announce.



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

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

Instance Attribute Details

#dataString

Returns the current value of data.

Returns:

  • (String)

    the current value of data



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

def data
  @data
end

#keypairObject

Returns the value of attribute keypair.



8
9
10
# File 'lib/nis/request/announce.rb', line 8

def keypair
  @keypair
end

#signature=(value) ⇒ String

Returns the newly set value.

Parameters:

  • value (String)

    the value to set the attribute signature to.

Returns:

  • (String)

    the newly set value



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

def signature=(value)
  @signature = value
end

#transactionObject

Returns the value of attribute transaction.



8
9
10
# File 'lib/nis/request/announce.rb', line 8

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
46
47
48
# File 'lib/nis/request/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

  serialized = serialize(entity_hash)
  hex_serialized = Nis::Util::Convert.ua2hex(serialized)

  { data: Nis::Util::Convert.ua2hex(serialized),
    signature: signature(hex_serialized) }
end