Created
February 9, 2024 19:41
-
-
Save mikeshultz/a254eac9c6e2c84ce362ff11b16f0122 to your computer and use it in GitHub Desktop.
Vyper console print test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pragma version ^0.3.0 | |
@view | |
@external | |
def printcall_uint(x: uint256) -> uint256: | |
print(x) | |
return x | |
@external | |
def printtx_uint(x: uint256): | |
print(x) | |
@external | |
def printtx_uint_combined(x: uint256): | |
print("combined", x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ape | |
import click | |
from ape.cli import ConnectedProviderCommand | |
from eth_abi import decode | |
from eth_utils import decode_hex | |
CONTRACT_ID = "0x000000000000000000636F6e736F6c652e6c6f67" | |
METHOD_ID = "0x23cdd8e8" # log(string,bytes) | |
def console_log(calldata): | |
bcalldata = decode_hex(calldata) | |
schema, payload = decode(["string", "bytes"], bcalldata) | |
data = decode(schema.strip("()").split(","), payload) | |
print(*data) | |
def extract_logs(receipt): | |
return filter( | |
lambda c: c.contract_id == CONTRACT_ID and c.method_id == METHOD_ID, | |
receipt.call_tree.calls, | |
) | |
@click.command(cls=ConnectedProviderCommand) | |
def cli(ecosystem, network): | |
click.echo( | |
f"You selected a provider on ecosystem '{ecosystem.name}' and {network.name}." | |
) | |
deployer = ape.accounts.test_accounts[0] | |
contract = ape.project.printing.deploy(sender=deployer) | |
receipt_uint = contract.printtx_uint(123, sender=deployer) | |
for log in extract_logs(receipt_uint): | |
console_log(log.inputs) | |
receipt_uint_combined = contract.printtx_uint_combined(321, sender=deployer) | |
for log in extract_logs(receipt_uint_combined): | |
console_log(log.inputs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment