Skip to content

Commit

Permalink
Check in eth openrpc schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Dec 7, 2024
1 parent 74e94cc commit adc00eb
Show file tree
Hide file tree
Showing 6 changed files with 5,686 additions and 82 deletions.
3 changes: 1 addition & 2 deletions packages/drift/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
execution-apis_temp.*
openrpc.json
execution-apis_temp
6 changes: 3 additions & 3 deletions packages/drift/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
}
},
"scripts": {
"build:evm-types": "sh scripts/buildEvmTypes.sh",
"build": "yarn build:evm-types && tsup",
"watch": "yarn build:evm-types && tsup --watch",
"build:ethereum": "sh scripts/buildEthereum.sh",
"build": "yarn build:ethereum && tsup",
"watch": "yarn build:ethereum && tsup --watch",
"test": "vitest run",
"test:watch": "vitest --reporter=verbose",
"coverage": "vitest run --coverage",
Expand Down
72 changes: 72 additions & 0 deletions packages/drift/scripts/buildEthereum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
set -e

# Clones the ethereum/execution-apis repo and generates types from the open-rpc schema.
#
# Usage: $0 [branch] [repo_url]
#
# branch: The branch to clone.
# repo_url: The url of the git repository to clone.

# SETTINGS
repo_url=${2:-"[email protected]:ethereum/execution-apis.git"}
branch=${1:-"main"}
schema_doc="refs-openrpc.json"
out_dir="src/ethereum"
out_schema_doc="$out_dir/openrpc.json"
out_types_name="ethereum"
out_types="$out_dir/$out_types_name".ts

if [ ! -d "$out_dir" ]; then
mkdir -p "$out_dir"
fi

if [ ! -f "$out_schema_doc" ]; then
temp_dir="execution-apis_temp"

if [ ! -d "$temp_dir" ]; then
echo "Cloning $branch from $repo_url"
git clone --depth 1 "$repo_url" --branch "$branch" "$temp_dir"
fi

echo "Installing dependencies and generating OpenRPC schema..."
(
cd "$temp_dir"
npm i ci
npm run build
)
cp "$temp_dir/$schema_doc" "$out_schema_doc"

echo "Deleting temp clone..."
rm -rf "$temp_dir"
fi

echo "Generating types..."
npx open-rpc-typings -d "$out_schema_doc" --output-ts "$out_dir" --name-ts "$out_types_name"

# Convert source name to PascalCase
out_types_name=$(echo "$out_types_name" |
sed 's/-/ /g' |
awk '{
for (i=1; i<=NF; i++) {
$i = toupper(substr($i,1,1)) substr($i,2)
}
print
}' |
sed 's/ //g')

{
echo "/* eslint-disable */"
echo "/* @ts-nocheck */"
echo ""
echo "// This file was generated using the OpenRPC schema from the ethereum/execution-apis repo."
echo "// See https://github.com/ethereum/execution-apis for more information."
echo "//"
echo "// Changes to this file will be lost when the code is regenerated."
echo "// Generated by: $0"
echo ""
echo "export namespace $out_types_name {"
cat "$out_types"
echo "}"
} >"$out_types.tmp"
mv "$out_types.tmp" "$out_types"
72 changes: 0 additions & 72 deletions packages/drift/scripts/buildEvmTypes.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable */
/* @ts-nocheck */

// This file was generated from the ethereum/execution-apis repo.
// This file was generated using the OpenRPC schema from the ethereum/execution-apis repo.
// See https://github.com/ethereum/execution-apis for more information.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// Changes to this file will be lost when the code is regenerated.
// Generated by: scripts/buildEthereum.sh


export namespace ExecutionApis {
export namespace Ethereum {
export type BlockNumber = string;
/**
*
Expand Down
5,606 changes: 5,606 additions & 0 deletions packages/drift/src/ethereum/openrpc.json

Large diffs are not rendered by default.

0 comments on commit adc00eb

Please sign in to comment.