Class: MixinBot::API

Inherits:
Object
  • Object
show all
Includes:
Address, App, Asset, Attachment, Auth, Blaze, Collectible, Conversation, EncryptedMessage, LegacyMultisig, LegacyOutput, LegacyPayment, LegacySnapshot, LegacyTransaction, LegacyTransfer, Me, Message, Multisig, Output, Payment, Pin, Rpc, Snapshot, Tip, Transaction, Transfer, User, Withdraw
Defined in:
lib/mixin_bot/api.rb,
lib/mixin_bot/api/me.rb,
lib/mixin_bot/api/app.rb,
lib/mixin_bot/api/pin.rb,
lib/mixin_bot/api/rpc.rb,
lib/mixin_bot/api/tip.rb,
lib/mixin_bot/api/auth.rb,
lib/mixin_bot/api/user.rb,
lib/mixin_bot/api/asset.rb,
lib/mixin_bot/api/blaze.rb,
lib/mixin_bot/api/output.rb,
lib/mixin_bot/api/address.rb,
lib/mixin_bot/api/message.rb,
lib/mixin_bot/api/payment.rb,
lib/mixin_bot/api/multisig.rb,
lib/mixin_bot/api/snapshot.rb,
lib/mixin_bot/api/transfer.rb,
lib/mixin_bot/api/withdraw.rb,
lib/mixin_bot/api/attachment.rb,
lib/mixin_bot/api/collectible.rb,
lib/mixin_bot/api/transaction.rb,
lib/mixin_bot/api/conversation.rb,
lib/mixin_bot/api/legacy_output.rb,
lib/mixin_bot/api/legacy_payment.rb,
lib/mixin_bot/api/legacy_multisig.rb,
lib/mixin_bot/api/legacy_snapshot.rb,
lib/mixin_bot/api/legacy_transfer.rb,
lib/mixin_bot/api/encrypted_message.rb,
lib/mixin_bot/api/legacy_transaction.rb

Defined Under Namespace

Modules: Address, App, Asset, Attachment, Auth, Blaze, Collectible, Conversation, EncryptedMessage, LegacyMultisig, LegacyOutput, LegacyPayment, LegacySnapshot, LegacyTransaction, LegacyTransfer, Me, Message, Multisig, Output, Payment, Pin, Rpc, Snapshot, Tip, Transaction, Transfer, User, Withdraw

Constant Summary collapse

COLLECTIBLE_TRANSACTION_ARGUMENTS =

collectible =

type: 'non_fungible_output',
user_id: '',
output_id: '',
token_id: '',
transaction_hash: '',
output_index: '',
amount: 1,
senders: [],
sender_threshold: 1,
receivers: [],
receivers_threshold: 1,
state: 'unspent'

%i[collectible nfo receivers receivers_threshold].freeze

Constants included from Transaction

Transaction::OUTPUT_TYPE_SCRIPT, Transaction::OUTPUT_TYPE_WITHDRAW_SUBMIT, Transaction::SAFE_RAW_TRANSACTION_ARGUMENTS, Transaction::SAFE_TX_VERSION, Transaction::SIGN_SAFE_TRANSACTION_ARGUMENTS

Constants included from Tip

Tip::TIP_ACTIONS

Constants included from LegacyTransfer

LegacyTransfer::TRANSFER_ARGUMENTS

Constants included from LegacyTransaction

LegacyTransaction::LEGACY_TX_VERSION, LegacyTransaction::MAINNET_TRANSACTION_ARGUMENTS, LegacyTransaction::MULTISIG_TRANSACTION_ARGUMENTS, LegacyTransaction::RAW_TRANSACTION_ARGUMENTS

Constants included from LegacyMultisig

LegacyMultisig::MULTISIG_REQUEST_ACTIONS

Constants included from Collectible

Collectible::COLLECTABLE_REQUEST_ACTIONS, Collectible::NFT_ASSET_MIXIN_ID

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Withdraw

#create_withdraw_address, #delete_withdraw_address, #get_withdraw_address, #withdrawals

