Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com
- function prompt()
- local block
- local data_table
- io.write("\n")
- print_help()
- while true do
- io.write("> ")
- input = io.read("*l")
- if input == "help" then
- print_help()
- elseif input == "quit" or input == "q" or input == "exit" then
- break
- elseif input == "create" then
- com:advertise_blockchain("test")
- elseif input == "new" then
- block = Block()
- if not block then
- error("An error has occurred: the block has not been created\n")
- os.exit()
- else
- print("Your block has been succefuly created.")
- print("Add data on this block before commiting it and advertising it.\n")
- end
- elseif input == "data" then
- if not block then
- print("You don't have any new current block to add data.")
- print("Please, create a new block to add data.\n")
- else
- print_add_help()
- while true do
- io.write("current_block> ")
- data_block = io.read("*l")
- if data_block == "show" then
- -- print data of your current block
- data_table = block:get_data()
- if table_is_empty(data_table) then
- print("There is no data on this block yet\n")
- else
- print("\nINDEX\tDATA")
- for key,value in pairs(data_table) do
- print(key, value)
- end
- io.write("\n")
- end
- elseif data_block == "add" then
- -- write data and put them on your block
- print("\nWrite your current Block new data:")
- -- prompt
- io.write("current_block:add> ")
- -- write new data
- data_add = io.read("*l")
- print("New data: " .. data_add .. "\n")
- -- checking if the data is satisfactory to the user
- print("Put this data on my block ?")
- print("\ty/yes -- put it")
- print("\tn/no -- quit without put any new data\n")
- data_add_check = io.read("*l")
- if data_add_check == "y" or data_add_check == "yes" then
- -- set data on this block
- block:set_data(data_add)
- elseif data_add_check == "n" or data_add_check == "no" then
- break
- else
- print("Invalid command\n")
- end
- elseif data_block == "remove" then
- -- remove a particular data you put on your block
- if table_is_empty(data_table) then
- print("You don't have any data on your block\n")
- else
- print("\nWrite the index of the data you want remove (0 to remove all data):")
- -- prompt
- io.write("current_block:remove> ")
- local index_remove = io.read("*n")
- local table_length = table_length(data_table)
- if index_remove <= table_length then
- if index_remove == 0 then
- print("Remove all the data of this block ?")
- print("\ty/yes -- remove all")
- print("\tn/no -- quit without remove")
- local remove_all_check = io.read("*l")
- if remove_all_check == "y" or remove_all_check == "yes" then
- -- remove all data on this block
- block:remove_all()
- elseif remove_all_check == "n" or remove_all_check == "no" then
- break
- else
- print("Invalid command\n")
- end
- else
- -- remove the data at the specify index
- block:remove(index_remove)
- print("Data at index " .. index_remove .. " have been remove\n")
- end
- else
- print("Invalid index.\n")
- print("Do \"show\" to see your data with their index\n")
- end
- end
- elseif data_block == "clear" then
- -- remove all data of your block
- print("clear")
- elseif data_block == "help_add" then
- -- display the add play
- print_add_help()
- elseif data_block == "help" then
- -- display the general help
- print_help()
- elseif data_block == "quit" or data_block == "q" or data_block == "exit" then
- -- quit the add command
- break
- else
- print("Invalid command\n")
- end
- end
- end
- elseif input == "commit" then
- print("commit")
- elseif input == "advertise" then
- print("advertise")
- elseif input == "request" then
- print("request")
- elseif input == "share" then
- print("share")
- elseif input == "validate" then
- print("validate")
- elseif input == "deny" then
- print("deny")
- elseif input == "accept" then
- print("accept")
- else
- print("Invalid command\n")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement