Пример #1
0
def main(operation: str, arg: str, val: str) -> Any:

    storage_context = get_context()
    print("context")

    if operation == 'sget':

        return get(arg, storage_context)

    elif operation == 'sput':

        put(arg, val, storage_context)
        return True

    elif operation == 'sdel':

        delete(arg, storage_context)
        return True

    return 'unknown operation'
def Main(key: Union[bytes, str]):
    context = get_context()
    delete(key, context)
Пример #3
0
def put_value_in_storage_read_only(key: str, value: str):
    put(key, value, get_context().as_read_only())
Пример #4
0
def get_value_in_storage_read_only(key: str) -> str:
    return get(key, get_context().as_read_only()).to_str()
Пример #5
0
def main() -> StorageContext:
    return get_context()
Пример #6
0
def Main(key: ByteString):
    context = get_context()
    delete(key, context)
def get_context_is_context() -> bool:
    context = get_context()
    return is_context(context)
Пример #8
0
def Main(key: ByteString) -> bytes:
    context = get_context()
    return get(key, context)
Пример #9
0
def create_map_is_storage_map() -> Any:
    storage_map = get_context().create_map('example_')
    return is_storage_map(storage_map)
Пример #10
0
"""
RC_TOKEN_NAME_PATTERN = f'RC_{COLLATERAL_TOKEN}_{MINT_RATIO}_{PARITY_TOKEN}_{EXPIRY_TIMESTAMP}'
RR_TOKEN_NAME_PATTERN = f'RR_{COLLATERAL_TOKEN}_{MINT_RATIO}_{PARITY_TOKEN}_{EXPIRY_TIMESTAMP}'
"""
'''
FILL this with compiled rToken contract nef and manifest.json!
'''
# rTokenTemplateNef: bytes = open('rToken.nef', 'rb').read()
# rTokenTemplateManifest: str = open('rToken.manifest.json', 'r').read()
rTokenTemplateNef: bytes = b'NEF3neo3-boa by COZ-0.8.1.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfdF\x04\x0c%rToken standard inherited from NEP-17@[A\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\xdb(@\\A\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\xdb!@ZA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\xdb!@W\x00\x01x\xca\x0c\x01\x14\xdb!\xb39xA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\xdb!@W\x02\x04x\xca\x0c\x01\x14\xdb!\xb3y\xca\x0c\x01\x14\xdb!\xb3\xab9z\x10\xb89xA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\xdb!phz\xb5&\x04\x10@xA9Sn<\x98&\rxA\xf8\'\xec\x8c\xaa&\x04\x10@xy\x98z\x10\xb4\xab&Ghz\xb3&\x0fxA\x9b\xf6g\xceA/X\xc5\xed"\x10hz\x9fxA\x9b\xf6g\xceA\xe6?\x18\x84yA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\xdb!qiz\x9eyA\x9b\xf6g\xceA\xe6?\x18\x84zyx\x13\xc0\x0c\x08TransferA\x95\x01oa{zyx4\x04\x11@W\x01\x04y\xd8\xaa&Sy\x11\xc0\x0c\x01\x0f\x0c\x0bgetContract\x0c\x14\xfd\xa3\xfaCF\xeaS*%\x8f\xc4\x97\xdd\xad\xdbd7\xc9\xfd\xffAb}[Rph\xd8\xaa&\x1f{zx\x13\xc0\x1f\x0c\x0eonNEP17PaymentyAb}[RE@W\x03\x02YA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(pA9Sn<h\x97hA\xf8\'\xec\x8c\xac9y\x10\xb795\x8c\xfe\xff\xffqx5\x9c\xfe\xff\xffriy\x9eZA\x9b\xf6g\xceA\xe6?\x18\x84jy\x9exA\x9b\xf6g\xceA\xe6?\x18\x84yx\x0b\x13\xc0\x0c\x08TransferA\x95\x01oa\x0byx\x0b5:\xff\xff\xff@W\x03\x02y\x10\xb79YA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(pA9Sn<h\x97hA\xf8\'\xec\x8c\xac9x50\xfe\xff\xffqiy\xb89iy\x9fxA\x9b\xf6g\xceA\xe6?\x18\x845\x01\xfe\xff\xffrjy\x9fZA\x9b\xf6g\xceA\xe6?\x18\x84y\x0bx\x13\xc0\x0c\x08TransferA\x95\x01oa\x0c\x14Burn rToken by Rulery\x0bx5\xaf\xfe\xff\xff@YA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(A\xf8\'\xec\x8c@W\x00\x03XA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\x0c\x00\x97YA\x9b\xf6g\xceA\x92]\xe81J\xd8&\x07E\x0c\x00\xdb(\x0c\x00\x97\xab5n\xfd\xff\xff\x10\xb3\xab9\x11XA\x9b\xf6g\xceA\xe6?\x18\x84xYA\x9b\xf6g\xceA\xe6?\x18\x84y[A\x9b\xf6g\xceA\xe6?\x18\x84z\\A\x9b\xf6g\xceA\xe6?\x18\x84\x11@W\x00\x03z\x0c\x1dTransfer from caller to Ruler\x98z\x0c\x1dTransfer from Ruler to caller\x98\xab&\x038@V\x05\x0c\x8e\ncan be compiled by neo3-boa==0.8.1\nrTokens are NEP17 tokens, but its token symbol and administrator can be dynamically changed when deployed\nE\x0c\x0cNOT_DEPLOYED`\x0c\x05RULERa\x0c\x0btotalSupplyb\x0c\x0cTOKEN_SYMBOLc\x0c\x0eTOKEN_DECIMALSd@\xcc\xa3\n\xde'
rTokenTemplateManifestPrefix: bytes = b'''{"name":"'''
# rTokenTemplateManifestPrefix + token_symbol + rTokenTemplateManifestSuffix == rTokenManifest
rTokenTemplateManifestSuffix: bytes = b''' ","groups":[],"abi":{"methods":[{"name":"main","offset":0,"parameters":[],"returntype":"String","safe":false},{"name":"symbol","offset":40,"parameters":[],"returntype":"String","safe":false},{"name":"decimals","offset":63,"parameters":[],"returntype":"Integer","safe":false},{"name":"totalSupply","offset":86,"parameters":[],"returntype":"Integer","safe":false},{"name":"balanceOf","offset":109,"parameters":[{"name":"account","type":"Hash160"}],"returntype":"Integer","safe":false},{"name":"transfer","offset":144,"parameters":[{"name":"from_address","type":"Hash160"},{"name":"to_address","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Boolean","safe":false},{"name":"mint","offset":415,"parameters":[{"name":"account","type":"Hash160"},{"name":"amount","type":"Integer"}],"returntype":"Void","safe":false},{"name":"burnByRuler","offset":529,"parameters":[{"name":"account","type":"Hash160"},{"name":"amount","type":"Integer"}],"returntype":"Void","safe":false},{"name":"verify","offset":668,"parameters":[],"returntype":"Boolean","safe":false},{"name":"deploy","offset":694,"parameters":[{"name":"ruler","type":"Hash160"},{"name":"symbol","type":"String"},{"name":"decimals","type":"Integer"}],"returntype":"Boolean","safe":false},{"name":"onNEP17Payment","offset":803,"parameters":[{"name":"from_address","type":"Hash160"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"_initialize","offset":877,"parameters":[],"returntype":"Void","safe":false}],"events":[{"name":"Transfer","parameters":[{"name":"from_addr","type":"Any"},{"name":"to_addr","type":"Any"},{"name":"amount","type":"Integer"}]}]},"permissions":[{"contract":"*","methods":"*"}],"trusts":[],"features":[],"supportedstandards":[],"extra":{"Author":"github.com/Hecate2","Email":"*****@*****.**","Description":"Ruler token prototype; inherited from NEP-17"}}'''
# TODO: run a public contract for users to access standard rToken nef and manifest?

