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;
    }
}
thefett
  • 3,873
  • 5
  • 26
  • 48
  • What do you mean it doesn't work? Do you get ang error? – Badr Bellaj May 27 '17 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 '17 at 18:59

1 Answers1

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.

thefett
  • 3,873
  • 5
  • 26
  • 48
  • You're correct. Have a look here for a method of representing prices as decimals (which I think is what you're getting at... ): https://ethereum.stackexchange.com/questions/11733/building-a-floating-rate-on-the-tokens – Richard Horrocks Jun 28 '17 at 11:28