Skip to content

Commit a929721

Browse files
committed
refactor: use regexp for parsing
1 parent 8deeb47 commit a929721

File tree

1 file changed

+8
-6
lines changed
  • packages/cosmic-swingset/provisioning-server/src/ag_pserver

1 file changed

+8
-6
lines changed

packages/cosmic-swingset/provisioning-server/src/ag_pserver/main.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import os
1010
import json
1111
import random
12+
import re
1213
from tempfile import NamedTemporaryFile
1314

1415
from twisted.python import log
@@ -427,18 +428,18 @@ def agCosmosHelper(reactor, opts, config, args, retries = 1):
427428

428429
return code, output
429430

431+
def splitToken(token):
432+
mo = re.search(r'^(\d+)(.*)$', token)
433+
(amount_s, denom) = mo.groups()
434+
return (int(amount_s), denom)
435+
430436
@defer.inlineCallbacks
431437
def doEnablePubkeys(reactor, opts, config, pkobjs):
432438
txes = []
433439
needIngress = []
434440

435441
# Find the token and amount.
436-
token = opts['initial-token']
437-
splitToken = len(token) - 1
438-
while splitToken > 0 and token[splitToken] in string.digits:
439-
splitToken -= 1
440-
amount = int(token[0:splitToken])
441-
denom = token[splitToken:]
442+
(amount, denom) = splitToken(opts['initial-token'])
442443

443444
for pkobj in pkobjs:
444445
pubkey = pkobj['pubkey']
@@ -451,6 +452,7 @@ def doEnablePubkeys(reactor, opts, config, pkobjs):
451452
missing = True
452453
for coin in output['value']['coins']:
453454
# Check if they have some of our coins.
455+
# TODO: This is just a rudimentary check, we really need a better policy.
454456
if coin['denom'] == denom and int(coin['amount']) >= amount:
455457
missing = False
456458
break

0 commit comments

Comments
 (0)