Cant change mapping after contract its created

AugustoLAugustoL ArgentinaMember Posts: 8
I have this contract:
contract DBIndex is Smart{
    // DB Name
    string db_name;
    // Addresses of the collections
    mapping (string => address) collections;

    // DBIndex constructor using name
    function DBIndex( string new_db_name ) {
        db_name = new_db_name;
        collections["Test"] = 0x68339135e5f2b0eab86dc594981c70fe9065701a;
    // Get collection by name
    function getCollection( string collection_name ) constant returns (address collection_address) {
        return collections[collection_name];


    // Add a collection
    function addCollection( string new_collection_name, address new_collection_address ) public constant returns (bool success) {
        if (msg.sender != super_owner)
            return false;
        collections[new_collection_name] = new_collection_address;
        return true;
    // Get DB name
    function getName() constant returns (string) {
        return string(db_name);
The contract its created fine, I add a "Test" on the mapping of collections for testing the getCollection() function.

And I execute the following actions, where I add a collection to the mapping of collections.
function addCollection(callback) {

        console.log("Adding collections on DB: "+web3.eth.contract(indexABI).at(indexAddress).getName());

        web3.eth.contract(indexABI).at(indexAddress).addCollection.sendTransaction( "Users", usersAddress, { from: web3.eth.accounts[0] }, function(err, tx) {
            if (err)

            console.log('Waiting '+tx+' to be mined.');
            var waitForTX = setInterval(function() {
                if (isTXMined(tx)) {
                    console.log('TX '+tx+' mined.');
            }, 1000);



    function isTXMined(tx){
        var txBlock = web3.eth.getTransaction(tx).blockNumber;
        var currentBlock = web3.eth.blockNumber;
        //console.log(txBlock+' <= '+currentBlock);
        if ( (txBlock != null) && (parseInt(txBlock) <= parseInt(currentBlock)) )
            return true;
            return false;
The problem is that it dosent seems to write coreectly the mapping collections, please see the output of the getCollections Users that im triying to add.

console.log("Getting collections on DB: "+web3.eth.contract(indexABI).at(indexAddress).getName());
console.log(web3.eth.contract(indexABI).at(indexAddress) "Users" )); <- HERE IS THE PROBLEM
console.log(web3.eth.contract(indexABI).at(indexAddress) "Test" ));

The output:

Getting collections on DB: DIDB

So..what Im doing wrong?!

Please help!

Sign In or Register to comment.