class Nem::Request::Announce
@attr [Nem::Model::Transaction] transaction @attr [Nem::Keypair] keypair @see nemproject.github.io/#requestAnnounce @see nemproject.github.io/#requestPrepareAnnounce
Attributes
keypair[R]
transaction[R]
Public Class Methods
new(transaction, keypair)
click to toggle source
# File lib/nem/request/announce.rb, line 10 def initialize(transaction, keypair) @transaction = transaction @keypair = keypair end
Public Instance Methods
to_entity(state = nil)
click to toggle source
@return [Hash] Attribute and value pairs
# File lib/nem/request/announce.rb, line 16 def to_entity(state = nil) entity = prepare_entity if Nem.debug Nem.logger.debug '%s' % [entity.inspect] end if state == :prepare { transaction: entity, privateKey: keypair.private } else serialized = serialize(entity) hex_serialized = Nem::Util::Convert.ua2hex(serialized) { data: Nem::Util::Convert.ua2hex(serialized), signature: signature(hex_serialized) } end end
Private Instance Methods
prepare_entity()
click to toggle source
# File lib/nem/request/announce.rb, line 34 def prepare_entity specify = if transaction.multisig? prepare_multisig(transaction) else transaction.to_hash end set_common(specify) end
prepare_multisig(tx)
click to toggle source
# File lib/nem/request/announce.rb, line 43 def prepare_multisig(tx) timestamp = Nem::Unit::Time.new(tx.other_trans.timestamp) deadline = Nem::Unit::Time.new(tx.other_trans.deadline) other_trans = tx.other_trans.to_hash.merge( type: tx.other_trans.type, fee: tx.other_trans.fee.to_i, timeStamp: timestamp.to_i, deadline: deadline.to_i, signer: tx.signer, version: tx.other_trans.version ) tx.to_hash.merge( otherTrans: other_trans ) end
serialize(hash)
click to toggle source
# File lib/nem/request/announce.rb, line 72 def serialize(hash) Nem::Util::Serializer.serialize_transaction(hash) end
set_common(hash)
click to toggle source
# File lib/nem/request/announce.rb, line 59 def set_common(hash) timestamp = Nem::Unit::Time.new(transaction.timestamp) deadline = Nem::Unit::Time.new(transaction.deadline) hash.merge( type: transaction.type, fee: transaction.fee.to_i, timeStamp: timestamp.to_i, deadline: deadline.to_i, signer: keypair.public, version: transaction.version ) end
signature(serialized)
click to toggle source
# File lib/nem/request/announce.rb, line 76 def signature(serialized) keypair.sign(serialized) end