Skip to content

Commit 5b5f41d

Browse files
authored
Merge pull request #812 from MeshJS/feat-tx-builderV2-prototype
Feat tx builder v2 prototype
2 parents eaac20b + a1c33b8 commit 5b5f41d

8 files changed

Lines changed: 747 additions & 24 deletions

File tree

packages/mesh-common/src/data/json/aliases.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ export type Tuple<T extends any[]> = { list: T };
8888
* Aiken alias
8989
* The Plutus Data Option in JSON
9090
*/
91-
export type Option<T> = Some<T> | None;
91+
export type Option<T extends PlutusData> = Some<T> | None;
9292

9393
/**
9494
* Aiken alias
9595
* The Plutus Data Option - Some in JSON
9696
*/
97-
export type Some<T> = ConStr0<[T]>;
97+
export type Some<T extends PlutusData> = ConStr0<[T]>;
9898

9999
/**
100100
* Aiken alias
@@ -246,7 +246,7 @@ export const tuple = <T extends PlutusData[]>(...args: T): Tuple<T> => ({
246246
* @param value The optional value of the option
247247
* @returns Return None constructor if the value is not provided, otherwise return Some constructor with the value
248248
*/
249-
export const option = <T>(value?: T): Option<T> => {
249+
export const option = <T extends PlutusData>(value?: T): Option<T> => {
250250
if (!value) {
251251
return none();
252252
}
@@ -258,7 +258,7 @@ export const option = <T>(value?: T): Option<T> => {
258258
* @param value The value of the option
259259
* @returns The Plutus Data Option - Some object
260260
*/
261-
export const some = <T>(value: T): Some<T> => conStr0([value]);
261+
export const some = <T extends PlutusData>(value: T): Some<T> => conStr0([value]);
262262

263263
/**
264264
* The utility function to create a Plutus Data Option - None in JSON
Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,88 @@
1+
import { PlutusData } from ".";
2+
13
/**
24
* The Plutus Data constructor object, representing custom data type in JSON
35
*/
4-
export type ConStr<N = 0, T = any> = { constructor: N; fields: T };
5-
6+
export interface ConStr<N = number, T extends PlutusData[] = PlutusData[]> {
7+
constructor: N;
8+
fields: T;
9+
}
610
/**
711
* The Plutus Data index 0 constructor object, representing custom data type in JSON
812
*/
9-
export type ConStr0<T = any> = ConStr<0, T>;
13+
export interface ConStr0<T extends PlutusData[] = PlutusData[]> extends ConStr<
14+
0,
15+
T
16+
> {}
1017

1118
/**
1219
* The Plutus Data index 1 constructor object, representing custom data type in JSON
1320
*/
14-
export type ConStr1<T = any> = ConStr<1, T>;
21+
export interface ConStr1<T extends PlutusData[] = PlutusData[]> extends ConStr<
22+
1,
23+
T
24+
> {}
1525

1626
/**
1727
* The Plutus Data index 2 constructor object, representing custom data type in JSON
1828
*/
19-
export type ConStr2<T = any> = ConStr<2, T>;
29+
export interface ConStr2<T extends PlutusData[] = PlutusData[]> extends ConStr<
30+
2,
31+
T
32+
> {}
2033

2134
/**
2235
* The Plutus Data index 3 constructor object, representing custom data type in JSON
2336
*/
24-
export type ConStr3<T = any> = ConStr<3, T>;
37+
export interface ConStr3<T extends PlutusData[] = PlutusData[]> extends ConStr<
38+
3,
39+
T
40+
> {}
2541

2642
/**
2743
* The utility function to create a Plutus Data constructor object, representing custom data type in JSON
2844
* @param constructor The constructor index number
2945
* @param fields The items in array
3046
* @returns The Plutus Data constructor object
3147
*/
32-
export const conStr = <N extends number, T>(
48+
export const conStr = <N extends number, T extends PlutusData[]>(
3349
constructor: N,
3450
fields: T,
3551
): ConStr<N, T> => {
3652
if (!Array.isArray(fields)) {
3753
throw new Error("fields of a constructor must be an array");
3854
}
39-
return {
40-
constructor,
41-
fields,
42-
};
55+
return { constructor, fields };
4356
};
4457

4558
/**
4659
* The utility function to create a Plutus Data index 0 constructor object, representing custom data type in JSON
4760
* @param fields The items of in array
4861
* @returns The Plutus Data constructor object
4962
*/
50-
export const conStr0 = <T>(fields: T): ConStr0<T> => conStr<0, T>(0, fields);
63+
export const conStr0 = <T extends PlutusData[]>(fields: T): ConStr0<T> =>
64+
conStr<0, T>(0, fields);
5165

5266
/**
5367
* The utility function to create a Plutus Data index 1 constructor object, representing custom data type in JSON
5468
* @param fields The items of in array
5569
* @returns The Plutus Data constructor object
5670
*/
57-
export const conStr1 = <T>(fields: T): ConStr1<T> => conStr<1, T>(1, fields);
71+
export const conStr1 = <T extends PlutusData[]>(fields: T): ConStr1<T> =>
72+
conStr<1, T>(1, fields);
5873

5974
/**
6075
* The utility function to create a Plutus Data index 2 constructor object, representing custom data type in JSON
6176
* @param fields The items of in array
6277
* @returns The Plutus Data constructor object
6378
*/
64-
export const conStr2 = <T>(fields: T): ConStr2<T> => conStr<2, T>(2, fields);
79+
export const conStr2 = <T extends PlutusData[]>(fields: T): ConStr2<T> =>
80+
conStr<2, T>(2, fields);
6581

6682
/**
6783
* The utility function to create a Plutus Data index 3 constructor object, representing custom data type in JSON
6884
* @param fields The items of in array
6985
* @returns The Plutus Data constructor object
7086
*/
71-
export const conStr3 = <T>(fields: T): ConStr3<T> => conStr<3, T>(3, fields);
87+
export const conStr3 = <T extends PlutusData[]>(fields: T): ConStr3<T> =>
88+
conStr<3, T>(3, fields);

packages/mesh-common/src/types/transaction-builder/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type MeshTxBuilderBody = {
3535
certificates: Certificate[];
3636
withdrawals: Withdrawal[];
3737
votes: Vote[];
38-
proposals: Proposal[];
38+
proposals: Proposal[];
3939
signingKey: string[];
4040
extraInputs: UTxO[];
4141
chainedTxs: string[];

packages/mesh-transaction/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export * from "./scripts";
33
export * from "./transaction";
44
export * from "./utils";
55
export * from "./tx-parser";
6+
export * from "./mesh-tx-builder-v2";
67
export { LargestFirstInputSelector } from "./mesh-tx-builder/coin-selection";

0 commit comments

Comments
 (0)