0

in my solidity code I create a tracking-contract and auction-contracts out of a factory-contract. The last function 'a4_Payment' of the auction-contract should be triggered out of the master-contract in the 'ProofOfDelivery'-function with a requirement that the destination defined in the auction is the same as the recent address in the tracking-contract. This requirement doesn't work for me and I am at a loss of what the problem is. The thing is that it worked quite well until I added another entity to the 'createAuction'-function. In the current code I add the recent address of the tracking-contract as the 'departure' for the auction. Without this addition my requirement for the 'ProofOfDelivery' worked fine. Do I run into some sort of loop right now? Compiling the whole thing works but then I can't deploy my master-contract.

Error Message: Creation of Pi_Container errored: transaction execution failed.

Current code:

pragma solidity ^0.5.11; 
pragma experimental ABIEncoderV2;

//Master contrauctor-tracking + RecentAddress ohne ProofOfDelivery

contract PI_Container {

    Auction auction;
    Tracking tracking;

    address NewAuction;
    address Pi_C_Owner;
    address public NewTracking;
    address payable public NewAuctionPayable;


    constructor() public {
        NewTracking = address (new Tracking(msg.sender));
        tracking = Tracking(NewTracking);
        Pi_C_Owner = msg.sender;
    }

    function checkBalance() public view returns(uint) { 
        require(msg.sender == Pi_C_Owner,"Insufficient permission");
        return(address(this).balance);
    }

    function increaseBalance() public payable {
        require(msg.sender == Pi_C_Owner,"Insufficient permission");
    }

    function createAuction(address _Destination, uint _WTP, uint _BiddingTime) public returns(address) {
        require(_WTP > 0,"Willingness to pay has to exceed 0.");
        require(_BiddingTime > 0,"Bidding time has to exceed 0.");
        NewAuction = address (new Auction(tracking.RecentAddress(), _Destination, _WTP, _BiddingTime, address(this)));
        NewAuctionPayable = address(uint160(NewAuction));
        auction = Auction(NewAuctionPayable);
        NewAuctionPayable.transfer(_WTP);
        return(NewAuctionPayable);
    }

    function ProofOfDelivery() public {
        //require(auction.Destination() == tracking.RecentAddress(),"Destination not yet reached.");
        auction.a4_Payment();
    }

    function() external payable {
    }
}

contract Tracking {

    uint RecordId;
    uint public RecordCount;
    address public RecentAddress;

    struct Record{
        uint id;
        address adr;            
        string pifunction;
        string coordinates;
        uint time;
    }    

    mapping(uint => Record) records;

    constructor(address _Source) public {
        RecentAddress = _Source;
    }

    function a_addRecord(string memory PI_Function, string memory Coordinates) public {
        records[RecordId] = Record(RecordId, msg.sender, PI_Function, Coordinates, now);
        RecordId++;
        RecordCount = RecordId;
        RecentAddress = msg.sender;
    }

    function b_getRecord(uint RecordID) public view returns(Record memory) {
        return records[RecordID];
    }

    function c_getAddresses() public view returns(address[] memory) {
        address[] memory adr = new address[](RecordId);
        for(uint i = 0; i < RecordId; i++) {
            Record storage record = records[i];
            adr[i] = record.adr;
        }
        return(adr);
    }

    function d_getPI_Functions() public view returns(string[] memory) {
        string[] memory pifunction = new string[](RecordId);
        for(uint i = 0; i < RecordId; i++) {
            Record storage record = records[i];
            pifunction[i] = record.pifunction;
        }
        return(pifunction);
    }

    function e_getCoordinates() public view returns(string[] memory) {
        string[] memory coordinates = new string[](RecordId);
        for(uint i = 0; i < RecordId; i++) {
            Record storage record = records[i];
            coordinates[i] = record.coordinates;
        }
        return(coordinates);
    }   
}

contract Auction {

    bool Ended;
    uint WTP;
    uint public LowestBid;
    uint public SafetyDeposit;
    uint public AuctionEndTime;
    address public Departure;
    address public Destination;
    address payable MasterPayable;
    address payable LowestBidder;
    address payable Payee;

    struct Participant {
        bool biddingright;
        uint amount;
    }

    mapping(address => Participant) participants;
    address payable[] depositor;


    constructor(address _Departure, address _Destination, uint _WTP, uint _BiddingTime, address payable _Master) public {
        Departure = _Departure;
        Destination = _Destination;
        WTP = _WTP;
        SafetyDeposit = _WTP/2;
        LowestBid = _WTP;
        AuctionEndTime = now + _BiddingTime;
        MasterPayable = _Master;
        Ended = false;
    }

    function a1_getRights() public payable { 
        require(now <= AuctionEndTime,"Auction already ended.");
        require(msg.value >= SafetyDeposit,"Value has to atleast amount to 'safety deposit'.");
        require(participants[msg.sender].biddingright == false,"Safety deposit already payed.");
        participants[msg.sender].biddingright = true;
        participants[msg.sender].amount = msg.value;
        depositor.push(msg.sender);
    }

    function a2_placeBid(uint Bid) public {                                         
        require(now <= AuctionEndTime,"Auction already ended.");
        require(Bid < LowestBid,"There already is a lower bid.");
        require(participants[msg.sender].biddingright == true,"Please note safety deposit.");
        LowestBidder = msg.sender;
        LowestBid = Bid;
    }

    function a3_AuctionEnd() public {
        require(now >= AuctionEndTime,"Auction not yet ended.");
        require(Ended == false,"Auction end has already been called.");
        Ended = true;
        MasterPayable.transfer(WTP-LowestBid);                          
        for(uint i=0; i<depositor.length; i++) {
            Payee = depositor[i];
            if(Payee != LowestBidder) {
                Payee.transfer(participants[Payee].amount);         
            }
        }
    }

    function a4_Payment() public {
        require(Ended == true,"Destination not yet reached.");
        selfdestruct(LowestBidder);
    }

    function() external payable {
    }
}

I know that this is a lot to take in but I feel stuck right now and would really need some help.

Thanks in advance.

  • 1
    Please define doesn't work for me (otherwise this is just a code-dump with a request for others to figure out what's wrong with it). – goodvibration Oct 17 '19 at 15:27
  • I added the error message I receive when trying to deploy my factory contract. I don't know how I can further describe the problem but I know that it has something to do with they requirement in my ProofOfDelivery-function because without it deployment works just fine. – Siewi Oct 19 '19 at 11:56
  • Works fine for me. Maybe you've got something wrong in your transaction parameters. Can you please share how you are attempting to deploy this contract? – goodvibration Oct 19 '19 at 15:21
  • Did you delete the slashes in the ProofOfDelivery-function. At the moment the code kind of works because the requirement is just added as a comment. If it still works in your case I feel really stupid ;) – Siewi Oct 19 '19 at 17:58
  • I didn't delete anything. Your error-message says Creation of Pi_Container errored, which means that the failure occurred at the actual construction (deployment) of your contract. And your contract's constructor does not call this function, so whether or not you delete this function is not supposed to have any impact on the error that you've described whatsoever. – goodvibration Oct 19 '19 at 18:05

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.