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 c1845cf commit 50a9e1f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
17 changes: 16 additions & 1 deletion packages/runtime/client/rest/src/contract/endpoints/singleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import {
ContractIdGuard,
HexTransactionWitnessSet,
TextEnvelope,
TextEnvelopeGuard,
transactionWitnessSetTextEnvelope,
} from "@marlowe.io/runtime-core";

import { ContractDetails, ContractDetailsGuard } from "../details.js";
import { ContractId } from "@marlowe.io/runtime-core";
import { unsafeEither, unsafeTaskEither } from "@marlowe.io/adapter/fp-ts";
import { assertGuardEqual, proxy } from "@marlowe.io/adapter/io-ts";

export type GET = (
contractId: ContractId
Expand Down Expand Up @@ -65,7 +67,20 @@ export type PUT = (
hexTransactionWitnessSet: HexTransactionWitnessSet
) => TE.TaskEither<Error, void>;

export const submitContractViaAxios =
export interface SubmitContractRequest {
contractId: ContractId;
txEnvelope: TextEnvelope;
}

export const SubmitContractRequestGuard = assertGuardEqual(
proxy<SubmitContractRequest>(),
t.type({
contractId: ContractIdGuard,
txEnvelope: TextEnvelopeGuard,
})
);

export const submitContract =
(axiosInstance: AxiosInstance) =>
(contractId: ContractId, envelope: TextEnvelope) =>
axiosInstance
Expand Down
24 changes: 16 additions & 8 deletions packages/runtime/client/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
HexTransactionWitnessSet,
WithdrawalId,
} from "@marlowe.io/runtime-core";
import { submitContractViaAxios } from "./contract/endpoints/singleton.js";
import { ContractDetails } from "./contract/details.js";
import { TransactionDetails } from "./contract/transaction/details.js";
import { ItemRange } from "./pagination.js";
Expand Down Expand Up @@ -165,10 +164,7 @@ export interface RestClient {
* Submits a signed contract creation transaction
* @see {@link https://docs.marlowe.iohk.io/api/submit-contract-to-chain | The backend documentation}
*/
submitContract(
contractId: ContractId,
txEnvelope: TextEnvelope
): Promise<void>;
submitContract(request: Contract.SubmitContractRequest): Promise<void>;

/**
* Gets a paginated list of {@link contract.TxHeader } for a given contract.
Expand Down Expand Up @@ -495,16 +491,28 @@ export function mkRestClient(
if (result._tag === "Left") {
throw new InvalidArgumentError(
result.left,
`Invalid argument to getContractSourceAdjacency(${request})`
`Invalid argument to getNextStepsForContract(${request})`
);
} else {
const test: typeof request = result.right;
}
}
return Next.getNextStepsForContract(axiosInstance)(request);
},
submitContract(contractId, txEnvelope) {
return submitContractViaAxios(axiosInstance)(contractId, txEnvelope);
submitContract(request) {
if (strict) {
const result = Contract.SubmitContractRequestGuard.decode(request);
if (result._tag === "Left") {
throw new InvalidArgumentError(
result.left,
`Invalid argument to submitContract(${request})`
);
} else {
const test: typeof request = result.right;
}
}
const { contractId, txEnvelope } = request;
return Contract.submitContract(axiosInstance)(contractId, txEnvelope);
},
getTransactionsForContract(contractId, range) {
return unsafeTaskEither(
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/lifecycle/src/generic/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ const createContract =
buildCreateContractTxResponse.tx.cborHex
);

await restClient.submitContract(
await restClient.submitContract({
contractId,
transactionWitnessSetTextEnvelope(hexTransactionWitnessSet)
);
txEnvelope: transactionWitnessSetTextEnvelope(hexTransactionWitnessSet),
});
return [contractId, contractIdToTxId(contractId)];
};

Expand Down

0 comments on commit 50a9e1f

Please sign in to comment.