Merge pull request #11399 from ethereum/hex-conversion

Turn toCompactHexWithPrefix into a template and support unsigned types
This commit is contained in:
Alex Beregszaszi 2021-05-18 11:36:43 +01:00 committed by GitHub
commit d61f21276d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View File

@ -340,7 +340,7 @@ CompilerContext& CompilerContext::appendPanic(util::PanicCode _code)
revert(0, 0x24) revert(0, 0x24)
})"); })");
templ("selector", util::selectorFromSignature("Panic(uint256)").str()); templ("selector", util::selectorFromSignature("Panic(uint256)").str());
templ("code", u256(_code).str()); templ("code", toCompactHexWithPrefix(static_cast<unsigned>(_code)));
appendInlineAssembly(templ.render()); appendInlineAssembly(templ.render());
return *this; return *this;
} }

View File

@ -4377,7 +4377,7 @@ string YulUtilFunctions::panicFunction(util::PanicCode _code)
)") )")
("functionName", functionName) ("functionName", functionName)
("selector", util::selectorFromSignature("Panic(uint256)").str()) ("selector", util::selectorFromSignature("Panic(uint256)").str())
("code", toCompactHexWithPrefix(_code)) ("code", toCompactHexWithPrefix(static_cast<unsigned>(_code)))
.render(); .render();
}); });
} }

View File

@ -404,7 +404,8 @@ inline std::string toHex(u256 val, HexPrefix prefix = HexPrefix::DontAdd)
return (prefix == HexPrefix::Add) ? "0x" + str : str; return (prefix == HexPrefix::Add) ? "0x" + str : str;
} }
inline std::string toCompactHexWithPrefix(u256 const& _value) template <class T>
inline std::string toCompactHexWithPrefix(T _value)
{ {
return toHex(toCompactBigEndian(_value, 1), HexPrefix::Add); return toHex(toCompactBigEndian(_value, 1), HexPrefix::Add);
} }