Example #1
0
def createExchange(token_hash):
    # Ensure token is a contract with nonzero contract hash
    assert (token_hash != ZERO_ADDRESS and len(token_hash) == 20)

    # Ensure templateCode existgetExchange
    templateScript = Get(GetContext(), EXCHANGE_TEMPLATE_KEY)
    assert (len(templateScript) > 0)
    # Make sure the token_hash has not been used to create exchange before
    assert (len(getExchange(token_hash)) == 0)

    tokenCount = Get(GetContext(), TOKEN_COUNT_KEY)

    # Append unused byte code to avm code to produce different contract hash, yet same executable opcode
    newTokenCount = tokenCount + 1
    templateScript = concat(
        templateScript,
        concat(
            concat(concat(GetExecutingScriptHash(), GetCurrentBlockHash()),
                   GetTime()), newTokenCount))

    # Deploy replica contract
    assert (Create(
        templateScript, True, "uniswap_exchange", "1.0", "uniswap_factory",
        "email",
        "uniswap_exchange contract created by uniswap_factory contract"))

    # Invoke the newly deployed contract to set up the token exchange pair
    exchangeHash = AddressFromVmCode(templateScript)
    exchangeAddr = bytearray_reverse(exchangeHash)
    tokenAddr = bytearray_reverse(token_hash)
    assert (DynamicAppCall(exchangeAddr, "setup",
                           [tokenAddr, GetExecutingScriptHash()]))

    # Store the map between token and exchange contract hash
    Put(GetContext(), concat(TOKEN_TO_EXCHANGE_PREFIX, token_hash),
        exchangeAddr)
    Put(GetContext(), concat(EXCHANGE_TO_TOKEN_PREFIX, exchangeHash),
        tokenAddr)

    # Add the token count
    Put(GetContext(), TOKEN_COUNT_KEY, newTokenCount)

    # Map token with token id
    Put(GetContext(), concat(ID_TO_TOKEN_PREFIX, newTokenCount), tokenAddr)

    # Fire the event
    NewExchangeEvent(tokenAddr, exchangeAddr)
    return True
Example #2
0
def Main(op):
    if op == "Hash":
        Hash()
        return True
    if op == "Constant":
        Constant()
        return True
    a = GetEntryScriptHash() + GetExecutingScriptHash()
    Notify(a)
    return False
def transferOngToContract(account, ongAmount):
    selfContractAddress = GetExecutingScriptHash()
    Notify(["111_transferOngToContract", selfContractAddress])
    param = state(account, selfContractAddress, ongAmount)
    ongContractAddress = ToScriptHash("AFmseVrdL9f9oyCzZefL9tG6UbvhfRZMHJ")
    res = Invoke(0, ongContractAddress, 'transfer', [param])
    if res and res == b'\x01':
        Notify('transfer succeed')
        return True
    else:
        Notify('transfer failed')

        return False
def cannotAvoidContractCallAttack(guessNumber):

    randomNumber = getRandomNumber()

    callerHash = GetCallingScriptHash()
    #Developers are wrong
    entryHash = GetExecutingScriptHash()
    Notify(["randomNumber:", randomNumber, "guessNumber:", guessNumber])
    #Never equal
    VaasRequire(callerHash == entryHash)
    if guessNumber == randomNumber:
        Notify(["You have won the big prize!"])
        return True
    return False
def balanceOf2():
    """
    transfer ONG from contract
    :param acct:
    :return:
    """
    # return ongContract("balanceOf", [acct])
    # return True

    # ONT native contract address
    # contractAddress = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02')
    ongContractAddress = ToScriptHash("AFmseVrdL9f9oyCzZefL9tG6UbvhfRZMHJ")
    param = state(GetExecutingScriptHash())
    res = Invoke(0, ongContractAddress, 'balanceOf', param)

    # res = ONGContract("balanceOf", [acct])

    return res
