Class: AppChain::Transaction
- Inherits:
-
Object
- Object
- AppChain::Transaction
- Defined in:
- lib/appchain/transaction.rb
Defined Under Namespace
Classes: VersionError
Instance Attribute Summary collapse
-
#chain_id ⇒ Object
Returns the value of attribute chain_id.
-
#data ⇒ Object
Returns the value of attribute data.
-
#nonce ⇒ Object
Returns the value of attribute nonce.
-
#quota ⇒ Object
Returns the value of attribute quota.
-
#to ⇒ Object
Returns the value of attribute to.
-
#valid_until_block ⇒ Object
Returns the value of attribute valid_until_block.
-
#value ⇒ Object
Returns the value of attribute value.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize(valid_until_block:, chain_id:, nonce: nil, version: 1, to: nil, data: nil, value: "0", quota: 1_000_000) ⇒ void
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/appchain/transaction.rb', line 21 def initialize(valid_until_block:, chain_id:, nonce: nil, version: 1, to: nil, data: nil, value: "0", quota: 1_000_000) # rubocop:disable Metrics/ParameterLists raise VersionError, "transaction version error, expected 0 or 1, got #{version}" unless [0, 1].include?(version) @to = to @nonce = nonce.blank? ? SecureRandom.hex : nonce @quota = quota @valid_until_block = valid_until_block @data = data @chain_id = if chain_id.is_a?(String) chain_id.delete("-") else chain_id end @version = version @value = if value.is_a?(Integer) Utils.to_hex(value) else value end end |
Instance Attribute Details
#chain_id ⇒ Object
Returns the value of attribute chain_id.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def chain_id @chain_id end |
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def data @data end |
#nonce ⇒ Object
Returns the value of attribute nonce.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def nonce @nonce end |
#quota ⇒ Object
Returns the value of attribute quota.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def quota @quota end |
#to ⇒ Object
Returns the value of attribute to.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def to @to end |
#valid_until_block ⇒ Object
Returns the value of attribute valid_until_block.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def valid_until_block @valid_until_block end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def value @value end |
#version ⇒ Object
Returns the value of attribute version.
9 10 11 |
# File 'lib/appchain/transaction.rb', line 9 def version @version end |
Class Method Details
.from_hash(hash) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/appchain/transaction.rb', line 42 def self.from_hash(hash) h = hash.map { |k, v| { k.to_sym => v } }.reduce({}, :merge) new( nonce: h[:nonce], valid_until_block: h[:valid_until_block], chain_id: h[:chain_id], to: h[:to], data: h[:data], version: h[:version] || 1, value: h[:value] || "0", quota: h[:quota] || 1_000_000 ) end |