def Main(): """ :return: """ count = 0 r = range(0, 4) for i in range(0, 4): count += wah(i, count) # h = wah() # print(count) return count
def ForceJudge(prediction_name, context): # Find Losers and Collect GAS # Find Winners # Distribute GAS to Winners # Move onto next timestamp current_timestamp = GetCurrentTimestamp(prediction_name, context) winning_prediction = GetPrediction(prediction_name, current_timestamp, context) oracles = GetOracles(prediction_name, current_timestamp, context) nOracles = len(oracles) // 20 LoserBalance = 0 nWinners = 0 for i in range(0, nOracles): start = 20 * i oracle = substr(oracles, start, 20) Log(oracle) Log("Checking if oracle lied") submitted_price = GetSubmission(prediction_name, current_timestamp, oracle, context) if winning_prediction != submitted_price: Log("Player did LIE!") LoserBalance = LoserBalance + GetBalance(prediction_name, oracle, context) ZeroBalance(prediction_name, oracle, context) else: Log("Player told the TRUTH!") AddWinner(prediction_name, current_timestamp, oracle, context) nWinners = nWinners + 1 # Now distribute winnings to Winners if nWinners > 0: winnings = LoserBalance // nWinners winners = GetWinners(prediction_name, current_timestamp, context) for i in range(0, nWinners): start = 20 * i winner = substr(winners, start, 20) AddBalance(prediction_name, winner, winnings, context) UpdatePrice(prediction_name, current_timestamp, winning_prediction, context) Notify(winning_prediction) # Move onto next timestamp next_ts = NextTimestamp(current_timestamp) UpdateTimestamp(prediction_name, next_ts, context) return True
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 return False
def Main(): """ :return: """ print("holla?" ) # using pythonic print(), this is tranlated to Neo.Runtime.Log start = 4 stop = 9 r = range(start, stop) # using built in Neo.Runtime.Log( this is the same as print(message) ) Log("hellllllllloo") # using the Neo.Runtime.Notify ( this is for logging variables... ) Notify(start) l = list(length=stop) l[3] = 17 b = r[3] print("hullo") return b
def deserialize_bytearray(data): # 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 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 = 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 contains(string, substr): string_len = len(string) last_search_index = string_len - len(substr) substr_len = len(substr) for i in range(0, last_search_index): if substr(string, i, substr_len) == substr: return True return False
def Main(): """ :return: """ mmm = range(2, 14) l = mmm[2] # type:int Notify(l) empty = list() b = get_thing() c = get_items_from_range(mmm, 7) k = range(10, 12) return l + b + c + k[0]
def Main(): """ :return: """ count = 0 for i in range(0, 5): count = count + i count += awesome() count += not_so_awesome() return count
def Main(a): # you can call a method that has no arguments like this # should I fix it? I kind of like it a = dostuff # even if a method doesnt return something, its result has to be # assigned otherwise stuff gets messed b = no_ret_val() for i in range(0, 13): print(i) return a
def Main(): """ :return: """ a = range(100, 120) # b = a[4] # this will fail, since the range list is only 4 elements long # ( 0, 1, 2, 3 ) b = a[3] # q = add_items(4, 4) return b
def deserialize_bytearray(self, data): # neo-boa bug, Something is require here for some reason... # pointless = True print('deserialize_bytearray') # 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) print(item) # store it in collection new_collection[i] = item # trim the data newdata = newdata[end:] return new_collection
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 deserialize_bytearray(data): """ Helper method to deserialize a byte array. """ # 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 AddEntry(): tx = GetScriptContainer() context = GetContext() references = tx.References if _TimeHasExpired(): # refund gas and neo and pick winner PickWinner() return 0 print("adding entry") if len(references) < 1: print("no gas attached") return False print("reading reference") reference = references[0] print("reference read") sender = GetScriptHash(reference) print("sender hash is") print(sender) print("reading script hash") print("getting asset ID. ID is here:") output_asset_id = GetAssetId(reference) print(output_asset_id) print('asset id printed above') if output_asset_id == GAS_ASSET_ID: print("executing script hash") receiver = GetExecutingScriptHash() for output in tx.Outputs: shash = GetScriptHash(output) print("getting shash..") if shash == receiver: print("adding value?") value = GetValue(output) / 100000000 print("value storing in entries") print(value) print('string we will save to the entries array') entries = Get(context, 'entries') print('current entries') print(entries) remainder = value % 1 print('remainder is') Notify(remainder) value = value - remainder print('remainder and value set') Notify(value) if value > 0: if entries != bytearray(b''): print('deserializing the byte array') entries = deserialize_bytearray(entries) end = len(entries) + value if end > 1024: print('contest capped at 1024') return 0 new_entries = range(0, end) i = 0 for item in new_entries: if i < len(entries): new_entries[i] = entries[i] else: new_entries[i] = sender i += 1 # last_entry = entries[len(entries) - 1] # colon_index = [pos for pos, char in enumerate( # last_entry) if char == ':'] # previous_total = substr( # last_entry, 0, colon_index) else: print('setting an empty array') # list isn't working below new_entries = range(0, value) j = 0 for item in new_entries: new_entries[j] = sender j += 1 else: print("no gas added") Notify(new_entries) new_entries = serialize_array(new_entries) Put(context, "entries", new_entries) return entries
def VerifyWithdrawalRequest(args): account = args[0] current_balance = BalanceOf(account) if current_balance == 0: print("No Current balance") return False if CheckHasPendingWithdrawal(account): print("already a pending withdrawal") return False arglen = len(args) txids_len = arglen / 2 vin_requests = list(length=txids_len) # so, this is a bit involved, so bear with me here # lets assume a person has a balance that the contract owes them # we need to allow them to put a hold on some tx vins that they can 'claim' # after they have put the hold on them, they can withdraw and in the # verification portion of the contract it will allow them # but they may need to put a hold on tx vins that have a value # more than they are owed. So we want to allow them to put a hold # on x number of txids, where the amount contained in x-1 vins is less than the amount they are owed # and the amount in x txids is greater than or equal to the amount they are owed # but only by one hold_amount = 0 okcount = 0 for i in range(0, txids_len): j = i * 2 request_vin_tx = args[j + 1] request_vin_index = args[j + 2] vin = LookupVIN(request_vin_tx, request_vin_index) if vin and vin[1] == NEO_ASSET_ID: actual_amount = vin[0] # if the amount being held is less than the current balance # it is ok, we allow the vin request # this allows the hold amount to go over # but if it is too much then invalidate # the entire request if hold_amount < current_balance: hold_amount += actual_amount vin_request = [request_vin_tx, request_vin_index] vin_requests[i] = vin_request okcount += 1 if okcount != txids_len: print("Invalid txid request") return False Notify(hold_amount) Notify(current_balance) # now that we've checked the requestor isn't requesting too much # we will check that the requestor can put a hold on the vins # we make sure they can put a hold on all the vins # before actually placing the hold on the vin for vin in vin_requests: vin_tx = vin[0] vin_index = vin[1] has_hold = HasVINHold(vin_tx, vin_index) if has_hold: print("Cannot request withdrawal, vin(s) already have hold") return False # now that we're sure we can put holds on all the requested vins # we will put holds on the requested vins output = None for vin in vin_requests: vin_tx = vin[0] vin_index = vin[1] hold_req = PlaceVINHold(account, vin_tx, vin_index) # now we assemble a bytearray # to save to storage vin = concat(vin_index, vin_tx) if len(output) > 1: output = concat(output, vin) else: output = vin onWithdrawRequestApproved(account, vin_requests) m = SetPendingWithdrawal(account, output) return vin_requests
def Main(operation, args): """ :param operation: new, submit, judge, getvalue :param args: optional arguments :return: Bool """ trigger = GetTrigger() if trigger == Application: Log("trigger: Application") context = GetContext() if operation == 'getvalue': Log("op: getvalue") key = args[0] return Get(context, key) if operation == 'new': id = args[0] Put(context, "current_game", id) Log("Created a new game") elif operation == 'submit': id = args[0] price = args[1] Log(id) Log(price) # Only allow submissions for the current game current_game = Get(context, "current_game") if current_game != id: Log("Not the correct game") return False tx = GetScriptContainer() refs = tx.References nRef = len(refs) Log(nRef) ref = refs[0] sender = GetScriptHash(ref) Log(sender) key = concat(sender, id) Log(key) oldprice = Get(context, key) if oldprice == 0: Append(context, sender, id) Put(context, key, price) # Update if already exists elif operation == 'judge': id = args[0] playerkey = concat("players::", id) curr_list = Get(context, playerkey) nplayers = len(curr_list) // 20 max = 0 best_price = -1 for i in range(0, nplayers): start = 20 * i player = substr(curr_list, start, 20) Log(player) key = concat(player, id) price = Get(context, key) price_key = concat(id, price) count = Increment(context, price_key) if count > max: max = count best_price = price if max == 0: Log("No entries") return False else: Log(max) Log(best_price) Put(context, id, best_price) return True return True return False
def Main(operation, args): """ :param operation: new, submit, judge, getvalue :param args: optional arguments :return: Bool """ trigger = GetTrigger() if trigger == Application: Log("trigger: Application") context = GetContext() if operation == 'getvalue': Log("op: getvalue") key = args[0] return Get(context, key) if operation == 'new': Log("op: new") id = args[0] Put(context, "current_game", id) Put(context, "max", 0) Log("Created a new game") Notify(id) elif operation == 'submit': id = args[0] price = args[1] sender = args[2] Log(id) Log(price) Log(sender) # Only allow submissions for the current game current_game = Get(context, "current_game") if current_game != id: Log("Not the correct game") return False if not CheckWitness(sender): Log("Oracle is not the right person") return False Log(sender) key = concat(sender, id) Log(key) oldprice = Get(context, key) if oldprice != 0: # Too late you've already submitted Log("Error: cannot submit twice for the same game") return False Append(context, sender, id) Put(context, key, price) # Update if already exists max = Get(context, 'max') price_key = concat(id, price) count = Increment(context, price_key) if count > max: Put(context, 'max', count) Put(context, id, price) Log("Updated best price") return True elif operation == 'judge': id = args[0] playerkey = concat("players::", id) curr_list = Get(context, playerkey) nplayers = len(curr_list) // 20 decided_price = Get(context, id) for i in range(0, nplayers): start = 20 * i player = substr(curr_list, start, 20) Log(player) Log("Checking if player lied") key = concat(player, id) price = Get(context, key) if decided_price != price: Log("Player did LIE!") else: Log("Player told the TRUTH!") return True return True return False