get childchain address from registry
MODIFY
dist/index.js
dist/index.js
@@ -70,7 +70,6 @@ var Matic = /** @class */ (function (_super) {
_this.rootChain = new RootChain_1.default(options.rootChain, _this.web3Client);
_this.depositManager = new DepositManager_1.default(options.depositManager, _this.web3Client);
_this.withdrawManager = new WithdrawManager_1.default(options.withdrawManager, _this.rootChain, _this.web3Client, _this.registry);
- _this.childChainAddress = options.childChain;
return _this;
}
Matic.prototype.initialize = function () {
@@ -173,12 +172,17 @@ var Matic = /** @class */ (function (_super) {
};
Matic.prototype.depositDataByHash = function (txHash) {
return __awaiter(this, void 0, void 0, function () {
- var depositReceipt, newDepositEvent, data, depositId, depositExists;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0: return [4 /*yield*/, this.web3Client.parentWeb3.eth.getTransactionReceipt(txHash)];
+ var _a, depositReceipt, newDepositEvent, data, depositId, depositExists;
+ return __generator(this, function (_b) {
+ switch (_b.label) {
+ case 0:
+ _a = this;
+ return [4 /*yield*/, this.registry.registry.methods.getChildChainAndStateSender().call()];
case 1:
- depositReceipt = _a.sent();
+ _a.childChainAddress = _b.sent();
+ return [4 /*yield*/, this.web3Client.parentWeb3.eth.getTransactionReceipt(txHash)];
+ case 2:
+ depositReceipt = _b.sent();
if (!depositReceipt) {
return [2 /*return*/, 'Transaction hash is not Found'];
}
@@ -186,8 +190,8 @@ var Matic = /** @class */ (function (_super) {
data = newDepositEvent.data;
depositId = parseInt(data.substring(data.length - 64), 16);
return [4 /*yield*/, this.depositManager.depositDataByID(depositId, this.childChainAddress)];
- case 2:
- depositExists = _a.sent();
+ case 3:
+ depositExists = _b.sent();
if (!depositExists) {
return [2 /*return*/, 'Deposit is not processed on Matic chain'];
}

MODIFY
src/index.ts
src/index.ts
@@ -21,23 +21,14 @@ export default class Matic extends ContractsBase {
options.parentProvider,
options.maticProvider,
options.parentDefaultOptions || {},
- options.maticDefaultOptions || {},
+ options.maticDefaultOptions || {}
)
super(web3Client)
this.web3Client = web3Client
this.registry = new Registry(options.registry, this.web3Client)
this.rootChain = new RootChain(options.rootChain, this.web3Client)
- this.depositManager = new DepositManager(
- options.depositManager,
- this.web3Client,
- )
- this.withdrawManager = new WithdrawManager(
- options.withdrawManager,
- this.rootChain,
- this.web3Client,
- this.registry,
- )
- this.childChainAddress = options.childChain
+ this.depositManager = new DepositManager(options.depositManager, this.web3Client)
+ this.withdrawManager = new WithdrawManager(options.withdrawManager, this.rootChain, this.web3Client, this.registry)
}
initialize() {
@@ -53,10 +44,9 @@ export default class Matic extends ContractsBase {
throw new Error('token address or user address is missing')
}
- const balance = this.getERC20TokenContract(
- token,
- options.parent,
- ).methods.balanceOf(userAddress).call()
+ const balance = this.getERC20TokenContract(token, options.parent)
+ .methods.balanceOf(userAddress)
+ .call()
return balance
}
@@ -65,10 +55,9 @@ export default class Matic extends ContractsBase {
throw new Error('token address or user address is missing')
}
- const balance = this.getERC721TokenContract(
- token,
- options.parent,
- ).methods.balanceOf(userAddress).call()
+ const balance = this.getERC721TokenContract(token, options.parent)
+ .methods.balanceOf(userAddress)
+ .call()
return balance
}
@@ -77,34 +66,23 @@ export default class Matic extends ContractsBase {
throw new Error('token address or user address is missing')
}
- const tokenID = this.getERC721TokenContract(
- token,
- options.parent,
- ).methods.tokenOfOwnerByIndex(userAddress, index).call()
+ const tokenID = this.getERC721TokenContract(token, options.parent)
+ .methods.tokenOfOwnerByIndex(userAddress, index)
+ .call()
return tokenID
}
- async transferERC20Tokens(
- token: address,
- to: address,
- amount: BN | string,
- options?: SendOptions,
- ) {
+ async transferERC20Tokens(token: address, to: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !token || !to)) {
throw new Error('options.from, to, token or amount is missing')
}
- const txObject = this.getERC20TokenContract(
- token,
- options.parent,
- ).methods.transfer(to, this.encode(amount))
+ const txObject = this.getERC20TokenContract(token, options.parent).methods.transfer(to, this.encode(amount))
const _options = await this._fillOptions(
options,
txObject,
- options.parent
- ? this.web3Client.getParentWeb3()
- : this.web3Client.getMaticWeb3(),
+ options.parent ? this.web3Client.getParentWeb3() : this.web3Client.getMaticWeb3()
)
if (options.encodeAbi) {
@@ -116,27 +94,17 @@ export default class Matic extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
- async transferERC721Tokens(
- token: address,
- to: address,
- tokenId: string,
- options?: SendOptions,
- ) {
+ async transferERC721Tokens(token: address, to: address, tokenId: string, options?: SendOptions) {
if (options && (!options.from || !tokenId || !token || !to)) {
throw new Error('options.from, to, token or tokenId is missing')
}
- const txObject = this.getERC721TokenContract(
- token,
- options.parent,
- ).methods.transferFrom(options.from, to, tokenId)
+ const txObject = this.getERC721TokenContract(token, options.parent).methods.transferFrom(options.from, to, tokenId)
const _options = await this._fillOptions(
options,
txObject,
- options.parent
- ? this.web3Client.getParentWeb3()
- : this.web3Client.getMaticWeb3(),
+ options.parent ? this.web3Client.getParentWeb3() : this.web3Client.getMaticWeb3()
)
if (options.encodeAbi) {
@@ -148,10 +116,7 @@ export default class Matic extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
- depositEther(
- amount: BN | string,
- options?: SendOptions,
- ) {
+ depositEther(amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount)) {
throw new Error('options.from or amount is missing')
}
@@ -159,12 +124,14 @@ export default class Matic extends ContractsBase {
}
async depositDataByHash(txHash: string) {
+ this.childChainAddress = await this.registry.registry.methods.getChildChainAndStateSender().call()
+
const depositReceipt = await this.web3Client.parentWeb3.eth.getTransactionReceipt(txHash)
if (!depositReceipt) {
return 'Transaction hash is not Found'
}
const newDepositEvent = depositReceipt.logs.find(
- l => l.topics[0].toLowerCase() === DepositManager.NEW_DEPOSIT_EVENT_SIG,
+ l => l.topics[0].toLowerCase() === DepositManager.NEW_DEPOSIT_EVENT_SIG
)
const data = newDepositEvent.data
@@ -176,11 +143,7 @@ export default class Matic extends ContractsBase {
return depositReceipt
}
- approveERC20TokensForDeposit(
- token: address,
- amount: BN | string,
- options?: SendOptions,
- ) {
+ approveERC20TokensForDeposit(token: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !token)) {
throw new Error('options.from, token or amount is missing')
}
@@ -188,12 +151,7 @@ export default class Matic extends ContractsBase {
return this.depositManager.approveERC20(token, amount, options)
}
- depositERC20ForUser(
- token: address,
- user: address,
- amount: BN | string,
- options?: SendOptions,
- ) {
+ depositERC20ForUser(token: address, user: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !token)) {
throw new Error('options.from, token or amount is missing')
}
@@ -204,17 +162,14 @@ export default class Matic extends ContractsBase {
if (options && (!options.from || !tokenId || !token)) {
throw new Error('options.from, token or tokenId is missing')
}
- const txObject = this.getERC721TokenContract(
- token,
- true,
- ).methods.safeTransferFrom(options.from, this.depositManager.getAddress(), tokenId)
-
- const _options = await this._fillOptions(
- options,
- txObject,
- this.web3Client.getParentWeb3()
+ const txObject = this.getERC721TokenContract(token, true).methods.safeTransferFrom(
+ options.from,
+ this.depositManager.getAddress(),
+ tokenId
)
+ const _options = await this._fillOptions(options, txObject, this.web3Client.getParentWeb3())
+
if (options.encodeAbi) {
_options.data = txObject.encodeABI()
_options.to = token
@@ -259,8 +214,7 @@ export default class Matic extends ContractsBase {
}
private _validateInputs(token: address, amountOrTokenId: BN | string, options?: SendOptions) {
- if (!this.web3Client.web3.utils.isAddress(
- this.web3Client.web3.utils.toChecksumAddress(token))) {
+ if (!this.web3Client.web3.utils.isAddress(this.web3Client.web3.utils.toChecksumAddress(token))) {
throw new Error(`${token} is not a valid token address`)
}
if (!amountOrTokenId) {

get childchain address from registry