Add basic Telegram ICP wallet
This commit is contained in:
parent
499e46a468
commit
dd9872bd4a
@ -71,6 +71,23 @@ class Bot < ActiveRecord::Base
|
||||
puts "Error from start"
|
||||
end
|
||||
end
|
||||
case message.text
|
||||
when /^\/fortune/i
|
||||
response_text = `fortune`
|
||||
begin
|
||||
bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: response_text, parse_mode: "Markdown")
|
||||
rescue
|
||||
puts "Error from fortune"
|
||||
end
|
||||
end
|
||||
case message.text
|
||||
when /^\/wallet/i, '/mywallet'
|
||||
# mywallet(message.from.id, bot, message)
|
||||
# unless get_wallet(message.from.id)
|
||||
# create_wallet(message.from.id, bot, message)
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
58
app/models/telegram_wallet.rb
Normal file
58
app/models/telegram_wallet.rb
Normal file
@ -0,0 +1,58 @@
|
||||
class TelegramWallet < ActiveRecord::Base
|
||||
def icprincipal
|
||||
return self.icp_principal if self.icp_principal
|
||||
if self.icp_id.nil?
|
||||
if !self.telegram_id.nil?
|
||||
if `dfx identity use #{self.telegram_id}; echo $?`.to_i == 255
|
||||
`dfx identity new #{self.telegram_id} --storage-mode=plaintext`
|
||||
`dfx identity use #{self.telegram_id}`
|
||||
self.icp_principal = `dfx identity get-principal`.strip
|
||||
self.icp_id = `dfx ledger account-id`.strip
|
||||
`dfx identity use anonymous`
|
||||
self.save
|
||||
else
|
||||
# Identity already exist
|
||||
self.icp_id = `dfx ledger account-id`.strip
|
||||
self.icp_principal = `dfx identity get-principal`.strip
|
||||
`dfx identity use anonymous`
|
||||
self.save
|
||||
end
|
||||
end
|
||||
elsif
|
||||
`dfx identity use #{self.telegram_id}`
|
||||
self.icp_id = `dfx ledger account-id`.strip
|
||||
self.icp_principal = `dfx identity get-principal`.strip
|
||||
`dfx identity use anonymous`
|
||||
self.save
|
||||
end
|
||||
return self.icp_principal
|
||||
end
|
||||
def icid
|
||||
return self.icp_id if self.icp_id
|
||||
if self.icp_principal.nil?
|
||||
if !self.telegram_id.nil?
|
||||
if `dfx identity use #{self.telegram_id}; echo $?`.to_i == 255
|
||||
`dfx identity new #{self.telegram_id} --storage-mode=plaintext`
|
||||
`dfx identity use #{self.telegram_id}`
|
||||
self.icp_principal = `dfx identity get-principal`.strip
|
||||
self.icp_id = `dfx ledger account-id`.strip
|
||||
`dfx identity use anonymous`
|
||||
self.save
|
||||
else
|
||||
# Identity already exist
|
||||
self.icp_id = `dfx ledger account-id`.strip
|
||||
self.icp_principal = `dfx identity get-principal`.strip
|
||||
`dfx identity use anonymous`
|
||||
self.save
|
||||
end
|
||||
end
|
||||
elsif
|
||||
`dfx identity use #{self.telegram_id}`
|
||||
self.icp_id = `dfx ledger account-id`.strip
|
||||
self.icp_principal = `dfx identity get-principal`.strip
|
||||
`dfx identity use anonymous`
|
||||
self.save
|
||||
end
|
||||
return self.icp_id
|
||||
end
|
||||
end
|
||||
11
db/migrate/20231201182512_create_telegram_wallet.rb
Normal file
11
db/migrate/20231201182512_create_telegram_wallet.rb
Normal file
@ -0,0 +1,11 @@
|
||||
class CreateTelegramWallet < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :telegram_wallets do |t|
|
||||
t.integer :telegram_id, null: false
|
||||
t.string :icp_id
|
||||
t.string :icp_principal
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
10
db/schema.rb
10
db/schema.rb
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_11_29_171945) do
|
||||
ActiveRecord::Schema.define(version: 2023_12_01_182512) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -202,6 +202,14 @@ ActiveRecord::Schema.define(version: 2023_11_29_171945) do
|
||||
t.index ["slug"], name: "index_tables_on_slug", unique: true
|
||||
end
|
||||
|
||||
create_table "telegram_wallets", force: :cascade do |t|
|
||||
t.integer "telegram_id", null: false
|
||||
t.string "icp_id"
|
||||
t.string "icp_principal"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "tokens", force: :cascade do |t|
|
||||
t.string "canister_id"
|
||||
t.integer "standard"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user