Add wallet principal to user and player
This commit is contained in:
parent
b7576482c9
commit
d2eb76b855
@ -18,6 +18,7 @@ class Play < ActiveRecord::Base
|
||||
if self.game.over?
|
||||
self.game.winner_player_id = self.player.id
|
||||
self.game.status = "Player #{self.player.display_name} wins!"
|
||||
# TODO Pay out crypto
|
||||
self.game.save
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,6 +10,23 @@ class Player < ActiveRecord::Base
|
||||
#validates :user, presence: true
|
||||
validates :game, presence: true
|
||||
|
||||
def principal
|
||||
stp = SoftTokenPrincipal.where(soft_token: self.soft_token).first_or_initialize
|
||||
if stp.principal.nil?
|
||||
#TODO use principal
|
||||
`dfx identity use anonymous`
|
||||
if `dfx identity use #{soft_token}; 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`
|
||||
stp.principal = @principal
|
||||
stp.save
|
||||
end
|
||||
end
|
||||
return stp.principal
|
||||
end
|
||||
|
||||
def inventory
|
||||
player_cards.where(play_id: nil).order(:value)
|
||||
end
|
||||
|
||||
2
app/models/soft_token_principal.rb
Normal file
2
app/models/soft_token_principal.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class SoftTokenPrincipal < ActiveRecord::Base
|
||||
end
|
||||
@ -4,6 +4,23 @@ class User < ActiveRecord::Base
|
||||
validates :email, presence: true, uniqueness: true
|
||||
validates :soft_token, presence: true, uniqueness: true
|
||||
|
||||
def principal
|
||||
stp = SoftTokenPrincipal.where(soft_token: self.soft_token).first_or_initialize
|
||||
if stp.principal.nil?
|
||||
#TODO use principal
|
||||
`dfx identity use anonymous`
|
||||
if `dfx identity use #{soft_token}; 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`
|
||||
stp.principal = @principal
|
||||
stp.save
|
||||
end
|
||||
end
|
||||
return stp.principal
|
||||
end
|
||||
|
||||
def set_default_role
|
||||
self.role ||= :user
|
||||
end
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
.player{id: "player-#{seat.player.id}", class: @game.controlling_player == seat.player ? "taking-turn" : "",
|
||||
data: {soft_token: seat.player.soft_token} }
|
||||
.user-name= seat.player.display_name
|
||||
.user-principal= seat.player.principal
|
||||
- if @game.started?
|
||||
.inventory-count
|
||||
Cards:
|
||||
|
||||
@ -28,9 +28,8 @@
|
||||
- 10.times do |i|
|
||||
.eyecandy
|
||||
= image_tag "ICYPEES-coin.png"
|
||||
-
|
||||
|
||||
- Dir.glob("app/assets/images/cards/png/**").each do |card_img|
|
||||
-# - Dir.glob("app/assets/images/cards/png/**").each do |card_img|
|
||||
- puts card_img
|
||||
= image_tag
|
||||
|
||||
|
||||
46
config/deploy/production_ext.rb
Normal file
46
config/deploy/production_ext.rb
Normal file
@ -0,0 +1,46 @@
|
||||
set :stage, :production
|
||||
|
||||
set :nginx_server_name, '13.tendy.zone' # optional, defaults to :application
|
||||
|
||||
# Simple Role Syntax
|
||||
# ==================
|
||||
# server in each group is considered to be the first
|
||||
# unless any hosts have the primary property set.
|
||||
role :app, %w{thirteen@13.tendy.zone}
|
||||
# Supports bulk-adding hosts to roles, the primary
|
||||
role :web, %w{thirteen@13.tendy.zone}
|
||||
role :db, %w{thirteen@13.tendy.zone}
|
||||
|
||||
# Extended Server Syntax
|
||||
# ======================
|
||||
# This can be used to drop a more detailed server
|
||||
# definition into the server list. The second argument
|
||||
# something that quacks like a hash can be used to set
|
||||
# extended properties on the server.
|
||||
server '13.tendy.zone', user: 'thirteen', roles: %w{web app db}, my_property: :my_value
|
||||
|
||||
set :ssh_options, { :verbose => :debug }
|
||||
|
||||
|
||||
|
||||
# you can set custom ssh options
|
||||
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
|
||||
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
|
||||
# set it globally
|
||||
set :ssh_options, { keys: %w(/home/bort/.ssh/id_ed25519), forward_agent: true, auth_methods: %w(publickey)}
|
||||
# you can set custom ssh options
|
||||
# it's possible to pass
|
||||
# and/or per server
|
||||
# server 'example.com',
|
||||
# user: 'user_name',
|
||||
# roles: %w{web app},
|
||||
# ssh_options: {
|
||||
# user: 'user_name', # overrides user setting above
|
||||
# keys: %w(/home/user_name/.ssh/id_rsa),
|
||||
# forward_agent: false,
|
||||
# auth_methods: %w(publickey password)
|
||||
# # password: 'please use keys'
|
||||
# }
|
||||
# setting per server overrides global ssh_options
|
||||
|
||||
# fetch(:default_env).merge!(rails_env: :production)
|
||||
8
db/migrate/20230709122324_create_soft_token_principal.rb
Normal file
8
db/migrate/20230709122324_create_soft_token_principal.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class CreateSoftTokenPrincipal < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :soft_token_principals do |t|
|
||||
t.string :soft_token
|
||||
t.string :principal
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_05_10_103647) do
|
||||
ActiveRecord::Schema.define(version: 2023_07_09_122324) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -91,6 +91,11 @@ ActiveRecord::Schema.define(version: 2023_05_10_103647) do
|
||||
t.index ["user_id"], name: "index_seats_on_user_id"
|
||||
end
|
||||
|
||||
create_table "soft_token_principals", force: :cascade do |t|
|
||||
t.string "soft_token"
|
||||
t.string "principal"
|
||||
end
|
||||
|
||||
create_table "tables", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.datetime "created_at"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user