Skip to content

Commit

Permalink
wallet: forgot to add file for last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfi committed Sep 28, 2024
1 parent bfd1949 commit 8f06b5c
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions bin/darkwallet/src/gfx/scr.rs
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
}
}

0 comments on commit 8f06b5c

Please sign in to comment.