Commit d53d2ad3 authored by yann300's avatar yann300

rename decode -> parseType

parent 5b06c33d
...@@ -263,7 +263,7 @@ function typeClass (fullType) { ...@@ -263,7 +263,7 @@ function typeClass (fullType) {
* @param {Object} stateDefinitions - all state stateDefinitions given by the AST (including struct and enum type declaration) * @param {Object} stateDefinitions - all state stateDefinitions given by the AST (including struct and enum type declaration)
* @return {Object} - return the corresponding decoder or null on error * @return {Object} - return the corresponding decoder or null on error
*/ */
function decode (type, stateDefinitions) { function parseType (type, stateDefinitions) {
var decodeInfos = { var decodeInfos = {
'address': Address, 'address': Address,
'array': ArrayType, 'array': ArrayType,
...@@ -285,7 +285,7 @@ function decode (type, stateDefinitions) { ...@@ -285,7 +285,7 @@ function decode (type, stateDefinitions) {
} }
module.exports = { module.exports = {
decode: decode, decode: parseType,
Uint: Uint, Uint: Uint,
Address: Address, Address: Address,
Bool: Bool, Bool: Bool,
......
...@@ -41,7 +41,7 @@ function extractStateVariables (contractName, sourcesList) { ...@@ -41,7 +41,7 @@ function extractStateVariables (contractName, sourcesList) {
for (var k in stateDefinitions) { for (var k in stateDefinitions) {
var variable = stateDefinitions[k] var variable = stateDefinitions[k]
if (variable.name === 'VariableDeclaration') { if (variable.name === 'VariableDeclaration') {
var decoded = decodeInfo.decode(variable.attributes.type, stateDefinitions) var decoded = decodeInfo.parseType(variable.attributes.type, stateDefinitions)
var type = new types[decoded.typeName](decoded) var type = new types[decoded.typeName](decoded)
if (location.offset + type.storageBytes > 32) { if (location.offset + type.storageBytes > 32) {
location.slot++ location.slot++
......
...@@ -9,47 +9,47 @@ tape('solidity', function (t) { ...@@ -9,47 +9,47 @@ tape('solidity', function (t) {
var output = compiler.compile(contracts, 0) var output = compiler.compile(contracts, 0)
var stateDec = index.solidity.astHelper.extractStateVariables('contractUint', output.sources) var stateDec = index.solidity.astHelper.extractStateVariables('contractUint', output.sources)
var decodeInfo = index.solidity.decodeInfo.decode(stateDec[0].attributes.type, stateDec) var decodeInfo = index.solidity.decodeInfo.parseType(stateDec[0].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 1, 'uint') checkDecodeInfo(st, decodeInfo, 1, 1, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint') checkDecodeInfo(st, decodeInfo, 1, 32, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[3].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[3].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint') checkDecodeInfo(st, decodeInfo, 1, 32, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[4].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[4].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 16, 'bytesX') checkDecodeInfo(st, decodeInfo, 1, 16, 'bytesX')
stateDec = index.solidity.astHelper.extractStateVariables('contractStructAndArray', output.sources) stateDec = index.solidity.astHelper.extractStateVariables('contractStructAndArray', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 2, 32, 'struct') checkDecodeInfo(st, decodeInfo, 2, 32, 'struct')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 6, 32, 'array') checkDecodeInfo(st, decodeInfo, 6, 32, 'array')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[3].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[3].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 2, 32, 'array') checkDecodeInfo(st, decodeInfo, 2, 32, 'array')
stateDec = index.solidity.astHelper.extractStateVariables('contractArray', output.sources) stateDec = index.solidity.astHelper.extractStateVariables('contractArray', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[0].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[0].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'array') checkDecodeInfo(st, decodeInfo, 1, 32, 'array')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'array') checkDecodeInfo(st, decodeInfo, 1, 32, 'array')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 4, 32, 'array') checkDecodeInfo(st, decodeInfo, 4, 32, 'array')
stateDec = index.solidity.astHelper.extractStateVariables('contractEnum', output.sources) stateDec = index.solidity.astHelper.extractStateVariables('contractEnum', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 2, 'enum') checkDecodeInfo(st, decodeInfo, 1, 2, 'enum')
stateDec = index.solidity.astHelper.extractStateVariables('contractSmallVariable', output.sources) stateDec = index.solidity.astHelper.extractStateVariables('contractSmallVariable', output.sources)
decodeInfo = index.solidity.decodeInfo.decode(stateDec[0].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[0].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 1, 'int') checkDecodeInfo(st, decodeInfo, 1, 1, 'int')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[1].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[1].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 1, 'uint') checkDecodeInfo(st, decodeInfo, 1, 1, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[2].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[2].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 2, 'uint') checkDecodeInfo(st, decodeInfo, 1, 2, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[3].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[3].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 4, 'int') checkDecodeInfo(st, decodeInfo, 1, 4, 'int')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[4].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[4].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 32, 'uint') checkDecodeInfo(st, decodeInfo, 1, 32, 'uint')
decodeInfo = index.solidity.decodeInfo.decode(stateDec[5].attributes.type, stateDec) decodeInfo = index.solidity.decodeInfo.parseType(stateDec[5].attributes.type, stateDec)
checkDecodeInfo(st, decodeInfo, 1, 2, 'int') checkDecodeInfo(st, decodeInfo, 1, 2, 'int')
st.end() st.end()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment