2

When I store data in the oracle and then try and refer to it on the testrpc through the pay function it just doesn't work. Any ideas?

pragma solidity ^0.4.6;

contract Oracle{
    struct DocumentStruct{
        uint value;
    }

    mapping(bytes32 => DocumentStruct) public documentStructs;

    function StoreDocument(bytes32 key, uint value) returns (bool success) {
        documentStructs[key].value = value;
        return true;
    }

}

contract Payment {
    address public counterparty1;
    address public counterparty2;
    uint public margin;
    address public oracleID;


    function Payment(address _cp2, address _oracleID) payable{
        margin = msg.value;
        counterparty1 = msg.sender;
        counterparty2 = _cp2;
        oracleID = _oracleID;
    }


    function Pay(bytes32 _keyval) returns (bool){
        var pValue = RetrieveData(_keyval);
        var npvalue = pValue >= margin ? (this.balance) : pValue;
        if (npvalue > 0 ){
            counterparty2.send(npvalue);
            return true;
        }
        else{
            throw;
        }
    }

    struct DocumentStruct{
        uint value;
    }    
    Oracle oracle;

    function RetrieveData(bytes32 key) 
    public
    constant
    returns(uint) 
    {
        oracle = Oracle(oracleID);
        DocumentStruct memory doc;
        (doc.value) = oracle.documentStructs(key);
        return doc.value;
    }
}
2
  • What do you mean it doesn't work? Do you get ang error?
    – Badr Bellaj
    May 27, 2017 at 14:47
  • It deploys fine, but then when I use the retrieve data function, it comes up blank and it pays as if it was blank. For some reason the contract isn't pulling the value (its as if I'm using the wrong key)
    – thefett
    May 27, 2017 at 18:59

1 Answer 1

1

Never mind guys, in case other people see this, the contract works, but it just pays out wei and its a uint. Correct me if I'm wrong, but I think I can't do decimals, and I'd need to somehow pay out that amount in Ether.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.