Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions clients/contracts/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ function hexcmp(x: string, y: string) {
}

export class BridgeContract extends DelphinusContract {
private readonly web3: DelphinusWeb3;

constructor(web3: DelphinusWeb3, address: string, account?: string) {
super(web3, BridgeContract.getJsonInterface(), address, account);
this.web3 = web3;
}

static getJsonInterface(): any {
Expand All @@ -82,6 +85,25 @@ export class BridgeContract extends DelphinusContract {
return this.getWeb3Contract().methods.addToken(tokenid).send();
}

async getEstimatedGasFee(calldata: number[], verifydata: BN[], vid: number, rid: BN) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for verify only so the name is not good enough.

const gasPrice = await this.web3.web3Instance.eth.getGasPrice();
console.log("The gas price is", gasPrice, "wei");
const tx = this.getWeb3Contract().methods.verify(
calldata,
verifydata,
vid,
rid
);
return tx.estimateGas()
.then((estimatedGas: number) => {
console.log("The estimated gas is", estimatedGas);
return estimatedGas * Number(gasPrice);
})
.catch((e: any) => {
console.log("%s", e);
});
}

private _verify(calldata: number[], verifydata: BN[], vid: number, rid: BN) {
const tx = this.getWeb3Contract().methods.verify(
calldata,
Expand Down