Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 358a64a

Browse files
authored
Add proper ABI generation from @thirdweb-dev/contracts-js (#125)
* Add abi scripts * Update ABIs * Make prerelease
1 parent e6853bf commit 358a64a

File tree

275 files changed

+289112
-6829
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

275 files changed

+289112
-6829
lines changed

Makefile

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,15 @@ init:
1111
poetry install
1212
poetry run yarn add hardhat
1313
poetry run pip3 install eth-brownie
14+
npm install -g @0x/abi-gen
15+
yarn
1416

1517
test:
1618
poetry run brownie test --network hardhat
1719

18-
abi:
20+
abis:
1921
# If you regenerate registry ABI, you will need to fix a typing error
20-
# abi-gen --language Python -o thirdweb/abi --abis abi/TWRegistry.json && mv thirdweb/abi/t_w_registry/__init__.py thirdweb/abi/t_w_registry.py && rm -rf thirdweb/abi/t_w_registry
21-
abi-gen --language Python -o thirdweb/abi --abis abi/TWFactory.json && mv thirdweb/abi/t_w_factory/__init__.py thirdweb/abi/t_w_factory.py && rm -rf thirdweb/abi/t_w_factory
22-
abi-gen --language Python -o thirdweb/abi --abis abi/TokenERC20.json && mv thirdweb/abi/token_erc20/__init__.py thirdweb/abi/token_erc20.py && rm -rf thirdweb/abi/token_erc20
23-
abi-gen --language Python -o thirdweb/abi --abis abi/TokenERC721.json && mv thirdweb/abi/token_erc721/__init__.py thirdweb/abi/token_erc721.py && rm -rf thirdweb/abi/token_erc721
24-
abi-gen --language Python -o thirdweb/abi --abis abi/TokenERC1155.json && mv thirdweb/abi/token_erc1155/__init__.py thirdweb/abi/token_erc1155.py && rm -rf thirdweb/abi/token_erc1155
25-
abi-gen --language Python -o thirdweb/abi --abis abi/Marketplace.json && mv thirdweb/abi/marketplace/__init__.py thirdweb/abi/marketplace.py && rm -rf thirdweb/abi/marketplace
26-
abi-gen --language Python -o thirdweb/abi --abis abi/IERC165.json && mv thirdweb/abi/ierc165/__init__.py thirdweb/abi/ierc165.py && rm -rf thirdweb/abi/ierc165
27-
abi-gen --language Python -o thirdweb/abi --abis abi/IERC20.json && mv thirdweb/abi/ierc20/__init__.py thirdweb/abi/ierc20.py && rm -rf thirdweb/abi/ierc20
28-
abi-gen --language Python -o thirdweb/abi --abis abi/IERC721.json && mv thirdweb/abi/ierc721/__init__.py thirdweb/abi/ierc721.py && rm -rf thirdweb/abi/ierc721
29-
abi-gen --language Python -o thirdweb/abi --abis abi/IERC1155.json && mv thirdweb/abi/ierc1155/__init__.py thirdweb/abi/ierc1155.py && rm -rf thirdweb/abi/ierc1155
30-
abi-gen --language Python -o thirdweb/abi --abis abi/DropERC721.json && mv thirdweb/abi/drop_erc721/__init__.py thirdweb/abi/drop_erc721.py && rm -rf thirdweb/abi/drop_erc721
31-
abi-gen --language Python -o thirdweb/abi --abis abi/DropERC1155.json && mv thirdweb/abi/drop_erc1155/__init__.py thirdweb/abi/drop_erc1155.py && rm -rf thirdweb/abi/drop_erc1155
32-
abi-gen --language Python -o thirdweb/abi --abis abi/Multiwrap.json && mv thirdweb/abi/multiwrap/__init__.py thirdweb/abi/multiwrap.py && rm -rf thirdweb/abi/multiwrap
33-
34-
abi-gen --language Python -o thirdweb/abi --abis abi/SignatureMintERC20.json && mv thirdweb/abi/signature_mint_erc20/__init__.py thirdweb/abi/signature_mint_erc20.py && rm -rf thirdweb/abi/signature_mint_erc20
35-
abi-gen --language Python -o thirdweb/abi --abis abi/SignatureMintERC721.json && mv thirdweb/abi/signature_mint_erc721/__init__.py thirdweb/abi/signature_mint_erc721.py && rm -rf thirdweb/abi/signature_mint_erc721
36-
abi-gen --language Python -o thirdweb/abi --abis abi/SignatureMintERC1155.json && mv thirdweb/abi/signature_mint_erc1155/__init__.py thirdweb/abi/signature_mint_erc1155.py && rm -rf thirdweb/abi/signature_mint_erc1155
37-
38-
abi-gen --language Python -o thirdweb/abi --abis abi/ITokenERC20.json && mv thirdweb/abi/i_token_erc20/__init__.py thirdweb/abi/i_token_erc20.py && rm -rf thirdweb/abi/i_token_erc20
39-
abi-gen --language Python -o thirdweb/abi --abis abi/ITokenERC721.json && mv thirdweb/abi/i_token_erc721/__init__.py thirdweb/abi/i_token_erc721.py && rm -rf thirdweb/abi/i_token_erc721
40-
abi-gen --language Python -o thirdweb/abi --abis abi/ITokenERC1155.json && mv thirdweb/abi/i_token_erc1155/__init__.py thirdweb/abi/i_token_erc1155.py && rm -rf thirdweb/abi/i_token_erc1155
41-
42-
abi-gen --language Python -o thirdweb/abi --abis abi/IPermissionsEnumerable.json && mv thirdweb/abi/i_permissions_enumerable/__init__.py thirdweb/abi/i_permissions_enumerable.py && rm -rf thirdweb/abi/i_permissions_enumerable
43-
abi-gen --language Python -o thirdweb/abi --abis abi/IPrimarySale.json && mv thirdweb/abi/i_primary_sale/__init__.py thirdweb/abi/i_primary_sale.py && rm -rf thirdweb/abi/i_primary_sale
44-
abi-gen --language Python -o thirdweb/abi --abis abi/IPlatformFee.json && mv thirdweb/abi/i_platform_fee/__init__.py thirdweb/abi/i_platform_fee.py && rm -rf thirdweb/abi/i_platform_fee
45-
abi-gen --language Python -o thirdweb/abi --abis abi/IRoyalty.json && mv thirdweb/abi/i_royalty/__init__.py thirdweb/abi/i_royalty.py && rm -rf thirdweb/abi/i_royalty
46-
22+
python3 scripts/generate_abis.py
4723

4824
snippets:
4925
poetry run python3 scripts/generate_snippets.py

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"devDependencies": {
3+
"@thirdweb-dev/contracts-js": "^1.3.1",
34
"hardhat": "^2.13.0"
45
}
56
}

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ packages = [
66
{include = "thirdweb"},
77
]
88
readme = "README.md"
9-
version = "3.0.2a1"
9+
version = "3.0.2a2"
1010

