def payToPlay(account, ongAmount): RequireWitness(account) Require(ongAmount >= 100000000) currentId = Add(getCurrentRound(), 1) Require(_transferONG(account, ContractAddress, ongAmount)) Put(GetContext(), ROUND_ID_NUMBER_KEY, currentId) Put(GetContext(), concatKey(currentId, ID_UNPAID_PLAYER_KEY), account) Put(GetContext(), concatKey(currentId, account), ongAmount) Put(GetContext(), TOTAL_ONG_FOR_ADMIN, Add(getTotalOngForAdmin(), ongAmount)) # deal with Lucky sending and referral Lucky sending _referralLuckyBalanceToBeAdd = 0 acctLuckyBalanceToBeAdd = Div(Mul(ongAmount, getLuckyToOngRate()), Magnitude) ############### Transfer Lucky TWO times to account and referral ############### # transfer LUCKY to account params = [ContractAddress, account, acctLuckyBalanceToBeAdd] revesedContractAddress = Get(GetContext(), LUCKY_CONTRACT_HASH_KEY) res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) referral = getReferral(account) if len(referral) == 20: # transfer LUCKY to referral _referralLuckyBalanceToBeAdd = Div( Mul(acctLuckyBalanceToBeAdd, getReferralBonusPercentage()), 100) params = [ContractAddress, referral, _referralLuckyBalanceToBeAdd] res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) Notify(["payToPlay", currentId, account, ongAmount]) return True
def adminWithdrawLucky(toAcct, luckyAmount): RequireWitness(Admin) revesedContractAddress = getLuckyContractHash() params = [ContractAddress] totalLuckyAmount = DynamicAppCall(revesedContractAddress, "balanceOf", params) if luckyAmount <= totalLuckyAmount: params = [ContractAddress, toAcct, luckyAmount] res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) Notify(["adminWithdrawLucky", toAcct, luckyAmount]) return True
def bet(account, ongAmount): RequireWitness(account) currentRound = getCurrentRound() Require(getRoundStatus(currentRound) == STATUS_ON) Require(getRoundBetStatus(currentRound)) playerRoundBalance = getPlayerBetBalance(currentRound, account) Require(not playerRoundBalance) Require(_transferONG(account, ContractAddress, ongAmount)) Put(GetContext(), TOTAL_ONG_FOR_ADMIN, Add(getTotalOngForAdmin(), ongAmount)) Put( GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), concatKey(ROUND_PLAYER_BET_BALANCE_KEY, account)), ongAmount) _referralLuckyBalanceToBeAdd = 0 acctLuckyBalanceToBeAdd = Div(Mul(ongAmount, getLuckyToOngRate()), Magnitude) ############### Transfer Lucky TWO times to account and referral ############### # transfer LUCKY to account params = [ContractAddress, account, acctLuckyBalanceToBeAdd] revesedContractAddress = Get(GetContext(), LUCKY_CONTRACT_HASH_KEY) res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) referral = getReferral(account) if len(referral) == 20: # transfer LUCKY to referral _referralLuckyBalanceToBeAdd = Div( Mul(acctLuckyBalanceToBeAdd, getReferralBonusPercentage()), 100) params = [ContractAddress, referral, _referralLuckyBalanceToBeAdd] res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) ############### multiTransfer Lucky ONE time to account and referral ############### # revesedContractAddress = Get(GetContext(), LUCKY_CONTRACT_HASH_KEY) # params = [] # params1 = [ContractAddress, account, acctLuckyBalanceToBeAdd] # params.append(params1) # referral = getReferral(account) # if len(referral) == 20: # _referralLuckyBalanceToBeAdd = Div(Mul(acctLuckyBalanceToBeAdd, getReferralBonusPercentage()), 100) # params2 = [ContractAddress, referral, _referralLuckyBalanceToBeAdd] # params.append(params2) # res = DynamicAppCall(revesedContractAddress, "transferMulti", params) # Require(res) Notify(["bet", currentRound, account, ongAmount]) return True
def migrateContract(code, needStorage, name, version, author, email, description, newReversedContractHash): RequireWitness(Admin) param = state(ContractAddress) totalOngAmount = Invoke(0, ONGAddress, 'balanceOf', param) if totalOngAmount > 0: res = _transferONGFromContact(newReversedContractHash, totalOngAmount) Require(res) revesedContractAddress = Get(GetContext(), LUCKY_CONTRACT_HASH_KEY) params = [ContractAddress] totalLuckyAmount = DynamicAppCall(revesedContractAddress, "balanceOf", params) if totalLuckyAmount > 0: params = [ContractAddress, newReversedContractHash, totalLuckyAmount] res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) res = Migrate(code, needStorage, name, version, author, email, description) Require(res) Notify(["Migrate Contract successfully"]) return True
def checkIn(account): RequireWitness(account) checkInDays = canCheckIn(account) Require(checkInDays > 0) Put(GetContext(), concatKey(PLAYER_LAST_CHECK_IN_DAY, account), checkInDays) freeLuckyAmount = LuckyMagnitude params = [ContractAddress, account, freeLuckyAmount] revesedContractAddress = Get(GetContext(), LUCKY_CONTRACT_HASH_KEY) res = DynamicAppCall(revesedContractAddress, "transfer", params) Require(res) Notify(["checkIn", account]) return True
def DynamicCallContract(revesedContractAddress, operation, params): Notify(["bytearray: ", revesedContractAddress]) res = DynamicAppCall(revesedContractAddress, operation, params) Notify(["111_DynamicCall", revesedContractAddress, operation, params]) Notify(["222_DynamicCall", res]) return res