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

Fixed Compiled Issues in example/nodejs(escrow example) #127

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions changelog.d/20231213_092859_nicolas.henin_revert_address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### @marlowe.io/runtime-core

- - `AddressBech32` is a branded type instead of newtype (`unAddressBech32` has been removed and is not necessary anymore) : [PR #127](https://github.com/input-output-hk/marlowe-ts-sdk/pull/127)
152 changes: 152 additions & 0 deletions examples/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion examples/nodejs/src/escrow-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Lucid, Blockfrost } from "lucid-cardano";
import { readConfig } from "./config.js";
import { datetoTimeout } from "@marlowe.io/language-core-v1";
import { addressBech32 } from "@marlowe.io/runtime-core";
import { mintRole } from "@marlowe.io/runtime-rest-client/contract";

const args = arg({
"--help": Boolean,
Expand Down Expand Up @@ -112,7 +113,11 @@ async function main(

const [contractId, txId] = await runtime.contracts.createContract({
contract: escrow,
roles: { Buyer, Seller, Mediator },
roles: {
Buyer: mintRole(Buyer),
Seller: mintRole(Seller),
Mediator: mintRole(Mediator),
},
nhenin marked this conversation as resolved.
Show resolved Hide resolved
});

console.log("Contract ID: " + contractId);
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
Metadata,
TextEnvelope,
TextEnvelopeGuard,
unAddressBech32,
unTxOutRef,
AddressesAndCollaterals,
AddressBech32,
Expand Down Expand Up @@ -584,13 +583,9 @@ export const postViaAxios: (
...(stakeAddress && {
"X-Stake-Address": unStakeAddressBech32(stakeAddress),
}),
"X-Change-Address": unAddressBech32(
addressesAndCollaterals.changeAddress
),
"X-Address": pipe(
addressesAndCollaterals.usedAddresses,
A.map(unAddressBech32),
(a) => a.join(",")
"X-Change-Address": addressesAndCollaterals.changeAddress,
"X-Address": pipe(addressesAndCollaterals.usedAddresses, (a) =>
a.join(",")
),
"X-Collateral-UTxO": pipe(
addressesAndCollaterals.collateralUTxOs,
Expand Down
1 change: 0 additions & 1 deletion packages/runtime/client/rest/src/contract/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ export {
TokenMetadataGuard as TokenMetadata,
RoleTokenConfigurationGuard as RoleTokenConfiguration,
RolesConfigurationGuard as RolesConfiguration,
AddressBech32Guard as AddressBech32,
} from "./rolesConfigurations.js";
2 changes: 0 additions & 2 deletions packages/runtime/client/rest/src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export { ContractDetails } from "./details.js";
export {
useMintedRoles,
mintRole,
AddressBech32Brand,
AddressBech32,
openRole,
ClosedRole,
OpenRole,
Expand Down
22 changes: 2 additions & 20 deletions packages/runtime/client/rest/src/contract/rolesConfigurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,7 @@ import * as t from "io-ts/lib/index.js";
import { PolicyId, RoleName } from "@marlowe.io/language-core-v1";

import * as G from "@marlowe.io/language-core-v1/guards";

/**
* @category Roles Configuration
*/
export interface AddressBech32Brand {
readonly AddressBech32: unique symbol;
}

export const AddressBech32Guard = t.brand(
t.string,
(s): s is t.Branded<string, AddressBech32Brand> => true,
"AddressBech32"
);

/**
* Cardano Address in a Bech32 format
* @category Roles Configuration
*/
export type AddressBech32 = t.TypeOf<typeof AddressBech32Guard>;
import { AddressBech32, AddressBech32Guard } from "@marlowe.io/runtime-core";

/**
* Definition a of Closed Role Tlken
Expand Down Expand Up @@ -147,7 +129,7 @@ export const TokenQuantityGuard: t.Type<TokenQuantity> = t.bigint;
*/
export interface RoleTokenConfiguration {
recipients:
| { [x: string & t.Brand<AddressBech32Brand>]: TokenQuantity }
| { [x: AddressBech32]: TokenQuantity }
| { OpenRole: TokenQuantity };
metadata?: TokenMetadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
TextEnvelopeGuard,
TxId,
TxOutRef,
unAddressBech32,
unTxOutRef,
} from "@marlowe.io/runtime-core";

Expand Down Expand Up @@ -164,13 +163,9 @@ export const postViaAxios: (axiosInstance: AxiosInstance) => POST =
Accept:
"application/vendor.iog.marlowe-runtime.apply-inputs-tx-json",
"Content-Type": "application/json",
"X-Change-Address": unAddressBech32(
addressesAndCollaterals.changeAddress
),
"X-Address": pipe(
addressesAndCollaterals.usedAddresses,
A.map(unAddressBech32),
(a) => a.join(",")
"X-Change-Address": addressesAndCollaterals.changeAddress,
"X-Address": pipe(addressesAndCollaterals.usedAddresses, (a) =>
a.join(",")
),
"X-Collateral-UTxO": pipe(
addressesAndCollaterals.collateralUTxOs,
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/client/rest/src/payout/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AddressBech32,
WithdrawalId,
AssetQuantity,
AddressBech32Guard,
} from "@marlowe.io/runtime-core";

import { PayoutStatus } from "./status.js";
Expand All @@ -24,7 +25,7 @@ export const PayoutDetails = t.type({
contractId: ContractIdGuard,
withdrawalId: optionFromNullable(WithdrawalId),
role: AssetId,
payoutValidatorAddress: AddressBech32,
payoutValidatorAddress: AddressBech32Guard,
status: PayoutStatus,
assets: Assets,
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
TextEnvelopeGuard,
TxOutRef,
WithdrawalId,
unAddressBech32,
unPolicyId,
unTxOutRef,
} from "@marlowe.io/runtime-core";
Expand Down Expand Up @@ -147,13 +146,9 @@ export const postViaAxios: (axiosInstance: AxiosInstance) => POST =
headers: {
Accept: "application/vendor.iog.marlowe-runtime.withdraw-tx-json",
"Content-Type": "application/json",
"X-Change-Address": unAddressBech32(
addressesAndCollaterals.changeAddress
),
"X-Address": pipe(
addressesAndCollaterals.usedAddresses,
A.map(unAddressBech32),
(a) => a.join(",")
"X-Change-Address": addressesAndCollaterals.changeAddress,
"X-Address": pipe(addressesAndCollaterals.usedAddresses, (a) =>
a.join(",")
),
"X-Collateral-UTxO": pipe(
addressesAndCollaterals.collateralUTxOs,
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"@marlowe.io/language-core-v1": "0.3.0-beta-rc1",
"@marlowe.io/adapter": "0.3.0-beta-rc1",
"fp-ts": "^2.16.1",
"io-ts": "2.2.21",
"newtype-ts": "0.3.5"
Expand Down
26 changes: 17 additions & 9 deletions packages/runtime/core/src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@ import * as t from "io-ts/lib/index.js";
import { iso, Newtype } from "newtype-ts";
import { fromNewtype } from "io-ts-types";
import { TxOutRef } from "./tx/outRef.js";
import { unsafeEither } from "@marlowe.io/adapter/fp-ts";

export type AddressBech32 = Newtype<
{ readonly AddressBech32: unique symbol },
string
>;
export const AddressBech32 = fromNewtype<AddressBech32>(t.string);
export const unAddressBech32 = iso<AddressBech32>().unwrap;
export const addressBech32 = iso<AddressBech32>().wrap;
export interface AddressBech32Brand {
readonly AddressBech32: unique symbol;
}

export const AddressBech32Guard = t.brand(
t.string,
(s): s is t.Branded<string, AddressBech32Brand> => true,
nhenin marked this conversation as resolved.
Show resolved Hide resolved
"AddressBech32"
);

export type AddressBech32 = t.TypeOf<typeof AddressBech32Guard>;

export const addressBech32 = (s: string) =>
unsafeEither(AddressBech32Guard.decode(s));
nhenin marked this conversation as resolved.
Show resolved Hide resolved
nhenin marked this conversation as resolved.
Show resolved Hide resolved

export type AddressesAndCollaterals = t.TypeOf<typeof AddressesAndCollaterals>;
export const AddressesAndCollaterals = t.type({
changeAddress: AddressBech32,
usedAddresses: t.array(AddressBech32),
changeAddress: AddressBech32Guard,
usedAddresses: t.array(AddressBech32Guard),
collateralUTxOs: t.array(TxOutRef),
});
nhenin marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
12 changes: 10 additions & 2 deletions packages/runtime/core/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"extends": "../../../../tsconfig-base.json",
"compilerOptions": {
"outDir": "../dist/esm"
}
"outDir": "../dist/esm",
"paths": {
"@marlowe.io/adapter/*": ["../../../../adapter/src/*"],
hrajchert marked this conversation as resolved.
Show resolved Hide resolved
"@marlowe.io/language-core-v1/*": ["../../../../language/core/v1/src/*"]
}
},
"references": [
{ "path": "../../../adapter/src" },
{ "path": "../../../language/core/v1/src" }
]
}
Loading