Skip to content

Commit

Permalink
Fix fee of CreateMultisigAccount neo-project/neo#2712 & neo-project/n…
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Jun 27, 2022
1 parent 2d57959 commit cf4dfe1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
17 changes: 16 additions & 1 deletion neo3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import importlib
import binascii
from enum import Enum, auto
from typing import List
from types import SimpleNamespace
from neo3.core import cryptography
Expand Down Expand Up @@ -46,13 +47,24 @@ def __len__(self):
def __getitem__(self, key):
return self.__dict__[key]

def __contains__(self, key):
try:
self.__dict__[key]
return True
except KeyError:
return False

def get(self, key, default=None):
try:
return self.__dict__[key]
except KeyError:
return default


class HardFork(Enum):
HF_2712_FIX_SYSCALL_FEES = auto()


class Settings(IndexableNamespace):
db = None
_cached_standby_committee = None
Expand All @@ -62,7 +74,10 @@ class Settings(IndexableNamespace):
'account_version': 53,
'seedlist': [],
'validators_count': 1,
'standby_committee': ['02158c4a4810fa2a6a12f7d33d835680429e1a68ae61161c5b3fbc98c7f1f17765']
'standby_committee': ['02158c4a4810fa2a6a12f7d33d835680429e1a68ae61161c5b3fbc98c7f1f17765'],
'hardforks': {
HardFork.HF_2712_FIX_SYSCALL_FEES.name: 2000000
}
},
'storage': {
'use_default': True,
Expand Down
9 changes: 8 additions & 1 deletion neo3/contracts/applicationengine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from neo3 import contracts, storage, vm
from neo3 import contracts, storage, vm, HardFork, settings
from neo3.network import payloads
from neo3.core import types, cryptography, IInteroperable, serialization, to_script_hash
from typing import Any, Dict, cast, List, Tuple, Type, Optional, Union
Expand Down Expand Up @@ -485,3 +485,10 @@ def _native_to_stackitem(self, value, native_type) -> vm.StackItem:
return _struct
else:
return vm.StackItem.from_interface(value)

def _is_hardfork_enabled(self, hf: HardFork) -> bool:
if self.snapshot and self.snapshot.persisting_block is None:
return True
if hf.name not in settings.network.hardforks:
return True
return self.snapshot.persisting_block.index >= settings.network.hardforks[hf.name]
15 changes: 12 additions & 3 deletions neo3/contracts/interop/contract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations
from typing import List
from neo3 import vm, contracts
from neo3 import vm, contracts, HardFork
from neo3.core import cryptography, types, to_script_hash
from neo3.contracts.interop import register
from neo3.contracts.interop.crypto import CHECKSIG_PRICE


@register("System.Contract.Call", 1 << 15, contracts.CallFlags.READ_STATES | contracts.CallFlags.ALLOW_CALL)
Expand Down Expand Up @@ -34,16 +35,24 @@ def get_callflags(engine: contracts.ApplicationEngine) -> contracts.CallFlags:
return contracts.CallFlags(engine.current_context.call_flags)


@register("System.Contract.CreateStandardAccount", 1 << 8, contracts.CallFlags.NONE)
@register("System.Contract.CreateStandardAccount", 0, contracts.CallFlags.NONE)
def contract_create_standard_account(engine: contracts.ApplicationEngine,
public_key: cryptography.ECPoint) -> types.UInt160:
fee = 1 << 8
if engine._is_hardfork_enabled(HardFork.HF_2712_FIX_SYSCALL_FEES):
fee = CHECKSIG_PRICE
engine.add_gas(fee * engine.exec_fee_factor)
return to_script_hash(contracts.Contract.create_signature_redeemscript(public_key))


@register("System.Contract.CreateMultisigAccount", 1 << 8, contracts.CallFlags.NONE)
@register("System.Contract.CreateMultisigAccount", 0, contracts.CallFlags.NONE)
def contract_create_multisigaccount(engine: contracts.ApplicationEngine,
m: int,
public_keys: List[cryptography.ECPoint]) -> types.UInt160:
fee = 1 << 8
if engine._is_hardfork_enabled(HardFork.HF_2712_FIX_SYSCALL_FEES):
fee = CHECKSIG_PRICE * len(public_keys)
engine.add_gas(fee * engine.exec_fee_factor)
return to_script_hash(contracts.Contract.create_multisig_redeemscript(m, public_keys))


Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/interop/test_contract_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_contract_call_flags(self):

def test_contract_create_standard_account(self):
keypair = cryptography.KeyPair(b'\x01' * 32)
engine = test_engine()
engine = test_engine(has_snapshot=True)
engine.push(vm.ByteStringStackItem(keypair.public_key.to_array()))
engine.invoke_syscall_by_name("System.Contract.CreateStandardAccount")
engine.execute()
Expand Down

0 comments on commit cf4dfe1

Please sign in to comment.