Beispiel #1
0
def DestroyContract():
    Destroy()
    Notify(["Destory"])
    return True
Beispiel #2
0
def Hello(msg):
    Notify(msg)
    return True
Beispiel #3
0
def GetCprOwner(cpr_cert):
    Notify(Get(GetContext(), CPR_KEY + cpr_cert))
    return True
Beispiel #4
0
def notify_list():
    Notify(['zou', 'xue', 'yan'])
    return True
def FunctionNameError():
    Notify(["Wrong function name"])
    return False
Beispiel #6
0
def put_dict(dict_args):
    dict_info = Serialize(dict_args)
    Put(CTX, 'dict', dict_info)
    Notify(['put dict', dict_info])
Beispiel #7
0
def put_list(list_args):
    list_info = Serialize(list_args)
    Put(CTX, 'list', list_info)
    Notify(['put list', list_args, list_info])
Beispiel #8
0
def migrateContract(code, needStorage, name, version, author, email, description):
    RequireWitness(Admin)
    Migrate(code, needStorage, name, version, author, email, description)
    Notify(["Migrate Contract successfully", Admin, GetTime()])
    return True
Beispiel #9
0
def _bankerInvest(account, ongAmount):
    currentRound = getCurrentRound()
    # RequireWitness(account)
    if CheckWitness(account) == False:
        # "bankerInvest: Check witness failed!",
        Notify(["Error", 101])
        return False
    if ongAmount < bankerQuota:
        # bankerInvest: Please make sure you invest at least 1000 ONG to become a banker
        Notify(["Error", 103])
        return False
    # Require(_transferONG(account, ContractAddress, ongAmount))
    res = _transferONG(account, ContractAddress, ongAmount)
    if res == False:
        # bankerInvest: Transfer ONG to contract failed!
        Notify(["Error", 102])
        return False
    # try to update banker list
    bankersListKey = concatKey(concatKey(ROUND_PREFIX, currentRound),
                               BANKERS_LIST_KEY)
    bankersListInfo = Get(GetContext(), bankersListKey)
    bankersList = []
    if bankersListInfo:
        bankersList = Deserialize(bankersListInfo)
        if not checkInBankerList(account, bankersList):
            bankersList.append(account)
            bankersListInfo = Serialize(bankersList)
            Put(GetContext(), bankersListKey, bankersListInfo)
    else:
        bankersList.append(account)
        bankersListInfo = Serialize(bankersList)
        Put(GetContext(), bankersListKey, bankersListInfo)

    dividendForBankersPercentage = getDividendForBankersPercentage(
        currentRound)
    runningVaultPercentage = getRunningVaultPercentage(currentRound)

    # add dividend to all the bankers, 48%
    dividend = Div(Mul(ongAmount, dividendForBankersPercentage), 100)

    # update profit per investment for bankers
    bankersInvestment = getBankersInvestment(currentRound)
    if bankersInvestment > 0:
        profitPerInvestmentForBankersToBeAdd = Div(
            Mul(dividend, MagnitudeForProfitPerSth), bankersInvestment)
        Put(
            GetContext(),
            concatKey(concatKey(ROUND_PREFIX, currentRound),
                      PROFIT_PER_INVESTMENT_FOR_BANKERS_KEY),
            Add(profitPerInvestmentForBankersToBeAdd,
                getProfitPerInvestmentForBankers(currentRound)))
    else:
        # there will be no dividend
        dividend = 0
    # add running vault, 50%
    increasingRunVaultToBeAdd = Div(Mul(ongAmount, runningVaultPercentage),
                                    100)
    Put(
        GetContext(),
        concatKey(concatKey(ROUND_PREFIX, currentRound),
                  INCREASING_RUN_VAULT_KEY),
        Add(getIncreasingRunnVault(currentRound), increasingRunVaultToBeAdd))

    # update real time running vault
    Put(
        GetContext(),
        concatKey(concatKey(ROUND_PREFIX, currentRound),
                  REAL_TIME_RUNNING_VAULT),
        Add(getRealTimeRunningVault(currentRound), increasingRunVaultToBeAdd))

    # treat the rest as the commission fee to admin, 2%
    restOngAmount = Sub(Sub(ongAmount, dividend), increasingRunVaultToBeAdd)
    # update the commission fee
    Put(GetContext(), COMMISSION_KEY, Add(getCommission(), restOngAmount))

    # update the account (or the banker) 's dividend and earning
    updateBankerDividend(account)
    updateBankerEarning(account)

    # update account's investment
    bankerKey = concatKey(concatKey(ROUND_PREFIX, currentRound),
                          concatKey(BANKER_INVEST_BALANCE_PREFIX, account))
    Put(GetContext(), bankerKey,
        Add(getBankerInvestment(currentRound, account), ongAmount))

    # update total bankers' investment
    Put(
        GetContext(),
        concatKey(concatKey(ROUND_PREFIX, currentRound),
                  BANKERS_INVESTMENT_KEY), Add(bankersInvestment, ongAmount))

    # update total ong amount
    Put(GetContext(), TOTAL_ONG_KEY, Add(getTotalONG(), ongAmount))

    Notify(["bankerInvest", currentRound, account, ongAmount])

    return True
