Class: MixinBot::InvoiceEntry
- Inherits:
-
Object
- Object
- MixinBot::InvoiceEntry
- Defined in:
- lib/mixin_bot/invoice.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#asset_id ⇒ Object
Returns the value of attribute asset_id.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#hash_references ⇒ Object
Returns the value of attribute hash_references.
-
#index_references ⇒ Object
Returns the value of attribute index_references.
-
#trace_id ⇒ Object
Returns the value of attribute trace_id.
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(**args) ⇒ InvoiceEntry
constructor
A new instance of InvoiceEntry.
- #to_hash ⇒ Object
Constructor Details
#initialize(**args) ⇒ InvoiceEntry
Returns a new instance of InvoiceEntry.
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/mixin_bot/invoice.rb', line 130 def initialize(**args) args = args.with_indifferent_access @trace_id = args[:trace_id] @asset_id = args[:asset_id] @amount = args[:amount].to_d @extra = args[:extra] @index_references = args[:index_references] @hash_references = args[:hash_references] end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
128 129 130 |
# File 'lib/mixin_bot/invoice.rb', line 128 def amount @amount end |
#asset_id ⇒ Object
Returns the value of attribute asset_id.
128 129 130 |
# File 'lib/mixin_bot/invoice.rb', line 128 def asset_id @asset_id end |
#extra ⇒ Object
Returns the value of attribute extra.
128 129 130 |
# File 'lib/mixin_bot/invoice.rb', line 128 def extra @extra end |
#hash_references ⇒ Object
Returns the value of attribute hash_references.
128 129 130 |
# File 'lib/mixin_bot/invoice.rb', line 128 def hash_references @hash_references end |
#index_references ⇒ Object
Returns the value of attribute index_references.
128 129 130 |
# File 'lib/mixin_bot/invoice.rb', line 128 def index_references @index_references end |
#trace_id ⇒ Object
Returns the value of attribute trace_id.
128 129 130 |
# File 'lib/mixin_bot/invoice.rb', line 128 def trace_id @trace_id end |
Instance Method Details
#encode ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/mixin_bot/invoice.rb', line 141 def encode bytes = [] bytes.concat MixinBot::UUID.new(hex: trace_id).packed.bytes bytes.concat MixinBot::UUID.new(hex: asset_id).packed.bytes amount_string = amount.to_d.to_s('F') amount_bytes = amount_string.bytes bytes.concat MixinBot.utils.encode_int(amount_bytes.size) bytes.concat amount_bytes extra_bytes = extra.bytes bytes.concat MixinBot.utils.encode_uint16(extra_bytes.size) bytes.concat extra_bytes references_count = (index_references || []).size + (hash_references || []).size bytes.concat MixinBot.utils.encode_int(references_count) index_references&.each do |index| bytes.concat MixinBot.utils.encode_int(1) bytes.concat MixinBot.utils.encode_int(index) end hash_references&.each do |hash| bytes.concat MixinBot.utils.encode_int(0) bytes.concat [hash].pack('H*').bytes end bytes end |
#to_hash ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/mixin_bot/invoice.rb', line 172 def to_hash { trace_id:, asset_id:, amount:, extra:, index_references:, hash_references: } end |