MCPcopy Create free account
hub / github.com/cowprotocol/services / hash_struct

Method hash_struct

crates/model/src/order.rs:236–257  ·  view source on GitHub ↗

Returns the value of hashStruct() over the order data as defined by EIP-712. https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct

(&self)

Source from the content-addressed store, hash-verified

234 ///
235 /// https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct
236 pub fn hash_struct(&self) -> [u8; 32] {
237 let mut hash_data = [0u8; 416];
238 hash_data[0..32].copy_from_slice(&Self::TYPE_HASH);
239 // Some slots are not assigned (stay 0) because all values are extended to 256
240 // bits.
241 hash_data[44..64].copy_from_slice(self.sell_token.as_slice());
242 hash_data[76..96].copy_from_slice(self.buy_token.as_slice());
243 hash_data[108..128].copy_from_slice(self.receiver.unwrap_or(Address::ZERO).as_slice());
244 hash_data[128..160].copy_from_slice(&self.sell_amount.to_be_bytes::<32>());
245 hash_data[160..192].copy_from_slice(&self.buy_amount.to_be_bytes::<32>());
246 hash_data[220..224].copy_from_slice(&self.valid_to.to_be_bytes());
247 hash_data[224..256].copy_from_slice(&self.app_data.0);
248 hash_data[256..288].copy_from_slice(&self.fee_amount.to_be_bytes::<32>());
249 hash_data[288..320].copy_from_slice(match self.kind {
250 OrderKind::Sell => &OrderKind::SELL,
251 OrderKind::Buy => &OrderKind::BUY,
252 });
253 hash_data[351] = self.partially_fillable as u8;
254 hash_data[352..384].copy_from_slice(&self.sell_token_balance.as_bytes());
255 hash_data[384..416].copy_from_slice(&self.buy_token_balance.as_bytes());
256 *keccak256(hash_data)
257 }
258
259 pub fn token_pair(&self) -> Option<TokenPair> {
260 TokenPair::new(self.buy_token, self.sell_token)

Callers 14

sign_withMethod · 0.45
uidMethod · 0.45
signMethod · 0.45
verify_ownerMethod · 0.45
validateMethod · 0.45
for_orderMethod · 0.45
order_creation_signatureFunction · 0.45
signatureMethod · 0.45
recover_jit_order_ownerFunction · 0.45
post_validate_okFunction · 0.45

Calls 4

as_sliceMethod · 0.80
to_be_bytesMethod · 0.80
as_bytesMethod · 0.80
lenMethod · 0.80

Tested by 2

order_creation_signatureFunction · 0.36