Beispiel #10
0
def reinvest(account, paperAmount):
    RequireWitness(account)
    currentRound = getCurrentRound()

    Require(getGameStatus(currentRound) == STATUS_ON)

    ongAmount = paperToONG(currentRound, paperAmount)

    updateDividendBalance(account)
    dividendBalance = getDividendBalance(account)
    awardBalance = getAwardBalance(account)
    referralBalance = getReferralBalance(account)
    assetToBeReinvest = Add(Add(dividendBalance, awardBalance), referralBalance)


    Require(assetToBeReinvest >= ongAmount)

    dividend1 = Div(Mul(ongAmount, PaperHolderPercentage), 100)
    # update referral balance
    referral = getReferral(account)
    referralAmount = 0
    if referral:
        referralAmount = Div(Mul(ongAmount, ReferralAwardPercentage), 100)
        Put(GetContext(), concatKey(REFERRAL_BALANCE_OF_PREFIX, referral), Add(referralAmount, getReferralBalance(referral)))
    dividend = Sub(dividend1, referralAmount)

    # update next vault
    nextVaultToBeAdd = Div(Mul(ongAmount, NextPercentage), 100)
    nextVaultKey = concatKey(concatKey(ROUND_PREFIX, currentRound), NEXT_VAULT_KEY)
    Put(GetContext(), nextVaultKey, Add(nextVaultToBeAdd, getNextVault(currentRound)))

    # update award vault
    awardVaultToBeAdd = Div(Mul(ongAmount, AwardPercentage), 100)
    awardVaultKey = concatKey(concatKey(ROUND_PREFIX, currentRound), AWARD_VAULT_KEY)
    Put(GetContext(), awardVaultKey, Add(awardVaultToBeAdd, getAwardVault(currentRound)))

    # update gas vault
    gasVaultToBeAdd = Sub(Sub(Sub(ongAmount, dividend1), nextVaultToBeAdd), awardVaultToBeAdd)
    Put(GetContext(), GAS_VAULT_KEY, Add(gasVaultToBeAdd, getGasVault()))

    # update total paper amount
    Put(GetContext(), TOTAL_PAPER, Add(paperAmount, getTotalPaper()))

    # update sold paper amount for the usage of calculating the price
    key = concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_PAPER_AMOUNT)
    Put(GetContext(), key, Add(paperAmount, getRoundSoldPaperAmount(currentRound)))

    updateDividendBalance(account)

    # update paper balance of account
    Put(GetContext(), concatKey(PAPER_BALANCE_PREFIX, account), Add(paperAmount, getPaperBalance(account)))

    # update profitPerPaper
    oldProfitPerPaper = Get(GetContext(), PROFIT_PER_PAPER_KEY)
    profitPerPaperToBeAdd = Div(dividend, getTotalPaper())
    Put(GetContext(), PROFIT_PER_PAPER_KEY, Add(profitPerPaperToBeAdd, oldProfitPerPaper))

    # update profitPerPaperFrom of account
    # key = concatKey(PROFIT_PER_PAPER_FROM_PREFIX, account)
    # Put(GetContext(), key, oldProfitPerPaper)

    # update the account balances of dividend, award, referral
    Delete(GetContext(), concatKey(AWARD_BALANCE_OF_PREFFIX, account))
    Delete(GetContext(), concatKey(REFERRAL_BALANCE_OF_PREFIX, account))
    ongAmountLeft = Sub(assetToBeReinvest, ongAmount)
    Put(GetContext(), concatKey(TOTAL_DIVIDEND_OF_PREFIX, account), ongAmountLeft)

    # update the invested ong amount for account
    Put(GetContext(), concatKey(INVEST_BALANCE_PREFFIX, account), Add(ongAmount, getInvestOngBalance(account)))

    # PurchaseEvent(account, ongAmount, paperAmount)
    Notify(["reBuyPaper", account, ongAmount, paperAmount, GetTime()])
Beispiel #11
0
def fillPaper(account, guessNumberList):
    """
    :param account:
    :param guessNumberList: can be a list of numbers
    :return:
    """
    RequireWitness(account)

    currentRound = getCurrentRound()
    Require(getGameStatus(currentRound) == STATUS_ON)
    guessNumberLen = len(guessNumberList)

    Require(guessNumberLen >= 1)

    currentFilledPaperBalance = getFilledPaperBalance(account, currentRound)
    # make sure his balance is greater or equal to current filled paper balance + guessNumberList length
    Require(getPaperBalance(account) >= Add(currentFilledPaperBalance, guessNumberLen))

    numberListKey = concatKey(concatKey(ROUND_PREFIX, currentRound), FILLED_NUMBER_LIST_KEY)
    numberListInfo = Get(GetContext(), numberListKey)
    numberList = []
    if numberListInfo:
        numberList = Deserialize(numberListInfo)

    for guessNumber in guessNumberList:

        Require(guessNumber < 10000)
        Require(guessNumber >= 0)

        numberPlayersKey = concatKey(concatKey(ROUND_PREFIX, currentRound), concatKey(FILLED_NUMBER_KEY, guessNumber))
        numberPlayersInfo = Get(GetContext(), numberPlayersKey)

        numberPlayers = []
        if numberPlayersInfo:
            numberPlayers = Deserialize(numberPlayersInfo)

            # make sure account has NOT filled the number before in this round
            for player in numberPlayers:
                Require(player != account)
        else:
            numberList.append(guessNumber)

        # add account to the players list that filled the number in this round
        numberPlayers.append(account)

        # Store the numberPlayers List
        numberPlayersInfo = Serialize(numberPlayers)
        Put(GetContext(), numberPlayersKey, numberPlayersInfo)
    # Store the numberList
    numberListInfo = Serialize(numberList)
    Put(GetContext(), numberListKey, numberListInfo)

    # update the filled paper amount in current round
    key = concatKey(concatKey(ROUND_PREFIX, currentRound), FILLED_PAPER_AMOUNT)
    Put(GetContext(), key, Add(guessNumberLen, getFilledPaperAmount(currentRound)))

    # update the filled paper balance in current round
    key1 = concatKey(ROUND_PREFIX, currentRound)
    key2 = concatKey(FILLED_PAPER_BALANCE_PREFIX, account)
    key = concatKey(key1, key2)
    Put(GetContext(), key, Add(guessNumberLen, currentFilledPaperBalance))

    # update the paper balance of account
    Put(GetContext(), concatKey(PAPER_BALANCE_PREFIX, account), Sub(getPaperBalance(account), guessNumberLen))

    Notify(["fillPaper", account, guessNumberList, GetTime()])

    return True
