2

I'm getting a strange error in Solidity. I have the following public function:

struct Bid {
    address bidder;
    uint amount; /* in wei */
    bool home; /* true=home, false=away */
    int64 line;
}

event BidPlaced(bytes32 indexed game_id, BookType book, address bidder, uint amount, bool home, int64 line);

function test(bytes32 game_id, bool home, int64 line) payable returns (int) {
    Game game = getGameById(game_id);
    Book book = game.books[uint(BookType.Spread)];
    Bid memory bid = Bid(msg.sender, msg.value, home, line);

    // problem is right here
    book.homeBids.push(bid);

    BidPlaced(game_id, BookType.Spread, msg.sender, msg.value, home, line);
    return 0;
}

When I call the function with contract.test.call(...), it returns 0, but when I run contract.test.sendTransaction(...), the BidPlaced event doesn't log.

When I check the receipt for how much gas is being used, it shows the expected amount, so I know an error isn't being thrown.

If I get rid of the book.homeBids.push(bid); line, the event logs properly. What about that line could cause a problem?

1

Figured out the answer, it was trivial, but I'll leave it up here anyways for others running into the same problem.

The default gas amount for my transactions was 90000 and the gas estimate for the functionality was 110000, so the transaction was running out of gas. I upped the gas passed to the transaction and it worked:

contract.test.sendTransaction(..., { from: 0x00.., value: 10000, gas: 120000 })
  • You should mark your answer correct – Tjaden Hess Mar 29 '17 at 1:35
  • 1
    @TjadenHess I have to wait 24 more hours to do so, I will do so as soon as I can – k26dr Mar 30 '17 at 0:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.