Skip to content

Commit

Permalink
fix (StorageDump) pass the contract name
Browse files Browse the repository at this point in the history
  • Loading branch information
tenbits committed Nov 22, 2023
1 parent d694409 commit 6d2eb7a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
29 changes: 26 additions & 3 deletions lib/0xweb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10421,6 +10421,9 @@ var Ast;
if (isNumberLiteral(node)) {
return node.number;
}
if (isStringLiteral(node)) {
return `"${node.value?.replace(/"/g, '\\"')}"`;
}
throw new Error(`Unknown node ${JSON.stringify(node)}`);
}
Ast.serialize = serialize;
Expand Down Expand Up @@ -10526,7 +10529,11 @@ var Ast;
return a >> b;
}
}
throw new Error(`Unknown node ${JSON.stringify(node)}`);
if (isStringLiteral(node)) {
return node.value;
}
console.error(`Skip unknown node ${JSON.stringify(node)}`);
return null;
}
Ast.evaluate = evaluate;
})(Ast = exports.Ast || (exports.Ast = {}));
Expand Down Expand Up @@ -33860,7 +33867,13 @@ var BlockChainExplorerFactory;
}
if (_address_1.$address.isEmpty(uint256Hex) === false) {
let hex = _address_1.$address.fromBytes32(uint256Hex);
return this.getContractAbi(hex);
try {
return await this.getContractAbi(hex);
}
catch (err) {
err.message += `. Proxy ${hex}`;
throw err;
}
}
}
if (hasImplementationSlot(abiJson)) {
Expand Down Expand Up @@ -43857,6 +43870,7 @@ class PackageService {
platformPkgs[pkg.address] = {
name: pkg.name,
main: pkg.main,
contractName: pkg.contractName,
implementation: pkg.implementation
};
}
Expand Down Expand Up @@ -46054,6 +46068,7 @@ class MappingKeysLoader {
_require_1.$require.Address(params?.address);
this.address = params.address;
this.implementation = params.implementation;
this.contractName = params.contractName;
this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth');
this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform);
this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer);
Expand Down Expand Up @@ -46095,6 +46110,7 @@ class MappingKeysLoader {
}
async loadSourceCode() {
let source = await this.sourceCodeProvider.getSourceCode({
contractName: this.contractName,
address: this.address,
implementation: this.implementation,
});
Expand Down Expand Up @@ -46175,13 +46191,15 @@ class SlotsDump {
_require_1.$require.Address(params?.address);
this.address = params.address;
this.implementation = params.implementation;
this.contractName = params.contractName;
this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth');
this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform);
this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer);
this.logger = params.logger ?? _logger_1.$logger;
this.keysLoader = new MappingKeysLoader_1.MappingKeysLoader({
address: this.address,
implementation: this.implementation,
contractName: this.contractName,
client: this.client,
explorer: this.explorer,
logger: this.logger,
Expand Down Expand Up @@ -46235,6 +46253,7 @@ class SlotsDump {
let sources = await this.sourceCodeProvider.getSourceCode({
address: this.address,
implementation: this.implementation,
contractName: this.contractName,
sources: this.params.sources?.files
});
let slots = await SlotsParser_1.SlotsParser.slots({
Expand Down Expand Up @@ -46281,6 +46300,9 @@ class BatchLoader {
this.isBusy = false;
}
getStorageAt(slot) {
if (slot in this.queueHash) {
return this.queueHash[slot];
}
let dfr = new atma_utils_1.class_Dfr();
this.total++;
this.queueArr.push(slot);
Expand Down Expand Up @@ -46377,12 +46399,13 @@ class ContractDumpService {
this.app = app;
}
async dump(nameOrAddress, params) {
let { _address, _output, _implementation, _sources } = await this.getContractData(nameOrAddress, params);
let { _address, _output, _implementation, _sources, _contractName } = await this.getContractData(nameOrAddress, params);
_require_1.$require.String(_output, 'Output file not defined');
_require_1.$require.notNull(this.app.chain, `--chain not specified`);
let dump = new SlotsDump_1.SlotsDump({
address: _address,
implementation: _implementation,
contractName: _contractName,
client: this.app.chain.client,
explorer: this.app.chain.explorer,
fields: params.fields?.split(',').map(x => x.trim()),
Expand Down
29 changes: 26 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10431,6 +10431,9 @@ var Ast;
if (isNumberLiteral(node)) {
return node.number;
}
if (isStringLiteral(node)) {
return `"${node.value?.replace(/"/g, '\\"')}"`;
}
throw new Error(`Unknown node ${JSON.stringify(node)}`);
}
Ast.serialize = serialize;
Expand Down Expand Up @@ -10536,7 +10539,11 @@ var Ast;
return a >> b;
}
}
throw new Error(`Unknown node ${JSON.stringify(node)}`);
if (isStringLiteral(node)) {
return node.value;
}
console.error(`Skip unknown node ${JSON.stringify(node)}`);
return null;
}
Ast.evaluate = evaluate;
})(Ast = exports.Ast || (exports.Ast = {}));
Expand Down Expand Up @@ -33870,7 +33877,13 @@ var BlockChainExplorerFactory;
}
if (_address_1.$address.isEmpty(uint256Hex) === false) {
let hex = _address_1.$address.fromBytes32(uint256Hex);
return this.getContractAbi(hex);
try {
return await this.getContractAbi(hex);
}
catch (err) {
err.message += `. Proxy ${hex}`;
throw err;
}
}
}
if (hasImplementationSlot(abiJson)) {
Expand Down Expand Up @@ -43867,6 +43880,7 @@ class PackageService {
platformPkgs[pkg.address] = {
name: pkg.name,
main: pkg.main,
contractName: pkg.contractName,
implementation: pkg.implementation
};
}
Expand Down Expand Up @@ -46064,6 +46078,7 @@ class MappingKeysLoader {
_require_1.$require.Address(params?.address);
this.address = params.address;
this.implementation = params.implementation;
this.contractName = params.contractName;
this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth');
this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform);
this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer);
Expand Down Expand Up @@ -46105,6 +46120,7 @@ class MappingKeysLoader {
}
async loadSourceCode() {
let source = await this.sourceCodeProvider.getSourceCode({
contractName: this.contractName,
address: this.address,
implementation: this.implementation,
});
Expand Down Expand Up @@ -46185,13 +46201,15 @@ class SlotsDump {
_require_1.$require.Address(params?.address);
this.address = params.address;
this.implementation = params.implementation;
this.contractName = params.contractName;
this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth');
this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform);
this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer);
this.logger = params.logger ?? _logger_1.$logger;
this.keysLoader = new MappingKeysLoader_1.MappingKeysLoader({
address: this.address,
implementation: this.implementation,
contractName: this.contractName,
client: this.client,
explorer: this.explorer,
logger: this.logger,
Expand Down Expand Up @@ -46245,6 +46263,7 @@ class SlotsDump {
let sources = await this.sourceCodeProvider.getSourceCode({
address: this.address,
implementation: this.implementation,
contractName: this.contractName,
sources: this.params.sources?.files
});
let slots = await SlotsParser_1.SlotsParser.slots({
Expand Down Expand Up @@ -46291,6 +46310,9 @@ class BatchLoader {
this.isBusy = false;
}
getStorageAt(slot) {
if (slot in this.queueHash) {
return this.queueHash[slot];
}
let dfr = new atma_utils_1.class_Dfr();
this.total++;
this.queueArr.push(slot);
Expand Down Expand Up @@ -46387,12 +46409,13 @@ class ContractDumpService {
this.app = app;
}
async dump(nameOrAddress, params) {
let { _address, _output, _implementation, _sources } = await this.getContractData(nameOrAddress, params);
let { _address, _output, _implementation, _sources, _contractName } = await this.getContractData(nameOrAddress, params);
_require_1.$require.String(_output, 'Output file not defined');
_require_1.$require.notNull(this.app.chain, `--chain not specified`);
let dump = new SlotsDump_1.SlotsDump({
address: _address,
implementation: _implementation,
contractName: _contractName,
client: this.app.chain.client,
explorer: this.app.chain.explorer,
fields: params.fields?.split(',').map(x => x.trim()),
Expand Down
3 changes: 2 additions & 1 deletion src/services/ContractDumpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ export class ContractDumpService {

async dump (nameOrAddress: string | TAddress, params: IContractDumpServiceParams) {

let { _address, _output, _implementation, _sources } = await this.getContractData(nameOrAddress, params);
let { _address, _output, _implementation, _sources, _contractName } = await this.getContractData(nameOrAddress, params);

$require.String(_output, 'Output file not defined');
$require.notNull(this.app.chain, `--chain not specified`);

let dump = new SlotsDump({
address: _address,
implementation: _implementation,
contractName: _contractName,
client: this.app.chain.client,
explorer: this.app.chain.explorer,
fields: params.fields?.split(',').map(x => x.trim()),
Expand Down
1 change: 1 addition & 0 deletions src/services/PackageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class PackageService {
platformPkgs[pkg.address] = {
name: pkg.name,
main: pkg.main,
contractName: pkg.contractName,
implementation: pkg.implementation
};
} else {
Expand Down

0 comments on commit 6d2eb7a

Please sign in to comment.