Class: Tapyrus::Color::ColorIdentifier
- Inherits:
-
Object
- Object
- Tapyrus::Color::ColorIdentifier
- Includes:
- HexConverter
- Defined in:
- lib/tapyrus/script/color.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.default ⇒ Object
Return ColorIdentifier for native token(i.e TPC).
- .nft(out_point) ⇒ Object
- .non_reissuable(out_point) ⇒ Object
- .parse_from_payload(payload) ⇒ Object
- .reissuable(script_pubkey) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#default? ⇒ Boolean
Return true if the coin is native token(i.e TPC), otherwise false.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #to_payload ⇒ Object
- #valid? ⇒ Boolean
Methods included from HexConverter
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
13 14 15 |
# File 'lib/tapyrus/script/color.rb', line 13 def payload @payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/tapyrus/script/color.rb', line 13 def type @type end |
Class Method Details
.default ⇒ Object
Return ColorIdentifier for native token(i.e TPC)
28 29 30 |
# File 'lib/tapyrus/script/color.rb', line 28 def self.default new(TokenTypes::NONE, "0000000000000000000000000000000000000000000000000000000000000000".htb) end |
.nft(out_point) ⇒ Object
23 24 25 |
# File 'lib/tapyrus/script/color.rb', line 23 def self.nft(out_point) new(TokenTypes::NFT, Tapyrus.sha256(out_point.to_payload)) end |
.non_reissuable(out_point) ⇒ Object
19 20 21 |
# File 'lib/tapyrus/script/color.rb', line 19 def self.non_reissuable(out_point) new(TokenTypes::NON_REISSUABLE, Tapyrus.sha256(out_point.to_payload)) end |
.parse_from_payload(payload) ⇒ Object
36 37 38 39 |
# File 'lib/tapyrus/script/color.rb', line 36 def self.parse_from_payload(payload) type, payload = payload.unpack("Ca*") new(type, payload) end |
.reissuable(script_pubkey) ⇒ Object
15 16 17 |
# File 'lib/tapyrus/script/color.rb', line 15 def self.reissuable(script_pubkey) new(TokenTypes::REISSUABLE, Tapyrus.sha256(script_pubkey.to_payload)) end |
Instance Method Details
#==(other) ⇒ Object
41 42 43 |
# File 'lib/tapyrus/script/color.rb', line 41 def ==(other) other && other.to_payload == to_payload end |
#default? ⇒ Boolean
Return true if the coin is native token(i.e TPC), otherwise false
60 61 62 |
# File 'lib/tapyrus/script/color.rb', line 60 def default? self == ColorIdentifier.default end |
#eql?(other) ⇒ Boolean
55 56 57 |
# File 'lib/tapyrus/script/color.rb', line 55 def eql?(other) to_payload.eql?(other.to_payload) end |
#hash ⇒ Object
51 52 53 |
# File 'lib/tapyrus/script/color.rb', line 51 def hash to_payload.hash end |
#to_payload ⇒ Object
32 33 34 |
# File 'lib/tapyrus/script/color.rb', line 32 def to_payload [type, payload].pack("Ca*") end |
#valid? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/tapyrus/script/color.rb', line 45 def valid? return false unless [TokenTypes::REISSUABLE, TokenTypes::NON_REISSUABLE, TokenTypes::NFT].include?(type) return false unless payload.bytesize == 32 true end |