1111
[tool.poetry.dependencies]
1212
python = ">=3.7.1"

scripts/generate_abis.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import subprocess
3+
4+
os.system("rm -rf thirdweb/abi")
5+
os.system("mkdir thirdweb/abi")
6+
7+
generated_abis = {}
8+
9+
directory = "node_modules/@thirdweb-dev/contracts-js/dist/abis"
10+
output_path = "thirdweb/abi"
11+
12+
for filename in os.listdir(directory):
13+
try:
14+
path = os.path.join(directory, filename)
15+
output = subprocess.check_output(f"abi-gen --language Python -o {output_path} --abis {path}", shell=True).decode()
16+
generated_path = output.replace("\n", "").replace("\"", "").split("Created: ")[1]
17+
binding_path = generated_path.split("/")[2]
18+
os.system(f"mv {generated_path} {output_path}/{binding_path}.py")
19+
os.system(f"rm -rf {output_path}/{binding_path}")
20+
generated_abis[filename.replace(".json", "")] = binding_path
21+
except:
22+
print(f"Failed to generate binding for {filename}, continuing...")
23+
24+
for filename in os.listdir(output_path):
25+
path = os.path.join(output_path, filename)
26+
if os.path.isdir(path):
27+
os.system(f"rm -rf {path}")
28+
29+
30+
for abi, binding in generated_abis.items():
31+
with open('thirdweb/abi/__init__.py', 'a') as file:
32+
file.write(f"\nfrom .{binding} import {abi} # pylint: disable=unused-import")

0 commit comments

Comments
 (0)