Example #1
0
def CheckHashExist(args):
    if len(args) != 1:
        return False

    inputHash = args[0]
    exist = Get(GetContext(), inputHash)
    return exist + 0
Example #2
0
def cancelRequest(requestId, payment, callBackFunc, expiration):
    assert (CheckWitness(OWNER))
    chainlinkClient = Get(GetContext(), CHAINLINK_CLIENT)
    assert (DynamicCallFunction(
        bytearray_reverse(chainlinkClient), 'cancelChainlinkRequest',
        [OWNER, requestId, payment, callBackFunc, expiration]))
    return True
Example #3
0
def setFeePercentage(feePercentage):
    RequireWitness(Operater)
    Require(feePercentage <= 100)
    Require(feePercentage >= 0)
    Put(GetContext(), FEE_PERCENTAGE_KEY, feePercentage)
    Notify(["setFeePercentage", feePercentage])
    return True
def init(_caller, _cut):
    ctx = GetContext()
    Put(ctx, INIT, 'TRUE')
    Put(ctx, _cut, 'TRUE')
    _cut = _concatkey(_caller, _cut)
    Put(ctx, _cut, 'TRUE')
    return True
Example #5
0
def approve(owner, spender, tokenId, amount):
    """
    approve amount of the tokenId token to toAcct address, it can overwrite older approved amount
    :param owner:
    :param spender:
    :param tokenId:
    :param amount:
    :return:
    """
    assert (_whenNotPaused())
    # make sure the invoker is the owner address
    assert (CheckWitness(owner))
    # make sure the address is legal
    assert (len(spender) == 20)
    assert (_tokenExist(tokenId))

    ownerBalance = balanceOf(owner, tokenId)
    # you can use "if" to notify the corresponding message, or use assert to raise exception
    assert (ownerBalance >= amount)
    assert (amount > 0)
    key = _concatkey(_concatkey(_concatkey(APPROVE_PREFIX, tokenId), owner), spender)
    Put(GetContext(), key, amount)

    ApprovalEvent(owner, spender, tokenId, amount)

    return True
def approve(owner, spender, tokenId, amount):
    """
    approve amount of the tokenId token to toAcct address, it can overwrite older approved amount
    :param owner:
    :param spender:
    :param tokenId:
    :param amount:
    :return:
    """
    res = int(owner)
    RequireWitness(owner)
    RequireScriptHash(owner)
    RequireScriptHash(spender)
    Require(checkTokenId(tokenId))

    ownerBalance = balanceOf(owner, tokenId)
    # you can use "if" to notify the corresponding message, or use Require to raise exception
    Require(ownerBalance >= amount)
    Require(amount > 0)
    key = concatkey(concatkey(concatkey(tokenId, APPROVE), owner), spender)
    Put(GetContext(), key, amount)

    ApprovalEvent(owner, spender, tokenId, amount)

    return True
def balanceOf(account):
    """
    :param account:
    :return: the token balance of account
    """
    assert (len(account) == 20)
    return Get(GetContext(), concat(BALANCE_PREFIX, account))
Example #8
0
def getDiskIdList(gameId):
    diskIdListInfo = Get(GetContext(),
                         concatKey(GAME_DISKID_LIST_PREFIX, gameId))
    if not diskIdListInfo:
        return []
    else:
        return Deserialize(diskIdListInfo)
Example #9
0
def canPlaceBet(gameId):
    """
    :param gameId:
    :return: False means can NOT place bets, True means CAN place bets.
    """
    return GetTime() < Get(GetContext(),
                           concatKey(GAME_BET_ENDTIME_PREFIX, gameId))
Example #10
0
def transferOwnership(newOwner):
    oldOwner = getOwner()
    assert (CheckWitness(oldOwner))
    assert (len(newOwner) == 20 and newOwner != ZERO_ADDRESS)
    Put(GetContext(), OWNER_KEY, newOwner)
    TransferOwnershipEvent(oldOwner, newOwner)
    return True
Example #11
0
def resetGameBetEndTime(gameId, newBetEndTime):
    RequireWitness(Operater)
    Require(getGameBetEndTime(gameId) > 0)
    Put(GetContext(), concatKey(GAME_BET_ENDTIME_PREFIX, gameId),
        newBetEndTime)
    Notify(["resetBetEndTime", gameId, newBetEndTime])
    return True
Example #12
0
def setDev1Percentage(dev1Percentage):
    RequireWitness(Dev1)
    Require(dev1Percentage <= 100)
    Require(dev1Percentage >= 0)
    Put(GetContext(), DEV1_PERCENTAGE_KEY, dev1Percentage)
    Notify(["setDev1Percentage", dev1Percentage])
    return True
