Class: TridentAssistant::Utils::Memo

Inherits:
Object
  • Object
show all
Defined in:
lib/trident_assistant/utils/memo.rb

Overview

build metadata of NFT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Memo

Returns a new instance of Memo.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trident_assistant/utils/memo.rb', line 10

def initialize(**kwargs)
  @type = kwargs[:type]
  @token_id = kwargs[:token_id]
  @asset_id = kwargs[:asset_id]
  @order_id = kwargs[:order_id]
  @price = kwargs[:price]
  @reserve_price = kwargs[:reserve_price]
  @receiver_id = kwargs[:receiver_id]
  @start_at = kwargs[:start_at]
  @expire_at = kwargs[:expire_at]
  @encoded = kwargs[:encoded]
end

Instance Attribute Details

#asset_idObject

Returns the value of attribute asset_id.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def asset_id
  @asset_id
end

#decodedObject

Returns the value of attribute decoded.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def decoded
  @decoded
end

#encodedObject

Returns the value of attribute encoded.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def encoded
  @encoded
end

#expire_atObject

Returns the value of attribute expire_at.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def expire_at
  @expire_at
end

#order_idObject

Returns the value of attribute order_id.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def order_id
  @order_id
end

#priceObject

Returns the value of attribute price.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def price
  @price
end

#receiver_idObject

Returns the value of attribute receiver_id.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def receiver_id
  @receiver_id
end

#reserve_priceObject

Returns the value of attribute reserve_price.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def reserve_price
  @reserve_price
end

#start_atObject

Returns the value of attribute start_at.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def start_at
  @start_at
end

#token_idObject

Returns the value of attribute token_id.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def token_id
  @token_id
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/trident_assistant/utils/memo.rb', line 7

def type
  @type
end

Instance Method Details

#decodeObject



57
58
59
# File 'lib/trident_assistant/utils/memo.rb', line 57

def decode
  json
end

#encodeObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/trident_assistant/utils/memo.rb', line 37

def encode
  hash = {
    T: type,
    N: token_id && MixinBot::Utils::UUID.new(hex: token_id).packed,
    A: asset_id && MixinBot::Utils::UUID.new(hex: asset_id).packed,
    O: order_id && MixinBot::Utils::UUID.new(hex: order_id).packed,
    P: price && format("%.8f", price.to_f).gsub(/(0)+\z/, ""),
    R: reserve_price && format("%.8f", reserve_price.to_f).gsub(/(0)+\z/, ""),
    RC: receiver_id && MixinBot::Utils::UUID.new(hex: receiver_id).packed,
    S: start_at && Time.parse(start_at).to_i,
    E: expire_at && Time.parse(expire_at).to_i
  }.compact

  @encoded =
    Base64.urlsafe_encode64(
      MessagePack.pack(hash),
      padding: false
    )
end

#jsonObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/trident_assistant/utils/memo.rb', line 23

def json
  {
    T: type,
    N: token_id,
    A: asset_id,
    O: order_id,
    P: price,
    R: reserve_price,
    RC: receiver_id,
    S: start_at,
    E: expire_at
  }.compact
end