Skip to content

Commit

Permalink
move parse amount to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
simluyt authored and norswap committed Jan 19, 2024
1 parent de16757 commit 3215c77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
16 changes: 2 additions & 14 deletions bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import sys
import tomli
import re

import libroll as lib

Expand Down Expand Up @@ -33,7 +32,7 @@ def main():
open(os.path.join('deployments', args.name, 'artifacts', 'addresses.json')))['L1StandardBridgeProxy']

if not private_key or not account:
sys.exit("Private key, account, and amount must be provided either via arguments or config.")
sys.exit("Private key and account must be provided either via arguments or config.")

try:
print("Sending eth to L1StandardBridgeProxy contract.")
Expand All @@ -42,7 +41,7 @@ def main():
"--rpc-url", config["l1_rpc_url"],
"--private-key", private_key,
bridge_proxy,
"--value", parse_amount(args.amount),
"--value", lib.parse_amount(args.amount),
"'depositETHTo(address,uint32, bytes)'", account, "0", "0x"
]

Expand All @@ -54,16 +53,5 @@ def main():
sys.exit(1)


def parse_amount(amount_str):
pattern = re.compile(r'^(\d+(\.\d+)?)(\s?(ether|gwei|wei))?$')
match = pattern.match(amount_str.lower())
if match:
amount = match.group(1)
unit = match.group(4) or 'ether'
return f"{amount}{unit}"
else:
raise ValueError("Invalid amount format.")


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions libroll/libroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import socket
import time
import re
from dataclasses import dataclass
from typing import Callable

Expand Down Expand Up @@ -309,3 +310,20 @@ def remove_paths(config, paths: list[str]):
shutil.rmtree(path, ignore_errors=True)

####################################################################################################


def parse_amount(amount_str):
"""
Parses an amount string and returns something a cast command understands.
"""
pattern = re.compile(r'^(\d+(\.\d+)?)(\s?(ether|gwei|wei))?$')
match = pattern.match(amount_str.lower())
if match:
amount = match.group(1)
unit = match.group(4) or 'ether'
return f"{amount}{unit}"
else:
raise ValueError("Invalid amount format.")


####################################################################################################

0 comments on commit 3215c77

Please sign in to comment.