-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsender.rs
More file actions
75 lines (65 loc) · 2.27 KB
/
sender.rs
File metadata and controls
75 lines (65 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use super::connection::{Web3Contract, Web3Http};
use crate::{error::Result, traits::*, utils::*, workflow::*};
use async_trait::async_trait;
use log::info;
use sgx_types::sgx_enclave_id_t;
use std::path::Path;
use web3::types::{Address, H256};
/// Components needed to send a transaction
#[derive(Debug)]
pub struct EthSender {
enclave_id: sgx_enclave_id_t,
contract: Web3Contract,
}
#[async_trait]
impl Sender for EthSender {
fn new<P: AsRef<Path>>(
enclave_id: sgx_enclave_id_t,
node_url: &str,
contract_info: ContractInfo<'_, P>,
) -> Result<Self> {
let web3_http = Web3Http::new(node_url)?;
let contract = Web3Contract::new(web3_http, contract_info)?;
Ok(EthSender {
enclave_id,
contract,
})
}
fn from_contract(enclave_id: sgx_enclave_id_t, contract: ContractKind) -> Self {
match contract {
ContractKind::Web3Contract(contract) => EthSender {
enclave_id,
contract,
},
}
}
async fn get_account(&self, index: usize, password: &str) -> Result<Address> {
self.contract.get_account(index, password).await
}
async fn send_report_handshake(
&self,
host_output: host_output::JoinGroup,
method: &str,
) -> Result<H256> {
info!("Sending a handshake to blockchain: {:?}", host_output);
self.contract
.send_report_handshake(host_output, method)
.await
}
async fn register_report(&self, host_output: host_output::RegisterReport) -> Result<H256> {
info!("Registering report to blockchain: {:?}", host_output);
self.contract.register_report(host_output).await
}
async fn send_command(&self, host_output: host_output::Command) -> Result<H256> {
info!("Sending a command to blockchain: {:?}", host_output);
// コントラクト実行
self.contract.send_command(host_output).await
}
async fn handshake(&self, host_output: host_output::Handshake) -> Result<H256> {
info!("Sending a handshake to blockchain: {:?}", host_output);
self.contract.handshake(host_output).await
}
fn get_contract(self) -> ContractKind {
ContractKind::Web3Contract(self.contract)
}
}