Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions proxy/common_neon/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@
@logged_group("neon.Proxy")
class GasEstimate:
def __init__(self, request: dict, solana: SolanaInteractor):
self.sender = request.get('from', "0x0000000000000000000000000000000000000000")[2:]
self.contract = request.get('to', '0x')[2:]
self.value = request.get('value', '0x00')
self.data = request.get('data', '0x')[2:]
self.sender = request.get('from') or '0x0000000000000000000000000000000000000000'
if self.sender:
self.sender = self.sender[2:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, the previous realization is the same, but shorter

Copy link
Contributor Author

@anton-lisanin anton-lisanin Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same, but it is not.
request.get('data', '0x') can return valid hex string, empty string, '0x', or None
And if it is empty string or None it will cause exception


self.contract = request.get('to') or ''
if self.contract:
self.contract = self.contract[2:]

self.data = request.get('data') or ''
if self.data:
self.data = self.data[2:]

self.value = request.get('value') or '0x00'

self.solana = solana

def execution_cost(self) -> int:
Expand Down Expand Up @@ -76,10 +85,8 @@ def estimate(self):
overhead = self.iterative_overhead_cost()

gas = execution_cost + trx_size_cost + overhead + EXTRA_GAS

# TODO: MM restriction. Uncomment ?
# if gas < 21000:
# gas = 21000
if gas < 21000:
gas = 21000

self.debug(f'execution_cost: {execution_cost}, ' +
f'trx_size_cost: {trx_size_cost}, ' +
Expand Down