@paradeum/burrow
Version:
TypeScript library that calls a Hyperledger Burrow server over GRPC.
55 lines • 2.11 kB
JavaScript
;
exports.__esModule = true;
exports.ContractManager = void 0;
var contract_1 = require("./contract");
var rpcquery_pb_1 = require("../../../proto/rpcquery_pb");
var ContractManager = /** @class */ (function () {
function ContractManager(burrow) {
this.burrow = burrow;
}
ContractManager.prototype.deploy = function (abi, byteCode, deployedBytecode, handlers) {
var _this = this;
var args = [];
for (var _i = 4; _i < arguments.length; _i++) {
args[_i - 4] = arguments[_i];
}
return new Promise(function (resolve, reject) {
var contract = new contract_1.Contract(abi, byteCode, deployedBytecode, null, _this.burrow, handlers);
contract._constructor.apply(contract, args).then(function (address) {
contract.address = address;
resolve(contract);
});
});
};
/**
* Creates a contract object interface from an address without ABI.
* The contract must be deployed using a recent burrow deploy which registers
* metadata.
*
* @method address
* @param {string} address - default contract address [can be null]
* @returns {Contract} returns contract interface object
*/
ContractManager.prototype.address = function (address, handlers) {
var _this = this;
var msg = new rpcquery_pb_1.GetMetadataParam();
msg.setAddress(Buffer.from(address, 'hex'));
return new Promise(function (resolve, reject) {
return _this.burrow.qc.getMetadata(msg, function (err, res) {
if (err)
reject(err);
var abi;
try {
abi = JSON.parse(res.getMetadata()).Abi;
}
catch (e) {
reject(e);
}
resolve(new contract_1.Contract(abi, null, null, address, _this.burrow, handlers));
});
});
};
return ContractManager;
}());
exports.ContractManager = ContractManager;
//# sourceMappingURL=manager.js.map