-
Notifications
You must be signed in to change notification settings - Fork 10
/
api.ts
134 lines (127 loc) · 3.77 KB
/
api.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { WalletAPI, WalletDI } from "@marlowe.io/wallet/api";
import {
AssetId,
ContractId,
PayoutAvailable,
PayoutId,
PayoutWithdrawn,
} from "@marlowe.io/runtime-core";
import {
DeprecatedRestDI,
RestClient,
RestDI,
} from "@marlowe.io/runtime-rest-client";
import {
ApplicableActionsAPI,
ApplicableAction,
ApplicableInput,
ApplicableActionsFilter,
ApplicableActionsWithDetailsFilter,
ApplyApplicableInputRequest,
CanAdvance,
CanChoose,
CanDeposit,
CanNotify,
GetApplicableActionsResponse,
} from "./generic/applicable-actions.js";
import {
ActiveContract,
ClosedContract,
ContractDetails,
} from "./generic/new-contract-api.js";
import {
ContractsAPI,
CreateContractRequestBase,
} from "./generic/deprecated-contracts.js";
export {
ApplicableActionsAPI,
ApplicableAction,
ApplicableInput,
ApplicableActionsFilter,
ApplicableActionsWithDetailsFilter,
ApplyApplicableInputRequest,
CanAdvance,
CanChoose,
CanDeposit,
CanNotify,
GetApplicableActionsResponse,
ActiveContract,
ClosedContract,
ContractDetails,
CreateContractRequestBase,
};
import * as NewContract from "./generic/new-contract-api.js";
/**
* This is the main entry point of the @marlowe.io/runtime-lifecycle package. It provides a set of APIs to
* interact with the Marlowe Runtime.
*
* This interface can be created from {@link @marlowe.io/runtime-lifecycle!index | a wallet API instance } or if you are in the browser
* from a {@link @marlowe.io/runtime-lifecycle!browser | wallet name}.
* @category RuntimeLifecycle
*/
export interface RuntimeLifecycle {
/**
* The wallet API as defined in the {@link @marlowe.io/wallet! } package. It is re-exported here for convenience.
*/
wallet: WalletAPI;
/**
* Access to the low-level REST API as defined in the {@link @marlowe.io/runtime-rest-client! } package. It is re-exported here for convenience.
*/
restClient: RestClient;
newContractAPI: NewContract.ContractsAPI;
/**
* The contracts API is a high level API that lets you create and interact with Marlowe contracts.
*/
deprecatedContractAPI: ContractsAPI;
payouts: PayoutsAPI;
applicableActions: ApplicableActionsAPI;
}
/**
* @hidden
*/
export type PayoutsDI = WalletDI & RestDI & DeprecatedRestDI;
/**
* @category PayoutsAPI
*/
export interface PayoutsAPI {
/**
* Provide All the availaible payouts for the connected Wallet
* @param filters provide filtering capabilities on the available payouts returned
* @throws DecodingError
*/
available(filters?: Filters): Promise<PayoutAvailable[]>;
// TODO : Withdraw should not `waitConfirmation` behind the scene and it should return a `TxId` (https://github.com/input-output-hk/marlowe-ts-sdk/issues/170)
/**
* TODO: comment
* @throws DecodingError
*/
withdraw(payoutIds: PayoutId[]): Promise<void>;
/**
* Provide All the withdrawn payouts for the connected Wallet
* @param filters provide filtering capabilities on the withdrawn payouts returned
* @throws DecodingError
*/
withdrawn(filters?: Filters): Promise<PayoutWithdrawn[]>;
}
/**
* Provide filtering capabilities on the payouts returned only by ContractIds
* @param byContractIds filters the payouts by contract Ids
* @throws DecodingError
* @category PayoutsAPI
*/
export const onlyByContractIds = (contractIds: ContractId[]) =>
({
byContractIds: contractIds,
byMyRoleTokens: (myRoles) => myRoles,
}) as Filters;
/**
* Provide filtering capabilities on the payouts returned
* @param byContractIds filters the payouts by contract Ids
* @param byMyRoleTokens filters the payouts by role tokens owned in the connected wallet
* @throws DecodingError
* @category PayoutsAPI
*/
export type Filters = {
byContractIds: ContractId[];
byMyRoleTokens: (myRolesOnWallet: AssetId[]) => AssetId[];
};