Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
add back check to check if the keyExists to support 'past' lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeseese committed Sep 22, 2020
1 parent 5e32dca commit f46d3af
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions lib/forking/forked_storage_trie.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,48 @@ ForkedStorageBaseTrie.prototype.get = function(key, callback) {

key = utils.toBuffer(key);

this.getTouchedAt(key, function(err, touchedAt) {
self.keyExists(key, function(err, keyExists) {
if (err) {
return callback(err);
}

if (typeof touchedAt !== "undefined") {
MerklePatriciaTree.prototype.get.call(self, key, function(err, r) {
callback(err, r);
});
} else {
// If this is the main trie, get the whole account.
if (self.address == null) {
self.blockchain.fetchAccountFromFallback(key, self.forkBlockNumber, function(err, account) {
if (err) {
return callback(err);
}

callback(null, account.serialize());
self.getTouchedAt(key, function(err, touchedAt) {
if (err) {
return callback(err);
}

if (keyExists && typeof touchedAt !== "undefined") {
MerklePatriciaTree.prototype.get.call(self, key, function(err, r) {
callback(err, r);
});
} else {
self.web3.eth.getStorageAt(
to.rpcDataHexString(self.address),
to.rpcDataHexString(key),
self.forkBlockNumber,
function(err, value) {
// If this is the main trie, get the whole account.
if (self.address == null) {
self.blockchain.fetchAccountFromFallback(key, self.forkBlockNumber, function(err, account) {
if (err) {
return callback(err);
}

value = utils.rlp.encode(value);

callback(null, value);
}
);
callback(null, account.serialize());
});
} else {
self.web3.eth.getStorageAt(
to.rpcDataHexString(self.address),
to.rpcDataHexString(key),
self.forkBlockNumber,
function(err, value) {
if (err) {
return callback(err);
}

value = utils.rlp.encode(value);

callback(null, value);
}
);
}
}
}
});
});
};

Expand Down

0 comments on commit f46d3af

Please sign in to comment.