Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
TX_V3 = {
'version': '0x3',
'nid': '0x1',
'from': 'hx522bff55a62e0c75a1b51855b0802cfec6a92e84',
'to': 'hx11de4e28be4845de3ea392fd8d758655bf766ca7',
'value': '0x71afd498d0000',
'stepLimit': '0xf4240',
'timestamp': '0x57a4e5556cc03',
'signature': 'fcEMXqEGlqEivXXr7YtD/F1RXgxSXF+R4gVrGKxT1zxi3HukX4NzkSl9/Es1G+nyZx+kviTAtQFUrA+/T0NrfAA=',
'txHash': '6c71ac77b2d130a1f81d234e814974e85cabb0a3ec462c66ff3f820502d0ded2'
}
STEP_LIMIT = 1_000_000_000
STEP_COSTS = {
StepType.DEFAULT: 0,
StepType.CONTRACT_CALL: 25_000,
StepType.CONTRACT_CREATE: 1_000_000_000,
StepType.CONTRACT_UPDATE: 1_600_000_000,
StepType.CONTRACT_DESTRUCT: -70000,
StepType.CONTRACT_SET: 30_000,
StepType.GET: 0,
StepType.SET: 320,
StepType.REPLACE: 80,
StepType.DELETE: -240,
StepType.INPUT: 200,
StepType.EVENT_LOG: 100,
StepType.API_CALL: 10_000
}
def _calc_step_cost(ratio: ScoreApiStepRatio) -> int:
step_cost: int = STEP_COSTS[StepType.API_CALL] * ratio // ScoreApiStepRatio.SHA3_256
return step_cost
def set_step_counter(cls, step_price_dict: dict=initial_costs,
step_limit: int=2_013_265_920, step_price: int=10_000_000_000):
for k, v in step_price_dict.items():
try:
cls.step_counter_factory.set_step_cost(
StepType(k), v)
except ValueError:
pass
cls.step_counter_factory.set_step_price(step_price)
cls.context.step_counter = cls.step_counter_factory.create(step_limit)
def test_step_tracer(step, expected):
step_tracer = StepTracer()
assert str(step_tracer) == ""
cumulative_step: int = 0
for step_type in StepType:
cumulative_step += step
step_tracer.add(step_type, step, cumulative_step)
assert step_tracer.cumulative_step == cumulative_step
assert str(step_tracer) == expected
# reset
step_tracer.reset()
assert step_tracer.cumulative_step == 0
assert str(step_tracer) == ""
def test_trace(self):
step_tracer = self.step_tracker
assert str(step_tracer) == ""
cumulative_step: int = 0
for step_type in StepType:
step: int = random.randint(0, 100_000)
cumulative_step += step
step_tracer.add(step_type, step, cumulative_step)
assert step_tracer.cumulative_step == cumulative_step
assert len(step_tracer) == len(StepType)
default_step_costs = {
'default': 1_000_000,
'contractCall': 15_000,
'contractCreate': 200_000,
'contractUpdate': 80_000,
'contractDestruct': -70_000,
'contractSet': 30_000,
'get': 0,
'set': 200,
'replace': 50,
'delete': -150,
'input': 200,
'eventLog': 100,
'apiCall': 0
}
default_step_costs = {StepType(key): val for key, val in default_step_costs.items()}
default_max_step_limits: dict = {
IconScoreContextType.INVOKE: 2_500_000_000,
IconScoreContextType.QUERY: 50_000_000
}
default_step_price: int = 0
default_score_black_list: list = []
default_import_white_list = {"iconservice": ['*']}
inv_container = INVContainer(is_migrated=False)
inv_container._icon_network_values = {
IconNetworkValueType.REVISION_CODE: RevisionCode(0),
IconNetworkValueType.SCORE_BLACK_LIST: ScoreBlackList(default_score_black_list),
IconNetworkValueType.STEP_PRICE: StepPrice(default_step_price),
IconNetworkValueType.STEP_COSTS: StepCosts(default_step_costs),
IconNetworkValueType.MAX_STEP_LIMITS: MaxStepLimits(default_max_step_limits),
IconNetworkValueType.SERVICE_CONFIG: ServiceConfig(default_service_config),
governance.STEP_TYPE_CONTRACT_UPDATE: 8000,
governance.STEP_TYPE_CONTRACT_DESTRUCT: -7000,
governance.STEP_TYPE_CONTRACT_SET: 1000,
governance.STEP_TYPE_GET: 5,
governance.STEP_TYPE_SET: 20,
governance.STEP_TYPE_REPLACE: 5,
governance.STEP_TYPE_DELETE: -15,
governance.STEP_TYPE_INPUT: 20,
governance.STEP_TYPE_EVENT_LOG: 10,
governance.STEP_TYPE_API_CALL: 10000
}
step_costs = {}
for key, value in raw_step_costs.items():
try:
step_costs[StepType(key)] = value
except ValueError:
# Pass the unknown step type
pass
# return IconScoreStepCounter(step_costs, 5000000, 0)
return step_costs
score_address = generate_score_address_for_tbears(path)
else:
score_address = generate_score_address(context.tx.origin,
context.tx.timestamp,
context.tx.nonce)
deploy_info = IconScoreContextUtil.get_deploy_info(context, score_address)
if deploy_info is not None:
raise AccessDeniedException(f'SCORE address already in use: {score_address}')
context.step_counter.apply_step(StepType.CONTRACT_CREATE, 1)
else:
# SCORE update
score_address = to
context.step_counter.apply_step(StepType.CONTRACT_UPDATE, 1)
content_size = get_deploy_content_size(context.revision, data.get('content', None))
context.step_counter.apply_step(StepType.CONTRACT_SET, content_size)
context.engine.deploy.invoke(context=context,
to=to,
icon_score_address=score_address,
data=data)
return score_address
elif data_type == 'deposit':
self._deposit_handler.handle_deposit_request(context, data)
else:
context.step_counter.apply_step(StepType.CONTRACT_CALL, 1)
IconScoreEngine.invoke(context, to, data_type, data)
return None
def from_bytes(cls, bytes_: bytes) -> 'StepCosts':
items: list = MsgPackForDB.loads(bytes_)
version: int = items[0]
value: dict = items[1]
converted_value: Dict[StepType, int] = {StepType(key): val for key, val in value.items()}
assert version == 0
return cls(converted_value, need_check_value=False)
Processes the transaction
:param params: JSON-RPC params
"""
# Checks the balance only on the invoke context(skip estimate context)
if context.type == IconScoreContextType.INVOKE:
tmp_context: 'IconScoreContext' = IconScoreContext(IconScoreContextType.QUERY)
tmp_context.block = self._get_last_block()
# Check if from account can charge a tx fee
self._icon_pre_validator.execute_to_check_out_of_balance(
context if context.revision >= Revision.THREE.value else tmp_context,
params,
step_price=context.step_counter.step_price)
# Every send_transaction are calculated DEFAULT STEP at first
context.step_counter.apply_step(StepType.DEFAULT, 1)
input_size = get_input_data_size(context.revision, params.get('data', None))
context.step_counter.apply_step(StepType.INPUT, input_size)
# TODO Branch IISS Engine
if self._check_new_process(params):
if context.revision < Revision.IISS.value:
"""
raise InvalidParamsException(f"Method Not Found")
above code is what I want to raise
but Main Net block sync fail issue happened when it mismatched updating version case.
https://tracker.icon.foundation/transaction/0x76c4c323c6787b2d44565cdaab2a3fc78c37136339a7f0b4faf3fb03fec64939#internaltransactions
so we must change raise contents like that.
"""
context.step_counter.apply_step(StepType.CONTRACT_CALL, 1)
addr_from: "Address",
addr_to: "Address",
amount: int,
func_name: str,
arg_params: Optional[tuple],
kw_params: Optional[dict],
) -> Any:
InternalCall.enter_call(context)
try:
InternalCall._make_trace(
context, addr_from, addr_to, amount, func_name, arg_params, kw_params
)
context.step_counter.apply_step(StepType.CONTRACT_CALL, 1)
context.engine.icx.transfer(context, addr_from, addr_to, amount)
if amount > 0:
InternalCall.emit_event_log_for_icx_transfer(
context, addr_from, addr_to, amount
)
if addr_to.is_contract:
return InternalCall._other_score_call(
context,
addr_from,
addr_to,
amount,
func_name,
arg_params,