Beispiel #12
0
def buyPaper(account, paperAmount):
    RequireWitness(account)
    currentRound = getCurrentRound()

    Require(getGameStatus(currentRound) == STATUS_ON)

    ongAmount = paperToONG(currentRound, paperAmount)

    Require(transferONG(account, ContractAddress, ongAmount))

    # PaperHolderPercentage = 50
    dividend1 = Div(Mul(ongAmount, PaperHolderPercentage), 100)
    # update referral balance <---> Get(GetContext(), concatKey(REFERRAL_PREFIX, account))
    referral = getReferral(account)
    referralAmount = 0

    if referral:
        # ReferralAwardPercentage = 1
        referralAmount = Div(Mul(ongAmount, ReferralAwardPercentage), 100)
        Put(GetContext(), concatKey(REFERRAL_BALANCE_OF_PREFIX, referral), Add(referralAmount, getReferralBalance(referral)))
    dividend = Sub(dividend1, referralAmount)

    # update next vault, NextPercentage = 10
    nextVaultToBeAdd = Div(Mul(ongAmount, NextPercentage), 100)
    nextVaultKey = concatKey(concatKey(ROUND_PREFIX, currentRound), NEXT_VAULT_KEY)
    Put(GetContext(), nextVaultKey, Add(nextVaultToBeAdd, getNextVault(currentRound)))

    # update award vault, AwardPercentage = 35
    awardVaultToBeAdd = Div(Mul(ongAmount, AwardPercentage), 100)
    awardVaultKey = concatKey(concatKey(ROUND_PREFIX, currentRound), AWARD_VAULT_KEY)
    Put(GetContext(), awardVaultKey, Add(awardVaultToBeAdd, getAwardVault(currentRound)))

    # update gas vault
    gasVaultToBeAdd = Sub(Sub(Sub(ongAmount, dividend1), nextVaultToBeAdd), awardVaultToBeAdd)
    Put(GetContext(), GAS_VAULT_KEY, Add(gasVaultToBeAdd, getGasVault()))

    # update total paper amount
    Put(GetContext(), TOTAL_PAPER, Add(paperAmount, getTotalPaper()))

    # update total invest ONG amount
    Put(GetContext(), concatKey(INVEST_BALANCE_PREFFIX, account), Add(ongAmount, getInvestOngBalance(account)))

    # update sold paper amount for the usage of calculating the price
    key = concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_PAPER_AMOUNT)
    Put(GetContext(), key, Add(paperAmount, getRoundSoldPaperAmount(currentRound)))

    updateDividendBalance(account)

    # update paper balance of account
    Put(GetContext(), concatKey(PAPER_BALANCE_PREFIX, account), Add(paperAmount, getPaperBalance(account)))

    # updateDividendBalance(account)
    # Notify(["111_buy", dividend1, dividend, nextVaultToBeAdd, awardVaultToBeAdd, gasVaultToBeAdd, getGasVault()])
    # update profitPerPaper
    oldProfitPerPaper = Get(GetContext(), PROFIT_PER_PAPER_KEY)
    totalPaper = getTotalPaper()

    profitPerPaperToBeAdd = Div(dividend, totalPaper)
    Put(GetContext(), PROFIT_PER_PAPER_KEY, Add(profitPerPaperToBeAdd, oldProfitPerPaper))

    # Notify(["222_buy", getGasVault()])
    # # update profitPerPaperFrom of account
    # Put(GetContext(), concatKey(PROFIT_PER_PAPER_FROM_PREFIX, account), oldProfitPerPaper)

    # PurchaseEvent(account, ongAmount, paperAmount)
    Notify(["buyPaper", account, ongAmount, paperAmount, GetTime()])

    return True
Beispiel #13
0
def endCurrentRound():
    if CheckWitness(Admin) == False:
        Notify(["checkwitness failed"])
        return False

    # # transfer Gas vault to admin to prepare for calculating winner of current round
    # gasVault = getGasVault()
    # if gasVault:
    #     # Require(withdrawGas())
    #     if withdrawGas() == False:
    #
    #         return False

    currentRound = getCurrentRound()

    # Require(GetTime() > getCurrentRoundEndTime() - 60)
    if GetTime() <= getCurrentRoundEndTime() - 60:
        Notify(["current round endtime error"])
        return False

    # Require(getGameStatus(currentRound) == STATUS_ON)
    if getGameStatus(currentRound) == STATUS_OFF:
        Notify(["game status error"])
        return False

    numberListKey = concatKey(concatKey(ROUND_PREFIX, currentRound), FILLED_NUMBER_LIST_KEY)
    numberListInfo = Get(GetContext(), numberListKey)
    if numberListInfo:
        numberList = Deserialize(numberListInfo)
    else:
        # if no one participate this round of game
        Put(GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_STATUS_KEY), STATUS_OFF)
        # update the next vault -- pass the award vault (coming from previous round) to the next round
        Put(GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), NEXT_VAULT_KEY), getAwardVault(currentRound))
        Notify(["endRound", currentRound])
        startNewRound()
        return True

    # to record the minimum distance
    minDistance = 10000
    # to record the number corresponding with minimum distance
    minIndex = 10000
    luckyNumber = getLuckyNumber()
    for number in numberList:
        # get the L1 norm of the distance between number and luckyNumber
        distance = ASub(number, luckyNumber)

        if distance < minDistance:
            minDistance = distance
            minIndex = number

    winnersListKey = concatKey(concatKey(ROUND_PREFIX, currentRound), concatKey(FILLED_NUMBER_KEY, minIndex))
    winnersListInfo = Get(GetContext(), winnersListKey)
    winnersList = Deserialize(winnersListInfo)
    winnersTotalPaper = 0
    for winner in winnersList:
        winnersTotalPaper = Add(winnersTotalPaper, getPaperBalance(winner))

    # split the Award Vault to the winners
    awardVault = getAwardVault(currentRound)

    totalTaxedAward = 0
    for winner in winnersList:
        paperBalance = getPaperBalance(winner)
        winnerAward = Div(Mul(awardVault, paperBalance), winnersTotalPaper)
        winnerPercentage = winnerAward * 100 / getInvestOngBalance(winner)
        fee = 0
        if winnerPercentage > 100:
            fee = Div(Mul(winnerAward, WinnerFeeLarge), 100)
        else:
            fee = Div(Mul(winnerAward, WinnerFeeSmall), 100)

        pureWinnerAwardToBeAdd = Sub(winnerAward, fee)
        totalTaxedAward = Add(totalTaxedAward, pureWinnerAwardToBeAdd)
        Put(GetContext(), concatKey(AWARD_BALANCE_OF_PREFFIX, winner), Add(pureWinnerAwardToBeAdd, getAwardBalance(winner)))

    # give Admin some fee from winner
    totalFee = Sub(awardVault, totalTaxedAward)
    Put(GetContext(), concatKey(TOTAL_DIVIDEND_OF_PREFIX, Admin), Add(totalFee, getDividendBalance(Admin)))

    # delete the award vault of this current round
    # Delete(GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), AWARD_VAULT_KEY))

    # delete the filled paper in current round and update their PROFIT_PER_PAPER_FROM_PREFIX
    profitPerPaperNow = Get(GetContext(), PROFIT_PER_PAPER_KEY)
    for number in numberList:
        numberPlayersKey = concatKey(concatKey(ROUND_PREFIX, currentRound), concatKey(FILLED_NUMBER_KEY, number))
        numberPlayersInfo = Get(GetContext(), numberPlayersKey)
        numberPlayers = Deserialize(numberPlayersInfo)

        for player in numberPlayers:

            profitPerPaperFrom = Get(GetContext(), concatKey(PROFIT_PER_PAPER_FROM_PREFIX, player))

            if Sub(profitPerPaperNow, profitPerPaperFrom) > 0:

                updateDividendBalance(player)

                # update the player's paper balance
                # Put(GetContext(), concatKey(PAPER_BALANCE_PREFIX, player), Sub(getPaperBalance(player), getFilledPaperBalance(player, currentRound)))

                # delete the filled paper balance of this round
                key = concatKey(concatKey(ROUND_PREFIX, currentRound), concatKey(FILLED_PAPER_BALANCE_PREFIX, player))
                Notify(["destroyPaper", player, getFilledPaperBalance(player, currentRound), GetTime()])
                # Delete(GetContext(), key)

    # update the paper total amount
    Put(GetContext(), TOTAL_PAPER, Sub(getTotalPaper(), getFilledPaperAmount(currentRound)))

    # Notify(["destroy",getFilledPaperAmount(currentRound), GetTime()])
    # mark this round game as END
    Put(GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_STATUS_KEY), STATUS_OFF)
    Notify(["endRound", currentRound, luckyNumber, winnersList])
    startNewRound()

    return True
