Skip to content

치킨집등록

KIMDAEYOUNG3144 edited this page Sep 7, 2021 · 3 revisions

Store 구조체 선언

struct Store {
        string storeName;
        address ceoAccount;
        string location;
        string menu;
        uint countRoom;
        uint256 cookingTime;
        uint8 finishType;
}

Stores 배열

Store[] public stores;

Store 등록

function StoreRegistration(string memory _storeName, address _ceoAccount, 
    string memory _location, string memory _menu, uint _countRoom, uint256 _cookingTime, uint8 _finishType) public returns(bool) {
    Store memory newStore;
    newStore.storeName = _storeName;
    newStore.ceoAccount = _ceoAccount;
    newStore.location = _location;
    newStore.menu = _menu;
    newStore.countRoom = _countRoom;
    newStore.cookingTime = _cookingTime;
    newStore.finishType = _finishType;

    stores.push(newStore);
      
    return true;
    }

호출예시

truffle console
ChickenHouse.deployed().then(function(instance) {return instance.StoreRegistration('BHC', '0x8eC5664F0Dc532F87A30e44580fEE8dEa1505635', 
'Gasan', 'Hot', 4, 10, 1)})
ChickenHouse.deployed().then(function(instance) {return instance.StoreRegistration('BHC', '0x94DEAb10A5Af0E31602981b75081c0C72bCB4e33', 
'Bucheon', 'Red', 4, 10, 1)})
ChickenHouse.deployed().then(function(instance) {return instance.StoreRegistration('KFC', '0x575C9c2925DECEed549318B8C77E56DF77585211', 
'Onsu', 'Nomal', 7, 15, 2)})

Store 조회

function getStoresById(uint _storeId) public view returns(
        string memory storeName,
        address ceoAccount,
        string memory location,
        string memory menu,
        uint countRoom,
        uint256 cookingTime,
        uint8 finishType) 
        {

        Store memory store = stores[_storeId];
        return (
            store.storeName,
            store.ceoAccount,
            store.location,
            store.menu,
            store.countRoom,
            store.cookingTime,
            store.finishType);
    }

호출예시

truffle console

truffle(development)> ChickenHouse.deployed().then(function(instance) {return instance.getStoresById.call(0)})
truffle(development)> ChickenHouse.deployed().then(function(instance) {return instance.getStoresById.call(1)})
truffle(development)> ChickenHouse.deployed().then(function(instance) {return instance.getStoresById.call(2)})