Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-9262: Fix missing minUTXO problem with 0.0.5 #172

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions packages/runtime/client/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import axios from "axios";
import * as TE from "fp-ts/lib/TaskEither.js";
import * as O from "fp-ts/lib/Option.js";
import { pipe } from "fp-ts/lib/function.js";

import { MarloweJSONCodec } from "@marlowe.io/adapter/codec";
import * as HTTP from "@marlowe.io/adapter/http";
import { ContractBundle } from "@marlowe.io/marlowe-object";

import * as Payouts from "./payout/endpoints/collection.js";
Expand All @@ -41,7 +39,7 @@ import { ContractDetails } from "./contract/details.js";
import { TransactionDetails } from "./contract/transaction/details.js";
import { ItemRange } from "./pagination.js";
import { RuntimeStatus, healthcheck } from "./runtime/status.js";
// import curlirize from 'axios-curlirize';
import { RuntimeVersion } from "./runtime/version.js";

export {
Page,
Expand Down Expand Up @@ -78,6 +76,11 @@ export interface RestClient {
*/
healthcheck(): Promise<RuntimeStatus>;

/**
* Returns the version of the connected runtime.
*/
version(): Promise<RuntimeVersion>;

/**
* Gets a paginated list of contracts {@link contract.ContractHeader }
* @param request Optional filtering and pagination options.
Expand Down Expand Up @@ -275,10 +278,18 @@ export function mkRestClient(baseURL: string): RestClient {
transformResponse: MarloweJSONCodec.decode,
});

// The runtime version is "cached" here as it is not expected to change during the lifetime of the rest client.
const runtimeVersion = healthcheck(axiosInstance).then(
(status) => status.version
);

return {
healthcheck() {
return healthcheck(axiosInstance);
},
version() {
return runtimeVersion;
},
getContracts(request) {
const range = request?.range;
const tags = request?.tags ?? [];
Expand All @@ -295,21 +306,22 @@ export function mkRestClient(baseURL: string): RestClient {
getContractById(contractId) {
return Contract.getContractById(axiosInstance, contractId);
},
buildCreateContractTx(request) {
async buildCreateContractTx(request) {
const version = await runtimeVersion;
// NOTE: Runtime 0.0.5 requires an explicit minUTxODeposit, but 0.0.6 and forward allows that field as optional
// and it will calculate the actual minimum required. We use the version of the runtime to determine
// if we use a "safe" default that is bigger than needed.
const minUTxODeposit =
request.minimumLovelaceUTxODeposit ??
(version === "0.0.5" ? 3000000 : undefined);
const postContractsRequest = {
contract: "contract" in request ? request.contract : request.sourceId,
version: request.version,
metadata: request.metadata ?? {},
tags: request.tags ?? {},
...(request.minimumLovelaceUTxODeposit && {
minUTxODeposit: request.minimumLovelaceUTxODeposit,
}),
...(request.roles && {
roles: request.roles,
}),
...(request.threadRoleName && {
threadTokenName: request.threadRoleName,
}),
minUTxODeposit,
roles: request.roles,
threadRoleName: request.threadRoleName,
};
const addressesAndCollaterals = {
changeAddress: request.changeAddress,
Expand Down
Loading