-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
46 lines (35 loc) · 1.45 KB
/
index.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
import { StateInterface, ActionInterface } from "./faces";
import { TogglePairGatekeeper } from "./modules/togglePairGatekeeper";
import { SetCommunityContract } from "./modules/setCommunityContract";
import { ForeignTransfer } from "./modules/foreignTransfer";
import { CreateOrder } from "./modules/createOrder";
import { CancelOrder } from "./modules/cancelOrder";
import { ReadOutbox } from "./modules/readOutbox";
import { AddPair } from "./modules/addPair";
import { Halt } from "./modules/halt";
export async function handle(state: StateInterface, action: ActionInterface) {
ContractAssert(
!state.halted || action.input.function === "halt",
"The contract is currently halted"
);
switch (action.input.function) {
case "addPair":
return { state: await AddPair(state, action) };
case "createOrder":
return await CreateOrder(state, action);
case "cancelOrder":
return { state: await CancelOrder(state, action) };
case "readOutbox":
return { state: await ReadOutbox(state, action) };
case "togglePairGatekeeper":
return { state: TogglePairGatekeeper(state, action) };
case "setCommunityContract":
return { state: SetCommunityContract(state, action) };
case "foreignTransfer":
return { state: ForeignTransfer(state, action) };
case "halt":
return { state: Halt(state, action) };
default:
throw new ContractError(`Invalid function: "${action.input.function}"`);
}
}