Skip to content

Commit

Permalink
multi coins
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 16, 2024
1 parent 1bff3ca commit bac77b1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions testground/benchmark/benchmark/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import socket
import time
from itertools import takewhile
from itertools import dropwhile, takewhile
from pathlib import Path

import bech32
Expand Down Expand Up @@ -145,10 +145,16 @@ def gen_account(global_seq: int, index: int) -> Account:
def parse_coins(s: str) -> dict:
"""
split denom from coins string.
for example: `"1000basecro"` to `("1000", "basecro")`
for example: `"1000.0stake,1000basetcro"` to
`[{'amount': '1000.0', 'denom': 'stake'}, {'amount': '1000', 'denom': 'basetcro'}]`
"""
num = "".join(takewhile(str.isdigit, s))
return {
"amount": num,
"denom": s[len(num) :],
}
coins = []
for coin in s.split(","):
amount = "".join(takewhile(is_float, coin))
denom = "".join(dropwhile(is_float, coin))
coins.append({"amount": amount, "denom": denom.strip()})
return coins


def is_float(s):
return str.isdigit(s) or s == "."

0 comments on commit bac77b1

Please sign in to comment.