diff options
author | chriseth <chris@ethereum.org> | 2018-04-13 02:55:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-13 02:55:03 +0800 |
commit | 44416d1ac65b2cfae4bb15d39bc84b1a78211baa (patch) | |
tree | 7b8ee302e1c4f0604f29d2fe21a2d0393cc60d11 /libsolidity/ast | |
parent | 7453ff0f3a94ce4ddce55cdbb77146dd75a01e1c (diff) | |
parent | 75b88286667690ffb4a5e079665ed8b70bcaeb87 (diff) | |
download | dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.gz dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.tar.zst dexon-solidity-44416d1ac65b2cfae4bb15d39bc84b1a78211baa.zip |
Merge pull request #2980 from ethereum/abi-api
Add abi.encode and abi.encodePacked
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/Types.cpp | 49 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 8 |
2 files changed, 54 insertions, 3 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 21353080..68b12777 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2375,7 +2375,11 @@ string FunctionType::richIdentifier() const case Kind::ByteArrayPush: id += "bytearraypush"; break; case Kind::ObjectCreation: id += "objectcreation"; break; case Kind::Assert: id += "assert"; break; - case Kind::Require: id += "require";break; + case Kind::Require: id += "require"; break; + case Kind::ABIEncode: id += "abiencode"; break; + case Kind::ABIEncodePacked: id += "abiencodepacked"; break; + case Kind::ABIEncodeWithSelector: id += "abiencodewithselector"; break; + case Kind::ABIEncodeWithSignature: id += "abiencodewithsignature"; break; default: solAssert(false, "Unknown function location."); break; } id += "_" + stateMutabilityToString(m_stateMutability); @@ -2996,6 +3000,8 @@ string MagicType::richIdentifier() const return "t_magic_message"; case Kind::Transaction: return "t_magic_transaction"; + case Kind::ABI: + return "t_magic_abi"; default: solAssert(false, "Unknown kind of magic"); } @@ -3036,6 +3042,45 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const {"origin", make_shared<IntegerType>(160, IntegerType::Modifier::Address)}, {"gasprice", make_shared<IntegerType>(256)} }); + case Kind::ABI: + return MemberList::MemberMap({ + {"encode", make_shared<FunctionType>( + TypePointers(), + TypePointers{make_shared<ArrayType>(DataLocation::Memory)}, + strings{}, + strings{}, + FunctionType::Kind::ABIEncode, + true, + StateMutability::Pure + )}, + {"encodePacked", make_shared<FunctionType>( + TypePointers(), + TypePointers{make_shared<ArrayType>(DataLocation::Memory)}, + strings{}, + strings{}, + FunctionType::Kind::ABIEncodePacked, + true, + StateMutability::Pure + )}, + {"encodeWithSelector", make_shared<FunctionType>( + TypePointers{make_shared<FixedBytesType>(4)}, + TypePointers{make_shared<ArrayType>(DataLocation::Memory)}, + strings{}, + strings{}, + FunctionType::Kind::ABIEncodeWithSelector, + true, + StateMutability::Pure + )}, + {"encodeWithSignature", make_shared<FunctionType>( + TypePointers{make_shared<ArrayType>(DataLocation::Memory, true)}, + TypePointers{make_shared<ArrayType>(DataLocation::Memory)}, + strings{}, + strings{}, + FunctionType::Kind::ABIEncodeWithSignature, + true, + StateMutability::Pure + )} + }); default: solAssert(false, "Unknown kind of magic."); } @@ -3051,6 +3096,8 @@ string MagicType::toString(bool) const return "msg"; case Kind::Transaction: return "tx"; + case Kind::ABI: + return "abi"; default: solAssert(false, "Unknown kind of magic."); } diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index ecfc2333..345f84a1 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -917,6 +917,10 @@ public: ObjectCreation, ///< array creation using new Assert, ///< assert() Require, ///< require() + ABIEncode, + ABIEncodePacked, + ABIEncodeWithSelector, + ABIEncodeWithSignature, GasLeft ///< gasleft() }; @@ -1052,7 +1056,7 @@ public: ASTPointer<ASTString> documentation() const; /// true iff arguments are to be padded to multiples of 32 bytes for external calls - bool padArguments() const { return !(m_kind == Kind::SHA3 || m_kind == Kind::SHA256 || m_kind == Kind::RIPEMD160); } + bool padArguments() const { return !(m_kind == Kind::SHA3 || m_kind == Kind::SHA256 || m_kind == Kind::RIPEMD160 || m_kind == Kind::ABIEncodePacked); } bool takesArbitraryParameters() const { return m_arbitraryParameters; } bool gasSet() const { return m_gasSet; } bool valueSet() const { return m_valueSet; } @@ -1210,7 +1214,7 @@ private: class MagicType: public Type { public: - enum class Kind { Block, Message, Transaction }; + enum class Kind { Block, Message, Transaction, ABI }; virtual Category category() const override { return Category::Magic; } explicit MagicType(Kind _kind): m_kind(_kind) {} |