Methods included from User

#create_safe_user, #create_user, #fetch_users, #migrate_to_safe, #safe_register, #search_user, #user

Methods included from Transfer

#create_safe_transfer

Methods included from Transaction

#build_safe_transaction, #create_safe_keys, #create_safe_transaction_request, #safe_transaction, #send_safe_transaction, #sign_safe_transaction

Methods included from Tip

#encrypt_tip_pin

Methods included from Snapshot

#create_safe_snapshot_notification, #safe_snapshots

Methods included from Rpc

#get_snapshot, #get_transaction, #get_utxo, #list_mint_distributions, #list_mint_works, #list_snapshots, #rpc_proxy, #send_raw_transaction

Methods included from Pin

#decrypt_pin, #encrypt_pin, #generate_shared_key_with_server, #prepare_tip_key, #update_pin, #verify_pin

Methods included from Payment

#safe_pay_url

Methods included from Output

#build_threshold_script, #safe_output, #safe_outputs

Methods included from Multisig

#create_safe_multisig_request, #safe_multisig_request, #sign_safe_multisig_request, #unlock_safe_multisig_request

Methods included from Message

#acknowledge_message_receipt, #app_button_group, #app_card, #base_message_params, #list_pending_message, #plain_audio, #plain_contact, #plain_data, #plain_image, #plain_post, #plain_sticker, #plain_text, #plain_video, #recall_message, #recall_message_params, #send_app_button_group_message, #send_app_card_message, #send_contact_message, #send_file_message, #send_image_message, #send_message, #send_plain_messages, #send_post_message, #send_text_message, #write_ws_message, #ws_message

Methods included from Me

#friends, #me, #safe_me, #update_me

Methods included from LegacyTransfer

#create_transfer, #transfer

Methods included from LegacyTransaction

#build_raw_transaction, #create_mainnet_transaction, #create_multisig_transaction, #transactions

Methods included from LegacySnapshot

#network_snapshot, #network_snapshots, #snapshots

Methods included from LegacyPayment

#pay_url, #verify_payment

Methods included from LegacyOutput

#build_output, #create_output, #outputs

Methods included from LegacyMultisig

#create_multisig_payment, #create_multisig_request, #create_sign_multisig_request, #create_unlock_multisig_request, #sign_multisig_request, #unlock_multisig_request, #verify_multisig

Methods included from EncryptedMessage

#base_encrypted_message_params, #decrypt_message, #encrypt_message, #encrypted_audio, #encrypted_contact, #encrypted_data, #encrypted_image, #encrypted_post, #encrypted_sticker, #encrypted_text, #encrypted_video, #send_encrypted_audio_message, #send_encrypted_contact_message, #send_encrypted_data_message, #send_encrypted_image_message, #send_encrypted_message, #send_encrypted_messages, #send_encrypted_post_message, #send_encrypted_sticker_message, #send_encrypted_text_message, #send_encrypted_video_message

Methods included from Conversation

#add_conversation_participants, #conversation, #conversation_by_user_id, #create_contact_conversation, #create_conversation, #create_group_conversation, #exit_conversation, #remove_conversation_participants, #rotate_conversation, #unique_uuid, #update_conversation_participants_role, #update_group_conversation_announcement, #update_group_conversation_name

Methods included from Collectible

#collectible, #collectibles, #collection, #create_collectible_request, #create_sign_collectible_request, #create_unlock_collectible_request, #sign_collectible_request, #unlock_collectible_request

Methods included from Blaze

#blaze, #start_blaze_connect

Methods included from Auth

#authorization_data, #authorize_code, #oauth_token, #request_oauth

Methods included from Attachment

#attachment, #create_attachment, #upload_attachment

Methods included from Asset

#asset, #assets, #ticker

Methods included from App

#add_favorite_app, #favorite_apps, #remove_favorite_app

Methods included from Address

#safe_deposit_entries

Constructor Details

#initialize(**kwargs) ⇒ API

Returns a new instance of API.



38
39
40
41
42
43
44
45
46
47
# File 'lib/mixin_bot/api.rb', line 38

