2

I have the following contract that handles address arrays:

contract C {

    address[] goodAddr;
    address[] badAddr;

    function initAddr() constant {

        if(goodAddr.length == 0) {
            goodAddr.push(0x029ddf2082bc96d321c9769ec8e27e10b3cb16ee);
        }

        if(badAddr.length == 0) {
            badAddr.push(0x115744603fedb255e5ab4765cc1dc6c832639fd5);
        }

        if(goodAddr.length == 1 && badAddr.length == 1) {
            return;
        }

        for(uint256 i = 0; i < goodAddr.length; i++) {
            if(goodAddr[i] == 0x029ddf2082bc96d321c9769ec8e27e10b3cb16ee)
                return;
        }

        for(i = 0; i < badAddr.length; i++) {
            if(badAddr[i] == 0x115744603fedb255e5ab4765cc1dc6c832639fd5)
                return;
        }

        goodAddr.push(0x029ddf2082bc96d321c9769ec8e27e10b3cb16ee);
        badAddr.push(0x115744603fedb255e5ab4765cc1dc6c832639fd5);
    }

    function getGoodAddr(uint256 i) constant returns (address) {
        if(i < 0 || i >= goodAddr.length) {
            return 0x0000000000000000000000000000000000000000;
        } else {
            return goodAddr[i];
        }
    }

    function getBadAddr(uint256 i) constant returns (address) {
        if(i < 0 || i >= badAddr.length) {
            return 0x0000000000000000000000000000000000000000;
        } else {
            return badAddr[i];
        }
    }
}

The code runs fine on browser solidity but fails to initialize the address arrays when run locally (on a private test net):

    > eth.accounts
["0x029ddf2082bc96d321c9769ec8e27e10b3cb16ee", "0x115744603fedb255e5ab4765cc1dc6c832639fd5"]
    > checkAllBalances();
  eth.accounts[0]: 0x029ddf2082bc96d321c9769ec8e27e10b3cb16ee   balance: 55922.95 ether
  eth.accounts[1]: 0x115744603fedb255e5ab4765cc1dc6c832639fd5   balance: 1337 ether
undefined
    > var c = cContract.new(
    ..    {
    ......      from: web3.eth.accounts[0], 
    ...... {0600101610568565b5090565b5b5050509190906000526020600020900160005b73115744603fedb255e5ab4765cc1dc6c832639fd5909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550505b5056', 
    ......      gas: 4700000
    ......    }, function (e, contract){
    ......     console.log(e, contract);
    ......     if (typeof contract.address !== 'undefined') {
    ..........          console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    ..........     }
    ......  });
    Unlock account 029ddf2082bc96d321c9769ec8e27e10b3cb16ee
    Passphrase: 
    null [object Object]
    undefined
    > null [object Object]
    Contract mined! address: 0xb43c8d6c6ee366358f170553602f2a0fc8ebe1d6 transactionHash: 0x8741c2ccae448a1cc647bdc03883e9136dadcec7adf942832f46bdcbe02e2eae

    > c
    {
      address: "0xb43c8d6c6ee366358f170553602f2a0fc8ebe1d6",
      transactionHash: "0x8741c2ccae448a1cc647bdc03883e9136dadcec7adf942832f46bdcbe02e2eae",
      allEvents: function(),
      getBadAddr: function(),
      getGoodAddr: function(),
      initAddr: function()
    }
    > c.initAddr.call();
    []
    > c.getBadAddr(0);
    "0x0000000000000000000000000000000000000000"
    > c.getGoodAddr(0);
    "0x0000000000000000000000000000000000000000"
    > 

Is this a bug in geth? I'm using version 1.3.5.

I've updated to version 1.4 but now all command line arguments are not valid. When I run the following instance:

 geth --datadir "./datadir" --networkid 13 --rpcapi eth,web3,personal --rpc --maxpeers 0 init "gen.json" --etherbase "0x0000000000000000000000000000000000000000" --mine --minerthreads 2

I get the error:

Incorrect Usage.

init [arguments...]

The init command initialises a new genesis block and definition for the network.
This is a destructive action and changes the network in which you will be
participating.


flag provided but not defined: -etherbase

Edit:

Any particular reason for the downvote?

Sebi
  • 5,294
  • 6
  • 27
  • 52
  • There where already serveral issues with old 1.3.5 version ... maybe upgrade? there are tutorials here how to do it... – Roland Kofler Jul 27 '16 at 11:43
  • I've updated geth but now all command line arguments are invalid. Do you know where I can find some details on the init argument? The explanation here https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options#init is not very intuitive. – Sebi Jul 27 '16 at 15:34
  • Any reason for the downvote? – Sebi Jul 27 '16 at 21:17
  • 1
    @Sebi Did you get your command line working? If not, it's a separate question. – eth Aug 10 '16 at 11:09
  • 1
    @Sebi, sorry I must have misclicked. – q9f Dec 25 '16 at 13:33

1 Answers1

2

I don't think that this is a bug. These lines in initAddr signifies that it is performing write operation (State Change). goodAddr.push(0x029ddf2082bc96d321c9769ec8e27e10b3cb16ee); badAddr.push(0x115744603fedb255e5ab4765cc1dc6c832639fd5);

Probably you need to use .sendTransaction() to call the initAddr. And remove the constant from this function, only then the changes will reflect in arrays. Code
> c.getBadAddr(0); "0x0000000000000000000000000000000000000000"
is returning the default initial value of the address data type. Let me know the result after implementing this.

Aniket
  • 3,545
  • 2
  • 20
  • 42
  • No, I don't since I have a contract object. – Sebi Jul 27 '16 at 13:42
  • I didn't get you – Aniket Jul 27 '16 at 13:45
  • You don't need sendTransaction() to call contract procedures. – Sebi Jul 27 '16 at 13:47
  • Go through it : https://github.com/ethereum/go-ethereum/wiki/Contract-Tutorial#cleaning-up-after-yourself – Aniket Jul 27 '16 at 13:52
  • 2
    Please don't downvote without expressing your reason. – Aniket Jul 28 '16 at 05:34
  • 2
    This answer seems correct. initAddr() should not be constant since it's changing state. The code works in Browser Solidity since the solidity compiler doesn't enforce constant yet, so a transaction is used when initAddr is invoked. – eth Aug 10 '16 at 11:15
  • The issue was that I did not send any balance associated to that method hence it did not get executed. – Sebi Aug 10 '16 at 11:58
  • I don't know why people down-voted the question & answer too. We are here to discuss. – Aniket Aug 10 '16 at 12:30