-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#86dthh0zp - Update native PolicyContract
- Loading branch information
luc10921
committed
May 16, 2024
1 parent
49731b6
commit 50bf881
Showing
13 changed files
with
220 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
__all__ = ['GetExecFeeFactorMethod', | ||
'GetFeePerByteMethod', | ||
'GetStoragePriceMethod', | ||
'IsBlockedMethod' | ||
] | ||
__all__ = [ | ||
'GetAttributeFeeMethod', | ||
'GetExecFeeFactorMethod', | ||
'GetFeePerByteMethod', | ||
'GetStoragePriceMethod', | ||
'IsBlockedMethod', | ||
'SetAttributeFeeMethod', | ||
'TransactionAttributeType', | ||
] | ||
|
||
from boa3.internal.model.builtin.interop.policy.getattributefeemethod import GetAttributeFeeMethod | ||
from boa3.internal.model.builtin.interop.policy.getexecfeefactormethod import GetExecFeeFactorMethod | ||
from boa3.internal.model.builtin.interop.policy.getfeeperbytemethod import GetFeePerByteMethod | ||
from boa3.internal.model.builtin.interop.policy.getstoragepricemethod import GetStoragePriceMethod | ||
from boa3.internal.model.builtin.interop.policy.isblockedmethod import IsBlockedMethod | ||
from boa3.internal.model.builtin.interop.policy.setattributefeemethod import SetAttributeFeeMethod | ||
from boa3.internal.model.builtin.interop.policy.transactionattributetype import TransactionAttributeType |
15 changes: 15 additions & 0 deletions
15
boa3/internal/model/builtin/interop/policy/getattributefeemethod.py
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 boa3.internal.model.builtin.interop.nativecontract import PolicyContractMethod | ||
from boa3.internal.model.builtin.interop.policy.transactionattributetype import TransactionAttributeType | ||
from boa3.internal.model.variable import Variable | ||
|
||
|
||
class GetAttributeFeeMethod(PolicyContractMethod): | ||
|
||
def __init__(self, tx_attribute_type: TransactionAttributeType): | ||
from boa3.internal.model.type.type import Type | ||
identifier = 'get_attribute_fee' | ||
native_identifier = 'getAttributeFee' | ||
args: dict[str, Variable] = { | ||
'attribute_type': Variable(tx_attribute_type) | ||
} | ||
super().__init__(identifier, native_identifier, args, return_type=Type.int) |
16 changes: 16 additions & 0 deletions
16
boa3/internal/model/builtin/interop/policy/setattributefeemethod.py
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,16 @@ | ||
from boa3.internal.model.builtin.interop.nativecontract import PolicyContractMethod | ||
from boa3.internal.model.builtin.interop.policy.transactionattributetype import TransactionAttributeType | ||
from boa3.internal.model.variable import Variable | ||
|
||
|
||
class SetAttributeFeeMethod(PolicyContractMethod): | ||
|
||
def __init__(self, tx_attribute_type: TransactionAttributeType): | ||
from boa3.internal.model.type.type import Type | ||
identifier = 'set_attribute_fee' | ||
native_identifier = 'setAttributeFee' | ||
args: dict[str, Variable] = { | ||
'attribute_type': Variable(tx_attribute_type), | ||
'value': Variable(Type.int), | ||
} | ||
super().__init__(identifier, native_identifier, args, return_type=Type.none) |
51 changes: 51 additions & 0 deletions
51
boa3/internal/model/builtin/interop/policy/transactionattributetype.py
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,51 @@ | ||
from typing import Any | ||
|
||
from boa3.internal.model.symbol import ISymbol | ||
from boa3.internal.model.type.itype import IType | ||
from boa3.internal.model.type.primitive.inttype import IntType | ||
from boa3.internal.neo3.network.payloads.transactionattributetype import TransactionAttributeType as TransactionAttribute | ||
|
||
|
||
class TransactionAttributeType(IntType): | ||
""" | ||
A class used to represent Neo TransactionAttributeType | ||
""" | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self._identifier = 'TransactionAttributeType' | ||
|
||
@classmethod | ||
def build(cls, value: Any) -> IType: | ||
if cls._is_type_of(value): | ||
from boa3.internal.model.builtin.interop.interop import Interop | ||
return Interop.TransactionAttributeType | ||
|
||
@classmethod | ||
def _is_type_of(cls, value: Any): | ||
return isinstance(value, (TransactionAttribute, TransactionAttributeType)) | ||
|
||
@property | ||
def symbols(self) -> dict[str, ISymbol]: | ||
""" | ||
Gets the class symbols of this type | ||
:return: a dictionary that maps each symbol in the module with its name | ||
""" | ||
from boa3.internal.model.variable import Variable | ||
|
||
_symbols = super().symbols | ||
_symbols.update({name: Variable(self) for name in TransactionAttribute.__members__.keys()}) | ||
|
||
return _symbols | ||
|
||
def get_value(self, symbol_id) -> Any: | ||
""" | ||
Gets the literal value of a symbol | ||
:return: the value if this type has this symbol. None otherwise. | ||
""" | ||
if symbol_id in self.symbols: | ||
return TransactionAttribute.__members__[symbol_id] | ||
|
||
return None |
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
35 changes: 35 additions & 0 deletions
35
boa3/internal/neo3/network/payloads/transactionattributetype.py
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,35 @@ | ||
from enum import IntFlag | ||
|
||
|
||
class TransactionAttributeType(IntFlag): | ||
""" | ||
Represents the TransactionAttributeType for running smart contracts. | ||
""" | ||
|
||
HIGH_PRIORITY = 0x01 | ||
""" | ||
Indicates that the transaction is of high priority. | ||
:meta hide-value: | ||
""" | ||
|
||
ORACLE_RESPONSE = 0x11 | ||
""" | ||
Indicates that the transaction is an oracle response | ||
:meta hide-value: | ||
""" | ||
|
||
NOT_VALID_BEFORE = 0x20 | ||
""" | ||
Indicates that the transaction is not valid before height. | ||
:meta hide-value: | ||
""" | ||
|
||
CONFLICTS = 0x21 | ||
""" | ||
Indicates that the transaction conflicts with hash. | ||
:meta hide-value: | ||
""" |
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,8 @@ | ||
from boa3.sc.compiletime import public | ||
from boa3.sc.contracts import PolicyContract | ||
from boa3.sc.types import TransactionAttributeType | ||
|
||
|
||
@public | ||
def main(tx_att: TransactionAttributeType) -> int: | ||
return PolicyContract.get_attribute_fee(tx_att) |
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,13 @@ | ||
from boa3.sc.compiletime import public | ||
from boa3.sc.contracts import PolicyContract | ||
from boa3.sc.types import TransactionAttributeType | ||
|
||
|
||
@public | ||
def main(tx_att: TransactionAttributeType, value: int): | ||
PolicyContract.set_attribute_fee(tx_att, value) | ||
|
||
|
||
@public | ||
def get_tx_attr(tx_att: TransactionAttributeType) -> int: | ||
return PolicyContract.get_attribute_fee(tx_att) |
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