deth
Version:
Ethereum node focused on Developer Experience
67 lines (66 loc) • 3.19 kB
JavaScript
import { callbackify } from 'util';
import { bufferToAddress } from '../../primitives/Address';
import { bufferToHash, hashToBuffer, bufferToQuantity } from '../../primitives';
import { callbackifySync } from './adapter-utils';
export class StateManagerAdapter {
constructor(dethStateManager) {
this.dethStateManager = dethStateManager;
this.getAccount = callbackify(async (address) => {
return this.dethStateManager.getAccount(bufferToAddress(address));
});
this.putAccount = callbackify(async (address, account) => {
return this.dethStateManager.putAccount(bufferToAddress(address), account);
});
this.putContractCode = callbackify(async (address, code) => {
return this.dethStateManager.putContractCode(bufferToAddress(address), code);
});
this.getContractCode = callbackify(async (address) => {
return this.dethStateManager.getContractCode(bufferToAddress(address));
});
this.getContractStorage = callbackify(async (address, key) => {
return this.dethStateManager.getContractStorage(bufferToAddress(address), bufferToQuantity(key));
});
this.putContractStorage = callbackify(async (address, key, value) => {
return this.dethStateManager.putContractStorage(bufferToAddress(address), bufferToQuantity(key), value);
});
this.clearContractStorage = callbackify(async (address) => {
return this.dethStateManager.clearContractStorage(bufferToAddress(address));
});
this.checkpoint = callbackifySync(this.dethStateManager.checkpoint.bind(this.dethStateManager));
this.commit = callbackifySync(this.dethStateManager.commit.bind(this.dethStateManager));
this.revert = callbackifySync(this.dethStateManager.revert.bind(this.dethStateManager));
this.getStateRoot = callbackify(async () => {
return hashToBuffer(this.dethStateManager.getStateRoot());
});
this.accountIsEmpty = callbackify(async (address) => {
return this.dethStateManager.isAccountEmpty(bufferToAddress(address));
});
this.setStateRoot = callbackify(async (root) => {
return this.dethStateManager.setStateRoot(bufferToHash(root));
});
this.getOriginalContractStorage = () => {
console.trace();
throw new Error('Not implemented yet!');
};
this.dumpStorage = () => {
console.trace();
throw new Error('Not implemented yet!');
};
this.hasGenesisState = () => {
console.trace();
throw new Error('Not implemented yet!');
};
this.generateCanonicalGenesis = () => {
console.trace();
throw new Error('Not implemented yet!');
};
this.generateGenesis = () => {
console.trace();
throw new Error('Not implemented yet!');
};
// eslint-disable-next-line
this.cleanupTouchedAccounts = callbackify(async () => { });
// eslint-disable-next-line
this._clearOriginalStorageCache = () => { };
}
}