def payOrder(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems): tryPayment = True attempts = 1 data = {} data["trace-id"] = str(TraceId) data["event-name"] = 2 # "Pay Order" data["actor"] = "Customer" data["n-items"] = str(nItems) while(tryPayment): data["attempt-num"] = str(attempts) json_data = json.dumps(data, indent=2) print("pay order") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) paymentAccepted = takePayment(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client) if(paymentAccepted): # Send Order return nItems elif(random() > 0.9): tryPayment = False else: tryPayment = True attempts += 1 print("Not retry") return 0 # Not Retry
def browseProducts(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, itemsInTheCart): data = {} data["trace-id"] = str(TraceId) data["event-name"] = 0 # "Browse Products on Amazon" data["actor"] = "Customer" json_data = json.dumps(data, indent=2) print("browse products") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) return addItemToCart(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, itemsInTheCart)
def placeInBin(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems): data = {} data["trace-id"] = str(TraceId) data["event-name"] = 5 # "Place in Bin" data["actor"] = "Amazon Picker" data["n-items"] = str(nItems) json_data = json.dumps(data, indent=2) print("place in bin") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) return receiveAndPackageItems(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems)
def receiveAndPackageItems(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems): data = {} data["trace-id"] = str(TraceId) data["event-name"] = 6 # "Receive and Package Items" data["actor"] = "Amazon Packager" data["n-items"] = str(nItems) json_data = json.dumps(data, indent=2) print("receive and package items") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) return sendToCarrierDock(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems)
def sendToCarrierDock(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems): data = {} data["trace-id"] = str(TraceId) data["event-name"] = 7 # "Send to Carrier Dock" data["actor"] = "Amazon Packager" data["n-items"] = str(nItems) json_data = json.dumps(data, indent=2) print("send to carrier dock") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) return loadTruck(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems)
def loadTruck(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems): data = {} data["trace-id"] = str(TraceId) data["event-name"] = 8 # "Load Truck" data["actor"] = "Carrier" data["n-items"] = str(nItems) json_data = json.dumps(data, indent=2) print("load truck") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) return deliverItems(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItems)
def receiveItems(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, nItemsReceived): data = {} data["trace-id"] = str(TraceId) data["event-name"] = 10 # "Receive Items" data["actor"] = "Customer" data["n-items"] = str(nItemsReceived) json_data = json.dumps(data, indent=2) print("receive items") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) return nItemsReceived
def addItemToCart(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, itemsInTheCart): itemsInTheCart += 1 data = {} data["trace-id"] = str(TraceId) data["event-name"] = 1 # "Add Item to Cart" data["n-items"] = str(itemsInTheCart) data["actor"] = "Customer" json_data = json.dumps(data, indent=2) print("add item to cart") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # Done Shopping? if(random() > 0.5): # No return browseProducts(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, itemsInTheCart) else: # Yes return payOrder(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client, itemsInTheCart)
def takePayment(TraceId, managerAddr, managerPassphrase, receiverAddr, algod_client): accepted = False if(random() <= 0.7): accepted = True data = {} data["trace-id"] = str(TraceId) data["event-name"] = 3 # "Take Payment" data["actor"] = "Credit Card Company" data["accepted"] = str(accepted) json_data = json.dumps(data, indent=2) print("take payment") newTransaction(algod_client, managerAddr, managerPassphrase, receiverAddr, 0, json_data) # print(json_data) return accepted