class Tapyrus::Color::ColorIdentifier

Attributes

payload[R]
type[R]

Public Class Methods

default() click to toggle source

Return ColorIdentifier for native token(i.e TPC)

# File lib/tapyrus/script/color.rb, line 28
def self.default
  new(TokenTypes::NONE, '0000000000000000000000000000000000000000000000000000000000000000'.htb)
end
new(type, payload) click to toggle source
# File lib/tapyrus/script/color.rb, line 66
def initialize(type, payload)
  @type = type
  @payload = payload
end
nft(out_point) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/tapyrus/script/color.rb, line 15
def self.reissuable(script_pubkey)
  new(TokenTypes::REISSUABLE, Tapyrus.sha256(script_pubkey.to_payload))
end

Public Instance Methods

==(other) click to toggle source
# File lib/tapyrus/script/color.rb, line 41
def ==(other)
  other && other.to_payload == to_payload
end
default?() click to toggle source

Return true if the coin is native token(i.e TPC), otherwise false

# File lib/tapyrus/script/color.rb, line 60
def default?
  self == ColorIdentifier.default
end
eql?(other) click to toggle source
# File lib/tapyrus/script/color.rb, line 55
def eql?(other)
  to_payload.eql?(other.to_payload)
end
hash() click to toggle source
# File lib/tapyrus/script/color.rb, line 51
def hash
  to_payload.hash
end
to_payload() click to toggle source
# File lib/tapyrus/script/color.rb, line 32
def to_payload
  [type, payload].pack('Ca*')
end
valid?() click to toggle source
# 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