Skip to content

Commit

Permalink
Merge pull request #124 from input-output-hk/PLT-7704
Browse files Browse the repository at this point in the history
PLT-7704, PLT-7705: Extend Rest API with procedures getPayouts and getPayoutById
  • Loading branch information
nhenin committed Dec 8, 2023
2 parents a73844b + 89ef0d8 commit 03f231f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### @marlowe.io/runtime-rest-client

- PLT-7704: Extend the rest client with procedure `getPayouts`. (Implemented in [PR-124](https://github.com/input-output-hk/marlowe-ts-sdk/pull/124))
- PLT-7705: Extend the rest client with procedure `getPayoutById`. (Implemented in [PR-124](https://github.com/input-output-hk/marlowe-ts-sdk/pull/124))
52 changes: 50 additions & 2 deletions packages/runtime/client/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,21 @@ export interface RestClient {
// getContractAdjacency: ContractSource.GET_ADJACENCY; // - Jamie, is it this one? https://docs.marlowe.iohk.io/api/get-adjacency-by-id if so lets unify
// getContractClosure: ContractSource.GET_CLOSURE; // Jamie is it this one? - https://docs.marlowe.iohk.io/api/get-closure-by-id

// getPayouts: Payouts.GET;
// getPayoutById: Payout.GET;
/**
* Get payouts to parties from role-based contracts.
* @see {@link https://docs.marlowe.iohk.io/api/get-role-payouts | The backend documentation}
*/
getPayouts(
request: Payouts.GetPayoutsRequest
): Promise<Payouts.GetPayoutsResponse>;

/**
* Get payout information associated with payout ID
* @see {@link https://docs.marlowe.iohk.io/api/get-payout-by-id | The backend documentation}
*/
getPayoutById(
request: Payout.GetPayoutByIdRequest
): Promise<Payout.GetPayoutByIdResponse>;
}

/**
Expand Down Expand Up @@ -360,6 +373,41 @@ export function mkRestClient(baseURL: string): RestClient {
() => true
)
)(),
async getPayouts({ contractIds, roleTokens, range, status }) {
const result = await unsafeTaskEither(
Payouts.getHeadersByRangeViaAxios(axiosInstance)(O.fromNullable(range))(
contractIds
)(roleTokens)(O.fromNullable(status))
);
return {
headers: result.headers,
...O.match(
() => ({}),
(previousRange) => ({ previousRange })
)(result.previousRange),
...O.match(
() => ({}),
(nextRange) => ({ nextRange })
)(result.nextRange),
};
},
async getPayoutById({ payoutId }) {
const result = await unsafeTaskEither(
Payout.getViaAxios(axiosInstance)(payoutId)
);
return {
payoutId: result.payoutId,
contractId: result.contractId,
...O.match(
() => ({}),
(withdrawalId) => ({ withdrawalId })
)(result.withdrawalId),
role: result.role,
payoutValidatorAddress: result.payoutValidatorAddress,
status: result.status,
assets: result.assets,
};
},
};
}

Expand Down
13 changes: 13 additions & 0 deletions packages/runtime/client/rest/src/payout/endpoints/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ export const ContractsRange = fromNewtype<ContractsRange>(t.string);
export const unContractsRange = iso<ContractsRange>().unwrap;
export const contractsRange = iso<ContractsRange>().wrap;

export type GetPayoutsRequest = {
contractIds: ContractId[];
roleTokens: AssetId[];
status?: PayoutStatus;
range?: ContractsRange;
};

export type GetPayoutsResponse = {
headers: PayoutHeader[];
previousRange?: ContractsRange;
nextRange?: ContractsRange;
};

export type GETHeadersByRange = (
rangeOption: O.Option<ContractsRange>
) => (
Expand Down
25 changes: 23 additions & 2 deletions packages/runtime/client/rest/src/payout/endpoints/singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,29 @@ import { formatValidationErrors } from "jsonbigint-io-ts-reporters";
import * as HTTP from "@marlowe.io/adapter/http";
import { DecodingError } from "@marlowe.io/adapter/codec";

import { PayoutId, unPayoutId } from "@marlowe.io/runtime-core";
import { PayoutDetails } from "../details.js";
import {
AddressBech32,
AssetId,
ContractId,
PayoutId,
WithdrawalId,
unPayoutId,
} from "@marlowe.io/runtime-core";
import { PayoutStatus, PayoutDetails, Assets } from "../index.js";

export type GetPayoutByIdRequest = {
payoutId: PayoutId;
};

export type GetPayoutByIdResponse = {
payoutId: PayoutId;
contractId: ContractId;
withdrawalId?: WithdrawalId;
role: AssetId;
payoutValidatorAddress: AddressBech32;
status: PayoutStatus;
assets: Assets;
};

export type GET = (
payoutId: PayoutId
Expand Down

0 comments on commit 03f231f

Please sign in to comment.