def Main(operation, args):
    if operation == 'name':
        return name()
    if operation == 'hello':
        if len(args) != 1:
            return False
        msg = args[0]
        return hello(msg)
    if operation == 'testHello':
        if len(args) != 5:
            return False
        msgBool = args[0]
        msgInt = args[1]
        msgByteArray = args[2]
        msgStr = args[3]
        msgAddress = args[4]
        return testHello(msgBool, msgInt, msgByteArray, msgStr, msgAddress)
    if operation == 'testList':
        if len(args) != 1:
            return False
        msgList = args[0]
        return testList(msgList)
    if operation == 'testListAndStr':
        Notify([args])
        if len(args) != 2:
            return False
        msgList = args[0]
        msgStr = args[1]
        return testListAndStr(msgList, msgStr)
    if operation == 'testStructList':
        Notify(args)
        structList = args[0]
        return testStructList(structList)
    if operation == 'testStructListAndStr':
        if len(args) != 2:
            return False
        structList = args[0]
        msgStr = args[1]
        return testStructListAndStr(structList, msgStr)
    if operation == 'testMap':
        msg = args[0]
        return testMap(msg)
    if operation == 'testGetMap':
        if len(args) != 1:
            return False
        key = args[0]
        return testGetMap(key)
    if operation == 'testMapInMap':
        msg = args[0]
        return testMapInMap(msg)
    if operation == 'testGetMapInMap':
        if len(args) != 1:
            return False
        key = args[0]
        return testGetMapInMap(key)
    if operation == 'transferMulti':
        states = args[0]
        return transferMulti(states)
    if operation == 'testTrue':
        return testTrue()
    if operation == 'testFalse':
        return testFalse()
    return False
Beispiel #15
0
def testStructList(structList):
    Notify(["testStructList", structList])
    return structList
