Class: Tapyrus::Color::ColorIdentifier

Inherits:
Object
  • Object
show all
Includes:
HexConverter
Defined in:
lib/tapyrus/script/color.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HexConverter

#to_hex

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



13
14
15
# File 'lib/tapyrus/script/color.rb', line 13

def payload
  @payload
end

#typeObject (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

.defaultObject

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/tapyrus/script/color.rb', line 60

def default?
  self == ColorIdentifier.default
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/tapyrus/script/color.rb', line 55

def eql?(other)
  to_payload.eql?(other.to_payload)
end

#hashObject



51
52
53
# File 'lib/tapyrus/script/color.rb', line 51

def hash
  to_payload.hash
end

#to_payloadObject



32
33
34
# File 'lib/tapyrus/script/color.rb', line 32

def to_payload
  [type, payload].pack("Ca*")
end

#valid?Boolean

Returns:

  • (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