83 lines
3.0 KiB
Handlebars
83 lines
3.0 KiB
Handlebars
public {{languageSpecificName}} = {
|
|
async sendTransactionAsync(
|
|
{{> typed_params inputs=inputs}}
|
|
txData?: Partial<TxData> | undefined,
|
|
): Promise<string> {
|
|
{{#each inputs}}
|
|
{{#assertionType name type}}{{/assertionType}}
|
|
{{/each}}
|
|
const self = this as any as {{contractName}}Contract;
|
|
const encodedData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> normalized_params inputs=inputs}}]);
|
|
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
|
|
{
|
|
to: self.address,
|
|
...txData,
|
|
data: encodedData,
|
|
},
|
|
self._web3Wrapper.getContractDefaults(),
|
|
self.{{languageSpecificName}}.estimateGasAsync.bind(
|
|
self,
|
|
{{> normalized_params inputs=inputs}}
|
|
),
|
|
);
|
|
if (txDataWithDefaults.from !== undefined) {
|
|
txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase();
|
|
}
|
|
|
|
const txHash = await self._web3Wrapper.sendTransactionAsync(txDataWithDefaults);
|
|
return txHash;
|
|
},
|
|
awaitTransactionSuccessAsync(
|
|
{{> typed_params inputs=inputs}}
|
|
txData?: Partial<TxData>,
|
|
pollingIntervalMs?: number,
|
|
timeoutMs?: number,
|
|
): PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs> {
|
|
{{#each inputs}}
|
|
{{#assertionType name type}}{{/assertionType}}
|
|
{{/each}}
|
|
const self = this as any as {{contractName}}Contract;
|
|
{{#if inputs}}
|
|
const txHashPromise = self.{{languageSpecificName}}.sendTransactionAsync({{> normalized_params input=inputs}}, txData);
|
|
{{else}}
|
|
const txHashPromise = self.{{languageSpecificName}}.sendTransactionAsync(txData);
|
|
{{/if}}
|
|
return new PromiseWithTransactionHash<TransactionReceiptWithDecodedLogs>(
|
|
txHashPromise,
|
|
(async (): Promise<TransactionReceiptWithDecodedLogs> => {
|
|
// When the transaction hash resolves, wait for it to be mined.
|
|
return self._web3Wrapper.awaitTransactionSuccessAsync(
|
|
await txHashPromise,
|
|
pollingIntervalMs,
|
|
timeoutMs,
|
|
);
|
|
})(),
|
|
);
|
|
},
|
|
async estimateGasAsync(
|
|
{{> typed_params inputs=inputs}}
|
|
txData?: Partial<TxData> | undefined,
|
|
): Promise<number> {
|
|
{{#each inputs}}
|
|
{{#assertionType name type}}{{/assertionType}}
|
|
{{/each}}
|
|
const self = this as any as {{contractName}}Contract;
|
|
const encodedData = self._strictEncodeArguments('{{this.functionSignature}}', [{{> normalized_params inputs=inputs}}]);
|
|
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
|
|
{
|
|
to: self.address,
|
|
...txData,
|
|
data: encodedData,
|
|
},
|
|
self._web3Wrapper.getContractDefaults(),
|
|
);
|
|
if (txDataWithDefaults.from !== undefined) {
|
|
txDataWithDefaults.from = txDataWithDefaults.from.toLowerCase();
|
|
}
|
|
|
|
const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults);
|
|
return gas;
|
|
},
|
|
{{> callAsync}}
|
|
};
|