aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/CompilerStack.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-06-22 18:02:50 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-06-26 04:17:33 +0800
commit3fc7da11db2b03e63a66e22b72df2d18e534c4e9 (patch)
tree20ae9171a067566091a7320e03a8d48263565132 /libsolidity/interface/CompilerStack.cpp
parent0ac46090971aab21120875e0e55317e4bd2b397e (diff)
downloaddexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.tar
dexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.tar.gz
dexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.tar.bz2
dexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.tar.lz
dexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.tar.xz
dexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.tar.zst
dexon-solidity-3fc7da11db2b03e63a66e22b72df2d18e534c4e9.zip
Pull out createCBORMetadata helper
Diffstat (limited to 'libsolidity/interface/CompilerStack.cpp')
-rw-r--r--libsolidity/interface/CompilerStack.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 4e8d1461..aa33bad8 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -719,27 +719,10 @@ void CompilerStack::compileContract(
string metadata = createMetadata(compiledContract);
compiledContract.metadata = metadata;
- // Prepare CBOR metadata for the bytecode
- bytes cborEncodedHash =
- // CBOR-encoding of the key "bzzr0"
- bytes{0x65, 'b', 'z', 'z', 'r', '0'}+
- // CBOR-encoding of the hash
- bytes{0x58, 0x20} + dev::swarmHash(metadata).asBytes();
- bytes cborEncodedMetadata;
- if (onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures))
- cborEncodedMetadata =
- // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)}
- bytes{0xa1} +
- cborEncodedHash;
- else
- cborEncodedMetadata =
- // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true}
- bytes{0xa2} +
- cborEncodedHash +
- bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5};
- solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large");
- // 16-bit big endian length
- cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2);
+ bytes cborEncodedMetadata = createCBORMetadata(
+ metadata,
+ !onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)
+ );
try
{
@@ -901,6 +884,31 @@ string CompilerStack::createMetadata(Contract const& _contract) const
return jsonCompactPrint(meta);
}
+bytes CompilerStack::createCBORMetadata(string _metadata, bool _experimentalMode)
+{
+ bytes cborEncodedHash =
+ // CBOR-encoding of the key "bzzr0"
+ bytes{0x65, 'b', 'z', 'z', 'r', '0'}+
+ // CBOR-encoding of the hash
+ bytes{0x58, 0x20} + dev::swarmHash(_metadata).asBytes();
+ bytes cborEncodedMetadata;
+ if (_experimentalMode)
+ cborEncodedMetadata =
+ // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true}
+ bytes{0xa2} +
+ cborEncodedHash +
+ bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5};
+ else
+ cborEncodedMetadata =
+ // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)}
+ bytes{0xa1} +
+ cborEncodedHash;
+ solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large");
+ // 16-bit big endian length
+ cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2);
+ return cborEncodedMetadata;
+}
+
string CompilerStack::computeSourceMapping(eth::AssemblyItems const& _items) const
{
string ret;