0

I am running into a strange issue with following contract-

pragma solidity ^0.4.25;
contract ApprovedPOCreateAndOwnershipTransferContract {

    struct PO{
        bytes32 bill_to_location;
        bytes32 ship_to_location;
        bool exists;
    }

    //mapping(bytes32 => PO) poMap;

    mapping(uint256 => PO) poMap;  


    event PODebugParameters(
        uint256 po_num,
        //bytes32 po_num_key,     
        uint256 business_unit_id,
        bytes32 ipfs_hash,
        bytes32 bill_to_location,
        bytes32 ship_to_location,
        uint256 po_status_code,
        uint256 bill_to_location_code,
        uint256 ship_to_location_code,
        address maintain_org_add_map_contract_add_sender,
        address maintain_org_add_map_contract_add_receiver,
        address msg_receiver,
        uint256 supplier_id,
        uint256  status
    );

    /**
     * Method to save approved PO in BC raised from ERP,compute hash of string (PO_num + PO Last Update date)
     */
    function saveApprovedPONotSigned(uint256 po_num,                                 
                                    uint256 business_unit_id,
                                    bytes32 ipfs_hash,
                                    bytes32 bill_to_location,
                                    bytes32 ship_to_location,
                                    uint256 po_status_code,
                                    uint256 bill_to_location_code,
                                    uint256 ship_to_location_code,
                                    address maintain_org_add_map_contract_add_sender,
                                    address maintain_org_add_map_contract_add_receiver,
                                    address msg_receiver,
                                    uint256 supplier_id,
                                    uint256  status) external {        


        //chk for approved status of PO
        require(po_status_code == 1, "PO is not approved in ERP");


        //chk whether bill_to_location = 'Dallas' & ship_to_location = 'Florida'
        require(bill_to_location_code == 1 && ship_to_location_code == 2, "PO raised with incorrect billing or shipping locations");

        poMap[po_num].exists = true;
        poMap[po_num].bill_to_location = bill_to_location;
        poMap[po_num].ship_to_location = ship_to_location;

        emit PODebugParameters(po_num,business_unit_id,ipfs_hash,bill_to_location,ship_to_location,po_status_code,bill_to_location_code,ship_to_location_code,maintain_org_add_map_contract_add_sender,maintain_org_add_map_contract_add_receiver,msg_receiver,supplier_id,status);

    }  


    /**
     * Method to verify for an existing PO in a bill_to_location & ship_to_location combination for ASN module
     */ 
    function verifyForExistingPO(uint256 po_num,bytes32 bill_to_location,bytes32 ship_to_location) constant external returns (bool){
        if (poMap[po_num].bill_to_location == bill_to_location && poMap[po_num].ship_to_location == ship_to_location){
            return true;
        }else{
            return false;
        }
    }


}

When I test this contract from remix the mapping variable is getting set but when I try testing using web3js(0.20.6) from a node js it program like below -

web3Obj.eth.sendTransaction({ from: sender_acct_info, to: contract_add, data: data, gasLimit: 105395, gasPrice: gasPriceHex }, function (err, result) {...}); 

The transaction gets mined mined but fails (I enabled debug trace also). The state of the variable is not changed.

Could anyone please help with this issue?

geth version - 1.7.3-stable

Thanks.

  • One strange thing observed if I remove bool exists field from the struct then it is working from web3js program also. Else the transaction is failing. – BlockchainNewbie Feb 2 at 11:34
  • Your web3 testing method is wrong. Function web3.eth.sendTransaction invokes the fallback function of your contract. – goodvibration Feb 2 at 11:35
  • You use gasLimit as an option in sendTransaction but the correct is gas (github.com/ethereum/wiki/wiki/…). – Ismael Feb 3 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.