-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: binary storage db #153
base: master
Are you sure you want to change the base?
Changes from all commits
1fbebe9
32f7731
8dceec6
6d9fe73
e6dfe4a
651aafc
2f59b25
ad375ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use std::str::FromStr; | ||
|
||
use async_std::io::ReadExt; | ||
use bytes::{BufMut, BytesMut}; | ||
use chrono::{DateTime, Utc}; | ||
use ethers::{ | ||
|
@@ -944,6 +945,7 @@ pub fn solidity_type_to_ethereum_sql_type_wrapper( | |
pub fn map_log_params_to_ethereum_wrapper( | ||
abi_inputs: &[ABIInput], | ||
params: &[LogParam], | ||
max_optimisation: bool, | ||
) -> Vec<EthereumSqlTypeWrapper> { | ||
let mut wrappers = vec![]; | ||
|
||
|
@@ -958,9 +960,38 @@ pub fn map_log_params_to_ethereum_wrapper( | |
.expect("tuple should have a component ABI on"), | ||
tuple, | ||
)); | ||
if max_optimisation { | ||
map_ethereum_wrapper_to_byte( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in wrappers.extend |
||
abi_input | ||
.components | ||
.as_ref() | ||
.expect("tuple should have component ABI on"), | ||
&wrappers, | ||
true, | ||
); | ||
} | ||
wrappers.extend(process_tuple( | ||
abi_input | ||
.components | ||
.as_ref() | ||
.expect("tuple should have a component ABI on"), | ||
tuple, | ||
)); | ||
} | ||
_ => { | ||
wrappers.push(map_log_token_to_ethereum_wrapper(abi_input, ¶m.value)); | ||
if max_optimisation { | ||
map_ethereum_wrapper_to_byte( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in wrappers.extend |
||
abi_input | ||
.components | ||
.as_ref() | ||
.expect("value should have component ABI on"), | ||
&wrappers, | ||
false, | ||
); | ||
} | ||
|
||
wrappers.push(map_log_token_to_ethereum_wrapper(abi_input, ¶m.value)); | ||
} | ||
} | ||
} else { | ||
|
@@ -971,6 +1002,138 @@ pub fn map_log_params_to_ethereum_wrapper( | |
wrappers | ||
} | ||
|
||
pub fn map_ethereum_wrapper_to_byte( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the only thing which can be bytes are address (handle array), bytes, + main tables tx hash, block hash, contract address so this is why i suggest above we turn this to max_optimisation we can then make: uint256 NUMBER(80) and then pass in optimisations on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so should |
||
abi_inputs: &[ABIInput], | ||
wrappers: &[EthereumSqlTypeWrapper], | ||
// transaction_information: &TxInformation, | ||
is_within_tuple: bool, | ||
) -> bytes::Bytes { | ||
let mut buf = vec![]; | ||
let mut current_wrapper_index = 0; | ||
let mut wrappers_index_processed = Vec::new(); | ||
|
||
for abi_input in abi_inputs.iter() { | ||
// tuples will take in multiple wrapper indexes, so we need to skip them if processed | ||
if wrappers_index_processed.contains(¤t_wrapper_index) { | ||
continue; | ||
} | ||
if let Some(wrapper) = wrappers.get(current_wrapper_index) { | ||
if abi_input.type_ == "tuple" { | ||
let components = | ||
abi_input.components.as_ref().expect("Tuple should have components defined"); | ||
let total_properties = count_components(components); | ||
let tuple_value = map_ethereum_wrapper_to_byte( | ||
components, | ||
&wrappers[current_wrapper_index..total_properties], | ||
// transaction_information, | ||
true, | ||
); | ||
buf.extend_from_slice(&abi_input.name.clone().into_bytes()); | ||
buf.extend_from_slice(&tuple_value); | ||
for i in current_wrapper_index..total_properties { | ||
wrappers_index_processed.push(i); | ||
} | ||
current_wrapper_index = total_properties; | ||
} else { | ||
let byte = match wrapper { | ||
EthereumSqlTypeWrapper::U256Bytes(u) | | ||
EthereumSqlTypeWrapper::U256BytesNullable(u) => { | ||
let mut bytes = vec![]; | ||
bytes.extend_from_slice(&u.low_u64().to_be_bytes()); | ||
let bytes = bytes::Bytes::from(bytes); | ||
bytes | ||
} | ||
EthereumSqlTypeWrapper::VecU256Bytes(u256s) => { | ||
let mut bytes = vec![]; | ||
for u in u256s { | ||
bytes.extend_from_slice(&u.low_u64().to_be_bytes()); | ||
} | ||
let bytes = bytes::Bytes::from(bytes); | ||
bytes | ||
} | ||
|
||
EthereumSqlTypeWrapper::I256Bytes(i) | | ||
EthereumSqlTypeWrapper::I256BytesNullable(i) => { | ||
let mut bytes = vec![]; | ||
bytes.extend_from_slice(&i.low_u64().to_be_bytes()); | ||
let bytes = bytes::Bytes::from(bytes); | ||
bytes | ||
} | ||
EthereumSqlTypeWrapper::VecI256Bytes(i256s) => { | ||
let mut bytes = vec![]; | ||
for i in i256s { | ||
bytes.extend_from_slice(&i.low_u64().to_be_bytes()); | ||
} | ||
let bytes = bytes::Bytes::from(bytes); | ||
bytes | ||
} | ||
EthereumSqlTypeWrapper::H256Bytes(h) => { | ||
let bytes = bytes::Bytes::from(h.as_bytes().to_vec()); | ||
bytes | ||
} | ||
EthereumSqlTypeWrapper::VecH256Bytes(h256s) => { | ||
let mut bytes = vec![]; | ||
for h in h256s { | ||
bytes.extend_from_slice(h.as_bytes()); | ||
} | ||
let bytes = bytes::Bytes::from(bytes); | ||
bytes | ||
} | ||
|
||
EthereumSqlTypeWrapper::AddressBytes(address) | | ||
EthereumSqlTypeWrapper::AddressBytesNullable(address) => { | ||
let bytes = bytes::Bytes::from(address.as_bytes().to_vec()); | ||
bytes | ||
} | ||
|
||
EthereumSqlTypeWrapper::VecAddressBytes(addresses) => { | ||
let mut bytes = vec![]; | ||
for address in addresses { | ||
bytes.extend_from_slice(address.as_bytes()); | ||
} | ||
let bytes = bytes::Bytes::from(bytes); | ||
bytes | ||
} | ||
|
||
EthereumSqlTypeWrapper::Bytes(bytes) | | ||
EthereumSqlTypeWrapper::BytesNullable(bytes) => { | ||
for byte in bytes { | ||
buf.push(*byte); | ||
} | ||
let bytes = bytes::Bytes::from(buf.clone()); | ||
bytes | ||
} | ||
EthereumSqlTypeWrapper::VecBytes(bytes) => { | ||
let mut buf = vec![]; | ||
for byte in bytes { | ||
buf.extend_from_slice(byte); | ||
} | ||
let bytes = bytes::Bytes::from(buf); | ||
bytes | ||
} | ||
_ => panic!("Wrapper types can't be converted to bytes"), | ||
}; | ||
|
||
buf.extend_from_slice(&byte); | ||
|
||
wrappers_index_processed.push(current_wrapper_index); | ||
current_wrapper_index += 1; | ||
} | ||
} else { | ||
panic!("No wrapper found for ABI input at index: {}", current_wrapper_index) | ||
} | ||
} | ||
// if !is_within_tuple { | ||
// let mut bytes: Vec<bytes::Bytes> = vec![]; | ||
// buf.extend_from_slice("transaction_information".to_bytes()); | ||
// buf.extend_from_slice(transaction_information.transaction_hash.as_bytes()); | ||
// let bytes = bytes::Bytes::from(buf); | ||
// return bytes | ||
|
||
// } | ||
bytes::Bytes::from(buf) | ||
} | ||
|
||
fn process_tuple(abi_inputs: &[ABIInput], tokens: &[Token]) -> Vec<EthereumSqlTypeWrapper> { | ||
let mut wrappers = vec![]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not everything can be stored in bytes like booleans etc we only want to store hex stuff as bytes so i think you need to filter out based on the solidity type which ones to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use a .filter() or .filter_map() for this? I'm not sure exactly