def endCurrentRound(explodePoint, salt, effectiveEscapeAcctPointList): RequireWitness(Admin) currentRound = getCurrentRound() hash = sha256(explodePoint) ^ sha256(salt) Require(hash == getRoundExplodePointHash(currentRound)) # if hash != getRoundExplodePointHash(currentRound): # # the explodePoint and salt are wrong # Notify(["Error", 101]) # return False Require(getRoundBetStatus(currentRound) == False) # if getRoundBetStatus(currentRound): # # please wait for the bets end # Notify(["Error", 102]) # return False Require(getRoundStatus(currentRound) == STATUS_ON) Put( GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_EXPLODE_NUM_KEY), explodePoint) effectiveEscapeAcctPointOddsProfitList = _settleAccounts( currentRound, explodePoint, effectiveEscapeAcctPointList) Require(_closeRound(currentRound)) Notify([ "endCurrentRound", currentRound, explodePoint, salt, effectiveEscapeAcctPointOddsProfitList ]) return True
def createOneToken(name, url, type): ''' create a new token :param name: :param url: :param type: :return: ''' # Notify(["111_createOneToken begins"]) # generate tokenID timestamp = GetTime() totalSupply = Get(ctx, TOTAL_SUPPLY) newTotalSupply = totalSupply + 1 Put(ctx, TOTAL_SUPPLY, newTotalSupply) tmp = concatkey(concatkey(selfAddr, timestamp), newTotalSupply) tokenID = sha256(tmp) # construct token map token = {'ID': tokenID, 'Name': name, 'Image': url, 'Type': type} Notify(["111_createOneToken", newTotalSupply, tokenID, concatkey(TOKEN_ID_PREFIX, tokenID)]) Put(ctx, concatkey(TOKEN_INDEX_PREFIX, newTotalSupply), tokenID) ownerKey = concatkey(OWNER_OF_TOKEN_PREFIX, tokenID) Put(ctx, ownerKey, admin) Put(ctx, concatkey(TOKEN_ID_PREFIX, tokenID), Serialize(token)) # add to adminBalance adminBalance = Get(ctx, concatkey(OWNER_BALANCE_PREFIX, admin)) Put(ctx, concatkey(OWNER_BALANCE_PREFIX, admin), adminBalance + 1) # Notify(["333_createOneToken ends"]) return True #################### For testing usage only ends ######################
def grant_copyright(copyright, address, expired): copyright = sha256(copyright) if not check_owner(copyright): return False Notify(['grant', copyright, address]) return put_grants(copyright, address, expired)
def getRandom(): time = GetTime() height = GetHeight() header = GetHeader(height) # return sha256(abs(GetHash(header)) % time) tmp = sha256(abs(GetHash(header)) % time) Notify(["getRandom", tmp]) return tmp
def transfer_copyright(copyright, address): copyright = sha256(copyright) if not check_owner(copyright): return False Notify(['transfer', copyright, address]) return set_owner(copyright, address)
def GeneratorRandom(id): txid = GetTransactionHash(GetScriptContainer()) blockHeigt = GetHeight() + 1 blockTime = GetTime() blockHash = GetCurrentBlockHash() sysseed = [0, id, blockHeigt, blockTime, blockHash] sysseed = sha256(Serialize(sysseed)) resseed = sha256(Serialize([txid, sysseed])) resseed = sha256(Serialize([resseed, resseed])) res = abs(resseed) number = res % 100 number = number + 1 return number
def endCurrentRound(explodePoint, salt, effectiveEscapeAcctPointList): RequireWitness(Admin) currentRound = getCurrentRound() hash = sha256(explodePoint) ^ sha256(salt) if hash != getRoundExplodePointHash(currentRound): # the explodePoint and salt are wrong Notify(["Error", 101]) return False Put( GetContext(), concatKey(concatKey(ROUND_PREFIX, currentRound), ROUND_EXPLODE_NUM_KEY), explodePoint) effectiveEscapeAcctPointOddsProfitList = _settleAccounts( currentRound, explodePoint, effectiveEscapeAcctPointList) Require(_closeRound(currentRound)) Notify([ "endCurrentRound", currentRound, explodePoint, effectiveEscapeAcctPointOddsProfitList ]) return True
def create_copyright(address, copyright): copyright = sha256(copyright) if not CheckWitness(address): return False if check_owner_exists(copyright): return False Notify(['create', copyright, address]) return set_owner(copyright, address)
def startNewRound(explodePoint, salt): RequireWitness(Admin) currentRound = getCurrentRound() Require(getRoundStatus(currentRound) == STATUS_OFF) # start new round nextRound = Add(currentRound, 1) Put(GetContext(), CURRET_ROUND_NUM_KEY, nextRound) explodePointHash = sha256(explodePoint) ^ sha256(salt) Put( GetContext(), concatKey(concatKey(ROUND_PREFIX, nextRound), ROUND_EXPLODE_NUM_HASH_KEY), explodePointHash) Put(GetContext(), concatKey(concatKey(ROUND_PREFIX, nextRound), ROUND_STATUS_KEY), STATUS_ON) now = GetTime() Put(GetContext(), concatKey(concatKey(ROUND_PREFIX, nextRound), ROUND_END_BET_TIME_KEY), Add(now, BettingDuration)) Notify(["startNewRound", nextRound, now, explodePointHash]) return True
def check_copyright(copyright, address): copyright = sha256(copyright) owner = get_owner(copyright) if owner == address: return True grants = get_grants(copyright) if not grants: return False for grant, expired in grants: if grant == address: return expired is None or expired > GetTime() return False
def buy_copyright(copyright, address): copyright = sha256(copyright) if check_owner(copyright): return False owner_adr = get_owner(copyright) Notify(['buy', copyright, address]) param = state(address, owner_adr, 10) OntContract = ToScriptHash("AFmseVrdL9f9oyCzZefL9tG6UbvhUMqNMV") res = Invoke(0, OntContract, "transfer", [param]) if res != b'\x01': raise Exception("transfer ont error.") Notify("transferONT succeed") return put_grants(copyright, address, 120)
def Main(operation, a, b): if operation == 'omin': return min(a, b) elif operation == 'omax': return max(a, b) elif operation == 'oabs': return abs(a) elif operation == 'sha1': return sha1(a) elif operation == 'sha256': return sha256(a) elif operation == 'hash160': return hash160(a) elif operation == 'hash256': return hash256(a) return 'unknown'
def put_answer(player, game_id, value, salt, player_index): context = GetContext() game_key_prefix = concat('game.', game_id) player_key = concat(game_key_prefix, concat('.player', player_index)) stored_player = Get(context, player_key) if stored_player != player: return 0 answer_key = concat(game_key_prefix, concat('.answer', player_index)) stored_answer = Get(context, answer_key) if stored_answer: return stored_answer answer_hash_key = concat(game_key_prefix, concat('.answer_hash', player_index)) answer_hash = sha256(concat(value, salt)) stored_answer_hash = Get(context, answer_hash_key) if answer_hash == stored_answer_hash: new_answer = get_answer_code(value) else: new_answer = -1 Put(context, answer_key, new_answer) check_winner(game_id) return new_answer
def Main(operation, a, b): if operation == "omin": return min(a, b) elif operation == "omax": return max(a, b) elif operation == "oabs": return abs(a) elif operation == "sha1": return sha1(a) elif operation == "sha256": return sha256(a) elif operation == "hash160": return hash160(a) elif operation == "hash256": return hash256(a) return "unknown"
def getRandom(): time = GetTime(); height = GetHeight(); header = GetHeader(height); tmp = sha256(abs(GetHash(header)) % time); return tmp;
def verifyRoundExplodePointIsRandom(roundNumber, salt): Require(getRoundStatus(roundNumber) == STATUS_OFF) tryToVerifyHash = sha256(getRoundExplodePoint(roundNumber)) ^ sha256(salt) return tryToVerifyHash == getRoundExplodePointHash(roundNumber)
def Main(operation, args): sha1("123456789") sha256("123456789") hash160("123456789") hash256("123456789")