def buyCat(from_acc, animal, amount): if not CheckWitness(from_acc): Notify("Not the owner, can't buy") return False tmplist = Get(ctx, from_acc + "CAT") if len(tmplist) != 0: delist = Deserialize(tmplist) Notify(delist) delist.append(animal) Notify(delist) Put(ctx, from_acc + "CAT", Serialize(delist)) else: Put(ctx, from_acc + "CAT", Serialize([animal])) Notify(Serialize([animal])) current_balance = Get(ctx, from_acc) if current_balance <= amount: Notify("Insufficient funds") return False to_balance = Get(ctx, TOKEN_OWNER) to_balance += amount Put(ctx, TOKEN_OWNER, to_balance) current_balance -= amount if current_balance != 0: Put(ctx, from_acc, current_balance) else: Delete(ctx, from_acc) OnTransfer(from_acc, TOKEN_OWNER, amount) return True
def add_to_board_list(board_id): serialized_list = Get(ctx, AD_LIST_KEY) board_list = Deserialize(serialized_list) board_list.append(board_id) serizlized_list = Serialize(board_list) Put(ctx, AD_LIST_KEY, serizlized_list) return True
def addPostId(postId): check_allPostIds() Notify("[!] Add PostID to all_posts object") serial = Get(GetContext(), get_all_ids) all_posts = Deserialize(serial) all_posts.append(postId) new_serial = Serialize(all_posts) Put(GetContext(), get_all_ids, new_serial) Notify("[!] Added PostID to all_posts object")
def put_serialized(ctx, key, value): list_bytes = Get(ctx, key) if len(list_bytes) != 0: lst = Deserialize(list_bytes) lst.append(value) else: lst = [value] list_bytes = Serialize(lst) Put(ctx, key, list_bytes) return True
def _save_space_ids(new_id): ids = Get(ctx, KEY_SPACE_IDS) if ids: deserialized = Deserialize(ids) deserialized.append(new_id) Put(ctx, KEY_SPACE_IDS, Serialize(deserialized)) else: Put(ctx, KEY_SPACE_IDS, Serialize([new_id]))
def create_group(args): #check number of arguments if not len(args) % 2 != 0: returnStr = "Not right number of arguments" returnArray = [] returnArray.append(returnStr) return returnArray # check proposal existence group_id = args[len(args) - 1] if Get(ctx, group_id): returnStr = "Already a group with that name" returnArray = [] returnArray.append(returnStr) return returnArray participants = (len(args) - 1) / 2 # iterate to get participants (address, nicknames) group_participants = [] index = 0 while index < (len(args) - 1) / 2: address = args[index] if len(address) != 20: returnStr = "Bad address format" returnArray = [] returnArray.append(returnStr) return returnArray index += 1 index = 0 while index < (len(args) - 1) / 2: address = args[index] nickname = args[index + participants] group_participants.append([address, nickname]) if Get(ctx, address): fromStorage = Get(ctx, address) participant_groups = Deserialize(fromStorage) participant_groups[0].append( group_id ) #[[group_id1, group_id2], [ [bet1], [bet2]], [transactions], total_balance, total_balance sign ( 0 positiv, 1 negative) ] participant_storage = Serialize(participant_groups) else: #create storage for the current address participant_groups = [] participant_groups.append([]) participant_groups.append([]) participant_groups.append([]) participant_groups.append(0) participant_groups.append(0) participant_groups[0].append(group_id) participant_storage = Serialize(participant_groups) Put(ctx, address, participant_storage) index += 1 # proposal arguments group = [] group.append(group_participants) # participants group_bet = [] group.append(group_bet) # serialize proposal and write to storage group_storage = Serialize(group) Put(ctx, group_id, group_storage) current_block = GetHeight() returnStr = "Ok" returnArray = [] returnArray.append(returnStr) returnArray.append(current_block) return returnArray