Skip to content

Commit

Permalink
Merge pull request #344 from BoostryJP/feature/#342
Browse files Browse the repository at this point in the history
feat: upgrade web3
  • Loading branch information
YoshihitoAso authored Jun 29, 2022
2 parents dd4ebf7 + f58bd15 commit 10df02c
Show file tree
Hide file tree
Showing 31 changed files with 247 additions and 241 deletions.
3 changes: 1 addition & 2 deletions app/routers/token_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"""
import uuid
from typing import List
import pytz

from fastapi import APIRouter, Depends, Header, Path
from fastapi.exceptions import HTTPException
Expand Down Expand Up @@ -85,7 +84,7 @@ def create_collection(
raise InvalidParameterError("wait for a while as the token is being processed")

# Validate block number
if data.block_number > web3.eth.blockNumber:
if data.block_number > web3.eth.block_number:
raise InvalidParameterError("Block number must be current or past one.")

# Check list id conflict
Expand Down
10 changes: 5 additions & 5 deletions app/utils/contract_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ def send_transaction(transaction: dict, private_key: str):

try:
# Get nonce
nonce = web3.eth.getTransactionCount(_tx_from)
nonce = web3.eth.get_transaction_count(_tx_from)
transaction["nonce"] = nonce
signed_tx = web3.eth.account.sign_transaction(
transaction_dict=transaction,
private_key=private_key
)
# Send Transaction
tx_hash = web3.eth.sendRawTransaction(signed_tx.rawTransaction.hex())
tx_receipt = web3.eth.waitForTransactionReceipt(
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction.hex())
tx_receipt = web3.eth.wait_for_transaction_receipt(
transaction_hash=tx_hash,
timeout=10
)
Expand All @@ -216,7 +216,7 @@ def send_transaction(transaction: dict, private_key: str):

@staticmethod
def inspect_tx_failure(tx_hash: str) -> str:
tx = web3.eth.getTransaction(tx_hash)
tx = web3.eth.get_transaction(tx_hash)

# build a new transaction to replay:
replay_tx = {
Expand Down Expand Up @@ -248,7 +248,7 @@ def get_block_by_transaction_hash(tx_hash: str):
:param tx_hash: transaction hash
:return: block
"""
tx = web3.eth.getTransaction(tx_hash)
tx = web3.eth.get_transaction(tx_hash)
block = web3.eth.get_block(tx["blockNumber"])
return block

Expand Down
4 changes: 2 additions & 2 deletions batch/indexer_e2e_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

class Processor:
def __init__(self):
self.latest_block = web3.eth.blockNumber
self.latest_block = web3.eth.block_number
self.e2e_messaging_contract = ContractUtils.get_contract(
contract_name="E2EMessaging",
contract_address=E2E_MESSAGING_CONTRACT_ADDRESS)
Expand All @@ -91,7 +91,7 @@ def process(self):
try:
# Get from_block_number and to_block_number for contract event filter
idx_e2e_messaging_block_number = self.__get_idx_e2e_messaging_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber
latest_block = web3.eth.block_number

if idx_e2e_messaging_block_number >= latest_block:
LOG.debug("skip process")
Expand Down
4 changes: 2 additions & 2 deletions batch/indexer_personal_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

class Processor:
def __init__(self):
self.latest_block = web3.eth.blockNumber
self.latest_block = web3.eth.block_number
self.personal_info_contract_list = []

def process(self):
Expand All @@ -64,7 +64,7 @@ def process(self):
self.__refresh_personal_info_list(db_session=db_session)
# most recent blockNumber that has been synchronized with DB
block_number = self.__get_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber # latest blockNumber
latest_block = web3.eth.block_number # latest blockNumber

if block_number >= latest_block:
LOG.debug("skip Process")
Expand Down
6 changes: 3 additions & 3 deletions batch/indexer_position_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class Processor:
def __init__(self):
self.latest_block = web3.eth.blockNumber
self.latest_block = web3.eth.block_number
self.token_list = []
self.exchange_address_list = []

