Module: MixinBot::API::Transaction
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/transaction.rb
Constant Summary collapse
- MULTISIG_TRANSACTION_ARGUMENTS =
%i[asset_id receivers threshold amount].freeze
- MAINNET_TRANSACTION_ARGUMENTS =
%i[asset_id opponent_key amount].freeze
Instance Method Summary collapse
- #create_mainnet_transaction(pin, options = {}) ⇒ Object
- #create_multisig_transaction(pin, options = {}) ⇒ Object
Instance Method Details
#create_mainnet_transaction(pin, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mixin_bot/api/transaction.rb', line 38 def create_mainnet_transaction(pin, = {}) raise ArgumentError, "#{MAINNET_TRANSACTION_ARGUMENTS.join(', ')} are needed for create main net transactions" unless MAINNET_TRANSACTION_ARGUMENTS.all? { |param| .keys.include? param } asset_id = [:asset_id] opponent_key = [:opponent_key] amount = [:amount].to_f memo = [:memo] trace_id = [:trace_id] || SecureRandom.uuid encrypted_pin = [:encrypted_pin] || encrypt_pin(pin) path = '/transactions' payload = { asset_id: asset_id, opponent_key: opponent_key, pin: encrypted_pin, amount: format('%.8f', amount), trace_id: trace_id, memo: memo } access_token = [:access_token] access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |
#create_multisig_transaction(pin, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mixin_bot/api/transaction.rb', line 7 def create_multisig_transaction(pin, = {}) raise ArgumentError, "#{MULTISIG_TRANSACTION_ARGUMENTS.join(', ')} are needed for create multisig transaction" unless MULTISIG_TRANSACTION_ARGUMENTS.all? { |param| .keys.include? param } asset_id = [:asset_id] receivers = [:receivers] threshold = [:threshold] amount = [:amount].to_f memo = [:memo] trace_id = [:trace_id] || SecureRandom.uuid encrypted_pin = [:encrypted_pin] || encrypt_pin(pin) path = '/transactions' payload = { asset_id: asset_id, opponent_multisig: { receivers: receivers, threshold: threshold }, pin: encrypted_pin, amount: format('%.8f', amount), trace_id: trace_id, memo: memo } access_token = [:access_token] access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |