Class: BTC::AssetTransactionInput
- Inherits:
-
Object
- Object
- BTC::AssetTransactionInput
- Defined in:
- lib/btcruby/open_assets/asset_processor.rb,
lib/btcruby/open_assets/asset_transaction_input.rb
Instance Attribute Summary collapse
-
#asset_id ⇒ Object
Verified inputs with ‘asset_id == nil` are uncolored.
-
#index ⇒ Object
Returns the value of attribute index.
-
#previous_asset_transaction ⇒ Object
Returns the value of attribute previous_asset_transaction.
-
#transaction_input ⇒ Object
BTC::TransactionInput.
-
#value ⇒ Object
Returns the value of attribute value.
-
#verified ⇒ Object
true if asset_id and value are verified and can be used.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #assets_data ⇒ Object
-
#colored? ⇒ Boolean
Input is colored when it has AssetID and a positive value.
-
#initialize(transaction_input: nil, asset_id: nil, value: nil, verified: false) ⇒ AssetTransactionInput
constructor
A new instance of AssetTransactionInput.
-
#parse_assets_data(data, offset: 0) ⇒ Object
Returns total length read.
-
#verified? ⇒ Boolean
Input is verified when we know for sure if it’s colored or not and if it is, what asset and how much is associated with it.
Constructor Details
#initialize(transaction_input: nil, asset_id: nil, value: nil, verified: false) ⇒ AssetTransactionInput
Returns a new instance of AssetTransactionInput.
14 15 16 17 18 19 20 21 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 14 def initialize(transaction_input: nil, asset_id: nil, value: nil, verified: false) raise ArgumentError, "No transaction_input provided" if !transaction_input @transaction_input = transaction_input @index = transaction_input ? transaction_input.index : nil @asset_id = asset_id @value = value @verified = !!verified end |
Instance Attribute Details
#asset_id ⇒ Object
Verified inputs with ‘asset_id == nil` are uncolored. Non-verified inputs are not known to have assets associated with them.
10 11 12 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 10 def asset_id @asset_id end |
#index ⇒ Object
Returns the value of attribute index.
5 6 7 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 5 def index @index end |
#previous_asset_transaction ⇒ Object
Returns the value of attribute previous_asset_transaction.
355 356 357 |
# File 'lib/btcruby/open_assets/asset_processor.rb', line 355 def previous_asset_transaction @previous_asset_transaction end |
#transaction_input ⇒ Object
BTC::TransactionInput
6 7 8 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 6 def transaction_input @transaction_input end |
#value ⇒ Object
Returns the value of attribute value.
11 12 13 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 11 def value @value end |
#verified ⇒ Object
true if asset_id and value are verified and can be used.
12 13 14 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 12 def verified @verified end |
Instance Method Details
#==(other) ⇒ Object
60 61 62 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 60 def ==(other) super(other) || self.transaction_input == other.transaction_input end |
#assets_data ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 38 def assets_data data = "".b data << WireFormat.encode_uint8(@verified ? 1 : 0) data << WireFormat.encode_string(@asset_id ? @asset_id.hash : "".b) data << WireFormat.encode_int64le(@value.to_i) data end |
#colored? ⇒ Boolean
Input is colored when it has AssetID and a positive value.
30 31 32 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 30 def colored? !!@asset_id && @value && @value > 0 end |
#parse_assets_data(data, offset: 0) ⇒ Object
Returns total length read
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 47 def parse_assets_data(data, offset: 0) v, len = WireFormat.read_uint8(data: data, offset: offset) raise ArgumentError, "Invalid data: verified flag" if !v asset_hash, len = WireFormat.read_string(data: data, offset: len) # empty or 20 bytes raise ArgumentError, "Invalid data: asset hash" if !asset_hash value, len = WireFormat.read_int64le(data: data, offset: len) raise ArgumentError, "Invalid data: value" if !value @verified = (v == 1) @asset_id = asset_hash.bytesize > 0 ? AssetID.new(hash: asset_hash) : nil @value = value len end |
#verified? ⇒ Boolean
Input is verified when we know for sure if it’s colored or not and if it is, what asset and how much is associated with it.
25 26 27 |
# File 'lib/btcruby/open_assets/asset_transaction_input.rb', line 25 def verified? !!@verified end |