vbox accept
This commit is contained in:
+2
-2
@@ -80,7 +80,7 @@ impl Rpc {
|
||||
|
||||
"vbox_state" => Rpc::vbox_state(data, &mut tx, account.unwrap(), client),
|
||||
"vbox_accept" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
|
||||
"vbox_discard" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
|
||||
"vbox_discard" => Rpc::vbox_discard(data, &mut tx, account.unwrap(), client),
|
||||
"vbox_combine" => Rpc::vbox_combine(data, &mut tx, account.unwrap(), client),
|
||||
|
||||
_ => Err(format_err!("unknown method - {:?}", v.method)),
|
||||
@@ -633,7 +633,7 @@ struct VboxAcceptMsg {
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct VboxAcceptParams {
|
||||
pub game_id: Uuid,
|
||||
pub index: u8,
|
||||
pub index: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
|
||||
+18
-3
@@ -63,6 +63,18 @@ impl Vbox {
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn accept(&mut self, i: usize) -> Result<&mut Vbox, Error> {
|
||||
if self.bound.len() > 8 {
|
||||
return Err(err_msg("too many vars bound"));
|
||||
}
|
||||
|
||||
self.free.get(i).ok_or(format_err!("no var at index {:?}", i))?;
|
||||
|
||||
self.bound.push(self.free.remove(i));
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vbox_write(vbox: Vbox, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||
@@ -109,7 +121,7 @@ pub fn vbox_get(tx: &mut Transaction, game_id: Uuid, account: &Account) -> Resul
|
||||
|
||||
pub fn vbox_state(params: VboxStateParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||
match vbox_get(tx, params.game_id, account) {
|
||||
Ok(v) => Ok(v),
|
||||
Ok(v) => Ok(v.fill()),
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
vbox_write(Vbox::new(account.id, params.game_id).fill(), tx, account)
|
||||
@@ -123,8 +135,11 @@ pub fn vbox_discard(params: VboxDiscardParams, tx: &mut Transaction, account: &A
|
||||
}
|
||||
|
||||
pub fn vbox_accept(params: VboxAcceptParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||
let vbox = vbox_get(tx, params.game_id, account)?;
|
||||
return Ok(vbox);
|
||||
let mut vbox = vbox_get(tx, params.game_id, account)?;
|
||||
|
||||
vbox.accept(params.index)?;
|
||||
|
||||
return vbox_write(vbox, tx, account);
|
||||
}
|
||||
|
||||
pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||
|
||||
Reference in New Issue
Block a user