Skip to content

Commit

Permalink
Merge pull request #406 from 1200wd/remove-deprecated-utcfromtimestamp
Browse files Browse the repository at this point in the history
Remove deprecated utcfromtimestamp
  • Loading branch information
mccwdev authored Jun 3, 2024
2 parents e554492 + c411200 commit 8b2c8e3
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bitcoinlib/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import enum
from .opcodes import *
from pathlib import Path
from datetime import datetime
from datetime import datetime, timezone

# General defaults
TYPE_TEXT = str
Expand Down
2 changes: 1 addition & 1 deletion bitcoinlib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class DbTransaction(Base):
doc="Transaction level locktime. Locks the transaction until a specified block "
"(value from 1 to 5 million) or until a certain time (Timestamp in seconds after 1-jan-1970)."
" Default value is 0 for transactions without locktime")
date = Column(DateTime, default=datetime.utcnow,
date = Column(DateTime, default=datetime.now(timezone.utc),
doc="Date when transaction was confirmed and included in a block. "
"Or when it was created when transaction is not send or confirmed")
coinbase = Column(Boolean, default=False, doc="Is True when this is a coinbase transaction, default is False")
Expand Down
2 changes: 1 addition & 1 deletion bitcoinlib/services/bcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _parse_transaction(self, tx):
t.locktime = tx['locktime']
t.network = self.network
t.fee = tx['fee']
t.date = datetime.utcfromtimestamp(tx['time']) if tx['time'] else None
t.date = datetime.fromtimestamp(tx['time'], timezone.utc) if tx['time'] else None
t.confirmations = tx['confirmations']
t.block_height = tx['height'] if tx['height'] > 0 else None
t.block_hash = tx['block']
Expand Down
10 changes: 5 additions & 5 deletions bitcoinlib/services/bitaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -52,9 +52,9 @@ def _parse_transaction(self, tx):
status = 'confirmed'
date = None
if 'timestamp' in tx and tx['timestamp']:
date = datetime.utcfromtimestamp(tx['timestamp'])
date = datetime.fromtimestamp(tx['timestamp'], timezone.utc)
elif 'blockTime' in tx and tx['blockTime']:
date = datetime.utcfromtimestamp(tx['blockTime'])
date = datetime.fromtimestamp(tx['blockTime'], timezone.utc)
block_height = None
if 'blockHeight' in tx:
block_height = tx['blockHeight']
Expand Down Expand Up @@ -128,7 +128,7 @@ def getutxos(self, address, after_txid='', limit=MAX_TRANSACTIONS):
'size': 0,
'value': utxo['value'],
'script': utxo['scriptPubKey'],
'date': datetime.utcfromtimestamp(tx['timestamp'])
'date': datetime.fromtimestamp(tx['timestamp'], timezone.utc)
}
)
if tx['txId'] == after_txid:
Expand Down Expand Up @@ -213,7 +213,7 @@ def blockcount(self):
# 'merkle_root': bd['merkleRoot'],
# 'nonce': bd['nonce'],
# 'prev_block': bd['previousBlockHash'],
# 'time': datetime.utcfromtimestamp(bd['blockTime']),
# 'time': datetime.fromtimestamp(bd['blockTime'], timezone.utc),
# 'total_txs': bd['transactionsCount'],
# 'txs': txs,
# 'version': bd['version'],
Expand Down
2 changes: 1 addition & 1 deletion bitcoinlib/services/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _parse_transaction(self, tx, block_height=None, get_input_values=True):
t.verified = True
t.version = tx['version'].to_bytes(4, 'big')
t.version_int = tx['version']
t.date = None if 'time' not in tx else datetime.utcfromtimestamp(tx['time'])
t.date = None if 'time' not in tx else datetime.fromtimestamp(tx['time'], timezone.utc)
t.update_totals()
return t

Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/services/blockbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -48,7 +48,7 @@ def _convert_to_transaction(self, tx):
status = 'confirmed'
else:
status = 'unconfirmed'
txdate = datetime.utcfromtimestamp(tx['blockTime'])
txdate = datetime.fromtimestamp(tx['blockTime'], timezone.utc)
t = Transaction.parse_hex(tx['hex'], strict=self.strict, network=self.network)
t.input_total = int(tx['valueIn'])
t.output_total = int(tx['value'])
Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/services/blockchaininfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -91,7 +91,7 @@ def gettransaction(self, txid, latest_block=None):
if not self.latest_block:
self.latest_block = self.blockcount()
t.status = 'confirmed'
t.date = datetime.utcfromtimestamp(tx['time'])
t.date = datetime.fromtimestamp(tx['time'], timezone.utc)
t.block_height = tx['block_height']
t.confirmations = 1
if self.latest_block > t.block_height:
Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/services/blocksmurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -88,7 +88,7 @@ def _parse_transaction(self, tx, block_height=None):
# FIXME: Blocksmurfer returns 'date' or 'time', should be consistent
tx_date = None if not tx.get('date') else datetime.strptime(tx['date'], "%Y-%m-%dT%H:%M:%S")
if not tx_date and 'time' in tx:
tx_date = datetime.utcfromtimestamp(tx['time'])
tx_date = datetime.fromtimestamp(tx['time'], timezone.utc)
t = Transaction(locktime=tx['locktime'], version=tx['version'], network=self.network,
fee=tx['fee'], size=tx['size'], txid=tx['txid'], date=tx_date, input_total=tx['input_total'],
output_total=tx['output_total'], confirmations=confirmations, block_height=block_height,
Expand Down
8 changes: 5 additions & 3 deletions bitcoinlib/services/blockstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -80,7 +80,8 @@ def getutxos(self, address, after_txid='', limit=MAX_TRANSACTIONS):
'size': 0,
'value': a['value'],
'script': '',
'date': None if 'block_time' not in a['status'] else datetime.utcfromtimestamp(a['status']['block_time'])
'date': None if 'block_time' not in a['status'] else
datetime.fromtimestamp(a['status']['block_time'], timezone.utc)
})
if a['txid'] == after_txid:
utxos = []
Expand All @@ -98,7 +99,8 @@ def _parse_transaction(self, tx):
fee = None if 'fee' not in tx else tx['fee']
t = Transaction(locktime=tx['locktime'], version=tx['version'], network=self.network,
fee=fee, size=tx['size'], txid=tx['txid'],
date=None if 'block_time' not in tx['status'] else datetime.utcfromtimestamp(tx['status']['block_time']),
date=None if 'block_time' not in tx['status'] else
datetime.fromtimestamp(tx['status']['block_time'], timezone.utc),
confirmations=confirmations, block_height=block_height, status=status,
coinbase=tx['vin'][0]['is_coinbase'])
index_n = 0
Expand Down
6 changes: 3 additions & 3 deletions bitcoinlib/services/chainso.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -80,7 +80,7 @@ def getutxos(self, address, after_txid='', limit=MAX_TRANSACTIONS):
'size': 0,
'value': int(round(float(tx['value']) * self.units, 0)),
'script': tx['script_hex'],
'date': datetime.utcfromtimestamp(tx['time']),
'date': datetime.fromtimestamp(tx['time'], timezone.utc),
})
if len(txs) >= 1000:
_logger.warning("ChainSo: transaction list has been truncated, and thus is incomplete")
Expand Down Expand Up @@ -119,7 +119,7 @@ def gettransaction(self, txid, block_height=None):
t.confirmations = tx['confirmations']
if tx['confirmations']:
t.status = 'confirmed'
t.date = datetime.utcfromtimestamp(tx['time'])
t.date = datetime.fromtimestamp(tx['time'], timezone.utc)
else:
t.status = 'unconfirmed'
t.date = None
Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/services/cryptoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -106,7 +106,7 @@ def gettransaction(self, txid):
t.status = 'confirmed'
else:
t.status = 'unconfirmed'
t.date = datetime.utcfromtimestamp(tx['time'])
t.date = datetime.fromtimestamp(tx['time'], timezone.utc)
t.block_height = tx_api['block']
t.block_hash = tx['blockhash']
t.confirmations = tx['confirmations']
Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/services/litecoinblockexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -53,7 +53,7 @@ def _convert_to_transaction(self, tx):
value_in = 0 if 'valueIn' not in tx else int(round(float(tx['valueIn']) * self.units, 0))
txdate = None
if 'blocktime' in tx:
txdate = datetime.utcfromtimestamp(tx['blocktime'])
txdate = datetime.fromtimestamp(tx['blocktime'], timezone.utc)
t = Transaction.parse_hex(tx['hex'], strict=self.strict, network=self.network)
t.fee = fees
t.input_total = value_in
Expand Down
3 changes: 2 additions & 1 deletion bitcoinlib/services/litecoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import configparser
from bitcoinlib.main import *
from datetime import datetime, timezone
from bitcoinlib.networks import Network
from bitcoinlib.services.authproxy import AuthServiceProxy
from bitcoinlib.services.baseclient import BaseClient, ClientError
Expand Down Expand Up @@ -203,7 +204,7 @@ def _parse_transaction(self, tx, block_height=None, get_input_values=True):
t.verified = True
t.version = tx['version'].to_bytes(4, 'big')
t.version_int = tx['version']
t.date = None if 'time' not in tx else datetime.utcfromtimestamp(tx['time'])
t.date = None if 'time' not in tx else datetime.fromtimestamp(tx['time'], timezone.utc)
t.update_totals()
return t

Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/services/litecoreio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

