kopia lustrzana https://github.com/bugout-dev/moonworm
Added a utility to get a constructor from ABI
Bumped version in preparation of this change.pull/26/head
rodzic
44c530e9be
commit
24fcc61ad5
|
@ -31,6 +31,20 @@ except Exception as e:
|
|||
logging.warn(e)
|
||||
|
||||
|
||||
DEFAULT_CONSTRUCTOR = {
|
||||
"inputs": [],
|
||||
"stateMutability": "payable",
|
||||
"type": "constructor",
|
||||
}
|
||||
|
||||
|
||||
def get_constructor(abi: List[Dict[str, Any]]) -> Dict[str, Any]:
|
||||
for item in abi:
|
||||
if item["type"] == "constructor":
|
||||
return item
|
||||
return DEFAULT_CONSTRUCTOR
|
||||
|
||||
|
||||
def format_code(code: str) -> str:
|
||||
formatted_code = black.format_str(code, mode=black.mode.Mode())
|
||||
return formatted_code
|
||||
|
|
|
@ -6,7 +6,7 @@ import libcst as cst
|
|||
from libcst._nodes.statement import SimpleStatementLine
|
||||
|
||||
from ..version import MOONWORM_VERSION
|
||||
from .basic import format_code, function_spec, make_annotation
|
||||
from .basic import format_code, function_spec, get_constructor, make_annotation
|
||||
|
||||
BROWNIE_INTERFACE_TEMPLATE_PATH = os.path.join(
|
||||
os.path.dirname(__file__), "brownie_contract.py.template"
|
||||
|
@ -63,15 +63,9 @@ def generate_brownie_contract_class(
|
|||
),
|
||||
)
|
||||
|
||||
contract_constructors = [c for c in abi if c["type"] == "constructor"]
|
||||
if len(contract_constructors) == 1:
|
||||
contract_constructor = contract_constructors[0]
|
||||
elif len(contract_constructors) == 0:
|
||||
contract_constructor = {"inputs": []}
|
||||
else:
|
||||
raise ValueError("Multiple constructors found in ABI")
|
||||
|
||||
contract_constructor = get_constructor(abi)
|
||||
contract_constructor["name"] = "constructor"
|
||||
|
||||
class_functions = (
|
||||
[class_constructor]
|
||||
+ [
|
||||
|
@ -445,6 +439,7 @@ def generate_cli_generator(
|
|||
cst.parse_statement("parser.set_defaults(func=lambda _: parser.print_help())"),
|
||||
cst.parse_statement("subcommands = parser.add_subparsers()"),
|
||||
]
|
||||
|
||||
for item in abi:
|
||||
if item["type"] != "function":
|
||||
continue
|
||||
|
|
|
@ -1 +1 @@
|
|||
MOONWORM_VERSION = "0.1.1"
|
||||
MOONWORM_VERSION = "0.1.2"
|
||||
|
|
Ładowanie…
Reference in New Issue