Module: MixinBot::API::LegacyMultisig

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

Constant Summary collapse

MULTISIG_REQUEST_ACTIONS =
%i[sign unlock].freeze

Instance Method Summary collapse

Instance Method Details

#create_multisig_payment(**kwargs) ⇒ Object

pay to the multisig address used for create multisig payment code_id



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 66

def create_multisig_payment(**kwargs)
  path = '/payments'
  payload = {
    asset_id: kwargs[:asset_id],
    amount: format('%.8f', kwargs[:amount].to_d),
    trace_id: kwargs[:trace_id] || SecureRandom.uuid,
    memo: kwargs[:memo],
    opponent_multisig: {
      receivers: kwargs[:receivers],
      threshold: kwargs[:threshold]
    }
  }
  client.post path, **payload, access_token: kwargs[:access_token]
end

#create_multisig_request(action, raw, access_token: nil) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 7

def create_multisig_request(action, raw, access_token: nil)
  raise ArgumentError, "request action is limited in #{MULTISIG_REQUEST_ACTIONS.join(', ')}" unless MULTISIG_REQUEST_ACTIONS.include? action.to_sym

  path = '/multisigs/requests'
  payload = {
    action:,
    raw:
  }
  client.post path, **payload, access_token:
end

#create_sign_multisig_request(raw, access_token: nil) ⇒ Object

transfer from the multisig address



19
20
21
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 19

def create_sign_multisig_request(raw, access_token: nil)
  create_multisig_request 'sign', raw, access_token:
end

#create_unlock_multisig_request(raw, access_token: nil) ⇒ Object

transfer from the multisig address create a request for unlock a multi-sign



25
26
27
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 25

def create_unlock_multisig_request(raw, access_token: nil)
  create_multisig_request 'unlock', raw, access_token:
end

#sign_multisig_request(request_id, pin = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 29

def sign_multisig_request(request_id, pin = nil)
  pin ||= config.pin
  path = format('/multisigs/requests/%<request_id>s/sign', request_id:)
  payload =
    if pin.length > 6
      {
        pin_base64: encrypt_tip_pin(pin, 'TIP:MULTISIG:REQUEST:SIGN:', request_id)
      }
    else
      {
        pin: encrypt_pin(pin)
      }
    end

  client.post path, **payload
end

#unlock_multisig_request(request_id, pin = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 46

def unlock_multisig_request(request_id, pin = nil)
  pin ||= config.pin

  path = format('/multisigs/requests/%<request_id>s/unlock', request_id:)
  payload =
    if pin.length > 6
      {
        pin_base64: encrypt_tip_pin(pin, 'TIP:MULTISIG:REQUEST:UNLOCK:', request_id)
      }
    else
      {
        pin: encrypt_pin(pin)
      }
    end

  client.post path, **payload
end

#verify_multisig(code_id, access_token: nil) ⇒ Object



81
82
83
84
# File 'lib/mixin_bot/api/legacy_multisig.rb', line 81

def verify_multisig(code_id, access_token: nil)
  path = format('/codes/%<code_id>s', code_id:)
  client.get path, access_token:
end