def init():
    """
    initialize the contract, init contract meta data, call xshard asset contract register function
    :return:
    """

    if len(OWNER) != 20:
        Notify(["Owner illegal!"])
        return False
    allShard = True
    frozen = False
    shardId = 0
    ContractAddress = GetExecutingScriptHash()
    res = InitMetaData(OWNER, allShard, frozen, shardId, [ContractAddress])
    assert (res)
    param = state(TOTAL_AMOUNT * FACTOR, OWNER)
    registerRes = Invoke(SHARD_VERSION, XSHARD_ASSET_ADDR, 'oep4Register',
                         param)
    assert (registerRes)
    shardId = GetShardId()
    Notify(["Register success, current shard", shardId])
Example #7
0
from ontology.interop.Ontology.Contract import Migrate
from ontology.interop.System.Action import RegisterAction
from ontology.interop.Ontology.Runtime import Base58ToAddress
from ontology.interop.System.Storage import Put, GetContext, Get, Delete
from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash
from ontology.interop.System.Runtime import CheckWitness, Notify, Serialize, Deserialize
from ontology.builtins import concat, state
from ontology.libont import bytearray_reverse
from ontology.interop.System.App import RegisterAppCall, DynamicAppCall

ZERO_ADDRESS = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
ONT_ADDRESS = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
ONG_ADDRESS = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02')
CROSS_CHAIN_CONTRACT_ADDRESS = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09')
CONTRACT_ADDRESS = GetExecutingScriptHash()
ctx = GetContext()

NAME = 'OEP4-Skip-LockProxy'
SYMBOL = 'OEP4SL'
DECIMALS = 18

PAUSED = 'p1'
INITIALIZED = "p2"
TOTAL_SUPPLY_KEY = 'p3'
SUPPLY_CONTROLLER_KEY = 'p4'
OWNER_KEY = 'p5'
BALANCE_KEY = 'p6'
APPROVE_KEY = 'p7'

ASSET_HASH = "Asset"
Example #8
0
from ontology.interop.System.App import DynamicAppCall
from ontology.libont import AddressFromVmCode

ZERO_ADDRESS = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
)
ONT_ADDRESS = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
)
ONG_ADDRESS = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02'
)
CROSS_CHAIN_CONTRACT_ADDRESS = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09'
)
CONTRACT_ADDRESS = GetExecutingScriptHash()

PROXY_HASH = "ProxyHash"
ASSET_HASH = "Asset"
OPERATOR_PREFIX = "Operator"

FROM_ASSET_LIST_KEY = "FromAssetList"

Operator = Base58ToAddress('AdzZ2VKufdJWeB8t9a8biXoHbbMe2kZeyH')

UnlockEvent = RegisterAction("unlock", "toAssetHash", "toAddress", "amount")
LockEvent = RegisterAction("lock", "fromAssetHash", "toChainId", "toAssetHash",
                           "fromAddress", "toAddress", "amount")

SelfContractAddress = GetExecutingScriptHash()
Example #9
0
OntCversion = '2.0.0'
from ontology.interop.Ontology.Contract import Migrate
from ontology.interop.System.Storage import GetContext, Get, Put, Delete
from ontology.interop.System.Runtime import CheckWitness, GetTime, Notify
from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash, GetScriptContainer
from ontology.interop.Ontology.Native import Invoke
from ontology.interop.Ontology.Runtime import GetCurrentBlockHash, Base58ToAddress
from ontology.builtins import concat, state, sha256
from ontology.interop.System.App import DynamicAppCall

# ONGAddress = Base58ToAddress("HJZMfRvhUbG69tfLZeCzoyf9L9rdeVmsAF") # service execute error!: wrong encoded address
ONGAddress = Base58ToAddress("AFmseVrdL9f9oyCzZefL9tG6UbvhfRZMHJ") # Get contract code from db fail
# bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02') # Get contract code from db fail
# ONGAddress = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02')

