Module: MixinBot::API::Output

Included in:
MixinBot::API
Defined in:
lib/mixin_bot/api/output.rb

Instance Method Summary collapse

Instance Method Details

#build_threshold_script(threshold) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/mixin_bot/api/output.rb', line 6

def build_threshold_script(threshold)
  s = threshold.to_s(16)
  s = "0#{s}" if s.length == 1
  raise 'NVALID THRESHOLD' if s.length > 2

  "fffe#{s}"
end

#safe_output(id, access_token: nil) ⇒ Object Also known as: output



41
42
43
44
# File 'lib/mixin_bot/api/output.rb', line 41

def safe_output(id, access_token: nil)
  path = format('/safe/outputs/%<id>s', id:)
  client.get path, access_token:
end

#safe_outputs(**kwargs) ⇒ Object Also known as: outputs



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mixin_bot/api/output.rb', line 14

def safe_outputs(**kwargs)
  asset = kwargs[:asset] || kwargs[:asset_id]
  limit = kwargs[:limit] || 500
  offset = kwargs[:offset] || ''
  state = kwargs[:state] || ''
  access_token = kwargs[:access_token]
  order = kwargs[:order] || 'ASC'
  members = kwargs[:members].presence || [config.app_id]
  threshold = kwargs[:threshold] || members.length

  members_hash = SHA3::Digest::SHA256.hexdigest(members&.sort&.join)

  path = '/safe/outputs'
  params = {
    asset:,
    limit:,
    offset:,
    state:,
    members: members_hash,
    threshold:,
    order:
  }.compact

  client.get path, **params, access_token:
end