kopia lustrzana https://github.com/bugout-dev/moonworm
adding cli generator
rodzic
fdaeee26db
commit
6559e46237
|
|
@ -0,0 +1,57 @@
|
|||
# Code generated by moonstream centipede : https://github.com/bugout-dev/centipede
|
||||
# Centipede version : {centipede_version}
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from eth_typing.evm import Address, ChecksumAddress
|
||||
import web3
|
||||
from web3 import Web3
|
||||
from web3.contract import Contract
|
||||
|
||||
|
||||
def init_web3(ipc_path: str) -> Web3:
|
||||
return web3.HTTPProvider(ipc_path)
|
||||
|
||||
|
||||
def init_contract(web3: Web3, abi: Dict[str, Any], address: Optional[str]) -> Contract:
|
||||
checksum_address: Optional[ChecksumAddress] = None
|
||||
if address is not None:
|
||||
checksum_address = web3.toChecksumAddress(address)
|
||||
return web3.eth.contract(address=checksum_address, abi=abi)
|
||||
|
||||
|
||||
def make_function_call(contract: Contract, function_name: str, *args):
|
||||
contract.functions[function_name](*args).call()
|
||||
|
||||
|
||||
def generate_argument_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description="Your smart contract cli")
|
||||
subcommands = parser.add_subparsers(
|
||||
dest="subcommand",
|
||||
)
|
||||
call = subcommands.add_parser("call", description="Call smart contract function")
|
||||
call_subcommands = call.add_subparsers(
|
||||
dest="fn_name",
|
||||
)
|
||||
my_fn = call_subcommands.add_parser("my_fn", description="My fn call")
|
||||
my_fn.add_argument("name")
|
||||
my_fn.add_argument("surname")
|
||||
|
||||
my_fn2 = call_subcommands.add_parser("my_fn2", description="My fn2 call")
|
||||
my_fn2.add_argument("name2")
|
||||
my_fn2.add_argument("surname2")
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = generate_argument_parser()
|
||||
args = parser.parse_args()
|
||||
print(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
# This file was generated by moonstream centipede : https://github.com/bugout-dev/centipede
|
||||
# Code generated by moonstream centipede : https://github.com/bugout-dev/centipede
|
||||
# Centipede version : {centipede_version}
|
||||
import json
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ import os
|
|||
from typing import Any, Dict, Union
|
||||
|
||||
import libcst as cst
|
||||
from eth_typing.evm import Address, ChecksumAddress
|
||||
from libcst._nodes.statement import SimpleStatementLine
|
||||
from libcst._parser.entrypoints import parse_statement
|
||||
|
||||
from .version import CENTIPEDE_VERSION
|
||||
|
||||
CONTRACT_TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), "contract.py.template")
|
||||
try:
|
||||
|
|
@ -131,6 +130,7 @@ def generate_contract_file(abi: Dict[str, Any], output_path: str):
|
|||
content = REPORTER_FILE_TEMPLATE.format(
|
||||
abi_json=JSON_FILE_PATH,
|
||||
contract_body=contract_body,
|
||||
centipede_version=CENTIPEDE_VERSION,
|
||||
)
|
||||
contract_file_path = os.path.join(output_path, "lol.py")
|
||||
with open(contract_file_path, "w") as ofp:
|
||||
|
|
@ -138,3 +138,7 @@ def generate_contract_file(abi: Dict[str, Any], output_path: str):
|
|||
|
||||
with open(JSON_FILE_PATH, "w") as ofp:
|
||||
ofp.write(json.dumps(abi))
|
||||
|
||||
|
||||
def generate_contract_cli_file(abi: Dict[str, Any], output_path: str):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from dataclasses import dataclass
|
||||
from os import name
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from eth_typing.evm import ChecksumAddress
|
||||
|
|
|
|||
|
|
@ -11,13 +11,14 @@ with open("abi.json", "r") as abi_file:
|
|||
|
||||
|
||||
class Contract:
|
||||
# GET CONTRACT ADDRESS IN INIT
|
||||
def __init__(self, web3: Web3):
|
||||
self.web3 = web3
|
||||
self.contract = web3.eth.contract(
|
||||
address=web3.toChecksumAddress(CONTRACT_ADDRESS), abi=CONTRACT_ABI
|
||||
)
|
||||
|
||||
def supportsInterface(self, _interfaceID: str) -> Any:
|
||||
def supportsInterface(self, _interfaceID: bytes) -> Any:
|
||||
return self.contract.functions.supportsInterface(_interfaceID).call()
|
||||
|
||||
def cfoAddress(self) -> Any:
|
||||
|
|
@ -222,5 +223,6 @@ IPC_PATH = "http://127.0.0.1:18375"
|
|||
w3 = Web3(Web3.HTTPProvider(IPC_PATH))
|
||||
cryptoKitties = Contract(w3)
|
||||
|
||||
|
||||
print(cryptoKitties.ownerOf(1))
|
||||
print(cryptoKitties.getKitty(1))
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
CENTIPEDE_VERSION = "0.0.1"
|
||||
Ładowanie…
Reference in New Issue