def initialize(**kwargs)
  @config =
    if kwargs.present?
      MixinBot::Configuration.new(**kwargs)
    else
      MixinBot.config
    end

  @client = Client.new(@config)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



36
37
38
# File 'lib/mixin_bot/api.rb', line 36

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



36
37
38
# File 'lib/mixin_bot/api.rb', line 36

def config
  @config
end

Instance Method Details

#access_token(method, uri, body, **kwargs) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mixin_bot/api.rb', line 57

def access_token(method, uri, body, **kwargs)
  utils.access_token(
    method,
    uri,
    body,
    exp_in: kwargs.delete(:exp_in) || 600,
    scp: kwargs.delete(:scp) || 'FULL',
    app_id: config.app_id,
    session_id: config.session_id,
    private_key: config.session_private_key
  )
end

#build_collectible_transaction(**kwargs) ⇒ Object

Raises:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/mixin_bot/api/collectible.rb', line 116

def build_collectible_transaction(**kwargs)
  raise ArgumentError, "#{COLLECTIBLE_TRANSACTION_ARGUMENTS.join(', ')} are needed for build collectible transaction" unless COLLECTIBLE_TRANSACTION_ARGUMENTS.all? { |param| kwargs.keys.include? param }

  kwargs = kwargs.with_indifferent_access
  collectible = kwargs['collectible']
  raise 'collectible is spent' if collectible['state'] == 'spent'

  build_raw_transaction(
    utxos: [collectible],
    senders: collectible['receivers'],
    senders_threshold: collectible['receivers_threshold'],
    receivers: kwargs['receivers'],
    receivers_threshold: kwargs['receivers_threshold'],
    extra: [kwargs['nfo']].pack('H*'),
    amount: 1,
    asset_mixin_id: NFT_ASSET_MIXIN_ID,
    hint: kwargs['hint']
  )
end

#client_idObject



53
54
55
# File 'lib/mixin_bot/api.rb', line 53

def client_id
  config.app_id
end

#decode_raw_transaction(raw) ⇒ Object



74
75
76
# File 'lib/mixin_bot/api.rb', line 74

def decode_raw_transaction(raw)
  utils.decode_raw_transaction raw
end

#decode_raw_transaction_native(raw) ⇒ Object

Use a mixin software to implement transaction build



94
95
96
97
98
99
100
101
102
# File 'lib/mixin_bot/api.rb', line 94

def decode_raw_transaction_native(raw)
  ensure_mixin_command_exist
  command = format("mixin decoderawtransaction --raw '%<arg>s'", arg: raw)

  output, error = Open3.capture3(command)
  raise error unless error.empty?

  JSON.parse output.chomp
end

#encode_raw_transaction(tx) ⇒ Object



70
71
72
# File 'lib/mixin_bot/api.rb', line 70

def encode_raw_transaction(tx)
  utils.encode_raw_transaction tx
end

#encode_raw_transaction_native(json) ⇒ Object

Use a mixin software to implement transaction build



83
84
85
86
87
88
89
90
91
# File 'lib/mixin_bot/api.rb', line 83

def encode_raw_transaction_native(json)
  ensure_mixin_command_exist
  command = format("mixin signrawtransaction --raw '%<arg>s'", arg: json)

  output, error = Open3.capture3(command)
  raise error unless error.empty?

  output.chomp
end

#generate_trace_from_hash(hash, output_index = 0) ⇒ Object



78
79
80
# File 'lib/mixin_bot/api.rb', line 78

def generate_trace_from_hash(hash, output_index = 0)
  utils.generate_trace_from_hash hash, output_index
end

#nft_memo(collection, token_id, meta) ⇒ Object



136
137
138
# File 'lib/mixin_bot/api/collectible.rb', line 136

def nft_memo(collection, token_id, meta)
  MixinBot.utils.nft_memo collection, token_id, meta
end

#utilsObject



49
50
51
# File 'lib/mixin_bot/api.rb', line 49

def utils
  MixinBot::Utils
end