Support gas modifier on addr.transfer()

This commit is contained in:
Alex Beregszaszi 2017-02-06 16:54:05 +00:00
parent ba437ef31a
commit 81006dae98
3 changed files with 10 additions and 2 deletions

View File

@ -2315,9 +2315,10 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
case Location::Bare: case Location::Bare:
case Location::BareCallCode: case Location::BareCallCode:
case Location::BareDelegateCall: case Location::BareDelegateCall:
case Location::Transfer:
{ {
MemberList::MemberMap members; MemberList::MemberMap members;
if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall) if (m_location != Location::BareDelegateCall && m_location != Location::DelegateCall && m_location != Location::Transfer)
{ {
if (m_isPayable) if (m_isPayable)
members.push_back(MemberList::Member( members.push_back(MemberList::Member(

View File

@ -620,7 +620,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
_functionCall.expression().accept(*this); _functionCall.expression().accept(*this);
// Provide the gas stipend manually at first because we may send zero ether. // Provide the gas stipend manually at first because we may send zero ether.
// Will be zeroed if we send more than zero ether. // Will be zeroed if we send more than zero ether.
m_context << u256(eth::GasCosts::callStipend); if (!function.gasSet())
m_context << u256(eth::GasCosts::callStipend);
arguments.front()->accept(*this); arguments.front()->accept(*this);
utils().convertType( utils().convertType(
*arguments.front()->annotation().type, *arguments.front()->annotation().type,

View File

@ -1693,6 +1693,10 @@ BOOST_AUTO_TEST_CASE(transfer_ether)
function b(address addr, uint amount) { function b(address addr, uint amount) {
addr.transfer(amount); addr.transfer(amount);
} }
function c(address addr, uint amount, uint gas) returns (uint) {
addr.transfer.gas(gas)(amount);
return this.balance;
}
} }
contract B { contract B {
@ -1715,6 +1719,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether)
BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10);
BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs());
BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs());
BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 9000) == encodeArgs(9));
BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 0) == encodeArgs());
} }
BOOST_AUTO_TEST_CASE(log0) BOOST_AUTO_TEST_CASE(log0)