take isParent on erc20 mthod
MODIFY
src/inherited/eth_method.ts
src/inherited/eth_method.ts
@@ -7,6 +7,7 @@ export class EthMethod extends BaseContractMethod {
constructor(private method: TransactionObject<any>) {
super();
+ console.log("method args", method.arguments);
}
read<T>(tx: ITransactionConfig): Promise<T> {
@@ -35,7 +36,7 @@ export class EthMethod extends BaseContractMethod {
try {
this.method.send(tx as any).
once("transactionHash", result.onTransactionHash).
- once("receipt", result.onTransactionHash).
+ once("receipt", result.onReceipt).
once("error", result.onError);
} catch (error) {

ADD
src/interfaces/contract_init_param.ts
+export interface IContractInitParam {
+ tokenAddress: string;
+ isParent: boolean;
+ abi: any;
+}
\ No newline at end of file

MODIFY
src/interfaces/index.ts
src/interfaces/index.ts
@@ -5,3 +5,4 @@ export * from "./transaction_config";
export * from "./send_result";
export * from "./transaction";
export * from "./transaction_option";
+export * from "./contract_init_param";
\ No newline at end of file

MODIFY
src/interfaces/transaction_option.ts
src/interfaces/transaction_option.ts
import { ITransactionConfig } from "./transaction_config";
export interface ITransactionOption extends ITransactionConfig {
- isParent?: boolean;
returnTransaction?: boolean;
}
\ No newline at end of file

MODIFY
src/model/base_token.ts
src/model/base_token.ts
import { Web3SideChainClient } from "./web3_side_chain_client";
-import { ITransactionConfig, ITransactionOption } from "@/interfaces";
+import { ITransactionConfig, ITransactionOption, IContractInitParam } from "@/interfaces";
import { BaseContractMethod } from "@/abstracts";
import { BaseWeb3Client } from "./web3_client";
import { EXTRA_GAS_FOR_PROXY_CALL } from "@/constant";
@@ -16,19 +16,19 @@ interface ITransactionConfigParam {
export class BaseToken {
+ contract: BaseContract;
constructor(
- private tokenAddress: string,
+ private contractParam: IContractInitParam,
public client: Web3SideChainClient,
- public abi
) {
-
+ this.contract = this.getContract(contractParam);
}
- getContract({ isParent }: ITransactionOption) {
+ getContract({ isParent, tokenAddress, abi }: IContractInitParam) {
const client = isParent ? this.client.parent.client :
this.client.child.client;
- return client.getContract(this.tokenAddress, this.abi);
+ return client.getContract(tokenAddress, abi);
}
get parentDefaultConfig() {

MODIFY
src/plasma/erc20.ts
src/plasma/erc20.ts
@@ -9,13 +9,18 @@ export class ERC20 extends BaseToken {
constructor(
tokenAddress: string,
+ isParent: boolean,
client: Web3SideChainClient,
public depositManager: DepositManager) {
- super(tokenAddress, client, client.getABI('ChildERC20'));
+ super({
+ isParent,
+ tokenAddress,
+ abi: client.getABI('ChildERC20')
+ }, client);
}
getBalance(userAddress: string, option: ITransactionOption = {}) {
- const contract = this.getContract(option);
+ const contract = this.contract;
const method = contract.method(
"balanceOf",
userAddress
@@ -31,8 +36,7 @@ export class ERC20 extends BaseToken {
}
approve(amount: BN | string | number, option: ITransactionOption = {}) {
- option.isParent = true;
- const contract = this.getContract(option);
+ const contract = this.contract;
const method = contract.method(
"approve",
this.depositManager.contract.address,

MODIFY
src/plasma/index.ts
src/plasma/index.ts
@@ -5,17 +5,16 @@ import { DepositManager } from "./deposit_manager";
export class PlasmaClient {
-
-
private client_: Web3SideChainClient;
withdrawManager;
depositManager: DepositManager;
- erc20(tokenAddress: string) {
+ erc20(tokenAddress: string, isParent?: boolean) {
return new ERC20(
tokenAddress,
+ isParent,
this.client_,
this.depositManager
);

MODIFY
test/debug.js
test/debug.js
@@ -31,13 +31,13 @@ const execute = async () => {
const balance = await childErc20.getBalance(from);
console.log('balance', balance);
- // const balance = await matic.erc20.getBalance(erc20TokenMumbaiAddress, from)
- // console.log('balance', balance)
-
- // const result = matic.erc20.approve(goerliTokenERC20, '1000000000000000');
+ // const rootTokenErc20 = matic.erc20(goerliTokenERC20);
+ // const result = await rootTokenErc20.approve(
+ // '1000000000000000'
+ // );
+ // console.log("approve result", result);
// console.log("result", result, result.on);
- // await result;
// result.onError = function () {
// console.log("error args", arguments);
// }

take isParent on erc20 mthod