2017-05-02 22:34:12 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2017-05-02 22:34:12 +00:00
|
|
|
/**
|
|
|
|
* @date 2017
|
|
|
|
* Metadata processing helpers.
|
|
|
|
*/
|
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/CommonData.h>
|
2021-09-10 13:50:37 +00:00
|
|
|
#include <libsolutil/JSON.h>
|
2019-03-04 22:43:55 +00:00
|
|
|
|
|
|
|
#include <map>
|
2019-10-28 10:39:30 +00:00
|
|
|
#include <optional>
|
2017-05-02 22:34:12 +00:00
|
|
|
#include <string>
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
namespace solidity::test
|
2017-05-02 22:34:12 +00:00
|
|
|
{
|
|
|
|
|
2019-02-05 23:20:15 +00:00
|
|
|
/// Returns only the CBOR metadata.
|
|
|
|
bytes onlyMetadata(bytes const& _bytecode);
|
|
|
|
|
2019-02-05 22:37:02 +00:00
|
|
|
/// Returns the bytecode with the metadata hash stripped out.
|
|
|
|
bytes bytecodeSansMetadata(bytes const& _bytecode);
|
|
|
|
|
2017-05-02 22:34:12 +00:00
|
|
|
/// Returns the bytecode with the metadata hash stripped out.
|
2019-02-05 22:53:25 +00:00
|
|
|
/// Throws exception on invalid hex string.
|
2017-05-02 22:34:12 +00:00
|
|
|
std::string bytecodeSansMetadata(std::string const& _bytecode);
|
|
|
|
|
2019-03-04 22:43:55 +00:00
|
|
|
/// Parse CBOR metadata into a map. Expects the input CBOR to be a
|
|
|
|
/// fixed length map, with each key being a string. The values
|
|
|
|
/// are parsed as follows:
|
|
|
|
/// - strings into strings
|
|
|
|
/// - bytes into hex strings
|
|
|
|
/// - booleans into "true"/"false" strings
|
|
|
|
/// - everything else is invalid
|
2019-10-28 10:39:30 +00:00
|
|
|
std::optional<std::map<std::string, std::string>> parseCBORMetadata(bytes const& _metadata);
|
2019-03-04 22:43:55 +00:00
|
|
|
|
2021-09-10 13:50:37 +00:00
|
|
|
/// Expects a serialised metadata JSON and returns true if the content is valid metadata.
|
|
|
|
bool isValidMetadata(std::string const& _serialisedMetadata);
|
|
|
|
|
|
|
|
/// Expects a deserialised metadata JSON and returns true if the content is valid metadata.
|
|
|
|
bool isValidMetadata(Json::Value const& _metadata);
|
2017-05-02 22:34:12 +00:00
|
|
|
|
|
|
|
} // end namespaces
|