diff --git a/jmclient/jmclient/wallet.py b/jmclient/jmclient/wallet.py index 24c74f3f6..216bbfdbb 100644 --- a/jmclient/jmclient/wallet.py +++ b/jmclient/jmclient/wallet.py @@ -2221,13 +2221,10 @@ def _time_number_to_timestamp(cls, timenumber): return timegm(datetime(year, month, *cls.TIMELOCK_DAY_AND_SHORTER).timetuple()) @classmethod - def timestamp_to_time_number(cls, timestamp): + def datetime_to_time_number(cls, dt): """ converts a datetime object to a time number """ - #workaround for the year 2038 problem on 32 bit systems - #see https://stackoverflow.com/questions/10588027/converting-timestamps-larger-than-maxint-into-datetime-objects - dt = datetime.utcfromtimestamp(0) + timedelta(seconds=timestamp) if (dt.month - cls.TIMELOCK_EPOCH_MONTH) % cls.TIMENUMBER_UNIT != 0: raise ValueError() day_and_shorter_tuple = (dt.day, dt.hour, dt.minute, dt.second, dt.microsecond) @@ -2239,6 +2236,16 @@ def timestamp_to_time_number(cls, timestamp): raise ValueError("datetime out of range") return timenumber + @classmethod + def timestamp_to_time_number(cls, timestamp): + """ + converts a unix timestamp to a time number + """ + #workaround for the year 2038 problem on 32 bit systems + #see https://stackoverflow.com/questions/10588027/converting-timestamps-larger-than-maxint-into-datetime-objects + dt = datetime.utcfromtimestamp(0) + timedelta(seconds=timestamp) + return cls.datetime_to_time_number(dt) + @classmethod def is_timelocked_path(cls, path): return len(path) > 4 and path[4] == cls.BIP32_TIMELOCK_ID diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index 111ce6eaf..68fc23686 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -5,7 +5,6 @@ import sqlite3 import sys from datetime import datetime, timedelta -from calendar import timegm from optparse import OptionParser from numbers import Integral from collections import Counter @@ -1226,8 +1225,7 @@ def wallet_gettimelockaddress(wallet, locktime_string): m = FidelityBondMixin.FIDELITY_BOND_MIXDEPTH address_type = FidelityBondMixin.BIP32_TIMELOCK_ID lock_datetime = datetime.strptime(locktime_string, "%Y-%m") - timenumber = FidelityBondMixin.timestamp_to_time_number(timegm( - lock_datetime.timetuple())) + timenumber = FidelityBondMixin.datetime_to_time_number(lock_datetime) index = timenumber path = wallet.get_path(m, address_type, index, timenumber)