From 00fe1f1e5a2e00fec9999f3b702e5e4daeeccf7c Mon Sep 17 00:00:00 2001 From: TheNeedful-DO Date: Thu, 18 Jul 2024 15:03:39 +0000 Subject: [PATCH] Use safer identity args for dfx --- app/models/play.rb | 4 +--- app/models/player.rb | 6 ++---- app/models/telegram_wallet.rb | 38 +++++++++++++---------------------- app/models/user.rb | 22 +++++++------------- 4 files changed, 24 insertions(+), 46 deletions(-) diff --git a/app/models/play.rb b/app/models/play.rb index 6602ad05..9685fe19 100644 --- a/app/models/play.rb +++ b/app/models/play.rb @@ -21,9 +21,7 @@ class Play < ActiveRecord::Base # TODO Pay out crypto # pay icypees rewards if !self.player.principal.nil? - `dfx identity use 13rewards` - player_wallet_balance = `dfx canister --network ic call es3he-kyaaa-aaaah-abzna-cai transfer '(principal "#{self.player.principal.strip}", 100000000:nat)'` - `dfx identity use anonymous` + player_wallet_balance = `dfx --identity 13rewards canister --network ic call es3he-kyaaa-aaaah-abzna-cai transfer '(principal "#{self.player.principal.strip}", 100000000:nat)'` end self.game.save diff --git a/app/models/player.rb b/app/models/player.rb index e232b351..d96ed08e 100644 --- a/app/models/player.rb +++ b/app/models/player.rb @@ -15,11 +15,9 @@ class Player < ActiveRecord::Base if stp.principal.nil? #TODO use principal if !soft_token.nil? - if `dfx identity use #{soft_token}; echo $?`.to_i == 255 + if `dfx --identity #{soft_token} identity whoami; echo $?`.to_i == 255 `dfx identity new #{soft_token} --disable-encryption` - `dfx identity use #{soft_token}` - @principal = `dfx identity get-principal` - `dfx identity use anonymous` + @principal = `dfx --identity #{soft_token} identity get-principal` stp.principal = @principal stp.save end diff --git a/app/models/telegram_wallet.rb b/app/models/telegram_wallet.rb index 9b81ca75..7b5bfb4d 100644 --- a/app/models/telegram_wallet.rb +++ b/app/models/telegram_wallet.rb @@ -3,26 +3,21 @@ class TelegramWallet < ActiveRecord::Base 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 + if `dfx --identity #{self.telegram_id} identity whoami; 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.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip + self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip 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.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip + self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip 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.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip + self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip self.save end return self.icp_principal @@ -31,26 +26,21 @@ class TelegramWallet < ActiveRecord::Base 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 + if `dfx --identity #{self.telegram_id} identity whoami; 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.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip + self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip 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.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip + self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip 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.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip + self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip self.save end return self.icp_id diff --git a/app/models/user.rb b/app/models/user.rb index a9832424..115255b4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,20 +23,16 @@ class User < ActiveRecord::Base if stp.principal.nil? #TODO use principal if !soft_token.nil? - if `dfx identity use #{soft_token}; echo $?`.to_i == 255 + if `dfx --identity #{soft_token} identity whoami; echo $?`.to_i == 255 `dfx identity new #{soft_token} --disable-encryption` - `dfx identity use #{soft_token}` - @principal = `dfx identity get-principal` - @icid = `dfx ledger account-id` - `dfx identity use anonymous` + @principal = `dfx --identity #{soft_token} identity get-principal` + @icid = `dfx --identity #{soft_token} ledger account-id` stp.principal = @principal stp.save end end elsif - `dfx identity use #{soft_token}` - @icid = `dfx ledger account-id` - `dfx identity use anonymous` + @icid = `dfx --identity #{soft_token} ledger account-id` end return @icid.strip end @@ -46,11 +42,9 @@ class User < ActiveRecord::Base if stp.principal.nil? #TODO use principal if !soft_token.nil? - if `dfx identity use #{soft_token}; echo $?`.to_i == 255 + if `dfx --identity #{soft_token} identity whoami; echo $?`.to_i == 255 `dfx identity new #{soft_token} --disable-encryption` - `dfx identity use #{soft_token}` - @principal = `dfx identity get-principal` - `dfx identity use anonymous` + @principal = `dfx --identity #{soft_token} identity get-principal` stp.principal = @principal stp.save end @@ -60,9 +54,7 @@ class User < ActiveRecord::Base end def icp_balance - `dfx identity use #{soft_token}` - balance = `dfx ledger --network ic balance` - `dfx identity use anonymous` + balance = `dfx --identity #{soft_token} ledger --network ic balance` return balance.strip end