Skip to content

Commit 22f0b83

Browse files
committed
fix: session_from_token contract call
1 parent 69da95c commit 22f0b83

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

adapter/src/ethereum.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Adapter for EthereumAdapter {
160160
None,
161161
)
162162
.wait()
163-
.map_err(|e| map_error("contract channel status query failed"))?;
163+
.map_err(|_| map_error("contract channel status query failed"))?;
164164

165165
if channel_status != *CHANNEL_STATE_ACTIVE {
166166
return Err(AdapterError::Configuration(
@@ -203,14 +203,16 @@ impl Adapter for EthereumAdapter {
203203

204204
let sess = match &verified.payload.identity {
205205
Some(identity) => {
206-
let contract_address = Address::from_slice(identity.as_bytes());
207-
let contract = get_contract(&self.config, contract_address, &IDENTITY_ABI)
208-
.map_err(|_| map_error("failed to init identity contract"))?;
206+
207+
let contract_address = Address::from_slice(identity);
208+
let (_eloop, transport) = web3::transports::Http::new(&self.config.ethereum_network)?;
209+
let web3 = web3::Web3::new(transport);
210+
let contract = Contract::from_json(web3.eth(), contract_address, &IDENTITY_ABI)?;
209211

210212
let privilege_level: U256 = contract
211213
.query(
212214
"privileges",
213-
verified.from.to_string(),
215+
(verified.from.to_string(),),
214216
None,
215217
Options::default(),
216218
None,
@@ -225,7 +227,7 @@ impl Adapter for EthereumAdapter {
225227
}
226228
Session {
227229
era: verified.payload.era,
228-
uid: ValidatorId::try_from(identity)?,
230+
uid: identity.into(),
229231
}
230232
}
231233
None => Session {
@@ -293,8 +295,12 @@ pub struct Payload {
293295
pub id: String,
294296
pub era: i64,
295297
pub address: String,
296-
#[serde(default, skip_serializing_if = "Option::is_none")]
297-
pub identity: Option<String>,
298+
#[serde(
299+
default,
300+
skip_serializing_if = "Option::is_none",
301+
with = "SerHexOpt::<StrictPfx>"
302+
)]
303+
pub identity: Option<[u8; 20]>,
298304
}
299305

300306
#[derive(Clone, Debug)]

adapter/src/lib.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ impl TryFrom<&Channel> for EthereumChannel {
109109

110110
impl EthereumChannel {
111111
pub fn new(
112-
creator: &[u8; 20], // 0x prefixed using string helps check if valid eth address
113-
token_addr: &[u8; 20], // 0x prefixed using string helps check if valid eth address
114-
token_amount: &str, // big num string
112+
creator: &[u8; 20],
113+
token_addr: &[u8; 20],
114+
token_amount: &str, // big num string
115115
valid_until: DateTime<Utc>,
116116
validators: &[ValidatorId],
117117
spec: &[u8; 32],
@@ -174,15 +174,6 @@ impl EthereumChannel {
174174
}
175175

176176
pub fn to_solidity_tuple(&self) -> Token {
177-
// let spec_h256 = hex::decode(&self.spec).expect("should deserialize spec");
178-
// let creator = hex::decode(&self.creator[2..]).expect("should deserialize creator");
179-
// let token_addr = hex::decode(&self.token_addr[2..]).expect("should deserialize token addr");
180-
// let token_amount = U256::from_dec_str(&self.token_amount).expect("should deserialize token amount");
181-
// let valid_until = U256::from_dec_str(&self.valid_until).expect("should deserialize valid until");
182-
183-
// let validator1 = hex::decode("2bdeafae53940669daa6f519373f686c1f3d3393").expect("should deserialize v1");
184-
// let validator2 = hex::decode("6704Fbfcd5Ef766B287262fA2281C105d57246a6").expect("should deserialize v2");
185-
186177
Token::Tuple(vec![
187178
Token::Address(self.creator.to_owned()),
188179
Token::Address(self.token_addr.to_owned()),
@@ -229,7 +220,7 @@ fn encode_params(params: &[(ParamType, &str)], lenient: bool) -> Result<Vec<u8>,
229220
}
230221
})
231222
.collect::<Result<Vec<_>, _>>()?;
232-
223+
233224
Ok(encode(&tokens).to_vec())
234225
}
235226

primitives/src/validator.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ impl ValidatorId {
2323
&self.0
2424
}
2525

26-
pub fn copy(&self) -> &[u8] {
27-
&self.0
28-
}
29-
3026
pub fn to_hex_non_prefix_string(&self) -> String {
3127
hex::encode(self.0)
3228
}
29+
3330
pub fn to_hex_checksummed_string(&self) -> String {
3431
eth_checksum::checksum(&format!("0x{}", hex::encode(self.0)))
3532
}
@@ -41,6 +38,12 @@ impl AsRef<[u8]> for ValidatorId {
4138
}
4239
}
4340

41+
impl From<&[u8; 20]> for ValidatorId {
42+
fn from(bytes: &[u8; 20]) -> Self {
43+
Self(*bytes)
44+
}
45+
}
46+
4447
impl TryFrom<&str> for ValidatorId {
4548
type Error = DomainError;
4649
fn try_from(value: &str) -> Result<Self, Self::Error> {

0 commit comments

Comments
 (0)