Beispiel #16
0
def bet(account, ongAmount, number):
    """
    :param account:
    :param ongAmount:
    :param number:
    :return:
    """
    # RequireWitness(account)
    if CheckWitness(account) == False:
        # bet: Check witness failed!
        Notify(["Error", 601])
        return False

    currentRound = getCurrentRound()

    # to prevent hack from other contract
    callerHash = GetCallingScriptHash()
    entryHash = GetEntryScriptHash()
    # Require(callerHash == entryHash)
    if callerHash != entryHash:
        # bet: Don't support bet method being invoked by another contract to prevent hacking
        Notify(["Error", 602])
        return False

    if getRoundGameStatus(currentRound) != STATUS_ON:
        # bet: Current round game ended, please wait for the starting of the next round game and try later
        Notify(["Error", 603])
        return False

    # make sure the contract has enough ong to pay to accont if account wins
    tryPayOutToWin = _calculatePayOutToWin(ongAmount, number)
    totalOngAmount = getTotalONG()
    realTimeRunVault = getRealTimeRunningVault(currentRound)

    # # Require(realTimeRunVault > tryPayOutToWin)
    if realTimeRunVault < Sub(tryPayOutToWin, ongAmount):
        # bet: Running pot/vault does not have enough asset to pay to the player, please try smaller bet
        Notify(["Error", 604])
        return False

    # Require(_transferONG(account, ContractAddress, ongAmount))
    res = _transferONG(account, ContractAddress, ongAmount)
    if res == False:
        # bet: Transfer ONG failed, please try later or again
        Notify(["Error", 605])
        return False

    # Require(number < 97)
    if number >= 97:
        # bet: Please try to bet with a number less than 97
        Notify(["Error", 606])
        return False
    # Require(number > 1)
    if number <= 1:
        # bet: Please try to bet with a number greater than 1
        Notify(["Error", 607])
        return False

    theNumber = _rollANumber()
    payOutToWin = 0
    if theNumber < number:
        payOutToWin = tryPayOutToWin
        Require(_transferONGFromContact(account, payOutToWin))

        # update total ongAmount
        ongAmountToBeSub = Sub(payOutToWin, ongAmount)
        Put(GetContext(), TOTAL_ONG_KEY, Sub(totalOngAmount, ongAmountToBeSub))
        # update real time running vault
        realTimeRunVaultKey = concatKey(concatKey(ROUND_PREFIX, currentRound),
                                        REAL_TIME_RUNNING_VAULT)
        Put(GetContext(), realTimeRunVaultKey,
            Sub(realTimeRunVault, ongAmountToBeSub))
        realTimeRunVault = getRealTimeRunningVault(currentRound)
        # mark the game as end if real time running vault is less than 1/10 of running vault
        if realTimeRunVault <= Div(getIncreasingRunnVault(currentRound), 10):
            # mark this round of game end
            Put(GetContext(),
                concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_STATUS),
                STATUS_OFF)
            # update profit per investment for bankers
            runVaultLeft = getRunningVault(currentRound)
            if runVaultLeft > 0:
                profitPerRuningVaultShareToBeAdd = Div(
                    Mul(realTimeRunVault, MagnitudeForProfitPerSth),
                    runVaultLeft)
                Put(
                    GetContext(),
                    concatKey(concatKey(ROUND_PREFIX, currentRound),
                              PROFIT_PER_RUNNING_VAULT_SHARE_KEY),
                    Add(profitPerRuningVaultShareToBeAdd,
                        getProfitPerRunningVaultShare(currentRound)))
            # update real time running vault
            Delete(GetContext(), realTimeRunVaultKey)
            Notify(["endCurrentRound", currentRound])
            return True
    else:
        # update total ong amount
        Put(GetContext(), TOTAL_ONG_KEY, Add(totalOngAmount, ongAmount))

        # update profit per investment for bankers
        runVaultLeft = getRunningVault(currentRound)
        if runVaultLeft > 0:
            profitPerRunNingVaultShareToBeAdd = Div(
                Mul(ongAmount, MagnitudeForProfitPerSth), runVaultLeft)
            Put(
                GetContext(),
                concatKey(concatKey(ROUND_PREFIX, currentRound),
                          PROFIT_PER_RUNNING_VAULT_SHARE_KEY),
                Add(profitPerRunNingVaultShareToBeAdd,
                    getProfitPerRunningVaultShare(currentRound)))

    Notify([
        "bet", currentRound, account, number, theNumber, ongAmount, payOutToWin
    ])
    return True
Beispiel #17
0
def notify_args(bool_args, int_args, list_args, str_args, bytes_address_args):
    Notify(['notify args', bool_args, int_args, list_args, str_args, bytes_address_args])
Beispiel #18
0
def Main(operation, args):
    if operation == "transferOntOng":
        if len(args) != 4:
            Notify("wrong params")
            return
        return TransferOntOng(args[0], args[1], args[2], args[3])
Beispiel #19
0
def put_dict_value(dict_value_args):
    new_dict = {}
    new_dict['key'] = dict_value_args
    new_dict_info = Serialize(new_dict)
    Put(CTX, 'dict', new_dict_info)
    Notify(['put dict value', new_dict_info])
Beispiel #20
0
def get(key):
    Notify([key])
    a = Deserialize(Get(ctx, _concatkey(testKey, key)))
    Notify([key])
    return [a['index'], a['value']]
Beispiel #21
0
def invokeA(operation, params):
    callerHash = GetCallingScriptHash()
    entryHash = GetEntryScriptHash()
    Notify(["111_invokeA",callerHash, entryHash, ContractAddress])
    return ContractB(operation, params)
