{"action":"created","issue":{"url":"https://api.github.com/repos/hyperledger/burrow/issues/258","repository_url":"https://api.github.com/repos/hyperledger/burrow","labels_url":"https://api.github.com/repos/hyperledger/burrow/issues/258/labels{/name}","comments_url":"https://api.github.com/repos/hyperledger/burrow/issues/258/comments","events_url":"https://api.github.com/repos/hyperledger/burrow/issues/258/events","html_url":"https://github.com/hyperledger/burrow/issues/258","id":175208278,"number":258,"title":"Unable to return array from contract","user":{"login":"somak12","id":14160083,"avatar_url":"https://avatars3.githubusercontent.com/u/14160083?v=3","gravatar_id":"","url":"https://api.github.com/users/somak12","html_url":"https://github.com/somak12","followers_url":"https://api.github.com/users/somak12/followers","following_url":"https://api.github.com/users/somak12/following{/other_user}","gists_url":"https://api.github.com/users/somak12/gists{/gist_id}","starred_url":"https://api.github.com/users/somak12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/somak12/subscriptions","organizations_url":"https://api.github.com/users/somak12/orgs","repos_url":"https://api.github.com/users/somak12/repos","events_url":"https://api.github.com/users/somak12/events{/privacy}","received_events_url":"https://api.github.com/users/somak12/received_events","type":"User","site_admin":false},"labels":[{"id":222028495,"url":"https://api.github.com/repos/hyperledger/burrow/labels/bug/confirmed","name":"bug/confirmed","color":"e99695","default":false},{"id":488125709,"url":"https://api.github.com/repos/hyperledger/burrow/labels/triaged","name":"triaged","color":"144900","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/hyperledger/burrow/milestones/6","html_url":"https://github.com/hyperledger/burrow/milestone/6","labels_url":"https://api.github.com/repos/hyperledger/burrow/milestones/6/labels","id":2152039,"number":6,"title":"0.16.1","description":null,"creator":{"login":"benjaminbollen","id":5057507,"avatar_url":"https://avatars3.githubusercontent.com/u/5057507?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaminbollen","html_url":"https://github.com/benjaminbollen","followers_url":"https://api.github.com/users/benjaminbollen/followers","following_url":"https://api.github.com/users/benjaminbollen/following{/other_user}","gists_url":"https://api.github.com/users/benjaminbollen/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaminbollen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaminbollen/subscriptions","organizations_url":"https://api.github.com/users/benjaminbollen/orgs","repos_url":"https://api.github.com/users/benjaminbollen/repos","events_url":"https://api.github.com/users/benjaminbollen/events{/privacy}","received_events_url":"https://api.github.com/users/benjaminbollen/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":4,"state":"open","created_at":"2016-11-22T17:25:40Z","updated_at":"2017-05-10T11:10:24Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-09-06T10:04:27Z","updated_at":"2017-05-10T15:59:42Z","closed_at":null,"body":"Hi,\r\nI have a simple contract which returns few arrays. Works fine in the online solidity compiler. But after deploying it to the chain and invoking it from the app.js its giving the following error. \r\n\r\nHave found a bug related to this https://github.com/eris-ltd/eris-db.js/issues/27\r\n\r\nAny particular reason why this error is occurring?  \r\n\r\nMy contract is like: \r\n```javascript\r\nfunction getMarket() constant returns(uint[], uint[], uint[], uint[]) {\r\n    uint[] memory optionIDs = new uint[](20);\r\n    uint[] memory strikes_ = new uint[](20);\r\n    uint[] memory positions_ = new uint[](20);\r\n    uint[] memory cashes = new uint[](20);\r\n    uint z = 0;\r\n      for (uint i=0; i<10; i++) {\r\n        optionIDs[i] = i;\r\n        strikes_[i] = i+10;\r\n        positions_[i] = i+100;\r\n        cashes[i] = i+50;\r\n        z++;\r\n      }\r\n    return (optionIDs, strikes_, positions_, cashes);\r\n  }\r\n```\r\n\r\nError is:\r\n```\r\n[JSON RPC 2.0 Error] Message Id: 1, (INTERNAL_ERROR) - Error when transacting: Memory out of bounds\r\n[Error: Error when transacting: Memory out of bounds]\r\nError callback from sendTransaction\r\n\r\n/home/azureuser/.eris/apps/test/app.js:50\r\n    if (error) { throw error; }\r\n                       ^\r\nError: Error when transacting: Memory out of bounds\r\n    at /home/azureuser/.eris/apps/test/node_modules/eris-contracts/node_modules/eris-db/lib/rpc/http.js:79:22\r\n    at httpRequest.onreadystatechange (/home/azureuser/.eris/apps/test/node_modules/eris-contracts/node_modules/eris-db/lib/rpc/http.js:103:17)\r\n    at dispatchEvent (/home/azureuser/.eris/apps/test/node_modules/eris-contracts/node_modules/eris-db/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:572:25)\r\n    at setState (/home/azureuser/.eris/apps/test/node_modules/eris-contracts/node_modules/eris-db/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:14)\r\n    at IncomingMessage.<anonymous> (/home/azureuser/.eris/apps/test/node_modules/eris-contracts/node_modules/eris-db/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:431:13)\r\n    at IncomingMessage.EventEmitter.emit (events.js:117:20)\r\n    at _stream_readable.js:920:16\r\n    at process._tickCallback (node.js:415:13)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/hyperledger/burrow/issues/comments/300529545","html_url":"https://github.com/hyperledger/burrow/issues/258#issuecomment-300529545","issue_url":"https://api.github.com/repos/hyperledger/burrow/issues/258","id":300529545,"user":{"login":"silasdavis","id":99715,"avatar_url":"https://avatars2.githubusercontent.com/u/99715?v=3","gravatar_id":"","url":"https://api.github.com/users/silasdavis","html_url":"https://github.com/silasdavis","followers_url":"https://api.github.com/users/silasdavis/followers","following_url":"https://api.github.com/users/silasdavis/following{/other_user}","gists_url":"https://api.github.com/users/silasdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/silasdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silasdavis/subscriptions","organizations_url":"https://api.github.com/users/silasdavis/orgs","repos_url":"https://api.github.com/users/silasdavis/repos","events_url":"https://api.github.com/users/silasdavis/events{/privacy}","received_events_url":"https://api.github.com/users/silasdavis/received_events","type":"User","site_admin":false},"created_at":"2017-05-10T15:59:42Z","updated_at":"2017-05-10T15:59:42Z","body":"@somak12 so having looked into this, the initialisation-time dynamic memory arrays (size is a parameter you pass the constructor at runtime) are not yet supported by the EVM. The issue there is that  As you correctly point out on remix (browser solidity) it does work, and I am told this is implemented as something as a work-around in web3 that uses internal knowledge of then state to allow for dynamic array returns.\r\n\r\nThe problem is that when you make a `CALL` you have to specify the return position and size in memory, see here: https://github.com/ethereum/solidity/issues/164. So there is not a general solution in Solidity. However there is a proposal to provide a mechanism in Ethereum to do this more efficiently via two new opcodes see: https://github.com/ethereum/EIPs/pull/211\r\n\r\nIn the meantime, the following will work (will return the arrays) (I have been trying this against #607):\r\n\r\n```javascript\r\n    function getMarket() constant returns(uint[20], uint[20], uint[20], uint[20]){\r\n        uint[20] memory optionIDs;\r\n        uint[20] memory strikes_;\r\n        uint[20] memory positions_;\r\n        uint[20] memory cashes;\r\n        uint z = 0;\r\n          for (uint i=0; i<10; i++) {\r\n            optionIDs[i] = i;\r\n            strikes_[i] = i+10;\r\n            positions_[i] = i+100;\r\n            cashes[i] = i+50;\r\n            z++;\r\n          }\r\n        return (optionIDs, strikes_, positions_, cashes);\r\n      }\r\n```\r\n\r\nIf you want to use dynamic arrays internally (as in without returning those values) then you will be able to do so after #607 is merged."}}
{"actor":{"display_login":"silasdavis"}}