MyAddress = GetExecutingScriptHash()

ONGMagnitude = 1000000000
OEP4TokenMagnitude = 100000000
Fee = 1000000

DaySeconds = 86400

Admin = Base58ToAddress('AHBSnEnABx9kTWHDmTZ6CDxekfVUpCmHR7')
OEP4_CONTRACT_HASH_KEY = "Key1"
PLAYER_LAST_CHECK_IN_DAY = "Key2"

def Main(operation, args):
    if operation == "setOEP4ContractHash":
        assert (len(args) == 1)
        reversedContractHash = args[0]
Example #10
0
def testbytearray(addr):
    assert (GetExecutingScriptHash() == addr)
    assert (len(addr) == 20)
    return addr
Example #11
0
AM_PREFIX = 'AM'  # against map
FL_PREFIX = 'FL'  # for list
AL_PREFIX = 'AL'  # against list
VAL_PREFIX = 'VAL'  # val list for each bet
ST_PREFIX = 'ST'  # stock_ticker
BL_PREFIX = 'BL'  # bets a user has participated in
RC_PREFIX = 'RC'  # user's track record
PT_PREFIX = 'PT'  # user's profit per bet
BT_PREFIX = 'BT'  # bet prefix for track record storage
AB_PREFIX = 'AB'  # bet prefix for active bets
PI_PREFIX = 'PI'  # profile information

ctx = GetContext()
AES_FACTOR = 100000000
ONG_FACTOR = 1000000000
contract_address = GetExecutingScriptHash()
contract_address_ONG = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02'
)

# call OEP4 contract for transfer of tokens
RepContract = RegisterAppCall('7f0ac00575b34c1f8a4fd4641f6c58721f668fd4',
                              'operation', 'args')
token_owner = 'ANXE3XovCwBH1ckQnPc6vKYiTwRXyrVToD'


def Main(operation, args):
    if operation == 'init':
        return init()

    if operation == 'aes_supply':
Example #12
0
from ontology.libont import bytearray_reverse
# bb7513b23fae0117eae21eea2cd732e1cc267e7e
AMOUNT_OVERRIDE = 0

SENDER_OVERRIDE = 0

ARGS_VERSION = 1

REQUEST_COUNT = "RequestCount"

ORACLE_ADDRESS = "oracle"
LINK_ADDRESS = "link"

PENDING_REQUESTS_PREFIX = "pendingRequests"

contractHash = GetExecutingScriptHash()

ChainlinkRequestedEvent = RegisterAction("chainlinkRequestedEvent", "requestId")

ChainlinkFulfilledEvent = RegisterAction("chainlinkFulfilledEvent", "requestId")

ChainlinkCancelledEvent = RegisterAction("chainlinkCancelledEvent", "requestId")

ChainlinkCall = RegisterAppCall('db6f26fb0f217d6762aa3d6d38e827789a3128d1', 'operation', 'args')

OWNER = Base58ToAddress("AbG3ZgFrMK6fqwXWR1WkQ1d1EYVunCwknu")

def Main(operation, args):
    if operation == 'buildChainlinkRequest':
        assert (len(args) == 3)
        _specId = args[0]
Example #13
0
def Hash():
    a = GetEntryScriptHash() + GetExecutingScriptHash()
    Notify(a)
    return False
UNLOCK_HASH_PERFIX = "Unlock"

EIO_ADDRESS = Base58ToAddress("APT362oHqpVMMa7tKcPbQA6VoGUJ1i9uuk")
PRESALE_ADDRESS = Base58ToAddress("AGFxBrm8MwPrzYLW6fB7vSXumhZMcJeVxQ")
REFERRAL_ADDRESS = Base58ToAddress("AbNifuJegzS6UiHAtwcPi4xy93cbRpYv5D")
TEAM_ADDRESS = Base58ToAddress("AVrN4QvcSLwtoXy925JmtAEebZ3wVDqcr9")

