Add isWithdrawExitedOnIndex function
MODIFY
examples/pos/erc721/withdraw_exit_many.js
examples/pos/erc721/withdraw_exit_many.js
+//
+// This function is only supported till Matic.js v3.3.0
+//
+
const { pos } = require('../../config')
const { getPOSClient, from } = require('../../utils')

ADD
examples/pos/erc721/withdraw_exit_on_index.js
+//
+// Only supported in versions after V3.4.0
+//
+
+const { pos } = require('../../config')
+const { getPOSClient, from } = require('../../utils')
+
+const execute = async () => {
+ const client = await getPOSClient()
+ const erc721Token = client.erc721(pos.parent.erc721, true)
+ const result = await erc721Token.withdrawExitOnIndex(
+ '0x54f47c891b460369661e22e27eeb4afbbb5dd792c7c8b48cab758892c14ffe85',
+ 1
+ )
+ const txHash = await result.getTransactionHash()
+ console.log('txHash', txHash)
+ const receipt = await result.getReceipt()
+ console.log('receipt', receipt)
+}
+execute()
+ .then(() => {})
+ .catch(err => {
+ console.error('err', err)
+ })
+ .finally(_ => {
+ process.exit(0)
+ })

MODIFY
examples/utils.js
examples/utils.js
@@ -3,12 +3,12 @@ const HDWalletProvider = require('@truffle/hdwallet-provider')
const config = require('./config')
const { POSClient, setProofApi, use } = require('@maticnetwork/maticjs')
const SCALING_FACTOR = new bn(10).pow(new bn(18))
-const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
+const { Web3ClientPlugin } = require('@maticnetwork/maticjs-web3')
-use(Web3ClientPlugin);
+use(Web3ClientPlugin)
if (config.proofApi) {
- setProofApi(config.proofApi);
+ setProofApi(config.proofApi)
}
const privateKey = config.user1.privateKey
@@ -23,16 +23,16 @@ const getPOSClient = (network = 'testnet', version = 'mumbai') => {
child: {
provider: new HDWalletProvider(privateKey, config.child.rpc),
defaultConfig: {
- from: userAddress
- }
+ from: userAddress,
+ },
},
parent: {
provider: new HDWalletProvider(privateKey, config.parent.rpc),
defaultConfig: {
- from: userAddress
- }
- }
- });
+ from: userAddress,
+ },
+ },
+ })
}
module.exports = {
@@ -44,5 +44,5 @@ module.exports = {
from: config.user1.address,
privateKey: config.user1.privateKey,
to: config.user2.address,
- proofApi: config.proofApi
+ proofApi: config.proofApi,
}

MODIFY
src/pos/erc721.ts
src/pos/erc721.ts
@@ -284,7 +284,6 @@ export class ERC721 extends POSToken {
withdrawExitFaster(burnTransactionHash: string, option?: ITransactionOption) {
this.checkForRoot("withdrawExitFaster");
-
return this.exitUtil.buildPayloadForExit(
burnTransactionHash,
0,
@@ -324,6 +323,12 @@ export class ERC721 extends POSToken {
);
}
+ isWithdrawExitedOnIndex(txHash: string, index: number) {
+ return this.isWithdrawnOnIndex(
+ txHash, index, Log_Event_Signature.Erc721Transfer
+ );
+ }
+
/**
* tranfer to another user
*

MODIFY
src/pos/exit_util.ts
src/pos/exit_util.ts
@@ -429,7 +429,7 @@ export class ExitUtil {
);
}
- getExitHash(burnTxHash, logEventSig) {
+ getExitHash(burnTxHash, index, logEventSig) {
let lastChildBlock: string,
receipt: ITransactionReceipt,
block: IBlockWithTransaction;
@@ -455,13 +455,20 @@ export class ExitUtil {
this.requestConcurrency
);
}).then((receiptProof: any) => {
- const logIndex = this.getLogIndex_(logEventSig, receipt);
+ let logIndex;
const nibbleArr = [];
receiptProof.path.forEach(byte => {
nibbleArr.push(Buffer.from('0' + (byte / 0x10).toString(16), 'hex'));
nibbleArr.push(Buffer.from('0' + (byte % 0x10).toString(16), 'hex'));
});
+ if(index > 0) {
+ const logIndices = this.getAllLogIndices_(logEventSig, receipt);
+ logIndex = logIndices[index];
+ }
+
+ logIndex = this.getLogIndex_(logEventSig, receipt);
+
return this.maticClient_.etheriumSha3(
receipt.blockNumber, bufferToHex(Buffer.concat(nibbleArr)), logIndex
);

MODIFY
src/pos/pos_token.ts
src/pos/pos_token.ts
@@ -52,7 +52,20 @@ export class POSToken extends BaseToken<IPOSClientConfig> {
throw new Error(`txHash not provided`);
}
return this.exitUtil.getExitHash(
- txHash, eventSignature
+ txHash, 0, eventSignature
+ ).then(exitHash => {
+ return this.rootChainManager.isExitProcessed(
+ exitHash
+ );
+ });
+ }
+
+ protected isWithdrawnOnIndex(txHash: string, index: number, eventSignature: string) {
+ if (!txHash) {
+ throw new Error(`txHash not provided`);
+ }
+ return this.exitUtil.getExitHash(
+ txHash, index, eventSignature
).then(exitHash => {
return this.rootChainManager.isExitProcessed(
exitHash

Add isWithdrawExitedOnIndex function