Skip to content

Commit

Permalink
lets go
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornkihlberg committed Jan 25, 2024
1 parent 50a9e1f commit d1e4623
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import { TxHeader, TxHeaderGuard } from "../header.js";
import { ContractId, ContractIdGuard } from "@marlowe.io/runtime-core";
import { assertGuardEqual, proxy } from "@marlowe.io/adapter/io-ts";
import { Input } from "@marlowe.io/language-core-v1";
import { ItemRange, Page, PageGuard } from "../../../pagination.js";
import {
ItemRange,
ItemRangeGuard,
Page,
PageGuard,
} from "../../../pagination.js";

export type GETHeadersByRange = (
contractId: ContractId,
Expand Down Expand Up @@ -74,6 +79,23 @@ const GetContractsRawResponse = t.type({
page: PageGuard,
});

export interface GetTransactionsForContractRequest {
contractId: ContractId;
range?: ItemRange;
}

export const GetTransactionsForContractRequestGuard = assertGuardEqual(
proxy<GetTransactionsForContractRequest>(),
t.intersection([
t.type({
contractId: ContractIdGuard,
}),
t.partial({
range: ItemRangeGuard,
}),
])
);

/**
* Represents the response of the {@link index.RestClient#getTransactionsForContract | Get transactions for contract } endpoint
* @category GetTransactionsForContractResponse
Expand Down
18 changes: 15 additions & 3 deletions packages/runtime/client/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ export interface RestClient {
// with an AxiosError 404, we could return a nullable value or wrap the error into a custom
// ContractNotFound error and specify it in the docs.
getTransactionsForContract(
contractId: ContractId,
range?: ItemRange
request: Transactions.GetTransactionsForContractRequest
): Promise<Transactions.GetTransactionsForContractResponse>;

/**
Expand Down Expand Up @@ -514,7 +513,20 @@ export function mkRestClient(
const { contractId, txEnvelope } = request;
return Contract.submitContract(axiosInstance)(contractId, txEnvelope);
},
getTransactionsForContract(contractId, range) {
getTransactionsForContract(request) {
if (strict) {
const result =
Transactions.GetTransactionsForContractRequestGuard.decode(request);
if (result._tag === "Left") {
throw new InvalidArgumentError(
result.left,
`Invalid argument to getTransactionsForContract(${request})`
);
} else {
const test: typeof request = result.right;
}
}
const { contractId, range } = request;
return unsafeTaskEither(
Transactions.getHeadersByRangeViaAxios(axiosInstance)(contractId, range)
);
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime/lifecycle/src/generic/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export function mkContractLifecycle(
const getInputHistory =
({ restClient }: ContractsDI) =>
async (contractId: ContractId): Promise<SingleInputTx[]> => {
const transactionHeaders =
await restClient.getTransactionsForContract(contractId);
const transactionHeaders = await restClient.getTransactionsForContract({
contractId,
});
const transactions = await Promise.all(
transactionHeaders.transactions.map((txHeader) =>
restClient.getContractTransactionById(
Expand Down

0 comments on commit d1e4623

Please sign in to comment.