This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.23; | |
contract OwnershipProof{ | |
//FileDetails structure | |
struct FileDetails { | |
uint256 timestamp; | |
string owner; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.23; | |
contract OwnershipProof{ | |
//FileDetails structure | |
struct FileDetails { | |
uint256 timestamp; | |
string owner; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract FoodCart{ | |
/* set owner of contract */ | |
address owner; | |
/* a variable to track the most recent sku of a food item */ | |
uint8 skuCount; | |
/* an enum to store food item state */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FoodCart = artifacts.require("./FoodCart.sol"); | |
module.exports = function(deployer) { | |
deployer.deploy(FoodCart); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truffle(develop)> let addFoodItemToCart = (foodName, price) => {foodCart.addFoodItem(foodName, price).then((trxn) => { const details = trxn.logs[0].args; details.sku = details.sku.toNumber(); details.price = details.price.toNumber(); details.state = trxn.logs[0].event; console.log(details);});} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truffle(develop)> addFoodItemToCart('Fried Rice', 10); | |
truffle(develop)> { name: 'Fried Rice',sku: 0, price: 10, state: 'ForSale', foodItemExist: true } //output | |
truffle(develop)> addFoodItemToCart('Chicken Pepper Soup', 10); | |
truffle(develop)> { name: 'Chicken Pepper Soup', sku: 1, price: 10, state: 'ForSale', foodItemExist: true } //output | |
truffle(develop)> addFoodItemToCart('Pepperoni Pizza', 50); | |
truffle(develop)> { name: 'Pepperoni Pizza', sku: 2, price: 50, state: 'ForSale', foodItemExist: true } //output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let buyFoodItemFromCart = (itemSku, amount) => {foodCart.buyFoodItem(itemSku, {from: buyerAddress, value: amount}).then((trxn) => { const details = trxn.logs[0].args; details.sku = details.sku.toNumber(); details.price = details.price.toNumber(); details.state = trxn.logs[0].event; console.log(details);});} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truffle(develop)> buyFoodItemFromCart(0, 10); | |
truffle(develop)> { name: 'Fried Rice', sku: 0, price: 10, state: 'Sold', foodItemExist: false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
truffle(develop)> buyFoodItemFromCart(6, 10); | |
truffle(develop)> UnhandledPromiseRejectionWarning: Error: VM Exception while processing transaction: revert ... |
OlderNewer