ton3-core
Version:
TON low-level API tools
49 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContractBase = void 0;
const helpers_1 = require("../utils/helpers");
const address_1 = require("../address");
const boc_1 = require("../boc");
class ContractBase {
constructor(options) {
const { code, workchain, storage = null, libraries = [] } = options;
this._state = ContractBase.stateInit({ code, storage, libraries });
this._workchain = workchain;
this._address = new address_1.Address(`${this._workchain}:${this._state.hash()}`);
}
get workchain() {
return this._workchain;
}
get address() {
return this._address;
}
get state() {
return this._state;
}
static stateInit(options) {
const { code, storage, libraries } = options;
const builder = new boc_1.Builder();
builder.storeBits([0, 0, 1]);
builder.storeRef(code);
if (storage !== null) {
builder.storeBit(1)
.storeRef(storage);
}
else {
builder.storeBit(0);
}
const serializers = {
key: (hash) => (0, helpers_1.hexToBits)(hash),
value: (lib) => new boc_1.Builder()
.storeBit(Number(lib.isPublic))
.storeRef(lib.code)
.cell()
};
const dict = new boc_1.HashmapE(256, { serializers });
libraries.forEach(lib => dict.set(lib.code.hash(), lib));
builder.storeDict(dict);
return builder.cell();
}
}
exports.ContractBase = ContractBase;
//# sourceMappingURL=base.js.map