Skip to content

Commit

Permalink
Maintain legacy compatible function singatures that we honour our old…
Browse files Browse the repository at this point in the history
… API contracts forever.
  • Loading branch information
miohtama committed Nov 28, 2017
1 parent 6e137ef commit 9e38547
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
10 changes: 9 additions & 1 deletion contracts/Crowdsale.sol
Expand Up @@ -119,11 +119,19 @@ contract Crowdsale is CrowdsaleBase {
* Invest to tokens, recognize the payer.
*
*/
function buyWithCustomerId(uint128 customerId, bytes1 checksum) public payable {
function buyWithCustomerIdWithChecksum(uint128 customerId, bytes1 checksum) public payable {
// see customerid.py
if (bytes1(sha3(customerId)) != checksum) throw;
investWithCustomerId(msg.sender, customerId);
}

/**
* Legacy API signature.
*/
function buyWithCustomerId(uint128 customerId) public payable {
investWithCustomerId(msg.sender, customerId);
}

/**
* The basic entry point to participate the crowdsale process.
*
Expand Down
11 changes: 10 additions & 1 deletion contracts/PaymentForwarder.sol
Expand Up @@ -72,6 +72,7 @@ contract PaymentForwarder is Haltable {
*
*/
function pay(uint128 customerId, address benefactor, bytes1 checksum) public stopInEmergency payable {
// see customerid.py
if (bytes1(sha3(customerId, benefactor)) != checksum) throw;
payWithoutChecksum(customerId, benefactor);
}
Expand All @@ -82,9 +83,17 @@ contract PaymentForwarder is Haltable {
* @param customerId Identifier in the central database, UUID v4
*
*/
function payForMyself(uint128 customerId, bytes1 checksum) public payable {
function payForMyselfWithChecksum(uint128 customerId, bytes1 checksum) public payable {
// see customerid.py
if (bytes1(sha3(customerId)) != checksum) throw;
payWithoutChecksum(customerId, msg.sender);
}

/**
* Legacy API signature.
*/
function payForMyself(uint128 customerId) public payable {
payWithoutChecksum(customerId, msg.sender);
}

}
3 changes: 2 additions & 1 deletion ico/tests/contracts/test_forwarder.py
Expand Up @@ -8,6 +8,7 @@
from sha3 import keccak_256
from rlp.utils import decode_hex


@pytest.fixture
def payment_forwarder(chain, team_multisig):
args = [team_multisig, team_multisig]
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_pay_for_myself(web3, payment_forwarder, team_multisig, customer):
team_multisig_begin = web3.eth.getBalance(team_multisig)

checksumbyte = keccak_256(decode_hex(format(customer_id, 'x').zfill(32))).digest()[:1]
payment_forwarder.transact({"value": value, "from": customer}).payForMyself(customer_id, checksumbyte)
payment_forwarder.transact({"value": value, "from": customer}).payForMyselfWithChecksum(customer_id, checksumbyte)
team_multisig_end = web3.eth.getBalance(team_multisig)

assert team_multisig_end - team_multisig_begin > 0
Expand Down
2 changes: 1 addition & 1 deletion ico/tests/contracts/test_require_customer_id.py
Expand Up @@ -45,7 +45,7 @@ def test_participate_with_customer_id(chain, crowdsale, customer, customer_id, t
wei_value = to_wei(1, "ether")
assert crowdsale.call().getState() == CrowdsaleState.Funding
checksumbyte = keccak_256(decode_hex(format(customer_id, 'x').zfill(32))).digest()[:1]
crowdsale.transact({"from": customer, "value": wei_value}).buyWithCustomerId(customer_id, checksumbyte)
crowdsale.transact({"from": customer, "value": wei_value}).buyWithCustomerIdWithChecksum(customer_id, checksumbyte)

# We got credited
assert token.call().balanceOf(customer) > 0
Expand Down

0 comments on commit 9e38547

Please sign in to comment.