from datetime import datetime
from datetime import datetime, timezone
import logging
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient
Expand Down Expand Up @@ -56,7 +56,7 @@ def _convert_to_transaction(self, tx):
isCoinbase = True
txdate = None
if 'blocktime' in tx:
txdate = datetime.utcfromtimestamp(tx['blocktime'])
txdate = datetime.fromtimestamp(tx['blocktime'])
t = Transaction(locktime=tx['locktime'], version=tx['version'], network=self.network,
fee=fees, size=tx['size'], txid=tx['txid'],
date=txdate, confirmations=tx['confirmations'],
Expand Down
7 changes: 4 additions & 3 deletions bitcoinlib/services/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

import logging
from datetime import datetime
from datetime import datetime, timezone
from bitcoinlib.main import MAX_TRANSACTIONS
from bitcoinlib.services.baseclient import BaseClient, ClientError
from bitcoinlib.transactions import Transaction
Expand Down Expand Up @@ -82,7 +82,8 @@ def getutxos(self, address, after_txid='', limit=MAX_TRANSACTIONS):
'size': 0,
'value': a['value'],
'script': '',
'date': None if 'block_time' not in a['status'] else datetime.utcfromtimestamp(a['status']['block_time'])
'date': None if 'block_time' not in a['status'] else
datetime.fromtimestamp(a['status']['block_time'], timezone.utc)
})
if a['txid'] == after_txid:
utxos = []
Expand All @@ -97,7 +98,7 @@ def _parse_transaction(self, tx):
if block_height:
self.latest_block = self.blockcount() if not self.latest_block else self.latest_block
confirmations = self.latest_block - block_height + 1
tx_date = datetime.utcfromtimestamp(tx['status']['block_time'])
tx_date = datetime.fromtimestamp(tx['status']['block_time'], timezone.utc)
status = 'confirmed'

