mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
solidity-upgrade can now change now to block.timestamp
This commit is contained in:
parent
a207613f17
commit
aed6c22318
@ -15,3 +15,4 @@ This section gives detailed instructions on how to update prior code for every b
|
|||||||
|
|
||||||
* Change ``f.value(...)()`` to ``f{value: ...}()``. Similarly ``(new C).value(...)()`` to
|
* Change ``f.value(...)()`` to ``f{value: ...}()``. Similarly ``(new C).value(...)()`` to
|
||||||
``(new C){value: ...}()`` and ``f.gas(...)()`` to ``f{gas: ...}()``.
|
``(new C){value: ...}()`` and ``f.gas(...)()`` to ``f{gas: ...}()``.
|
||||||
|
* Change ``now`` to ``block.timestamp``.
|
||||||
|
@ -580,6 +580,12 @@ Available upgrade modules
|
|||||||
| | | ``f{gas: ..., value: ...}()`` and |
|
| | | ``f{gas: ..., value: ...}()`` and |
|
||||||
| | | ``(new C){value: ...}()``. |
|
| | | ``(new C){value: ...}()``. |
|
||||||
+-----------------+---------+--------------------------------------------------+
|
+-----------------+---------+--------------------------------------------------+
|
||||||
|
| ``now`` | 0.7.0 | The ``now`` keyword is deprecated. Use |
|
||||||
|
| | | ``block.timestamp`` instead. |
|
||||||
|
| | | |
|
||||||
|
| | | |
|
||||||
|
| | | |
|
||||||
|
+-----------------+---------+--------------------------------------------------+
|
||||||
|
|
||||||
Please read :doc:`0.5.0 release notes <050-breaking-changes>`,
|
Please read :doc:`0.5.0 release notes <050-breaking-changes>`,
|
||||||
:doc:`0.6.0 release notes <060-breaking-changes>` and
|
:doc:`0.6.0 release notes <060-breaking-changes>` and
|
||||||
|
@ -267,6 +267,24 @@ public:
|
|||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string nowUpdate(langutil::SourceLocation const& _location)
|
||||||
|
{
|
||||||
|
std::regex nowRegex{"now"};
|
||||||
|
|
||||||
|
if (regex_search(_location.text(), nowRegex))
|
||||||
|
{
|
||||||
|
return regex_replace(_location.text(), nowRegex, "block.timestamp");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
solAssert(
|
||||||
|
false,
|
||||||
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
|
"\nNeeds to be fixed manually."
|
||||||
|
);
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,8 @@ Allowed options)",
|
|||||||
m_suite.activateModule(Module::VirtualFunction);
|
m_suite.activateModule(Module::VirtualFunction);
|
||||||
else if (module == "dotsyntax")
|
else if (module == "dotsyntax")
|
||||||
m_suite.activateModule(Module::DotSyntax);
|
m_suite.activateModule(Module::DotSyntax);
|
||||||
|
else if (module == "now")
|
||||||
|
m_suite.activateModule(Module::NowKeyword);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error() << "Unknown upgrade module \"" + module + "\"" << endl;
|
error() << "Unknown upgrade module \"" + module + "\"" << endl;
|
||||||
|
@ -58,7 +58,8 @@ private:
|
|||||||
AbstractContract,
|
AbstractContract,
|
||||||
OverridingFunction,
|
OverridingFunction,
|
||||||
VirtualFunction,
|
VirtualFunction,
|
||||||
DotSyntax
|
DotSyntax,
|
||||||
|
NowKeyword
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Upgrade suite that hosts all available modules.
|
/// Upgrade suite that hosts all available modules.
|
||||||
@ -84,6 +85,8 @@ private:
|
|||||||
/// Solidity 0.7.0
|
/// Solidity 0.7.0
|
||||||
if (isActivated(Module::DotSyntax))
|
if (isActivated(Module::DotSyntax))
|
||||||
DotSyntax{m_changes}.analyze(_sourceUnit);
|
DotSyntax{m_changes}.analyze(_sourceUnit);
|
||||||
|
if (isActivated(Module::NowKeyword))
|
||||||
|
NowKeyword{m_changes}.analyze(_sourceUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void activateModule(Module _module) { m_modules.insert(_module); }
|
void activateModule(Module _module) { m_modules.insert(_module); }
|
||||||
@ -103,7 +106,8 @@ private:
|
|||||||
Module::AbstractContract,
|
Module::AbstractContract,
|
||||||
Module::OverridingFunction,
|
Module::OverridingFunction,
|
||||||
Module::VirtualFunction,
|
Module::VirtualFunction,
|
||||||
Module::DotSyntax
|
Module::DotSyntax,
|
||||||
|
Module::NowKeyword
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,3 +40,22 @@ void DotSyntax::endVisit(FunctionCall const& _functionCall)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NowKeyword::endVisit(Identifier const& _identifier)
|
||||||
|
{
|
||||||
|
IdentifierAnnotation& annotation = _identifier.annotation();
|
||||||
|
|
||||||
|
if (MagicVariableDeclaration const* magicVar
|
||||||
|
= dynamic_cast<MagicVariableDeclaration const*>(annotation.referencedDeclaration))
|
||||||
|
{
|
||||||
|
if (magicVar->type()->category() == Type::Category::Integer)
|
||||||
|
{
|
||||||
|
solAssert(_identifier.name() == "now", "");
|
||||||
|
m_changes.emplace_back(
|
||||||
|
UpgradeChange::Level::Safe,
|
||||||
|
_identifier.location(),
|
||||||
|
SourceTransform::nowUpdate(_identifier.location())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,4 +32,13 @@ private:
|
|||||||
void endVisit(frontend::FunctionCall const& _expression) override;
|
void endVisit(frontend::FunctionCall const& _expression) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class NowKeyword: public AnalysisUpgrade
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using AnalysisUpgrade::AnalysisUpgrade;
|
||||||
|
void analyze(frontend::SourceUnit const& _sourceUnit) { _sourceUnit.accept(*this); }
|
||||||
|
private:
|
||||||
|
void endVisit(frontend::Identifier const& _expression) override;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user