Example #13
0
def fulfill(requestId, price):
    assert (ChainlinkClientCall(
        'recordChainlinkFulfillment',
        [bytearray_reverse(GetCallingScriptHash()), requestId]))
    # Notify(['test'])
    Put(GetContext(), CURRENT_PRICE, price)
    return True
Example #14
0
def getContractAddrWithChainId(toChainId):
    """
    return the asset contract hash of btc in 'toChainId' blockchain
    :param toChainId: this parameter is in integer format
    :return: the asset contract hash of btc in 'toChainId' blockchain, returned value is in hex format
    """
    return Get(GetContext(), concat(CONTRACT_HASH, toChainId))
Example #15
0
def oracleRequest(spender, payment, specId, callbackAddress,
                  callbackFunctionId, nonce, dataVersion, data,
                  callFunctionId):
    onlyLINK()
    RequireWitness(spender)
    payment = payment + 0
    # TODO
    requestId = sha256(Serialize([callbackAddress, spender, nonce]))
    assert (not Get(GetContext(), concatKey(COMMITMENTS_PRIFX, requestId)))
    expiration = GetTime() + EXPIRY_TIME
    Put(GetContext(), concatKey(COMMITMENTS_PRIFX, requestId),
        Serialize([payment, callbackAddress, callbackFunctionId, expiration]))
    OracleRequestEvent(specId, spender, requestId, payment, callbackAddress,
                       callbackFunctionId, expiration, dataVersion, data,
                       callFunctionId)
    return True
Example #16
0
def StoreUsedNum(args):
    if len(args) != 3:
        return False

    addr = Get(GetContext(), KeyOwnerAddress)
    assert (len(addr) != 0)
    assert (CheckWitness(addr))

    userId = args[0]
    orderId = args[1]
    usedNum = args[2]
    t = concat(KeyPrefix, userId)
    KEY = concat(t, orderId)

    Put(GetContext(), KEY, usedNum)
    Notify([userId, orderId, usedNum])
    return True
Example #17
0
def balanceOf(acct, tokenId):
    """
    get balance of account in terms of token with the tokenId
    :param acct: used to check the acct balance
    :param tokenId: the tokenId determines which token balance of acct needs to be checked
    :return: the balance of acct in terms of tokenId tokens
    """
    return Get(GetContext(), _concatkey(_concatkey(BALANCE_PREFIX, tokenId), acct))
def burn(amount):
    """
    Burns the amount of Minglechain token from the owner's address.
    :param _amount: MC amount to burn.
    """
    # only owner can burn the token
    assert (CheckWitness(OWNER))
    ownerBalance = balanceOf(OWNER)
    total = totalSupply()
    assert (total >= amount and ownerBalance >= amount and amount >= 0)
    newTotal = total - amount
    # update total supply
    Put(GetContext(), SUPPLY_KEY, newTotal)
    # update the owner's balance
    Put(GetContext(), concat(BALANCE_PREFIX, OWNER), ownerBalance - amount)
    TransferEvent(OWNER, "", amount)
    return True
def init(_caller, _cut):
    ctx = GetContext()
    Put(ctx, _cut, 'TRUE')
    _cut = _concatkey(_caller, _cut)
    Put(ctx, _cut, 1)
    a = Get(ctx, _cut)
    c = 20 / a
    return True
Example #20
0
def setFeeCollector(feeCollector):
    """
    :param feeCollector: address
    :return:
    """
    assert (CheckWitness(getOwner()))
    Put(GetContext(), FEE_COLLECTOR_KEY, feeCollector)
    return True
Example #21
0
def init():
    # init list
    list1 = [1,2,3]
    list1Info = Serialize(list1)
    Put(GetContext(), LISTKEY, list1Info)
    # init map
    map1 = {
        "key1":1,
        "key2":2
    }
    map1Info = Serialize(map1)
    Put(GetContext(), MAPKEY, map1Info)

    Notify(["init list is ",list1])
    Notify(["init map is ", map1["key1"], map1["key2"]])

    return True
def checkIn(address, userId):
    assert (CheckWitness(address))
    checkInDays = canCheckIn(address)
    assert (checkInDays > 0)
    Put(GetContext(), concat(PLAYER_LAST_CHECK_IN_DAY, address), checkInDays)

    Notify(["checkIn", address, userId, GetTime()])
    return True
