pull/7/head
yann300 8 years ago
parent ce16924682
commit 0958b7eb29
  1. 21
      src/storage/mappingPreimages.js

@ -4,6 +4,13 @@ module.exports = {
extractMappingPreimages: extractMappingPreimages extractMappingPreimages: extractMappingPreimages
} }
/**
* Uses the storageViewer to retrieve the storage and returns a mapping containing possible solidity mappping type location.
* like { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... }
*
* @param {Object} address - storageViewer
* @return {Map} - solidity mapping location
*/
async function extractMappingPreimages (storageViewer) { async function extractMappingPreimages (storageViewer) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
storageViewer.storageRange(function (error, storage) { storageViewer.storageRange(function (error, storage) {
@ -22,6 +29,14 @@ async function extractMappingPreimages (storageViewer) {
}) })
} }
/**
* Uses the storageViewer to retrieve the storage and returns a mapping containing possible solidity mappping type location.
* like { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... }
*
* @param {Object} storage - storage given by storage Viewer (basically a mapping hashedkey : {key, value})
* @param {Function} callback - calback
* @return {Map} - solidity mapping location (e.g { "<mapping_slot>" : { "<mapping-key1>": preimageOf1 }, { "<mapping-key2>": preimageOf2 }, ... })
*/
async function decodeMappingsKeys (storage, callback) { async function decodeMappingsKeys (storage, callback) {
var ret = {} var ret = {}
for (var hashedLoc in storage) { for (var hashedLoc in storage) {
@ -45,6 +60,12 @@ async function decodeMappingsKeys (storage, callback) {
callback(null, ret) callback(null, ret)
} }
/**
* Uses web3 to return preimage of a key
*
* @param {String} key - key to retrieve the preimage of
* @return {String} - preimage of the given key
*/
function getPreimage (key) { function getPreimage (key) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
global.web3.debug.preimage(key, function (error, preimage) { global.web3.debug.preimage(key, function (error, preimage) {

Loading…
Cancel
Save