Skip to content

Commit

Permalink
[runtime-lifecycle] added payouts logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nhenin committed Aug 27, 2023
1 parent 811b632 commit f923e88
Show file tree
Hide file tree
Showing 48 changed files with 389 additions and 279 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ It is composed of the following [npm workspaces](https://docs.npmjs.com/cli/v7/u
- Wallet Extension Capabalities (Browser / CIP-30)
- Single Wallet Address Capabalities(NodeJS / Version used for e2e tests only)
- Runtime
- [@marlowe.io/runtime](./packages/runtime/api/) : Entry Point for Running remotely Marlowe Contracts over a backend instance of the runtime using a connected wallet.
- [@marlowe.io/runtime-lifecycle](./packages/runtime/lifecycle/) : Entry Point for Running remotely Marlowe Contracts over a backend instance of the runtime using a connected wallet.
- Marlowe Tx Commands
- Create
- Applying Inputs
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"packages/wallet",
"packages/runtime/client/rest",
"packages/runtime/core",
"packages/runtime/api"
"packages/runtime/lifecycle"
],
"devDependencies": {
"@blockfrost/blockfrost-js": "5.2.0",
Expand All @@ -42,10 +42,10 @@
"@types/jest": "^26.0.24",
"@types/json-bigint": "^1.0.1",
"@types/node": "^18.14.2",
"axios-curlirize": "2.0.0",
"dotenv": "^16.0.3",
"eslint": "^7.32.0",
"http-server": "^14.1.1",
"axios-curlirize":"2.0.0",
"jest": "^29.4",
"jest-serial-runner": "^1.2.1",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 0 additions & 2 deletions packages/runtime/api/Readme.md

This file was deleted.

13 changes: 0 additions & 13 deletions packages/runtime/api/src/apis/runtime.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/runtime/api/src/index.ts

This file was deleted.

63 changes: 0 additions & 63 deletions packages/runtime/api/src/instance/overRestAPI/runtime.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/runtime/client/rest/src/contract/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './header.js'
export * from './details.js'
export * from './role.js'
17 changes: 0 additions & 17 deletions packages/runtime/client/rest/src/contract/withdrawal/id.ts

This file was deleted.

9 changes: 7 additions & 2 deletions packages/runtime/client/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import * as HTTP from '@marlowe.io/adapter/http';
import * as Payouts from './payout/endpoints/collection.js';
import * as Payout from './payout/endpoints/singleton.js';

import * as Withdrawal from './contract/withdrawal/endpoints/singleton.js';
import * as Withdrawals from './contract/withdrawal/endpoints/collection.js';
import * as Withdrawal from './withdrawal/endpoints/singleton.js';
import * as Withdrawals from './withdrawal/endpoints/collection.js';
import * as Contract from './contract/endpoints/singleton.js';
import * as Contracts from './contract/endpoints/collection.js';
import * as Transaction from './contract/transaction/endpoints/singleton.js';
import * as Transactions from './contract/transaction/endpoints/collection.js';
import * as ContractNext from './contract/next/endpoint.js';
import curlirize from 'axios-curlirize';


export * from './contract/index.js'
export * from './withdrawal/index.js'
export * from './payout/index.js'

export interface RestAPI {
healthcheck : () => TE.TaskEither<Error,Boolean>
payouts : {
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/client/rest/src/payout/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import * as t from "io-ts/lib/index.js";
import { optionFromNullable } from "io-ts-types";

import { ContractId, AssetId, PayoutId, AddressBech32, Assets } from "@marlowe.io/runtime-core";
import { WithdrawalId } from "../contract/withdrawal/id.js";
import { ContractId, AssetId, PayoutId, AddressBech32, Assets, WithdrawalId } from "@marlowe.io/runtime-core";

import { PayoutStatus } from "./status.js";

export type PayoutDetails = t.TypeOf<typeof PayoutDetails>
export const PayoutDetails
= t.type(
{ payoutId: PayoutId
, contractId: ContractId
, withdrawalId : optionFromNullable(WithdrawalId)
, withdrawalIdOption : optionFromNullable(WithdrawalId)
, role: AssetId
, payoutValidatorAddress: AddressBech32
, status : PayoutStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export type GETHeadersByRange = (rangeOption: O.Option<ContractsRange>)
=> (statusOption : O.Option<PayoutStatus>)
=> TE.TaskEither<Error | DecodingError,GETByRangeResponse>

const roleToParameter = (role : AssetId) => `${unPolicyId(role.policyId)}.${role.assetName}`
const roleToParameter = (roleToken : AssetId) => `${unPolicyId(roleToken.policyId)}.${roleToken.assetName}`
const contractIdToParameter = (contractId : ContractId) => unContractId(contractId)
const statusOptionToParameter = (statusOption : O.Option<PayoutStatus>) => pipe ( statusOption, O.match(() => '', a => `status=${a}&`))

export const getHeadersByRangeViaAxios:(axiosInstance: AxiosInstance) => GETHeadersByRange
= (axiosInstance) => (rangeOption) => (contractIds) => (roles) => (statusOption) =>
pipe( ({ url : '/payouts?' + statusOptionToParameter(statusOption) + stringify(({contractId:contractIds.map(contractIdToParameter)
,roles:roles.map(roleToParameter)}), { indices: false })
,roleToken:roles.map(roleToParameter)}), { indices: false })
, configs : pipe(rangeOption
, O.match( () => ({})
, range => ({ headers: { Range: unContractsRange(range) }})))})
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime/client/rest/src/payout/header.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

import * as t from "io-ts/lib/index.js";

import { ContractId, AssetId, PayoutId } from "@marlowe.io/runtime-core";
import { ContractId, AssetId, PayoutId, WithdrawalId } from "@marlowe.io/runtime-core";
import { PayoutStatus } from "./status.js";
import { WithdrawalId } from "../contract/withdrawal/id.js";
import { optionFromNullable } from "io-ts-types";

export type PayoutHeader = t.TypeOf<typeof PayoutHeader>
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/client/rest/src/payout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './details.js'
export * from './header.js'
export * from './status.js'
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

import * as t from "io-ts/lib/index.js";


import { WithdrawalId } from "./id.js";
import { TxStatus } from "../transaction/status.js";
import { TxStatus } from "../contract/transaction/status.js";

import { optionFromNullable } from "io-ts-types/lib/optionFromNullable.js";
import { BlockHeader } from "@marlowe.io/runtime-core";
import { PayoutHeader } from "../../payout/header.js";
import { BlockHeader, WithdrawalId } from "@marlowe.io/runtime-core";
import { PayoutHeader } from "../payout/header.js";


export type WithdrawalDetails = t.TypeOf<typeof WithdrawalDetails>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import { formatValidationErrors } from 'jsonbigint-io-ts-reporters'
import * as HTTP from '@marlowe.io/adapter/http';
import { DecodingError } from '@marlowe.io/adapter/codec';

import { AddressesAndCollaterals, PayoutIds, TextEnvelope, unAddressBech32, unTxOutRef } from '@marlowe.io/runtime-core';
import { AddressesAndCollaterals, PayoutId, TextEnvelope, WithdrawalId, unAddressBech32, unTxOutRef } from '@marlowe.io/runtime-core';

import { WithdrawalId } from '../id.js';
import { WithdrawalHeader } from '../header.js';


Expand Down Expand Up @@ -57,7 +56,8 @@ export const GETByRangeResponse
, nextRange :optionFromNullable(WithdrawalsRange)
});

export type POST = ( payoutIds: PayoutIds

export type POST = ( payoutIds: PayoutId[]
, addressesAndCollaterals: AddressesAndCollaterals) => TE.TaskEither<Error | DecodingError ,WithdrawalTextEnvelope>

export type WithdrawalTextEnvelope = t.TypeOf<typeof WithdrawalTextEnvelope>;
Expand All @@ -73,7 +73,7 @@ export const postViaAxios:(axiosInstance: AxiosInstance) => POST
= (axiosInstance) => (payoutIds, addressesAndCollaterals) =>
pipe( HTTP.Post (axiosInstance)
( '/withdrawals'
, payoutIds
, {payouts : payoutIds}
, { headers: {
'Accept': 'application/vendor.iog.marlowe-runtime.withdraw-tx-json',
'Content-Type':'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import * as HTTP from '@marlowe.io/adapter/http';

import {formatValidationErrors} from 'jsonbigint-io-ts-reporters'

import { unWithdrawalId, WithdrawalId } from '../id.js';
import { WithdrawalDetails } from '../details.js';
import { DecodingError } from '@marlowe.io/adapter/codec';
import { HexTransactionWitnessSet, transactionWitnessSetTextEnvelope } from '@marlowe.io/runtime-core';
import { HexTransactionWitnessSet, WithdrawalId, transactionWitnessSetTextEnvelope, unWithdrawalId } from '@marlowe.io/runtime-core';


export type GET = ( withdrawalId: WithdrawalId) => TE.TaskEither<Error | DecodingError, WithdrawalDetails>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import * as t from "io-ts/lib/index.js";


import { WithdrawalId } from "./id.js";
import { TxStatus } from "../transaction/status.js";
import { TxStatus } from "../contract/transaction/status.js";
import { optionFromNullable } from "io-ts-types/lib/optionFromNullable.js";
import { BlockHeader } from "@marlowe.io/runtime-core";
import { BlockHeader, WithdrawalId } from "@marlowe.io/runtime-core";


export type WithdrawalHeader = t.TypeOf<typeof WithdrawalHeader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './id.js'
export * from './header.js'
export * from './details.js'
17 changes: 16 additions & 1 deletion packages/runtime/core/src/asset/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as t from "io-ts/lib/index.js";
import { PolicyId } from "../policyId.js";
import { PolicyId, mkPolicyId, unPolicyId } from "../policyId.js";

import * as Marlowe from '@marlowe.io/language-core-v1/tokenValue'

export type AssetName = t.TypeOf<typeof AssetName>
export const AssetName = t.string
Expand All @@ -14,12 +15,18 @@ export const AssetId
{ policyId: PolicyId
, assetName: AssetName })

export const assetId : (policyId : PolicyId) => (assetName : AssetName) => AssetId
= (policyId) => (assetName) => ({ policyId: policyId, assetName: assetName})

export type Token = t.TypeOf<typeof Token>
export const Token
= t.type(
{ quantity: AssetQuantity
, assetId: AssetId
})

export const token : (quantity : AssetQuantity) => (assetId : AssetId)=> Token = (quantity) => (assetId) => ({quantity: quantity, assetId : assetId})
export const lovelaces : (quantity : AssetQuantity) => Token = (quantity) => token(quantity)(assetId(mkPolicyId(''))(''))

export type Tokens = t.TypeOf<typeof Tokens>
export const Tokens = t.record(PolicyId, t.record(AssetName, AssetQuantity))
Expand All @@ -31,3 +38,11 @@ export const Assets
, tokens: Tokens
})

export const assetIdToString : (assetId : AssetId) => string = (assetId) => `${unPolicyId(assetId.policyId)}|${assetId.assetName}`

export const runtimeTokenToMarloweTokenValue : (runtimeToken: Token) => Marlowe.TokenValue
= (runtimeToken) =>
({ amount :runtimeToken.quantity
, token:
{ currency_symbol:unPolicyId(runtimeToken.assetId.policyId)
, token_name:runtimeToken.assetId.assetName} })
2 changes: 1 addition & 1 deletion packages/runtime/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export * from './metadata.js'
export * from './tag.js'
export * from './contract/id.js'
export * from './asset/index.js'
export * from './payout/id.js'
export * from './payout/index.js'
23 changes: 0 additions & 23 deletions packages/runtime/core/src/payout/id.ts

This file was deleted.

Loading

0 comments on commit f923e88

Please sign in to comment.