Use safer identity args for dfx

This commit is contained in:
Jesse C. Fisher 2024-07-18 15:03:39 +00:00 committed by TheNeedful-DO
parent 901b4bab5e
commit e9e684f67d
4 changed files with 24 additions and 46 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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