insert battle

This commit is contained in:
ntr 2018-10-20 12:01:35 +11:00
parent b0c80472e6
commit 9419b1cc3d

View File

@ -329,7 +329,6 @@ impl Battle {
} }
// add the ability
// add client function call // add client function call
// check for cryp ability ownership // check for cryp ability ownership
// check for battle participation // check for battle participation
@ -358,6 +357,25 @@ pub fn battle_ability(params: BattleAbilityParams, tx: &mut Transaction, account
return battle_write(battle, tx); return battle_write(battle, tx);
} }
pub fn battle_new(battle: Battle, tx: &mut Transaction) -> Result<Battle, Error> {
let battle_bytes = to_vec(&battle)?;
let query = "
INSERT INTO battles (id, data)
VALUES ($1, $2, $3)
RETURNING id, account;
";
let result = tx
.query(query, &[&battle_bytes, &battle.id])?;
let _returned = result.iter().next().expect("no row returned");
println!("{:?} wrote battle", battle.id);
return Ok(battle);
}
pub fn battle_write(battle: Battle, tx: &mut Transaction) -> Result<Battle, Error> { pub fn battle_write(battle: Battle, tx: &mut Transaction) -> Result<Battle, Error> {
let battle_bytes = to_vec(&battle)?; let battle_bytes = to_vec(&battle)?;