Skip to content

Commit

Permalink
Merge pull request #172 from input-output-hk/hrajchert/plt-9262-minutxo
Browse files Browse the repository at this point in the history
PLT-9262: Fix missing minUTXO problem with 0.0.5
  • Loading branch information
hrajchert authored Jan 15, 2024
2 parents db2f342 + 6ede73c commit 0acd659
Showing 1 changed file with 25 additions and 13 deletions.
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

0 comments on commit 0acd659

Please sign in to comment.