Skip to content
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(examples): implement a jupyter notebook example #186

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
feat(example): raise error for unhandled types
peyha committed Apr 18, 2024
commit d3061c16ffcb8122db8e73fe4fde76ad0a36bde5
34 changes: 17 additions & 17 deletions examples/morpho_blue.ipynb

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peyha, I think that you have a slightly updated version of helper functions right?

Otherwise, you can resolve the open comment that I thumbed up. You should also probably rename the PR with a slightly better name

Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -81,7 +81,7 @@
" return data[offset + 32: offset + 32 + length].decode('utf-8')\n",
" elif '[]' in type:\n",
" # TODO\n",
" return '0x'\n",
" raise ValueError(\"Array not implemented yet\")\n",
" elif len(type) > 4 and type[:4] == 'uint':\n",
" return float(int(data[data_offset+22: data_offset+32].hex(), 16))\n",
" elif type == 'address':\n",
@@ -92,7 +92,7 @@
" bytes_left = 32 - int(type[5:])\n",
" return '0x' + data[data_offset+bytes_left: data_offset+32].hex()\n",
" else:\n",
" return data\n",
" raise ValueError(\"Type not handled yet\")\n",
" \n",
"def parse_raw_events(raw_events: pl.DataFrame, signature: str) -> pl.DataFrame:\n",
" '''\n",
@@ -125,12 +125,12 @@
" dfs = []\n",
" for index, (type, name) in enumerate(data_types):\n",
" data_events_cur_df = raw_events.select([\n",
" pl.col(\"data\").map_elements(lambda x: convert_to_type(x, type, name, 32*index)).alias(name)\n",
" pl.col(\"data\").map_elements(lambda x: convert_to_type(x, type, 32*index)).alias(name)\n",
" ] + [pl.col(\"block_number\"), pl.col(\"transaction_index\", \"log_index\")])\n",
" dfs.append(data_events_cur_df)\n",
"\n",
" data_events_df = raw_events.select([\n",
" pl.col(\"data\").map_elements(lambda x: convert_to_type(x, type, name, 32*index)).alias(name)\n",
" pl.col(\"data\").map_elements(lambda x: convert_to_type(x, type, 32*index)).alias(name)\n",
" for index, (type, name) in enumerate(data_types)\n",
" ] + [pl.col(\"block_number\"), pl.col(\"transaction_index\", \"log_index\")])\n",
" indexed_events_df = raw_events.select([\n",
@@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -205,7 +205,7 @@
"└─────────────┴─────────────┴───────────┴────────────┴───┴────────┴────────┴────────────┴──────────┘"
]
},
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -231,7 +231,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@@ -286,7 +286,7 @@
"└───────────┴───────────┴───────────┴───────────┴───┴───────────┴───────────┴───────────┴──────────┘"
]
},
"execution_count": 5,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -316,7 +316,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -403,7 +403,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -490,7 +490,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -573,7 +573,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -661,7 +661,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -749,7 +749,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -837,7 +837,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
@@ -924,7 +924,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{