deth
Version:
Ethereum node focused on Developer Experience
29 lines (28 loc) • 1.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
const ethereumjs_util_1 = require("ethereumjs-util");
const primitives_1 = require("../../primitives");
const adapter_utils_1 = require("./adapter-utils");
/**
* Wraps DethBlockchain into ethereum-js/blockchain compatible interface
*/
class BlockchainAdapter {
constructor(dethBlockchain) {
this.dethBlockchain = dethBlockchain;
this.putGenesis = adapter_utils_1.callbackifySync(this.dethBlockchain.putGenesis.bind(this.dethBlockchain));
this.getLatestBlock = adapter_utils_1.callbackifySync(this.dethBlockchain.getLatestBlock.bind(this.dethBlockchain));
this.getBlock = util_1.callbackify(async (numberOrTag) => {
if (numberOrTag instanceof Buffer) {
return this.dethBlockchain.getBlockByHash(primitives_1.bufferToHash(numberOrTag));
}
if (numberOrTag instanceof ethereumjs_util_1.BN) {
return this.dethBlockchain.getBlockByNumber(primitives_1.bnToQuantity(numberOrTag));
}
return this.dethBlockchain.getBlockByNumber(primitives_1.numberToQuantity(numberOrTag));
});
// @todo isGenesis arg is missing
this.putBlock = adapter_utils_1.callbackifySync(this.dethBlockchain.putBlock.bind(this.dethBlockchain));
}
}
exports.BlockchainAdapter = BlockchainAdapter;