Use safer identity args for dfx
This commit is contained in:
parent
901b4bab5e
commit
e9e684f67d
@ -21,9 +21,7 @@ class Play < ActiveRecord::Base
|
|||||||
# TODO Pay out crypto
|
# TODO Pay out crypto
|
||||||
# pay icypees rewards
|
# pay icypees rewards
|
||||||
if !self.player.principal.nil?
|
if !self.player.principal.nil?
|
||||||
`dfx identity use 13rewards`
|
player_wallet_balance = `dfx --identity 13rewards canister --network ic call es3he-kyaaa-aaaah-abzna-cai transfer '(principal "#{self.player.principal.strip}", 100000000:nat)'`
|
||||||
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`
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.game.save
|
self.game.save
|
||||||
|
|||||||
@ -15,11 +15,9 @@ class Player < ActiveRecord::Base
|
|||||||
if stp.principal.nil?
|
if stp.principal.nil?
|
||||||
#TODO use principal
|
#TODO use principal
|
||||||
if !soft_token.nil?
|
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 new #{soft_token} --disable-encryption`
|
||||||
`dfx identity use #{soft_token}`
|
@principal = `dfx --identity #{soft_token} identity get-principal`
|
||||||
@principal = `dfx identity get-principal`
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
stp.principal = @principal
|
stp.principal = @principal
|
||||||
stp.save
|
stp.save
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,26 +3,21 @@ class TelegramWallet < ActiveRecord::Base
|
|||||||
return self.icp_principal if self.icp_principal
|
return self.icp_principal if self.icp_principal
|
||||||
if self.icp_id.nil?
|
if self.icp_id.nil?
|
||||||
if !self.telegram_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 new #{self.telegram_id} --storage-mode=plaintext`
|
||||||
`dfx identity use #{self.telegram_id}`
|
self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip
|
||||||
self.icp_principal = `dfx identity get-principal`.strip
|
self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip
|
||||||
self.icp_id = `dfx ledger account-id`.strip
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
self.save
|
self.save
|
||||||
else
|
else
|
||||||
# Identity already exist
|
# Identity already exist
|
||||||
self.icp_id = `dfx ledger account-id`.strip
|
self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip
|
||||||
self.icp_principal = `dfx identity get-principal`.strip
|
self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip
|
||||||
`dfx identity use anonymous`
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif
|
elsif
|
||||||
`dfx identity use #{self.telegram_id}`
|
self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip
|
||||||
self.icp_id = `dfx ledger account-id`.strip
|
self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip
|
||||||
self.icp_principal = `dfx identity get-principal`.strip
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
return self.icp_principal
|
return self.icp_principal
|
||||||
@ -31,26 +26,21 @@ class TelegramWallet < ActiveRecord::Base
|
|||||||
return self.icp_id if self.icp_id
|
return self.icp_id if self.icp_id
|
||||||
if self.icp_principal.nil?
|
if self.icp_principal.nil?
|
||||||
if !self.telegram_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 new #{self.telegram_id} --storage-mode=plaintext`
|
||||||
`dfx identity use #{self.telegram_id}`
|
self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip
|
||||||
self.icp_principal = `dfx identity get-principal`.strip
|
self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip
|
||||||
self.icp_id = `dfx ledger account-id`.strip
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
self.save
|
self.save
|
||||||
else
|
else
|
||||||
# Identity already exist
|
# Identity already exist
|
||||||
self.icp_id = `dfx ledger account-id`.strip
|
self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip
|
||||||
self.icp_principal = `dfx identity get-principal`.strip
|
self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip
|
||||||
`dfx identity use anonymous`
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif
|
elsif
|
||||||
`dfx identity use #{self.telegram_id}`
|
self.icp_id = `dfx --identity #{self.telegram_id} ledger account-id`.strip
|
||||||
self.icp_id = `dfx ledger account-id`.strip
|
self.icp_principal = `dfx --identity #{self.telegram_id} identity get-principal`.strip
|
||||||
self.icp_principal = `dfx identity get-principal`.strip
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
self.save
|
self.save
|
||||||
end
|
end
|
||||||
return self.icp_id
|
return self.icp_id
|
||||||
|
|||||||
@ -23,20 +23,16 @@ class User < ActiveRecord::Base
|
|||||||
if stp.principal.nil?
|
if stp.principal.nil?
|
||||||
#TODO use principal
|
#TODO use principal
|
||||||
if !soft_token.nil?
|
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 new #{soft_token} --disable-encryption`
|
||||||
`dfx identity use #{soft_token}`
|
@principal = `dfx --identity #{soft_token} identity get-principal`
|
||||||
@principal = `dfx identity get-principal`
|
@icid = `dfx --identity #{soft_token} ledger account-id`
|
||||||
@icid = `dfx ledger account-id`
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
stp.principal = @principal
|
stp.principal = @principal
|
||||||
stp.save
|
stp.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif
|
elsif
|
||||||
`dfx identity use #{soft_token}`
|
@icid = `dfx --identity #{soft_token} ledger account-id`
|
||||||
@icid = `dfx ledger account-id`
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
end
|
end
|
||||||
return @icid.strip
|
return @icid.strip
|
||||||
end
|
end
|
||||||
@ -46,11 +42,9 @@ class User < ActiveRecord::Base
|
|||||||
if stp.principal.nil?
|
if stp.principal.nil?
|
||||||
#TODO use principal
|
#TODO use principal
|
||||||
if !soft_token.nil?
|
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 new #{soft_token} --disable-encryption`
|
||||||
`dfx identity use #{soft_token}`
|
@principal = `dfx --identity #{soft_token} identity get-principal`
|
||||||
@principal = `dfx identity get-principal`
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
stp.principal = @principal
|
stp.principal = @principal
|
||||||
stp.save
|
stp.save
|
||||||
end
|
end
|
||||||
@ -60,9 +54,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def icp_balance
|
def icp_balance
|
||||||
`dfx identity use #{soft_token}`
|
balance = `dfx --identity #{soft_token} ledger --network ic balance`
|
||||||
balance = `dfx ledger --network ic balance`
|
|
||||||
`dfx identity use anonymous`
|
|
||||||
return balance.strip
|
return balance.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user