implement erc20 deposit
MODIFY
src/inherited/eth_method.ts
src/inherited/eth_method.ts
@@ -34,14 +34,14 @@ export class EthMethod extends BaseContractMethod {
// to: tx.to,
// value: tx.value?.toString()
// }
- try {
+ // try {
this.method.send(tx as any).
once("transactionHash", result.onTransactionHash).
once("receipt", result.onReceipt).
once("error", result.onError);
- } catch (error) {
+ // } catch (error) {
- }
+ // }
}, 0);
return result;
}

MODIFY
src/model/contract_write_result.ts
src/model/contract_write_result.ts
import { ISendResult, ITransactionReceipt } from "../interfaces";
export class ContractWriteResult {
- private result_: ISendResult;
+ private txHashPromise: Promise<string>;
+ private receiptPromise: Promise<string>;
- constructor(result_: ISendResult) {
- this.result_ = result_;
+ constructor(result: ISendResult) {
+ this.txHashPromise = new Promise((res, rej) => {
+ result.onTransactionHash = res;
+ result.onError = rej;
+ });
+ this.receiptPromise = new Promise((res, rej) => {
+ result.onReceipt = res;
+ result.onError = rej;
+ });
}
getReceipt() {
- return new Promise<ITransactionReceipt>((res, rej) => {
- this.result_.onReceipt = res;
- this.result_.onError = rej;
- });
+ return this.receiptPromise;
}
getTransactionHash() {
- return new Promise<string>((res, rej) => {
- this.result_.onTransactionHash = res;
- this.result_.onError = rej;
- });
+ return this.txHashPromise;
}
}
\ No newline at end of file

MODIFY
src/pos/erc20.ts
src/pos/erc20.ts
@@ -59,6 +59,24 @@ export class ERC20 extends POSToken {
);
}
+ /**
+ * Deposit given amount of token for user
+ *
+ * @param {TYPE_AMOUNT} amount
+ * @param {string} userAddress
+ * @param {ITransactionOption} [option]
+ * @returns
+ * @memberof ERC20
+ */
+ deposit(amount: TYPE_AMOUNT, userAddress: string, option?: ITransactionOption) {
+ return this.rootChainManager.deposit(
+ userAddress,
+ this.contractParam.tokenAddress,
+ amount,
+ option
+ );
+ }
+
/**
* initiate withdraw by burning provided amount
*
@@ -125,4 +143,6 @@ export class ERC20 extends POSToken {
txHash, Log_Event_Signature.Erc20Transfer
);
}
+
+
}
\ No newline at end of file

MODIFY
src/pos/exit_manager.ts
src/pos/exit_manager.ts
-import { BaseContract, BaseWeb3Client } from "../model";
+import { BaseWeb3Client } from "../model";
import { RootChainManager } from "./root_chain_manager";
-import { Logger, formatAmount, ProofUtil } from "../utils";
-import { LOGGER } from "../constant";
+import { formatAmount, ProofUtil } from "../utils";
import assert from "assert";
import BN from "bn.js";
import ethUtils from "ethereumjs-util";

MODIFY
src/pos/root_chain_manager.ts
src/pos/root_chain_manager.ts
@@ -2,6 +2,8 @@ import { BaseContract, BaseWeb3Client, BaseToken, Web3SideChainClient } from "..
import { TYPE_AMOUNT } from "../types";
import BN from "bn.js";
import { BIG_ONE, CHECKPOINT_INTERVAL, BIG_TWO, LOGGER } from "../constant";
+import { ITransactionOption } from "../interfaces";
+import { formatAmount } from "../utils";
export class RootChainManager extends BaseToken {
@@ -61,5 +63,15 @@ export class RootChainManager extends BaseToken {
return ans.mul(CHECKPOINT_INTERVAL);
}
+ deposit(userAddress: string, tokenAddress: string, amount: TYPE_AMOUNT, option?: ITransactionOption) {
+ const method = this.method(
+ "depositFor",
+ userAddress,
+ tokenAddress,
+ formatAmount(amount)
+ );
+
+ return this.processWrite(method, option);
+ }
}
\ No newline at end of file

implement erc20 deposit