diff options
Diffstat (limited to 'docs/frequently-asked-questions.rst')
-rw-r--r-- | docs/frequently-asked-questions.rst | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 5c427c69..a6bead29 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -39,12 +39,13 @@ This is just the bytecode "data" sent along with the request. Is there a decompiler available? ================================ -There is no decompiler to Solidity. This is in principle possible -to some degree, but for example variable names will be lost and -great effort will be necessary to make it look similar to -the original source code. +There is no exact decompiler to Solidity, but +`Porosity <https://github.com/comaeio/porosity>`_ is close. +Because some information like variable names, comments, and +source code formatting is lost in the compilation process, +it is not possible to completely recover the original source code. -Bytecode can be decompiled to opcodes, a service that is provided by +Bytecode can be disassembled to opcodes, a service that is provided by several blockchain explorers. Contracts on the blockchain should have their original source @@ -111,10 +112,10 @@ array in the return statement. Pretty cool, huh? Example:: - pragma solidity ^0.4.0; + pragma solidity ^0.4.16; contract C { - function f() returns (uint8[5]) { + function f() public pure returns (uint8[5]) { string[4] memory adaArr = ["This", "is", "an", "array"]; return ([1, 2, 3, 4, 5]); } @@ -190,11 +191,11 @@ you should always convert it to a ``bytes`` first:: contract C { string s; - function append(byte c) { + function append(byte c) public { bytes(s).push(c); } - function set(uint i, byte c) { + function set(uint i, byte c) public { bytes(s)[i] = c; } } @@ -232,12 +233,14 @@ situation. If you do not want to throw, you can return a pair:: - pragma solidity ^0.4.0; + pragma solidity ^0.4.16; contract C { uint[] counters; function getCounter(uint index) + public + view returns (uint counter, bool error) { if (index >= counters.length) return (0, true); @@ -245,7 +248,7 @@ If you do not want to throw, you can return a pair:: return (counters[index], false); } - function checkCounter(uint index) { + function checkCounter(uint index) public view { var (counter, error) = getCounter(index); if (error) { // ... @@ -316,11 +319,11 @@ Example:: uint[] data1; uint[] data2; - function appendOne() { + function appendOne() public { append(data1); } - function appendTwo() { + function appendTwo() public { append(data2); } @@ -349,7 +352,7 @@ be created in memory, although it will be created in storage:: uint someVariable; uint[] data; - function f() { + function f() public { uint[] x; x.push(2); data = x; @@ -375,7 +378,7 @@ The correct way to do this is the following:: uint someVariable; uint[] data; - function f() { + function f() public { uint[] x = data; x.push(2); } @@ -431,14 +434,14 @@ What happens to a ``struct``'s mapping when copying over a ``struct``? This is a very interesting question. Suppose that we have a contract field set up like such:: - struct user { + struct User { mapping(string => string) comments; } - function somefunction { - user user1; + function somefunction public { + User user1; user1.comments["Hello"] = "World"; - user user2 = user1; + User user2 = user1; } In this case, the mapping of the struct being copied over into the userList is ignored as there is no "list of mapped keys". @@ -456,13 +459,13 @@ In this example:: pragma solidity ^0.4.0; contract B { - function B() payable {} + function B() public payable {} } contract A { address child; - function test() { + function test() public { child = (new B).value(10)(); //construct a new B with 10 wei } } @@ -501,17 +504,17 @@ Can a contract pass an array (static size) or string or ``bytes`` (dynamic size) Sure. Take care that if you cross the memory / storage boundary, independent copies will be created:: - pragma solidity ^0.4.0; + pragma solidity ^0.4.16; contract C { uint[20] x; - function f() { + function f() public { g(x); h(x); } - function g(uint[20] y) internal { + function g(uint[20] y) internal pure { y[2] = 3; } |