0

My solidity "0.7.0" contract

pragma solidity ^0.7.0;

contract DoubleEscrowTrade {
    uint256 private locked = 2; //2: unlocked, 1: locked. uint256 is gas efficient than bool
    uint256 public value=0;  //poster value
    uint256 public bidItemValue=0;  //bidder item value
    bool public openForBid = false;  //allow items with any value to bid.
    string public posterItemName;
    string public whoInitDispute;
    uint256 public posterItemID;
    string public bidderItemName; //no string array supported
    uint256 public bidderItemID;
    mapping (address=>address) public bidItemAddress; // bidder address and bidder item deploy address
    mapping (address=>uint256) public bidItemID;
    mapping (address=>uint256) public bidValue;
    mapping (address=>string) public bidItemName;
    uint256 public howManyBidItem=0;
    address payable public poster;
    address payable public bidder;
    bool public delisted = false;
    bool public posterDispute = false;
    bool public bidderDispute = false;
    bool public posterShipped = false;
    bool public bidderShipped = false;
    uint256 public posterReceiveProdTime = 0;
    uint256 public bidderReceiveProdTime = 0;
    uint256 public posterReceiveReturnTime = 0;
    uint256 public bidderReceiveReturnTime = 0;
    uint256 public posterAcceptBidTime = 0;
    uint256 public posterEscrowBalance = 0;
    uint256 public posterEscrowRefund = 0;
    uint256 public bidderEscrowBalance = 0;
    uint256 public bidderEscrowRefund = 0;
    uint256 public bidderShipProdTime = 0;
    uint256 public posterShipProdTime = 0;
    uint256 public posterDepositTime = 0;
    uint256 public bidderDepositTime = 0;
    uint256 public posterDisputeTime = 0;
    uint256 public bidderDisputeTime = 0;
    uint256 public posterDelistTime = 0;
    uint256 private graceDay = 14;
    uint256 private dayInSecond = 24*3600;
    enum State { ForTrade, PosterAcceptBid, PosterEscrowDeposited, BidderEscrowDeposited, PosterDelisted, BidderCancelled, BidderShipped, PosterShipped, 
    InDispute, Complete, PosterReceiveProduct, PosterReceiveReturn, BidderReceiveProduct, BidderReceiveReturn }
    State public state;

The public variables include address, mapping, uint256, string and bool. The app can get value for a public variable myVar with myContract.myVar(). However there will be excessive number of requests with so many variables and it is tedious as well. Based on my reading, I probably can get all uint256 variables with return (var1, var2, ... varN) in an array. But I am not sure if mapping, bool, string and address can be all returned within one return in solidity 0.7.0. Or there is a even better way to handle this.

1

2 Answers 2

1

By return(<...>) you can return not so many values. These values will be returned in a stack and compiler doesn't let you make the stack too deep. It is independent of variables type. There are many variables in the contract code and I am almost sure that you can't return all them by just one return(<...>).

By observing the number limit in the returned values in return(<...>), You can return public bool, string, address, and mapping by it.

1

I had a similar issue, and there are a few approaches to this.

1.You can -as you had noted- return it all one by one.

2.You can try to pack it all into a single huge array.

3.You could return multiple arrays. One containing addresses, the other one containing uint256 variables etc.

In your case (If you don't need an entire map, but just a single value mapped here). I would advise using an array of strings that returns all the values as such. In that way, all the data will be preserved in a nice readable format.

However, to return an array of strings you need to add [pragma experimental ABIEncoderV2; ] to your code.

Like this:

pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; // Added experimental encoder

contract DoubleEscrowTrade {
    uint256 private locked = 2; //2: unlocked, 1: locked. uint256 is gas efficient than bool
    uint256 public value=0;  //poster value
    uint256 public bidItemValue=0;  //bidder item value
    bool public openForBid = false;  //allow items with any value to bid.
    string public posterItemName;
    string public whoInitDispute;
    uint256 public posterItemID;
    string public bidderItemName; //no string array supported
    uint256 public bidderItemID;
    mapping (address=>address) public bidItemAddress; // bidder address and bidder item deploy address
    mapping (address=>uint256) public bidItemID;
    mapping (address=>uint256) public bidValue;
    mapping (address=>string) public bidItemName;
    uint256 public howManyBidItem=0;
    address payable public poster;
    address payable public bidder;
    bool public delisted = false;
    bool public posterDispute = false;
    bool public bidderDispute = false;
    bool public posterShipped = false;
    bool public bidderShipped = false;
    uint256 public posterReceiveProdTime = 0;
    uint256 public bidderReceiveProdTime = 0;
    uint256 public posterReceiveReturnTime = 0;
    uint256 public bidderReceiveReturnTime = 0;
    uint256 public posterAcceptBidTime = 0;
    uint256 public posterEscrowBalance = 0;
    uint256 public posterEscrowRefund = 0;
    uint256 public bidderEscrowBalance = 0;
    uint256 public bidderEscrowRefund = 0;
    uint256 public bidderShipProdTime = 0;
    uint256 public posterShipProdTime = 0;
    uint256 public posterDepositTime = 0;
    uint256 public bidderDepositTime = 0;
    uint256 public posterDisputeTime = 0;
    uint256 public bidderDisputeTime = 0;
    uint256 public posterDelistTime = 0;
    uint256 private graceDay = 14;
    uint256 private dayInSecond = 24*3600;
    enum State { ForTrade, PosterAcceptBid, PosterEscrowDeposited, BidderEscrowDeposited, PosterDelisted, BidderCancelled, BidderShipped, PosterShipped, 
    InDispute, Complete, PosterReceiveProduct, PosterReceiveReturn, BidderReceiveProduct, BidderReceiveReturn }
    State public state;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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