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 Main(): """ :return: """ start = 4 stop = 9 # int # out = [10,2, 3, 4, 6, 7] length = stop - start out = list(length=length) index = 0 orig_start = start while start < stop: val = index + orig_start out[index] = val index = index + 1 start = orig_start + index Notify(start) # d = stuff(1, 2) # this doesn't work at the moment return out[4]
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 n_range(start, stop): """ range(start, stop) -> list object Return an list that is a a sequence of integers from start (inclusive) to stop (exclusive). range(i, j) produces i, i+1, i+2, ..., j-1. """ # out = [] # if start >= stop: # return out length = stop - start out = list(length=length) index = 0 orig_start = start while start < stop: val = index + orig_start out[index] = val index = index + 1 start = orig_start + index return out
def _data_unpacking(data_str): output = list() str_tmp='' for c in data_str : if (c == ';'): output.append(str_tmp) str_tmp = '' else : str_tmp = str_tmp+c return output
def license_product(args): """ Grant a license for a specific product, can only be called by the product owner: :param args: args[0]: product_id args[1]: user_id (user public key) :return: bool """ # unpacking args product_id = args[0] user_id = args[1] if not is_owner(product_id): return False product = init_product(product_id) height = GetHeight() product_expiration = product.pe # check if the product can still be licensed if height > product_expiration: print('This product cannot be licensed anymore, it has expired') return False # check if there are still licenses available max_license_number = product.mln current_licenses = product.cln if current_licenses == max_license_number: print('licenses have been sold out!') return False license_id = concat(product_id, user_id) # block height at which the license expires license_duration = product.le license_expiration = height + license_duration license_data = list(length=3) license_data[0] = user_id license_data[1] = license_expiration license_data[2] = product_id Put(GetContext, license_id, license_data) cln = increment_cln(product_id) return True
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 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 GetTXInputs(): tx = GetScriptContainer() inputs = tx.Inputs inputlen = len(inputs) results = list(length=inputlen) count = 0 for input in tx.Inputs: txid = GetHash(input) index = GetIndex(input) item = [txid, index] results[count] = item count += 1 return results
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): # 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 register_product(args): """ :param args: args[0]: senderhash args[1]: product id (something unique) args[2]: description (human readable description of the product, keep as short as possible to keep gas price as low as possible) args[3]: max_license_number; args[4]: make transferable; args[5]: product_expiration; blockheight at which the product is expired (no more licences will be distributed) args[6]: license_expiration; number of blocks for which a license is valid args[7]: autosell (bool) args[8]: price (gas) :return: bool """ product_id = args[1] product_exists = Get(GetContext, product_id) product_data = list(length=8) product_data[0] = args[0] product_data[2] = args[2] product_data[3] = args[3] product_data[4] = args[4] product_data[5] = args[5] product_data[6] = args[6] # this is the total amount sold product_data[7] = 0 product_data[8] = args[7] product_data[9] = args[8] if not product_exists: serialized_product_data = serialize_array(args) Put(GetContext, product_id, serialized_product_data) print("product registered") return True else: print("product already exists") return
def ClaimBounty(issue_url): attachments = get_asset_attachments() storage = StorageAPI() storage_location = 'issue:claims:' + issue_url bounty_claims = storage.get(storage_location) element_count = 1 for c in bounty_claims: if c == ',': element_count = element_count + 1 elements = list(length=element_count) current_element = 0 for c in bounty_claims: if c == ',': current_element = current_element + 1 else: elements[current_element] = elements[current_element] + c found = False for element in elements: if element == attachments.sender_addr: found = True break if not found: if element_count > 0: bounty_claims = bounty_claims + ',' bounty_claims = bounty_claims + attachments.sender_addr storage.put(storage_location, bounty_claims) return True return False
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