throw error when proof api is not set and fast api is called
MODIFY
src/enums/error_type.ts
src/enums/error_type.ts
export enum ERROR_TYPE {
AllowedOnRoot = "allowed_on_root",
AllowedOnChild = "allowed_on_child",
- Unknown = "unknown"
+ Unknown = "unknown",
+ ProofAPINotSet = "proof_api_not_set"
}
\ No newline at end of file

MODIFY
src/plasma/erc721.ts
src/plasma/erc721.ts
@@ -42,7 +42,7 @@ export class ERC721 extends PlasmaToken {
* @param index starting from zero, if no token found on that it will return error
* @param options
*/
- getTokenIdForOwnerByIndex(index: number, userAddress: string, options?: ITransactionOption) {
+ getTokenIdForUserByIndex(index: number, userAddress: string, options?: ITransactionOption) {
return this.getContract().then(contract => {
const method = contract.method(
"tokenOfOwnerByIndex",
@@ -50,7 +50,7 @@ export class ERC721 extends PlasmaToken {
index
);
- return this.processRead(method, options);
+ return this.processRead<string>(method, options);
});
}
@@ -124,4 +124,19 @@ export class ERC721 extends PlasmaToken {
option
);
}
+
+ getAllTokens(userAddress: string) {
+ return this.getBalance(userAddress).then(balance => {
+ balance = Number(balance);
+ const promises = [];
+ for (let i = 0; i < balance; i++) {
+ promises.push(
+ this.getTokenIdForUserByIndex(i, userAddress)
+ );
+ }
+ return Promise.all(
+ promises
+ );
+ });
+ }
}

MODIFY
src/plasma/index.ts
src/plasma/index.ts
import { ERC20 } from "./erc20";
import { ERC721 } from "./erc721";
-import { Web3SideChainClient } from "../utils";
+import { BridgeClient, Web3SideChainClient } from "../utils";
import { IPlasmaClientConfig, IPlasmaContracts, ITransactionOption } from "../interfaces";
import { DepositManager } from "./deposit_manager";
import { RegistryContract } from "./registry";
@@ -8,12 +8,11 @@ import { Ether } from "./ether";
import { ExitManager, RootChain } from "../pos";
import { WithdrawManager } from "./withdraw_manager";
-export class PlasmaClient {
+export class PlasmaClient extends BridgeClient {
private client_: Web3SideChainClient;
withdrawManager: WithdrawManager;
- exitManager: ExitManager;
depositManager: DepositManager;
registry: RegistryContract;
@@ -47,6 +46,7 @@ export class PlasmaClient {
}
constructor(config: IPlasmaClientConfig) {
+ super();
this.client_ = new Web3SideChainClient(config);
this.client_.logger.enableLog(config.log);
}

MODIFY
src/pos/exit_manager.ts
src/pos/exit_manager.ts
@@ -6,6 +6,8 @@ import ethUtils from "ethereumjs-util";
import { ITransactionReceipt } from "../interfaces";
import { service } from "../services";
import { BaseWeb3Client } from "../abstracts";
+import { ErrorHelper } from "../utils/error_helper";
+import { ERROR_TYPE } from "..";
interface IChainBlockInfo {
lastChildBlock: string;
@@ -145,6 +147,10 @@ export class ExitManager {
async buildPayloadForExit(burnTxHash: string, logEventSig: string, isFast: boolean) {
+ if (isFast && !service.network) {
+ new ErrorHelper(ERROR_TYPE.ProofAPINotSet).throw();
+ }
+
const blockInfo = await this.getChainBlockInfo(
burnTxHash
);

MODIFY
src/pos/index.ts
src/pos/index.ts
import { ERC20 } from "./erc20";
import { RootChainManager } from "./root_chain_manager";
-import { Web3SideChainClient } from "../utils";
+import { BridgeClient, Web3SideChainClient } from "../utils";
import { IPOSClientConfig } from "../interfaces";
import { ExitManager } from "./exit_manager";
import { RootChain } from "./root_chain";
@@ -10,16 +10,16 @@ export * from "./exit_manager";
export * from "./root_chain_manager";
export * from "./root_chain";
-export class POSClient {
+export class POSClient extends BridgeClient {
rootChainManager: RootChainManager;
rootChain: RootChain;
private client_: Web3SideChainClient;
- exitManager: ExitManager;
constructor(config: IPOSClientConfig) {
+ super();
this.client_ = new Web3SideChainClient(config);
this.client_.logger.enableLog(config.log);
}
@@ -78,29 +78,4 @@ export class POSClient {
this.exitManager
);
}
-
- /**
- * check whether a txHash is checkPointed
- *
- * @param {string} txHash
- * @returns
- * @memberof POSClient
- */
- isCheckPointed(txHash: string) {
- return this.exitManager.isCheckPointed(
- txHash
- );
- }
-
- // getBalanceUsingRPC() {
- // return this.client_.child.client.sendRPCRequest({
- // jsonrpc: '2.0',
- // method: 'eth_getBalance',
- // params: [
- // '0x0ef2e86a73c7be7f767d7abe53b1d4cbfbccbf3a',
- // 'latest'
- // ],
- // id: new Date().getTime()
- // });
- // }
}
\ No newline at end of file

ADD
src/utils/bridge_client.ts
+import { ExitManager } from "../pos";
+
+export class BridgeClient {
+ exitManager: ExitManager;
+
+ /**
+ * check whether a txHash is checkPointed
+ *
+ * @param {string} txHash
+ * @returns
+ * @memberof BridgeClient
+ */
+ isCheckPointed(txHash: string) {
+ return this.exitManager.isCheckPointed(
+ txHash
+ );
+ }
+
+}
\ No newline at end of file

MODIFY
src/utils/error_helper.ts
src/utils/error_helper.ts
@@ -30,6 +30,9 @@ export class ErrorHelper implements IError {
case ERROR_TYPE.AllowedOnRoot:
errMsg = `The action ${info} is allowed only on root token.`;
break;
+ case ERROR_TYPE.ProofAPINotSet:
+ errMsg = `Proof api is not set, please set it using "setProofApi"`;
+ break;
default:
if (!this.type) {
this.type = ERROR_TYPE.Unknown;

MODIFY
src/utils/index.ts
src/utils/index.ts
@@ -12,3 +12,4 @@ export * from "./base_token";
export * from "./set_proof_api_url";
export * from "./resolve";
export * from "./promise_resolve";
+export * from "./bridge_client";
\ No newline at end of file

MODIFY
test/debug.js
test/debug.js
-const { PlasmaClient, POSClient, use } = require("@maticnetwork/maticjs");
+const { PlasmaClient, POSClient, use, Web3SideChainClient } = require("@maticnetwork/maticjs");
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3");
const HDWalletProvider = require("@truffle/hdwallet-provider");
@@ -42,6 +42,11 @@ const execute = async () => {
// );
// return console.log("balance", balance);
+ // const tokens = await goerliERC720Token.getAllTokens(
+ // from
+ // );
+ // return console.log("tokens", tokens);
+
// const tx = await goerliERC720Token.safeDeposit(104, from);
// // const tx = await goerliERC720Token.withdrawChallenge('0x454f159823351b24ce0e675e7b308cc8c7ba39e175059a4d2b8f9507c17b5133');
// console.log("txHash", await tx.getTransactionHash());
@@ -50,16 +55,20 @@ const execute = async () => {
//txhash to plasma exit - 0x63aa095e0d6ee8698399b871daa202eb5522933e2d94c5929cf0fb86b6b0c628
const tokenId = '60399350241383852757821046101235634991156913804166740995010931519407953501076'
- const tx = await mumbaiERC720Token.withdrawStart(104);
+ // const tx = await (client['client_']).child.getTransactionCount(from, 'pending');
// console.log("tx", tx);
- // const tx = await mumbaiERC720Token.withdrawStart(
- // 10,
- // {
- // // nonce: 1974,
- // // gasPrice: '1000',
- // // gas: 100
- // }
- // );
+ // const result = await client.isCheckPointed('0x41162584974896bfc96d91e7ce72009373cd31acabe92024950831ee7b8067c0')
+ // console.log("result", result);
+ const tx = await goerliERC720Token.withdrawChallengeFaster(
+ '0x41162584974896bfc96d91e7ce72009373cd31acabe92024950831ee7b8067c0',
+ {
+ // nonce: 11793,
+ // gasPrice: '1000',
+ // gas: 10000,
+ // returnTransaction: true,
+ // gasPrice: '4000000000'
+ }
+ );
console.log("txHash", await tx.getTransactionHash());
console.log("txReceipt", await tx.getReceipt());
}

throw error when proof api is not set and fast api is called