Expand All @@ -68,7 +68,7 @@ def sync_new_logs(self):

# Get from_block_number and to_block_number for contract event filter
idx_position_block_number = self.__get_idx_position_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber
latest_block = web3.eth.block_number

if idx_position_block_number >= latest_block:
LOG.debug("skip process")
Expand Down Expand Up @@ -217,7 +217,7 @@ def __sync_transfer(self, db_session: Session, block_from: int, block_to: int):
for event in events:
args = event["args"]
for account in [args.get("from", ZERO_ADDRESS), args.get("to", ZERO_ADDRESS)]:
if web3.eth.getCode(account).hex() == "0x":
if web3.eth.get_code(account).hex() == "0x":
balance, pending_transfer, exchange_balance, exchange_commitment = \
self.__get_account_balance_all(token, account)
self.__sink_on_position(
Expand Down
6 changes: 3 additions & 3 deletions batch/indexer_position_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class Processor:
def __init__(self):
self.latest_block = web3.eth.blockNumber
self.latest_block = web3.eth.block_number
self.token_list = []
self.exchange_address_list = []

Expand All @@ -68,7 +68,7 @@ def sync_new_logs(self):

# Get from_block_number and to_block_number for contract event filter
idx_position_block_number = self.__get_idx_position_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber
latest_block = web3.eth.block_number

if idx_position_block_number >= latest_block:
LOG.debug("skip process")
Expand Down Expand Up @@ -217,7 +217,7 @@ def __sync_transfer(self, db_session: Session, block_from: int, block_to: int):
for event in events:
args = event["args"]
for account in [args.get("from", ZERO_ADDRESS), args.get("to", ZERO_ADDRESS)]:
if web3.eth.getCode(account).hex() == "0x":
if web3.eth.get_code(account).hex() == "0x":
balance, pending_transfer, exchange_balance, exchange_commitment = \
self.__get_account_balance_all(token, account)
self.__sink_on_position(
Expand Down
2 changes: 1 addition & 1 deletion batch/indexer_token_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def __process_transfer(self, block_from: int, block_to: int):
amount = args.get("value")

# Skip sinking in case of deposit to exchange or withdrawal from exchange
if web3.eth.getCode(from_account).hex() != "0x" or web3.eth.getCode(to_account).hex() != "0x":
if web3.eth.get_code(from_account).hex() != "0x" or web3.eth.get_code(to_account).hex() != "0x":
continue

if amount is not None and amount <= sys.maxsize:
Expand Down
4 changes: 2 additions & 2 deletions batch/indexer_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

class Processor:
def __init__(self):
self.latest_block = web3.eth.blockNumber
self.latest_block = web3.eth.block_number
self.token_list = []

def sync_new_logs(self):
Expand All @@ -62,7 +62,7 @@ def sync_new_logs(self):

# Get from_block_number and to_block_number for contract event filter
idx_transfer_block_number = self.__get_idx_transfer_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber
latest_block = web3.eth.block_number

if idx_transfer_block_number >= latest_block:
LOG.debug("skip process")
Expand Down
6 changes: 3 additions & 3 deletions batch/indexer_transfer_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

class Processor:
def __init__(self):
self.latest_block = web3.eth.blockNumber
self.latest_block = web3.eth.block_number
self.token_list = []

def sync_new_logs(self):
Expand All @@ -87,7 +87,7 @@ def sync_new_logs(self):

# Get from_block_number and to_block_number for contract event filter
idx_transfer_approval_block_number = self.__get_idx_transfer_approval_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber
latest_block = web3.eth.block_number

if idx_transfer_approval_block_number >= latest_block:
LOG.debug("skip process")
Expand Down Expand Up @@ -470,7 +470,7 @@ def __register_notification(self,
token = db_session.query(Token). \
filter(Token.token_address == token_address). \
first()
sender = web3.eth.getTransaction(transaction_hash)["from"]
sender = web3.eth.get_transaction(transaction_hash)["from"]
if token is not None:
if token.issuer_address != sender: # Operate from other than issuer
if notice_code == 0: # ApplyForTransfer
Expand Down
4 changes: 2 additions & 2 deletions batch/processor_create_utxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def process(self):

# Get from_block_number and to_block_number for contract event filter
utxo_block_number = self.__get_utxo_block_number(db_session=db_session)
latest_block = web3.eth.blockNumber
latest_block = web3.eth.block_number

if utxo_block_number >= latest_block:
LOG.debug("skip process")
Expand Down Expand Up @@ -209,7 +209,7 @@ def __process_transfer(self, db_session: Session, token_contract: Contract, bloc
amount = args.get("value")

# Skip sinking in case of deposit to exchange or withdrawal from exchange
if web3.eth.getCode(from_account).hex() != "0x" or web3.eth.getCode(to_account).hex() != "0x":
if web3.eth.get_code(from_account).hex() != "0x" or web3.eth.get_code(to_account).hex() != "0x":
continue

transaction_hash = event["transaction_hash"]
Expand Down
4 changes: 2 additions & 2 deletions batch/processor_monitor_block_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __set_node_info(self, db_session: Session, endpoint_uri: str, priority: int)
try:
# NOTE: Immediately after the processing, the monitoring data is not retained,
# so the past block number is acquired.
block = web3.eth.get_block(max(web3.eth.blockNumber - BLOCK_SYNC_STATUS_CALC_PERIOD, 0))
block = web3.eth.get_block(max(web3.eth.block_number - BLOCK_SYNC_STATUS_CALC_PERIOD, 0))
except Web3WrapperException:
self.__web3_errors(db_session=db_session, endpoint_uri=endpoint_uri)
LOG.error(f"Node connection failed: {endpoint_uri}")
Expand Down Expand Up @@ -170,7 +170,7 @@ def __process(self, db_session: Session, endpoint_uri: str):
# Check increased block number
data = {
"time": time.time(),
"block_number": web3.eth.blockNumber
"block_number": web3.eth.block_number
}
old_data = history.peek_oldest()
elapsed_time = data["time"] - old_data["time"]
Expand Down
13 changes: 10 additions & 3 deletions requirements.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
aiohttp==3.8.1
aiosignal==1.2.0
alembic==1.5.6
anyio==3.6.1
asgiref==3.5.2
asn1crypto==1.5.1
async-timeout==4.0.2
attrs==21.4.0
base58==2.1.1
bitarray==2.5.1
Expand All @@ -10,6 +13,7 @@ botocore==1.20.112
certifi==2022.6.15
cffi==1.15.0
chardet==4.0.0
charset-normalizer==2.1.0
click==8.1.3
coincurve==14.0.0
cytoolz==0.11.2
Expand All @@ -22,17 +26,19 @@ eth-rlp==0.2.1
eth-typing==2.3.0
eth-utils==1.10.0
fastapi==0.75.2
frozenlist==1.3.0
gunicorn==20.1.0
h11==0.13.0
hexbytes==0.2.2
idna==2.10
ipfshttpclient==0.7.0a1
ipfshttpclient==0.7.0
jmespath==0.10.0
jsonschema==3.2.0
lru-dict==1.1.7
Mako==1.2.0
MarkupSafe==2.1.1
multiaddr==0.0.9
multidict==6.0.2
netaddr==0.8.0
parsimonious==0.8.1
protobuf==3.20.1
Expand All @@ -59,5 +65,6 @@ typing_extensions==4.2.0
urllib3==1.26.9
uvicorn==0.17.6
varint==1.0.2
web3==5.15.0
websockets==8.1
web3==5.20.1
websockets==9.1
yarl==1.7.2
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SQLAlchemy==1.3.22
psycopg2-binary==2.8.6
web3==5.15.0
web3==5.20.1
eth-keyfile==0.5.1
pysha3==1.0.2
coincurve==14.0.0
Expand Down
Loading

0 comments on commit 10df02c

Please sign in to comment.