current_storage_context = get_context()

# collaterals: List[UInt160] = []
collaterals = StorageMap(current_storage_context, b'collaterals')
# collateral => minimum collateralizing ratio, paired token default to 1e8

# minColRatioMap: Dict[UInt160, int] = {}
minColRatioMap = StorageMap(current_storage_context, 'minColRatioMap')

# pairs: collateral => pairedToken => expiry => mintRatio => Pair
# pairs: Dict[UInt160, Dict[UInt160, Dict[int, Dict[int, Dict[str, Any]]]]] = {}
pairs_map = StorageMap(current_storage_context, b'pairs')
# get(f'{collateral}{pairedToken}{expiry}{mintRatio}') for the index of a pair
max_pair_index_key = b'max_pair_index'
# pair: Dict[gen_pair_key, Any]; class Pair => attributes
pair_map = StorageMap(current_storage_context,
Пример #11
0
def Main(key: bytes):
    context = get_context()
    value: bytes = b'\x01\x02\x03'
    put(key, value, context)
Пример #12
0
def find_by_prefix(prefix: Union[str, bytes]) -> Iterator:
    context = get_context()
    return find(prefix, context)
from typing import cast

from boa3.builtin import public
from boa3.builtin.interop.contract import GAS, NEO
from boa3.builtin.interop.runtime import executing_script_hash, notify
from boa3.builtin.interop.storage import find, get, get_context, put
from boa3.builtin.type import UInt160

FEE_RECEIVER_KEY = b'FEE_RECEIVER'

feesMap = get_context().create_map('feesMap')


@public
def test_end_while_jump() -> bool:
    iterator = find(b'feesMap')
    fee_receiver = get(FEE_RECEIVER_KEY)
    while iterator.next():
        token_bytes = cast(bytes, iterator.value[0])
        token_bytes = token_bytes[
            7:]  # cut 'feesMap' at the beginning of the bytes
        token = cast(UInt160, token_bytes)
        fee_amount = cast(int, iterator.value[1])
        if fee_amount > 0:
            notify([token, executing_script_hash, fee_receiver, fee_amount])
    return True


@public
def deploy() -> bool:
    # placeholders for testing
Пример #14
0
def Main(key: Union[bytes, str]) -> bytes:
    context = get_context()
    return get(key, context)
Пример #15
0
def find_by_prefix(prefix: ByteString) -> Iterator:
    context = get_context()
    return find(prefix, context)