implement isDeposited
MODIFY
src/abstracts/base_web3_client.ts
src/abstracts/base_web3_client.ts
@@ -39,5 +39,6 @@ export abstract class BaseWeb3Client {
abstract sendRPCRequest(request: IJsonRpcRequestPayload): Promise<IJsonRpcResponse>;
abstract encodeParameters(params: any[], types: any[]): string;
+ abstract decodeParameters(hexString: string, types: any[]): any[];
abstract etheriumSha3(...value): string;
}

MODIFY
src/pos/exit_util.ts
src/pos/exit_util.ts
@@ -259,5 +259,4 @@ export class ExitUtil {
receipt.blockNumber, ethUtils.bufferToHex(Buffer.concat(nibbleArr)), logIndex
);
}
-
}
\ No newline at end of file

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -11,43 +11,41 @@ export * from "./exit_util";
export * from "./root_chain_manager";
export * from "./root_chain";
-export class POSClient extends BridgeClient {
+export class POSClient extends BridgeClient<IPOSClientConfig> {
rootChainManager: RootChainManager;
- private client_: Web3SideChainClient<IPOSClientConfig>;
constructor(config: IPOSClientConfig) {
- super();
- this.client_ = new Web3SideChainClient(config);
+ super(config);
}
init() {
- const client = this.client_;
+ const client = this.client;
let config: IPOSClientConfig = client.config;
return client.init().then(_ => {
- const mainPOSContracts = this.client_.mainPOSContracts;
+ const mainPOSContracts = this.client.mainPOSContracts;
client.config = config = Object.assign(
{
rootChainManager: mainPOSContracts.RootChainManagerProxy,
- rootChain: this.client_.mainPlasmaContracts.RootChainProxy
+ rootChain: this.client.mainPlasmaContracts.RootChainProxy
} as IPOSClientConfig,
config
);
this.rootChainManager = new RootChainManager(
- this.client_,
+ this.client,
config.rootChainManager,
);
const rootChain = new RootChain(
- this.client_,
+ this.client,
config.rootChain,
);
this.exitUtil = new ExitUtil(
- this.client_.child,
+ this.client.child,
rootChain,
config.requestConcurrency
);
@@ -60,7 +58,7 @@ export class POSClient extends BridgeClient {
return new ERC20(
tokenAddress,
isParent,
- this.client_,
+ this.client,
this.getContracts_.bind(this)
);
}
@@ -69,14 +67,14 @@ export class POSClient extends BridgeClient {
return new ERC721(
tokenAddress,
isParent,
- this.client_,
+ this.client,
this.getContracts_.bind(this)
);
}
depositEther(amount: TYPE_AMOUNT, option: ITransactionOption) {
return new ERC20(
- '', true, this.client_,
+ '', true, this.client,
this.getContracts_,
)['depositEther_'](amount, option);
}

MODIFY
src/utils/bridge_client.ts
src/utils/bridge_client.ts
+import BN from "bn.js";
+import { Web3SideChainClient } from "../utils";
import { ExitUtil } from "../pos";
-export class BridgeClient {
+export class BridgeClient<T> {
+
+ protected client: Web3SideChainClient<T>;
+
+ constructor(config: T) {
+ this.client = new Web3SideChainClient(config as any);
+ }
+
exitUtil: ExitUtil;
/**
@@ -16,4 +25,28 @@ export class BridgeClient {
);
}
+ isDeposited(depositTxHash: string) {
+ const client = this.client;
+ return client.getABI(
+ "StateReceiver",
+ "genesis",
+ ).then(abi => {
+ const contract = client.child.getContract(
+ client.abiManager.getAddress("Matic.GenesisContracts.StateReceiver"),
+ abi
+ );
+ return Promise.all([
+ client.parent.getTransactionReceipt(depositTxHash),
+ contract.method("lastStateId").read<string>()
+ ]);
+ }).then(result => {
+ const [receipt, lastStateId] = result;
+ const rootStateId = client.child.decodeParameters(receipt.logs[3].topics[0], ['uint256'])[0];
+ const rootStateIdBN = BN.isBN(rootStateId) ? rootStateId : new BN(rootStateId);
+ return new BN(lastStateId).gte(
+ rootStateIdBN
+ );
+ });
+ }
+
}
\ No newline at end of file

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
@@ -10,7 +10,7 @@ export class Web3SideChainClient<T_CONFIG> {
config: T_CONFIG;
- abiHelper: ABIManager;
+ abiManager: ABIManager;
logger = new Logger();
@@ -34,7 +34,7 @@ export class Web3SideChainClient<T_CONFIG> {
const config = this.config as any as IBaseClientConfig;
const network = config.network;
const version = config.version;
- const abiHelper = this.abiHelper = new ABIManager(network, version);
+ const abiHelper = this.abiManager = new ABIManager(network, version);
console.log("init called", abiHelper);
return abiHelper.init().catch(err => {
throw new Error(`network ${network} - ${version} is not supported`);
@@ -42,15 +42,15 @@ export class Web3SideChainClient<T_CONFIG> {
}
getABI(name: string, type?: string) {
- return this.abiHelper.getABI(name, type);
+ return this.abiManager.getABI(name, type);
}
get mainPlasmaContracts() {
- return this.abiHelper.getAddress("Main.Contracts");
+ return this.abiManager.getAddress("Main.Contracts");
}
get mainPOSContracts() {
- return this.abiHelper.getAddress("Main.POSContracts");
+ return this.abiManager.getAddress("Main.POSContracts");
}

MODIFY
test/debug.js
test/debug.js
@@ -36,10 +36,10 @@ const execute = async () => {
const mumbaiERC20Token = client.erc20(mumbaiERC20);
const goerliERC20Token = client.erc20(goerliERC20, true);
- // return console.log(await goerliERC20Token.getAllowance(from));
+ return console.log(await client.isDeposited('0xc67599f5c967f2040786d5924ec55d37bf943c009bdd23f3b50e5ae66efde258'));
- // const balance = await mumbaiERC720Token.getBalance(
+ // const balance = await mumbaiERC20Token.getBalance(
// from
// );
// return console.log("balance", balance);
@@ -49,11 +49,11 @@ const execute = async () => {
// );
// return console.log("tokens", tokens);
- // const tx = await goerliERC720Token.safeDeposit(104, from);
- // setProofApi("https://apis.matic.network")
- const tx = await goerliERC20Token.withdrawExit('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7');
- console.log("txHash", await tx.getTransactionHash());
- console.log("txReceipt", await tx.getReceipt());
+ // const tx = await goerliERC20Token.deposit(10, from);
+ // // setProofApi("https://apis.matic.network")
+ // // const tx = await goerliERC20Token.withdrawExit('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7');
+ // console.log("txHash", await tx.getTransactionHash());
+ // console.log("txReceipt", await tx.getReceipt());
//txhash to plasma exit - 0x63aa095e0d6ee8698399b871daa202eb5522933e2d94c5929cf0fb86b6b0c628
const tokenId = '60399350241383852757821046101235634991156913804166740995010931519407953501076'

implement isDeposited