forked from darkrenaissance/darkfi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet: forgot to add file for last commit
- Loading branch information
darkfi
committed
Sep 28, 2024
1 parent
bfd1949
commit 8f06b5c
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* This file is part of DarkFi (https://dark.fi) | ||
* | ||
* Copyright (C) 2020-2024 Dyne.org foundation | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
use async_trait::async_trait; | ||
use darkfi_serial::{SerialEncodable, SerialDecodable, serialize, Encodable, Decodable, deserialize}; | ||
use std::{fs::{OpenOptions, File}, time::Instant}; | ||
|
||
use super::GraphicsMethod; | ||
|
||
const FILENAME: &str = "drawinstrs.dat"; | ||
|
||
#[derive(Debug, SerialEncodable, SerialDecodable)] | ||
struct Instruction { | ||
timest: u64, | ||
method: GraphicsMethod | ||
} | ||
|
||
pub struct DrawLog { | ||
instant: Instant, | ||
fd: File, | ||
} | ||
|
||
impl DrawLog { | ||
pub fn new() -> Self { | ||
let instant = Instant::now(); | ||
let fd = OpenOptions::new().write(true).create(true).open(FILENAME).unwrap(); | ||
Self { | ||
instant, | ||
fd, | ||
} | ||
} | ||
|
||
pub fn log(&mut self, method: GraphicsMethod) { | ||
let instr = Instruction { | ||
timest: self.instant.elapsed().as_millis() as u64, | ||
method | ||
}; | ||
let data = serialize(&instr); | ||
data.encode(&mut self.fd).unwrap(); | ||
} | ||
|
||
pub fn read() -> Vec<Instruction> { | ||
let mut instrs = vec![]; | ||
let mut f = File::open(FILENAME).unwrap(); | ||
loop { | ||
let Ok(data) = Vec::<u8>::decode(&mut f) else { break }; | ||
|
||
let instr: Instruction = deserialize(&data).unwrap(); | ||
} | ||
instrs | ||
} | ||
} | ||
|