-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
88 additions
and
12 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from util.logging import get_logger | ||
from server.sync.onchain import w3 | ||
import time | ||
|
||
logger = get_logger() | ||
|
||
def wait_for_blocks(blocks=10): | ||
initial_block_number = w3.eth.block_number | ||
|
||
while True: | ||
current_block_number = w3.eth.block_number | ||
if current_block_number >= initial_block_number + blocks: | ||
break | ||
logger.info(f"Waiting for blocks... Current: {current_block_number - initial_block_number}, Required: {blocks}") | ||
time.sleep(5) # Wait for 5 seconds before checking again |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from server.sync.onchain import w3 | ||
from util.logging import get_logger | ||
from web3utils.wallet import Wallet | ||
|
||
logger = get_logger() | ||
|
||
def send_eth(sender: Wallet, rcpt: str, amount: int, gas_price: int) -> str: | ||
"""Send a specified amount of wei to a specified address.""" | ||
nonce = w3.eth.get_transaction_count(sender.account.address) | ||
tx = { | ||
'nonce': nonce, #prevents from sending a transaction twice on ethereum | ||
'to': rcpt, | ||
'value': w3.to_wei(amount, 'wei'), | ||
'gas': 21000, | ||
'gasPrice': gas_price, | ||
'chainId': w3.eth.chain_id | ||
} | ||
signed_tx = w3.eth.account.sign_transaction(tx, sender.account.key) | ||
logger.info(f"Sending {amount} wei to {rcpt}") | ||
#send the transaction | ||
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction) | ||
logger.info(f"Transaction sent: {tx_hash.hex()}") | ||
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) | ||
logger.info(f"Transaction mined: {tx_hash}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters