Skip to content

Commit 2f6325e

Browse files
committed
contractservice added prepareFunctions
1 parent 7505abe commit 2f6325e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/api/service/service/ContractService.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ContractService {
2222

2323
getFunctions(contractName: string, source: string, path: string): any {
2424
const contract = this.compileContract(contractName, source, path)
25-
return contract.abi.filter(abi => abi.type === 'function' || abi.type === 'constructor')
25+
return this.prepareFunctions(contract.abi)
2626
}
2727

2828
compileContract(contractName: string, source: string, path: string): any {
@@ -60,6 +60,22 @@ export class ContractService {
6060
return this.sendTx(web3, to, functionCallEncoded, txBase.from, txBase.gas, txBase.gasPrice, txBase.value)
6161
}
6262

63+
private prepareFunctions(abi: any[]): any[] {
64+
const functions = abi.filter(abi => abi.type === 'function')
65+
let constructor = abi.find(f => f.type === 'constructor')
66+
if (!constructor) {
67+
constructor = [
68+
{
69+
inputs: [],
70+
payable: false,
71+
stateMutability: "nonpayable",
72+
type: "constructor"
73+
}
74+
]
75+
}
76+
return [constructor].concat(functions)
77+
}
78+
6379
private async sendTx(web3: any, to: string, input: string, from?: string, gas?: number, gasPrice?: number, value?: number): Promise<any> {
6480
const accounts = await web3.eth.getAccounts()
6581
return web3.eth.sendTransaction({

0 commit comments

Comments
 (0)