Example #23
0
def setLockProxy(lockProxy):
    """
    :param lockProxy: ont lock proxy
    :return:
    """
    assert (CheckWitness(getOwner()))
    Put(GetContext(), LOCK_PROXY_KEY, bytearray_reverse(lockProxy))
    return True
Example #24
0
def getSaltAfterEnd(gameId):
    """
    can only get game's salt after end
    :param gameId: game's id
    :return: salt number
    """
    salt = Get(GetContext(), concatKey(gameId, GAME_SALT_KEY))
    return salt
Example #25
0
def removeAuthorizedLevel(account):
    RequireWitness(CEOAddress)
    Require(len(account) == 20)
    # make sure account is authorized before.
    Require(isAuthorizedLevel(account))
    Delete(GetContext(), _concatkey(AUTHORIZED_LEVEL_PREFIX, account))
    Notify(["removeAuthorizedLevel", account])
    return True
Example #26
0
def getDiskPlayersList(diskId, betStatus):
    playersListInfo = Get(
        GetContext(),
        concatKey(concatKey(DISK_BET_PLAYER_LIST_PREFIX, diskId), betStatus))
    if not playersListInfo:
        return []
    else:
        return Deserialize(playersListInfo)
Example #27
0
def fulfillOracleRequest(node, requestId, payment, callbackAddress,
                         callbackFunctionId, expiration, data):
    RequireWitness(node)
    onlyAuthorizedNode(node)
    expiration = expiration + 0
    payment = payment + 0
    paramsHash = Serialize(
        [payment, callbackAddress, callbackFunctionId, expiration])
    assert (Get(GetContext(), concatKey(COMMITMENTS_PRIFX,
                                        requestId)) == paramsHash)

    Put(GetContext(), WITHDRAWABLETOKENS,
        Get(GetContext(), WITHDRAWABLETOKENS) + payment)
    Delete(GetContext(), concatKey(COMMITMENTS_PRIFX, requestId))
    assert (callBackFunction(callbackAddress, callbackFunctionId, requestId,
                             data))
    return True
Example #28
0
def updateState(stateRootHash, height, version, depositIds, withdrawAmounts,
                toAddresses, assetAddresses):
    operator = Get(GetContext(), OPERATOR_ADDRESS)
    assert (CheckWitness(operator))
    preHeight = Get(GetContext(), CURRENT_HEIGHT)
    assert (preHeight + 1 == height)

    Put(GetContext(), CURRENT_HEIGHT, height)
    stateRoot = [stateRootHash, height, version]
    stateRootInfo = Serialize(stateRoot)
    Put(GetContext(), concatKey(Current_STATE_PREFIX, height), stateRootInfo)
    # 返回满足条件用户的钱
    currentWithDrawId = Get(GetContext(), CURRENT_WITHDRAW_ID)
    confirmHeight = Get(GetContext(), CONFRIM_HEIGHT)
    if currentWithDrawId:
        while currentWithDrawId > 1:
            withdrawStatusInfo = Get(
                GetContext(), concatKey(WITHDRAW_PREFIX,
                                        currentWithDrawId - 1))
            withdrawStatus = Deserialize(withdrawStatusInfo)
            if (height - withdrawStatus[3] == confirmHeight):
                assert (withdraw(withdrawStatus[0]))
            elif height - withdrawStatus[3] > confirmHeight:
                break
            currentWithDrawId = currentWithDrawId - 1
    # 更新deposit状态
    _updateDepositState(depositIds)
    # 更新withdraw状态
    _createWithdrawState(height, withdrawAmounts, toAddresses, assetAddresses)
    Notify([
        'updateState', stateRootHash, height, version, depositIds,
        withdrawAmounts, toAddresses, assetAddresses
    ])
    return True
Example #29
0
def getGP(gpId):
    gpMapInfo = Get(GetContext(), _concatkey(GP_PREFIX, gpId))
    if not gpMapInfo:
        return []
    gpMap = Deserialize(gpMapInfo)
    price = gpMap["price"]
    contentInfo = gpMap["content"]
    content = Deserialize(contentInfo)
    return [price, content]
Example #30
0
def checkIn(account):
    assert (CheckWitness(account))
    checkInDays = canCheckIn(account)
    if (checkInDays > 0):
        _transferTokenTo(account, 100 * OEP4TokenMagnitude)
        _chargeONG(account, Fee)
        Put(GetContext(), concatKey(PLAYER_LAST_CHECK_IN_DAY, account), checkInDays)
        Notify(["checkIn", account])
    return True