TEAMLOCK_END = [
    1569888000,  # 1 October 2019 0:00:00 GMT
    1601510400,  # 1 October 2020 0:00:00 GMT
    1633046400,  # 1 October 2021 0:00:00 GMT
    1664582400,  # 1 October 2022 0:00:00 GMT
    1696118400  # 1 October 2023 0:00:00 GMT
]

SELF_ADDRESS = GetExecutingScriptHash()


def Main(operation, args):
    """
    :param operation:
    :param args:
    :return:
    """
    # 'init' has to be invokded first after deploying the contract to store the necessary and important info in the blockchain
    if operation == 'init':
        return init()
    if operation == 'name':
        return name()
    if operation == 'symbol':
        return symbol()
admin = Base58ToAddress('AQf4Mzu1YJrhz9f3aRkkwSm9n3qhXGSh4p')

NAME = 'My Non-Fungibles Token'
SYMBOL = 'MNFT'

OWNER_BALANCE_PREFIX = 'Balance'
OWNER_OF_TOKEN_PREFIX = 'OwnerOf'
APPROVE_PREFIX = 'Approve'
TOKEN_ID_PREFIX = 'TokenID'
# TOKEN_INDEX_PREFIX, INITED, and TOTAL_SUPPLY for testing usage only
TOKEN_INDEX_PREFIX = 'Index'
TOTAL_SUPPLY = 'TotalSupply'
INITED = 'Initialized'

ctx = GetContext()
selfAddr = GetExecutingScriptHash()


def Main(operation, args):
    if operation == 'name':
        return name()
    if operation == 'symbol':
        return symbol()
    if operation == 'balanceOf':
        if len(args) != 1:
            return False
        owner = args[0]
        return balanceOf(owner)
    if operation == 'ownerOf':
        if len(args) != 1:
            return False
from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash, GetScriptContainer
from ontology.interop.Ontology.Native import Invoke
from ontology.interop.Ontology.Runtime import Base58ToAddress, GetCurrentBlockHash
from ontology.builtins import concat, state, sha256, len, append
from ontology.interop.System.Transaction import GetTransactionHash
from ontology.libont import str, AddressFromVmCode
from ontology.interop.System.Action import RegisterAction
from ontology.interop.System.Blockchain import GetHeight, GetHeader, GetBlock

ONTAddress = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
)
ONGAddress = bytearray(
    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02'
)
SelfContractAddress = GetExecutingScriptHash()

Admin = Base58ToAddress("AQf4Mzu1YJrhz9f3aRkkwSm9n3qhXGSh4p")

PLAYER_LAST_CHECK_IN_DAY = bytearray(b'\x01')
DaySeconds = 86400


def Main(operation, args):
    if operation == "deposit":
        assert (len(args) == 4)
        address = args[0]
        amount = args[1]
        ongOrOnt = args[2]
        userId = args[3]
        return deposit(address, amount, ongOrOnt, userId)
OntCversion = '2.0.0'
from ontology.interop.System.App import RegisterAppCall, DynamicAppCall
from ontology.interop.System.Runtime import Log, Notify
from ontology.interop.System.ExecutionEngine import GetExecutingScriptHash

CallContract = RegisterAppCall('ebe0ff4ee0524c2dabcd1331c3c842896bf40b97',
                               'operation', 'args')
selfContractAddr_ = GetExecutingScriptHash()

# input = b'\x33...\xb1''
# b16e976491982ddccd195dd73bd952a423a5e833

NAME = "Dynamic"


def Main(operation, args):
    if operation == "DynamicCallContract":
        if len(args) != 3:
            return False
        revesedContractAddress = args[0]
        opt = args[1]
        params = args[2]
        return DynamicCallContract(revesedContractAddress, opt, params)
    if operation == "StaticCallContract":
        opt = args[0]
        params = args[1]
        return StaticCallContract(opt, params)

    if operation == "getName":
        return getName()