Class: ArkEcosystem::Crypto::Builder::Transaction
- Inherits:
-
Object
- Object
- ArkEcosystem::Crypto::Builder::Transaction
- Defined in:
- lib/arkecosystem/crypto/builder/transaction.rb
Overview
The base builder for transactions.
Direct Known Subclasses
DelegateRegistration, MultiSignatureRegistration, SecondSignatureRegistration, Transfer, Vote
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#asset ⇒ Object
Returns the value of attribute asset.
-
#fee ⇒ Object
Returns the value of attribute fee.
-
#id ⇒ Object
Returns the value of attribute id.
-
#recipient_id ⇒ Object
Returns the value of attribute recipient_id.
-
#sender_public_key ⇒ Object
Returns the value of attribute sender_public_key.
-
#sign_signature ⇒ Object
Returns the value of attribute sign_signature.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#type ⇒ Object
Returns the value of attribute type.
-
#vendor_field ⇒ Object
Returns the value of attribute vendor_field.
Instance Method Summary collapse
-
#initialize ⇒ Transaction
constructor
A new instance of Transaction.
- #second_sign(second_secret) ⇒ Object
- #second_verify(second_public_key_hex) ⇒ Object
- #sign(secret) ⇒ Object
- #sign_and_create_id(secret) ⇒ Object
- #to_hash ⇒ Object
- #to_params ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize ⇒ Transaction
Returns a new instance of Transaction.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 16 def initialize @type = type @fee = ArkEcosystem::Crypto::Configuration::Fee.get(@type) @sender_public_key = nil @recipient_id = nil @amount = 0 @vendor_field = nil @timestamp = seconds_after_epoch @asset = {} end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def amount @amount end |
#asset ⇒ Object
Returns the value of attribute asset.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def asset @asset end |
#fee ⇒ Object
Returns the value of attribute fee.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def fee @fee end |
#id ⇒ Object
Returns the value of attribute id.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def id @id end |
#recipient_id ⇒ Object
Returns the value of attribute recipient_id.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def recipient_id @recipient_id end |
#sender_public_key ⇒ Object
Returns the value of attribute sender_public_key.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def sender_public_key @sender_public_key end |
#sign_signature ⇒ Object
Returns the value of attribute sign_signature.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def sign_signature @sign_signature end |
#signature ⇒ Object
Returns the value of attribute signature.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def signature @signature end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def @timestamp end |
#type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def type @type end |
#vendor_field ⇒ Object
Returns the value of attribute vendor_field.
14 15 16 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 14 def vendor_field @vendor_field end |
Instance Method Details
#second_sign(second_secret) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 43 def second_sign(second_secret) second_key = ArkEcosystem::Crypto::Identity::PrivateKey.from_secret(second_secret) bytes = ArkEcosystem::Crypto::Crypto.get_bytes(to_hash, false) @sign_signature = second_key.ecdsa_signature(Digest::SHA256.digest(bytes)).unpack('H*').first self end |
#second_verify(second_public_key_hex) ⇒ Object
56 57 58 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 56 def second_verify(second_public_key_hex) ArkEcosystem::Crypto::Crypto.second_verify(self, second_public_key_hex) end |
#sign(secret) ⇒ Object
27 28 29 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 27 def sign(secret) sign_and_create_id(secret) end |
#sign_and_create_id(secret) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 31 def sign_and_create_id(secret) private_key = ArkEcosystem::Crypto::Identity::PrivateKey.from_secret(secret) @sender_public_key = private_key.public_key.unpack('H*').first transaction_bytes = ArkEcosystem::Crypto::Crypto.get_bytes(to_hash) @signature = private_key.ecdsa_signature(Digest::SHA256.digest(transaction_bytes)).unpack('H*').first transaction_bytes = ArkEcosystem::Crypto::Crypto.get_bytes(to_hash, false, false) @id = Digest::SHA256.digest(transaction_bytes).unpack('H*').first self end |
#to_hash ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 77 def to_hash { amount: amount, asset: asset, fee: fee, id: id, recipient_id: recipient_id, sender_public_key: sender_public_key, sign_signature: sign_signature, signature: signature, timestamp: , type: type, vendor_field: vendor_field } end |
#to_params ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 60 def to_params { type: type, amount: amount, fee: fee, vendorField: vendor_field, timestamp: , recipientId: recipient_id, senderPublicKey: sender_public_key, signature: signature, id: id }.tap do |h| h[:asset] = asset.deep_transform_keys { |key| snake_case_to_camel_case(key) } if asset.any? h[:signSignature] = sign_signature if sign_signature end end |
#verify ⇒ Object
52 53 54 |
# File 'lib/arkecosystem/crypto/builder/transaction.rb', line 52 def verify ArkEcosystem::Crypto::Crypto.verify(self) end |