Skip to content

Commit 3b12086

Browse files
committed
rusk: persisting driver code signature
1 parent 2058ea5 commit 3b12086

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

rusk/src/lib/http/rusk.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ impl Rusk {
220220
}
221221

222222
let mut driver_store = self.driver_store.write();
223-
driver_store.store_bytecode(&contract_id, data)?;
223+
driver_store.store_bytecode_and_signature(
224+
&contract_id,
225+
data,
226+
signature.to_bytes(),
227+
)?;
224228
let mut instance_cache = self.instance_cache.write();
225229
instance_cache.remove(&contract_id);
226230
Ok(ResponseData::new(UPLOAD_DRIVER_RESPONSE.to_string()))

rusk/src/lib/node/driverstore.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
//
55
// Copyright (c) DUSK NETWORK. All rights reserved.
66

7+
use dusk_bytes::Serializable;
78
use std::path::{Path, PathBuf};
89
use std::{fs, io};
910

1011
use dusk_core::abi::ContractId;
12+
use dusk_core::signatures::bls::Signature;
13+
14+
const SIGNATURE_FILE_EXTENSION: &str = "sign";
1115

1216
pub struct DriverStore {
1317
store_path: Option<PathBuf>,
@@ -27,13 +31,27 @@ impl DriverStore {
2731
self.contract_path(contract_id).map(fs::read).transpose()
2832
}
2933

30-
pub fn store_bytecode(
34+
pub fn get_signature(
35+
&self,
36+
contract_id: &ContractId,
37+
) -> io::Result<Option<Vec<u8>>> {
38+
self.contract_path(contract_id)
39+
.map(|path| fs::read(path.with_extension(SIGNATURE_FILE_EXTENSION)))
40+
.transpose()
41+
}
42+
43+
pub fn store_bytecode_and_signature(
3144
&mut self,
3245
contract_id: &ContractId,
3346
bytecode: &[u8],
47+
signature_bytes: [u8; Signature::SIZE],
3448
) -> io::Result<()> {
3549
if let Some(path) = self.contract_path(contract_id) {
36-
fs::write(path, bytecode)?;
50+
fs::write(&path, bytecode)?;
51+
fs::write(
52+
path.with_extension(SIGNATURE_FILE_EXTENSION),
53+
signature_bytes,
54+
)?;
3755
}
3856
Ok(())
3957
}

0 commit comments

Comments
 (0)