-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
invocation-scope.ts
60 lines (49 loc) · 1.55 KB
/
invocation-scope.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { FunctionFragment } from '@fuel-ts/abi-coder';
import type { CoinQuantity } from '@fuel-ts/providers';
import { coinQuantityfy } from '@fuel-ts/providers';
import type { CallConfig, CallParams } from '../../types';
import type Contract from '../contract';
import { BaseInvocationScope } from './base-invocation-scope';
export class FunctionInvocationScope<
TArgs extends Array<any> = Array<any>,
TReturn = any
> extends BaseInvocationScope<TReturn> {
private func: FunctionFragment;
private callParameters?: CallParams;
private forward?: CoinQuantity;
private args: TArgs;
constructor(contract: Contract, func: FunctionFragment, args: TArgs) {
super(contract, false);
this.func = func;
this.args = args || [];
this.setArguments(...args);
super.addCall(this);
}
getCallConfig(): CallConfig<TArgs> {
return {
func: this.func,
contract: this.contract,
callParameters: this.callParameters,
txParameters: this.txParameters,
forward: this.forward,
args: this.args,
};
}
setArguments(...args: TArgs) {
this.args = args || [];
this.updateScriptRequest();
return this;
}
callParams(callParams: CallParams) {
this.callParameters = callParams;
if (callParams?.forward) {
this.forward = coinQuantityfy(callParams.forward);
}
// Update transaction script with new forward params
this.setArguments(...this.args);
// Update required coins
this.updateRequiredCoins();
return this;
}
}