Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/out
/out
/build
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export SOLC_FLAGS=--optimize
export SETH_GAS=3000000
all:; dapp build
test:; dapp test -v
deploy:; seth send --create 0x"`cat out/DSFeeds200.bin`" -G 3000000
deploy:; dapp create DSFeeds
24 changes: 6 additions & 18 deletions src/feeds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pragma solidity ^0.4.8;

import "./interface.sol";


contract DSFeeds is DSFeedsInterface, DSFeedsEvents
{
mapping (bytes12 => Feed) feeds;
Expand Down Expand Up @@ -137,31 +136,20 @@ contract DSFeeds is DSFeedsInterface, DSFeedsEvents
// Reading feeds
//------------------------------------------------------------------

function has(bytes12 id) returns (bool) {
if (expired(id)) {
return false;
} else {
return true;
}
}

function get(bytes12 id) returns (bytes32 value) {
var (val, ok) = tryGet(id);
if(!ok) throw;
return val;
function peek(bytes12 id) constant returns (bool) {
return can_get(msg.sender, id);
}

function tryGet(bytes12 id) returns (bytes32 value, bool ok) {
if (can_get(msg.sender, id)) {
return (feeds[id].value, true);
}
function read(bytes12 id) returns (bytes32 value) {
if (!can_get(msg.sender, id)) throw;
return feeds[id].value;
}

// Override for PaidDSFeeds
function can_get(address user, bytes12 id)
internal returns (bool)
{
return has(id);
return !expired(id);
}

}
7 changes: 2 additions & 5 deletions src/interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ contract DSFeedsEvents {
contract DSFeedsInterface {
function claim() returns (bytes12 id);
function set(bytes12 id, bytes32 value, uint40 expiration);
function has(bytes12 id) returns (bool ok);
function get(bytes12 id) returns (bytes32 value);
function tryGet(bytes12 id) returns (bytes32 value, bool ok);
function peek(bytes12 id) constant returns (bool ok);
function read(bytes12 id) returns (bytes32 value);
}


1 change: 0 additions & 1 deletion src/paid_feeds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
pragma solidity ^0.4.8;

import "erc20/erc20.sol";
import "./interface.sol";
import "./feeds.sol";

contract PaidDSFeedsEvents is DSFeedsEvents {
Expand Down
37 changes: 16 additions & 21 deletions src/paid_feeds.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pragma solidity ^0.4.8;

import "ds-test/test.sol";
import "erc20/erc20.sol";
import "./interface.sol";
import "./paid_feeds.sol";

contract PaidDSFeedsTest is DSTest,
Expand Down Expand Up @@ -62,9 +61,8 @@ contract PaidDSFeedsTest is DSTest,
feeds.set(id, 0x1234, time() + 1);
LogSet(id, 0x1234, time() + 1);

var (value, ok) = assistant.tryGet(id);
var value = assistant.read(id);
assertEq32(value, 0x1234);
assert(ok);
}

function test_get_expired() {
Expand All @@ -73,8 +71,7 @@ contract PaidDSFeedsTest is DSTest,
feeds.set(id, 0x1234, 123);
LogSet(id, 0x1234, 123);

var (value, ok) = feeds.tryGet(id);
assertEq32(value, 0);
var ok = feeds.peek(id);
assert(!ok);
}

Expand All @@ -89,10 +86,11 @@ contract PaidDSFeedsTest is DSTest,

token.set_balance(assistant, 2000);

var (value, ok) = assistant.tryGet(id);
var ok = assistant.peek(id);
assert(ok);
var value = assistant.read(id);
LogPay(id, assistant);
assertEq32(value, 0x1234);
assert(ok);

assertEq(token.balances(assistant), 1950);
}
Expand All @@ -108,19 +106,17 @@ contract PaidDSFeedsTest is DSTest,

token.set_balance(assistant, 2000);

var (value_1, ok_1) = assistant.tryGet(id);
var value_1 = assistant.read(id);
LogPay(id, assistant);
assertEq32(value_1, 0x1234);
assert(ok_1);

var (value_2, ok_2) = assistant.tryGet(id);
var value_2 = assistant.read(id);
assertEq32(value_2, 0x1234);
assert(ok_2);

assertEq(token.balances(assistant), 1950);
}

function test_failed_payment_throwing_token() {
function testFail_payment_throwing_token() {
expectEventsExact(feeds);

feeds.set_price(id, 50);
Expand All @@ -131,11 +127,7 @@ contract PaidDSFeedsTest is DSTest,

token.set_balance(assistant, 49);

var (value, ok) = assistant.tryGet(id);
assertEq32(value, 0);
assert(!ok);

assertEq(token.balances(assistant), 49);
var value = assistant.read(id);
}

function test_failed_payment_nonthrowing_token() {
Expand All @@ -150,8 +142,7 @@ contract PaidDSFeedsTest is DSTest,
token.set_balance(assistant, 49);
token.disable_throwing();

var (value, ok) = assistant.tryGet(id);
assertEq32(value, 0);
var ok = assistant.peek(id);
assert(!ok);

assertEq(token.balances(assistant), 49);
Expand Down Expand Up @@ -202,8 +193,12 @@ contract FakePerson {
feed = feed_;
}

function tryGet(bytes12 id) returns (bytes32 value, bool ok) {
return feed.tryGet(id);
function peek(bytes12 id) returns (bool ok) {
return feed.peek(id);
}

function read(bytes12 id) returns (bytes32 value) {
return feed.read(id);
}

function set_price(bytes12 id, uint price) {
Expand Down