Skip to content

Commit

Permalink
update script
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Sep 23, 2024
1 parent 4f056fe commit 2bf813a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Fullstack Web3 Template v2.3.0
# Fullstack Web3 Template v2.3.1

## QuickStart

Expand Down
87 changes: 60 additions & 27 deletions smartcontracts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from dataclasses import dataclass, field
from json import dumps, load
from typing import List
import json
import glob


@dataclass
Expand All @@ -26,40 +28,71 @@ class Contract:
TRANSACTIONS_PATH = f"broadcast/{CONTRACT_SCRIPT_NAME}/{CHAIN_ID}/run-latest.json"
TARGET_DIR = "../ui/contracts/deployedContracts.ts"

CONTRACTS = []


def abi_path(name) -> str:
return f"artifacts/{name}.sol/{name}.json"


with open(TRANSACTIONS_PATH) as deployed_contracts:
json_file = load(deployed_contracts)
transactions = json_file["transactions"]
contracts: List[Contract] = []

for contract in transactions:
if contract["transactionType"] == "CREATE":
name, address = contract["contractName"], contract["contractAddress"]
with open(abi_path(name)) as full_abi_json:
abi = load(full_abi_json)["abi"]
contracts.append(Contract(name, address, abi))


typescript_content = f"""
import {{ GenericContractsDeclaration }} from "~~/utils/fwt/contract";
def updateABI():
with open(TRANSACTIONS_PATH) as deployed_contracts:
json_file = load(deployed_contracts)
transactions = json_file["transactions"]
contracts: List[Contract] = []

for contract in transactions:
if contract["transactionType"] == "CREATE":
name, address = contract["contractName"], contract["contractAddress"]
CONTRACTS.append(name)
with open(abi_path(name)) as full_abi_json:
abi = load(full_abi_json)["abi"]
contracts.append(Contract(name, address, abi))

typescript_content = f"""
import {{ GenericContractsDeclaration }} from "~~/utils/fwt/contract";
const deployedContracts = {{
{CHAIN_ID}: {dumps({
contract.name: {
"address": contract.address,
"abi": contract.abi,
}
for contract in contracts
})}
}} as const;
export default deployedContracts satisfies GenericContractsDeclaration;
"""

const deployedContracts = {{
{CHAIN_ID}: {dumps({
contract.name: {
"address": contract.address,
"abi": contract.abi,
with open(TARGET_DIR, "w") as ts_file:
ts_file.write(typescript_content)


def get_metadata():
BUILD_INFO = glob.glob("artifacts/build-info/*.json")[0]
with open(BUILD_INFO) as build_info:
json_file = load(build_info)
contracts_data = json_file["output"]["contracts"]

# Filtrar os contratos relevantes
filtered_contracts = {
contract_path: {
name: contracts_data[contract_path][name]
for name in contracts_data[contract_path]
if name in CONTRACTS
}
for contract_path in contracts_data
if any(name in contracts_data[contract_path] for name in CONTRACTS)
}
for contract in contracts
})}
}} as const;

export default deployedContracts satisfies GenericContractsDeclaration;
"""
# Atualiza a estrutura original com os contratos filtrados
json_file["output"]["contracts"] = filtered_contracts

# Salvar o conteúdo filtrado de volta ao arquivo original
with open(BUILD_INFO, "w") as build_info:
json.dump(json_file, build_info, indent=4)


with open(TARGET_DIR, "w") as ts_file:
ts_file.write(typescript_content)
updateABI()
get_metadata()
2 changes: 1 addition & 1 deletion ui/app/blockexplorer/address/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const getContractData = async (address: string) => {
"..",
"..",
"..",
"hardhat",
"smartcontracts",
"artifacts",
"build-info",
);
Expand Down

0 comments on commit 2bf813a

Please sign in to comment.