Beispiel #22
0
def testStructListAndStr(structList, msgStr):
    Notify(["testStructListAndStr", structList, msgStr])
    resList = []
    resList.append(structList)
    resList.append(msgStr)
    return resList
def ParamError():
    Notify(["param error"])
    return False
Beispiel #24
0
def testGetMapInMap(key):
    mapInfo = Get(GetContext(), 'map_key2')
    Notify(["testGetMapInMap", mapInfo])
    map = Deserialize(mapInfo)
    return map[key]
def InitContractAdmin(adminOntID):
    authContractAddr = bytearray(
        b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06'
    )
    res = Invoke(0, authContractAddr, "initContractAdmin", adminOntID)
    Notify(["Admin has been registered", adminOntID])
Beispiel #26
0
def testList(msgList):
    Notify(["testMsgList", msgList])
    return msgList
Beispiel #27
0
def VerifyPerson(cpr_cert):
    owner = Get(GetContext(), CPR_KEY + cpr_cert)
    is_owner = CheckWitness(owner)
    Notify(is_owner)
    return is_owner
Beispiel #28
0
def testListAndStr(msgList, msgStr):
    Notify(["testListAndStr", msgList, msgStr])
    resList = []
    resList.append(msgList)
    resList.append(msgStr)
    return resList
Beispiel #29
0
def createGameByOracleRes(jsonIndex):
    RequireWitness(Operater)

    # # make sure the result hasn't be saved before
    # Require(not getGameResult(gameId))

    # make sure the request to initiate games has been sent out to the oracle contract
    sentReqTxhash = Get(GetContext(),
                        concatKey(SENTREQHASH_FORMGAME_PREFIX, jsonIndex))
    # Require(sentReqTxhash)
    if not sentReqTxhash:
        Notify(["createGameErr", "Request To Initiate Game Failed!"])
        return False
    response = OracleContract('GetOracleOutcome', [sentReqTxhash])
    # Require(response)
    if not response:
        Notify(["createGameErr", "Get Response From Oracle Failed!"])
        return False

    a = Deserialize(response)
    if a[2] != 0:
        Notify(["createGameErr", "Get Response From Oracle With Error!"])
        return False
    # Notify(["111", a])
    b = Deserialize(a[0])

    # Notify(["222", b])
    c = b[0]
    # Notify(["333", c])
    gameIdList = []
    endTimeList = []
    gameDiskIdList = []
    # resultList = []
    for game in c:
        gameId = game[0]
        gameIdList.append(gameId)
        endTime = game[1]
        endTimeList.append(endTime)
        tmpDiskIdList = []
        tmp = game[2]
        for gameDisk in tmp:
            tmpDiskId = gameDisk[0]
            # tmpDiskRes = gameDisk[1]
            tmpDiskIdList.append(tmpDiskId)
        gameDiskIdList.append(tmpDiskIdList)

    gameIdLen = len(gameIdList)
    gameIdIndex = 0
    while gameIdIndex < gameIdLen:
        gameId = gameIdList[gameIdIndex]
        diskIdList = gameDiskIdList[gameIdIndex]
        betEndTime = endTimeList[gameIdIndex]
        Put(GetContext(), concatKey(GAME_DISKID_LIST_PREFIX, gameId),
            Serialize(diskIdList))
        Put(GetContext(), concatKey(GAME_BET_ENDTIME_PREFIX, gameId),
            betEndTime)

        gameIdIndex = gameIdIndex + 1

    # # extract game and disk info from res
    # # make sure gameId is consistent with that provided within response
    # # gameId, diskIdList, betEndTime

    Notify(["createGameByOracleRes", gameIdList, gameDiskIdList, endTimeList])
    return True
Beispiel #30
0
def setLuckyContractHash(reversedLuckyContractHash):
    RequireWitness(Admin)
    Put(GetContext(), LUCKY_CONTRACT_HASH_KEY, reversedLuckyContractHash)
    Notify(["setLuckyContractHash", reversedLuckyContractHash])
    return True