Skip to content

Commit

Permalink
ERC20 Withdraw (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardonunesp authored and enlight committed Aug 24, 2018
1 parent 7a1d9fb commit 881a693
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/contracts/transfer-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Contract } from '../contract'
import { Address } from '../address'
import {
TransferGatewayWithdrawERC721Request,
TransferGatewayWithdrawERC20Request,
TransferGatewayWithdrawalReceiptRequest,
TransferGatewayWithdrawalReceiptResponse,
TransferGatewayWithdrawalReceipt,
Expand Down Expand Up @@ -128,6 +129,14 @@ export class TransferGateway extends Contract {
return this.callAsync<void>('WithdrawERC721', tgWithdrawERC721Req)
}

withdrawERC20Async(amount: BN, tokenContract: Address): Promise<void> {
const tgWithdrawERC20Req = new TransferGatewayWithdrawERC20Request()
tgWithdrawERC20Req.setAmount(marshalBigUIntPB(amount))
tgWithdrawERC20Req.setTokenContract(tokenContract.MarshalPB())

return this.callAsync<void>('WithdrawERC20', tgWithdrawERC20Req)
}

async withdrawalReceiptAsync(owner: Address): Promise<IWithdrawalReceipt | null> {
const tgWithdrawReceiptReq = new TransferGatewayWithdrawalReceiptRequest()
tgWithdrawReceiptReq.setOwner(owner.MarshalPB())
Expand Down
9 changes: 7 additions & 2 deletions src/proto/transfer_gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ message TransferGatewayWithdrawERC721Request {
BigUInt token_id = 1;
// DAppChain address of ERC721 contract token belongs to
Address token_contract = 2;
// DAppChain address of the current owner of the token
//Address token_owner = 3;
}

message TransferGatewayWithdrawERC20Request {
// Amount of tokens to withdraw
BigUInt amount = 1;
// DAppChain address of ERC20 contract tokens belongs to
Address token_contract = 2;
}

message TransferGatewayWithdrawalReceiptRequest {
Expand Down
28 changes: 28 additions & 0 deletions src/proto/transfer_gateway_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ export namespace TransferGatewayWithdrawERC721Request {
}
}

export class TransferGatewayWithdrawERC20Request extends jspb.Message {
hasAmount(): boolean;
clearAmount(): void;
getAmount(): proto_loom_pb.BigUInt | undefined;
setAmount(value?: proto_loom_pb.BigUInt): void;

hasTokenContract(): boolean;
clearTokenContract(): void;
getTokenContract(): proto_loom_pb.Address | undefined;
setTokenContract(value?: proto_loom_pb.Address): void;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): TransferGatewayWithdrawERC20Request.AsObject;
static toObject(includeInstance: boolean, msg: TransferGatewayWithdrawERC20Request): TransferGatewayWithdrawERC20Request.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: TransferGatewayWithdrawERC20Request, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): TransferGatewayWithdrawERC20Request;
static deserializeBinaryFromReader(message: TransferGatewayWithdrawERC20Request, reader: jspb.BinaryReader): TransferGatewayWithdrawERC20Request;
}

export namespace TransferGatewayWithdrawERC20Request {
export type AsObject = {
amount?: proto_loom_pb.BigUInt.AsObject,
tokenContract?: proto_loom_pb.Address.AsObject,
}
}

export class TransferGatewayWithdrawalReceiptRequest extends jspb.Message {
hasOwner(): boolean;
clearOwner(): void;
Expand Down

0 comments on commit 881a693

Please sign in to comment.