0

I have a problem with my code.

contract Registration {
address public owner;
uint conceptPrice;
uint conceptValue;

function Registration(uint _conceptPrice) public {
    owner = msg.sender;
    conceptPrice = _conceptPrice;
    conceptValue = conceptPrice;
}
/////////////////////////////////////
/* Others code*/
/////////////////////////////////////
struct Request {
    uint reqId;
    uint amount;
    uint percentage;
    address modAdd;
    //0 for pending, 1 accept, 2 decline
    uint state;
}
//
Request[] public requests;
//mapping (uint => Request) requests;
function request(uint _amount, uint _percentage) public returns (uint numRequests) {
    bool present = false;
    for (uint i = 0; i <= participants.length; i++) {
        if (participants[i] == msg.sender) {
            present = true;
            break;
        }
    }
    //
    if (msg.sender == owner || _amount < conceptPrice || _amount < balances[msg.sender] || _percentage > 5 || present == false) return;
    Request memory req = Request({reqId : requests.length + 1, amount : _amount, percentage : _percentage, modAdd : msg.sender, state : 0});
    //bissogna togliere i soldi a chi fa l'offerta
    requests.push(req);
    numRequests = requests.length;
}

uint[] ident;
uint[] per;
uint[] amountV;

function pendingRequest() public {

    for (uint i = 0; i == requests.length; i++) {
        if (requests[i].state == 0) {
            ident.push(requests[i].reqId);
            per.push(requests[i].percentage);
            amountV.push(requests[i].amount);
        }
    }
}
function printReq() public constant returns (uint[] ident_){
    ident_ = ident;
}
}

I created two different request (numRequests =2) but when i try to take value from array of object Request through the function pendingRequest i have an error: status 0x0 Transaction mined but execution failed. Array requests have values inside for example requests at position one is:requests[1] Why?

Davide
  • 13
  • 3

1 Answers1

0

There is an error with your for loop:

for (uint i = 0; i == requests.length; i++) { ...  <-- this code is wrong

You probably are trying to iterate over the values of requests, so your code should look like:

function pendingRequest() public {
    for (uint i = 0; i < requests.length; i++) {
        ... do stuff
    }
}
Shawn Tabrizi
  • 8,008
  • 4
  • 19
  • 38