Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #82 from ethereum/simplerdeed
Browse files Browse the repository at this point in the history
Simplify deed, so it takes its balance in the constructor
  • Loading branch information
Arachnid committed Mar 27, 2017
2 parents 6df4527 + 80b138a commit 2603c38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
11 changes: 3 additions & 8 deletions HashRegistrarSimplified.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ contract Deed {
_;
}

function Deed(uint _value) {
function Deed() payable {
registrar = msg.sender;
creationDate = now;
active = true;
value = _value;
value = msg.value;
}

function setOwner(address newOwner) onlyRegistrar {
Expand Down Expand Up @@ -88,9 +88,6 @@ contract Deed {
if(owner.send(this.balance))
selfdestruct(burn);
}

// The default function just receives an amount
function () payable {}
}

/**
Expand Down Expand Up @@ -305,11 +302,9 @@ contract Registrar {
if (address(sealedBids[msg.sender][sealedBid]) > 0 ) throw;
if (msg.value < minPrice) throw;
// creates a new hash contract with the owner
Deed newBid = new Deed(msg.value);
Deed newBid = (new Deed).value(msg.value)();
sealedBids[msg.sender][sealedBid] = newBid;
NewBid(sealedBid, msg.sender, msg.value);

if (!newBid.send(msg.value)) throw;
}

/**
Expand Down
27 changes: 20 additions & 7 deletions test/simplehashregistrar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,15 +1070,28 @@ describe('SimpleHashRegistrar', function() {
},
// Sneakily top up the bid
function(done) {
registrar.sealedBids(bid.account, bid.sealedBid, function(err, result) {
registrar.sealedBids(bid.account, bid.sealedBid, function(err, deedAddress) {
assert.equal(err, null, err);
web3.eth.sendTransaction({from: accounts[0], to: result, value: 2e18}, function(err, txid) {
web3.eth.getBalance(result, function(err, balance) {
done();
});
});
// Deploy a self-destructing contract to top up the account
web3.eth.contract([{"inputs":[{"name":"target","type":"address"}],"payable":true,"type":"constructor"}]).new(
deedAddress,
{
from: accounts[0],
data: "0x6060604052604051602080607b833981016040528080519060200190919050505b8073ffffffffffffffffffffffffffffffffffffffff16ff5b505b60338060486000396000f30060606040525bfe00a165627a7a72305820d4d9412759c88c41f1dd38f8ae34c9c2fa9d5c9fa90eadb1b343a98155e74bb50029",
gas: 4700000,
value: 2e18,
}, function(err, contract) {
assert.equal(err, null, err);
if(contract.address != undefined) {
// Check the balance was topped up.
web3.eth.getBalance(deedAddress, function(err, balance) {
assert.equal(err, null, err);
assert.equal(balance, 3000000000000000000);
done();
});
}
});
});
// done();
},
// Reveal the underfunded bid
function(done) {
Expand Down

0 comments on commit 2603c38

Please sign in to comment.