2

I am trying to update a struct variable of type enum

contract BookStore {

enum BookStatus { Open, Sold, Unsold }

mapping(uint => Book) stores;
uint public count;

struct Book{  
uint bookId;  
string name;    
BookStatus status;
}

function BookStore() {
count = 0;   
}

function addP(string _name) {
count += 1;
Book memory b1= Book(count,_name,BookStatus.Open);
stores[count] = b1;    
}

function updateStatus (uint _bookId) public {
Book storage b1= stores[_bookId];
b1.status = BookStatus.Sold;
}

function getStatus(uint _bookId) public returns (BookStatus) {
Book storage b1= stores[_bookId];
return b1.status;
}

}

I am running my project on testrpc. When I try to call the function from truffle console

BookStore.deployed().then(function(i) {i.updateStatus(7, {from: web3.eth.accounts[3], gas: 1000000}).then(function(f) {console.log(f)})});

I get the following error :

(node:2584) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): Error : VM Exception while processing transaction: invalid opcode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.