def Main(operation, key, value): context = GetContext() if operation == 'put': Put(context, key, value) return True if operation == 'put_and_get': Put(context, key, value) item = Get(context, key) return item if operation == 'put_5': for i in range(0, 5): new_key = concat(key, i) Put(context, new_key, value) return True if operation == 'put_9': for i in range(0, 9): new_key = concat(key, i) Put(context, new_key, value) return True return False
def match_rank(numbers, winning_numbers): rank = 0 number_matched = 0 five_number_dict = {} for i in range(0, 5): five_number_dict[numbers[i]] = "1" for i in range(0, 5): if has_key(five_number_dict, winning_numbers[i]): number_matched += 1 if number_matched == 5: rank = 1 elif number_matched == 4: rank = 2 elif number_matched == 3: rank = 3 elif number_matched == 2: rank = 4 return rank
def deserialize_bytearray(data): # ok this is weird. if you remove this print statement, it stops working :/ # get length of length collection_length_length = data[0:1] # get length of collection collection_len = data[1:collection_length_length + 1] # create a new collection new_collection = list(length=collection_len) # trim the length data offset = 1 + collection_length_length for i in range(0, collection_len): # get the data length length itemlen_len = data[offset:offset + 1] # get the length of the data item_len = data[offset + 1:offset + 1 + itemlen_len] # get the data item = data[offset + 1 + itemlen_len:offset + 1 + itemlen_len + item_len] # store it in collection new_collection[i] = item offset = offset + item_len + itemlen_len + 1 return new_collection
def GetUserPublications(args): user = args[0] context = GetContext() publications_key = concat('publications', user) publications = Get(context, publications_key) user_publications = [] if not publications: return [True, user_publications] publications = Deserialize(publications) # Go through each user publication and get details for i in range(0, len(publications)): publication_key = concat(publications_key, sha1(publications[i])) publication = Get(context, publication_key) publication = Deserialize(publication) # Append only if publication is active if publication[5]: user_publications.append(publication) return [True, user_publications]
def deserialize_bytearray(data): print('deserialize_bytearray') # get length of length collection_length_length = data[0:1] # get length of collection collection_len = data[1:collection_length_length + 1] # create a new collection new_collection = list(length=collection_len) # trim the length data offset = 1 + collection_length_length for i in range(0, collection_len): # get the data length length itemlen_len = data[offset:offset + 1] # get the length of the data item_len = data[offset + 1:offset + 1 + itemlen_len] # get the data item = data[offset + 1 + itemlen_len:offset + 1 + itemlen_len + item_len] # store it in collection new_collection[i] = item offset = offset + item_len + itemlen_len + 1 return new_collection
def GetNewPublications(): context = GetContext() publications = Get(context, 'new_publications') new_publications = [] if not publications: return [True, new_publications] publications = Deserialize(publications) # Go through each new publication and get details for i in range(0, len(publications)): user = publications[i][0] name = publications[i][1] publications_key = concat('publications', user) publication_key = concat(publications_key, sha1(name)) publication = Get(context, publication_key) publication = Deserialize(publication) # Append only if publication is active if publication[5]: new_publications.append(publication) return [True, new_publications]
def GetAuctionByMonth(args): owner = args[0] name = args[1] date = args[2] context = GetContext() publication_key = validatePublicationAuction(context, args) if not publication_key: return [False, 'Invalid auction params'] auctions = [] # For simplicity, assume given first day of month & always retreive 31 days worth of info for days in range(0, 30): next_date = date + days * SECONDS_IN_DAY auction_key = concat(publication_key, sha1(next_date)) auction_info = Get(context, auction_key) if auction_info: auction_info = Deserialize(auction_info) auctions.append(auction_info) else: auctions.append([]) return [True, auctions]
def deserialize(self, data): # neo-boa bug, Something is require here for some reason... print('deserialize_bytearray') collection_length_length = substr(data, 0, 1) collection_len = substr(data, 1, collection_length_length) new_collection = list(length=collection_len) offset = 1 + collection_length_length newdata = data[offset:] for i in range(0, collection_len): datalen_len = substr(newdata, 0, 1) data_len = substr(newdata, 1, datalen_len) start = 1 + datalen_len stop = start + data_len data = substr(newdata, start, data_len) new_collection[i] = data newdata = newdata[stop:] return new_collection
def Main(): count = 0 for i in range(0, 12): count += 1 return count
def ConvertToList(dict): converted = list() allKeys = keys(dict) for i in range(0, len(allKeys)): key = allKeys[i] converted.append(key) converted.append(dict[key]) return converted
def GetOrderList(): orders_id = GetOrderIdList() orders = [] collection_len = len(orders_id) for i in range(0, collection_len): id = orders_id[i] single_order = GetOrder(id) orders.append(single_order) return orders
def GetRecordList(usr_adr): records_id = GetRecordIdList(usr_adr) records = [] collection_len = len(records_id) for i in range(0, collection_len): id = records_id[i] single_record = GetRecord(id) records.append(single_record) return records
def Main(): rangestart = 2 count = 0 for i in range(rangestart, getrangeend()): count += 1 return count
def remove_userInvite(wallet_id, invite_id): invites = get_userInvites(wallet_id) for i in range(0, len(invites)): if invite_id == invites[i]: invites.remove(i) serial = Serialize(invites) Put(GetContext(), wallet_id, serial) return True return False
def ConvertFromList(keyValArgs): instance = NewInstance() nArgs = len(keyValArgs) for i in range(0, nArgs): if i % 2 == 0: key = keyValArgs[i] else: value = keyValArgs[i] instance[key] = value return instance
def Main(): items = range(0, 10) count = 0 for i in items: count += 1 throw_if_null(count == 10)
def Main(): items = range(0, 10) count = 0 for i in items: count += 1 return count
def add_delimiter(items): """ Concats a list of strings as an JSON array""" content = '' size = len(items) for item in range(0, size): new_item = concat(items[item], '***') content = concat(content, new_item) return content
def ConvertToString(dict): serialized = '{' allKeys = keys(dict) for i in range(0, len(allKeys)): key = allKeys[i] if i != 0: serialized = concat(serialized, ',') keyValPair = concat(concat(key, ':'), dict[key]) serialized = concat(serialized, keyValPair) serialized = concat(serialized, '}') return serialized
def GetAllRooms(): ## FIXME ctx = GetContext() all_rooms_raw = Get(ctx, ALL_ROOMS_KEY) return all_rooms_raw all_rooms = Deserialize(all_rooms_raw) ret = "" for i in range(0, len(all_rooms)): if i != 0: ret = concat(ret, ",") ret = concat(ret, all_rooms[i]) return ret
def CheckStringVaild(Str): allow = { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, "-": 27, "1": 28, "2": 29, "3": 30, "4": 31, "5": 32, "6": 33, "7": 34, "8": 39, "9": 40, "0": 41 } for i in range(0, len(Str)): s = (Str[i:i + 1]) try: result = allow[s] except: return True return False
def valuesToFormatStr(values): if (len(values) % 2 != 0): return False ret = "" for i in range(0, len(values)): value = values[i] if (i % 2 == 0): if (i != 0): ret = concat(ret, ":") ret = concat(ret, value) else: ret = concat(ret, ",") ret = concat(ret, value) return ret
def getRangeMessage(address, start, end): count = getMessageCount(address) if start < 1: start = 1 if start > count: return None if end > count: end = count res = [] for idex in range(start, end + 1): content = getMessage(address, idex) res.append(content) return Serialize(res)
def stringCompare(Str): allow = { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, "-": 27, "1": 28, "2": 29, "3": 30, "4": 31, "5": 32, "6": 33, "7": 34, "8": 39, "9": 40, "0": 41 } for i in range(0, len(Str)): if not allow.has_key(substr(Str, i, 1)): return True return False
def getOracleReq(date): gck = _concatKey(GameCountPrefix, date) gameCount = Get(ctx, gck) url = concat(concat('"http://data.nba.net/prod/v2/', date), '/scoreboard.json"') reqtmp = """{ "scheduler":{ "type": "runAfter", "params": "2018-06-15 08:37:18" }, "tasks":[ { "type": "httpGet", "params": { "url":""" reqhead = concat(concat(reqtmp, url), """}},""") bodyhead = """{"type":"jsonParse","params":{"data":[ """ tmpbody = [] for i in range(0, gameCount): idx = _itoa(i) s1 = concat(concat('{"type":"String","path":["games","', idx), '","gameId"]}') s2 = concat(concat('{"type":"String","path":["games","', idx), '","hTeam","teamId"]}') s3 = concat(concat('{"type":"String","path":["games","', idx), '","hTeam","score"]}') s4 = concat(concat('{"type":"String","path":["games","', idx), '","vTeam","teamId"]}') s5 = concat(concat('{"type":"String","path":["games","', idx), '","vTeam","score"]}') tmpbody.append(_concatStrs([s1, s2, s3, s4, s5], ',')) body = _concatStrs(tmpbody, ',') bodytail = """]}}]}""" req = concat(concat(concat(reqhead, bodyhead), body), bodytail) return req
def deserialize_bytearray(data): # ok this is weird. if you remove this print statement, it stops working :/ print("deserializing data...") # get length of length collection_length_length = substr(data, 0, 1) # get length of collection collection_len = substr(data, 1, collection_length_length) # create a new collection new_collection = list(length=collection_len) # calculate offset offset = 1 + collection_length_length # trim the length data newdata = data[offset:] for i in range(0, collection_len): # get the data length length itemlen_len = substr(newdata, 0, 1) # get the length of the data item_len = substr(newdata, 1, itemlen_len) start = 1 + itemlen_len end = start + item_len # get the data item = substr(newdata, start, item_len) # store it in collection new_collection[i] = item # trim the data newdata = newdata[end:] return new_collection
def autopick(player): samples = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 ] numbers = [] # Use current time in blockchain to in order to generate the numbers. randomNumber = GetTime() for i in range(1, 6): percentage = (randomNumber * i) % (39 - i) numbers.append(samples[percentage]) samples.remove(percentage) return buy(player, numbers)
def inputMatch(date, gameID, hTeamID, vTeamID): _require(CheckWitness(operaterAddress) or CheckWitness(adminAddress)) gck = _concatKey(GameCountPrefix, date) gameCount = Get(ctx, gck) if not gameCount: gameCount = 0 if gameCount > 0: for i in range(1, gameCount + 1): tmpgk = _concatKey(_concatKey(GamePrefix, date), i) tmpGame = Deserialize(Get(ctx, tmpgk)) if tmpGame['GameID'] == gameID: return False Put(ctx, gck, gameCount + 1) gk = _concatKey(_concatKey(GamePrefix, date), gameCount + 1) game = { 'GameID': gameID, 'HTeamID': hTeamID, 'HTeamScore': '0', 'VTeamID': vTeamID, 'VTeamScore': '0' } Put(ctx, gk, Serialize(game)) betKey = _concatKey(BetPrefix, gameID) bet = { 'BetEnd': False, 'Finished': False, 'HomeList': [], 'VistorList': [], 'HomeTotal': 0, 'VisitorTotal': 0 } Put(ctx, betKey, Serialize(bet)) return True
def getMatchByDate(date): gck = _concatKey(GameCountPrefix, date) gameCount = Get(ctx, gck) res = '' if (gameCount > 0): for i in range(1, gameCount + 1): gk = _concatKey(_concatKey(GamePrefix, date), i) gamei = Get(ctx, gk) gameMap = Deserialize(gamei) gameid = gameMap[GameID] hteamid = gameMap[HTeamID] hteamScore = gameMap[HTeamScore] vteamid = gameMap[VTeamID] vteamScore = gameMap[VTeamScore] tmp = _concatStrs( [gameid, hteamid, hteamScore, vteamid, vteamScore], ',') if i == 1: res = tmp else: res = _concatKey(res, tmp) return res
def endBet(date): _require(CheckWitness(operaterAddress) or CheckWitness(adminAddress)) ekey = _concatKey(EndPrefix, date) end = Get(ctx, ekey) if end == True: return False gameCount = Get(ctx, _concatKey(GameCountPrefix, date)) for i in range(1, gameCount + 1): gk = _concatKey(_concatKey(GamePrefix, date), i) gamei = Get(ctx, gk) gameMap = Deserialize(gamei) gameid = gameMap[GameID] betKey = _concatKey(BetPrefix, gameid) betgame = Get(ctx, betKey) betgameMap = Deserialize(betgame) betgameMap[BetEnd] = True Put(ctx, betKey, Serialize(betgameMap)) Put(ctx, ekey, True) return True