t = Transaction(locktime=tx['locktime'], version=tx['version'], network=self.network, block_height=block_height,
Expand Down
2 changes: 1 addition & 1 deletion bitcoinlib/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ def info(self):
if self.locktime < 500000000:
print("Locktime: Until block %d" % self.locktime)
else:
print("Locktime: Until %s UTC" % datetime.utcfromtimestamp(self.locktime))
print("Locktime: Until %s UTC" % datetime.fromtimestamp(self.locktime, timezone.utc))
print("Version: %d" % self.version_int)
print("Witness type: %s" % self.witness_type)
print("Status: %s" % self.status)
Expand Down
4 changes: 2 additions & 2 deletions bitcoinlib/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3141,7 +3141,7 @@ def utxos_update(self, account_id=None, used=None, networks=None, key_id=None, d
raise WalletError("No response from any service provider, could not update UTXO's. "
"Errors: %s" % srv.errors)
if srv.complete:
self.last_updated = datetime.now()
self.last_updated = datetime.now(timezone.utc)
elif utxos and 'date' in utxos[-1:][0]:
self.last_updated = utxos[-1:][0]['date']

Expand Down Expand Up @@ -3412,7 +3412,7 @@ def transactions_update(self, account_id=None, used=None, network=None, key_id=N
txs = []
addresslist = self.addresslist(
account_id=account_id, used=used, network=network, key_id=key_id, change=change, depth=depth)
last_updated = datetime.now()
last_updated = datetime.now(timezone.utc)
for address in addresslist:
txs += srv.gettransactions(address, limit=limit, after_txid=self.transaction_last(address))
if not srv.complete:
Expand Down

0 comments on commit 8b2c8e3

Please sign in to comment.