Skip to content

Commit 31c8ba2

Browse files
author
Dan Volkov
authored
Merge pull request #15 from Gusarich/main
Update old stateinit declarations to use existing `StateInit` type
2 parents be1f3f8 + 46dd44c commit 31c8ba2

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

src/contract/Contract.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
import { Address } from "../address/Address";
1010
import { Cell } from "../boc/Cell";
11+
import { StateInit } from "../types/StateInit";
1112
import { Maybe } from "../utils/maybe";
1213
import { ContractABI } from "./ContractABI";
1314

1415
export interface Contract {
1516
readonly address: Address;
16-
readonly init?: Maybe<{ code: Cell, data: Cell }>;
17+
readonly init?: Maybe<StateInit>;
1718
readonly abi?: Maybe<ContractABI>;
1819
}

src/contract/Sender.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
import { Address } from "../address/Address";
1010
import { Cell } from "../boc/Cell";
1111
import { SendMode } from "../types/SendMode";
12+
import { StateInit } from "../types/StateInit";
1213
import { Maybe } from "../utils/maybe";
1314

1415
export type SenderArguments = {
1516
value: bigint,
1617
to: Address,
1718
sendMode?: Maybe<SendMode>,
1819
bounce?: Maybe<boolean>,
19-
init?: Maybe<{ code?: Maybe<Cell>, data?: Maybe<Cell> }>,
20+
init?: Maybe<StateInit>,
2021
body?: Maybe<Cell>
2122
}
2223

src/contract/openContract.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88

99
import { Address } from "../address/Address";
1010
import { Cell } from "../boc/Cell";
11+
import { Dictionary } from "../dict/Dictionary";
12+
import { StateInit } from "../types/StateInit";
1113
import { Contract } from "./Contract";
1214
import { ContractProvider } from "./ContractProvider";
15+
import { SimpleLibrary } from "../types/SimpleLibrary";
1316

1417
export type OpenedContract<F> = {
1518
[P in keyof F]: P extends `${'get' | 'send'}${string}`
1619
? (F[P] extends (x: ContractProvider, ...args: infer P) => infer R ? (...args: P) => R : never)
1720
: F[P];
1821
}
1922

20-
export function openContract<T extends Contract>(src: T, factory: (params: { address: Address, init: { code: Cell, data: Cell } | null }) => ContractProvider): OpenedContract<T> {
23+
export function openContract<T extends Contract>(src: T, factory: (params: { address: Address, init: StateInit | null }) => ContractProvider): OpenedContract<T> {
2124

2225
// Resolve parameters
2326
let address: Address;
24-
let init: { code: Cell, data: Cell } | null = null;
27+
let init: StateInit | null = null;
2528

2629
if (!Address.isAddress(src.address)) {
2730
throw Error('Invalid address');

src/types/_helpers.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { beginCell } from "../boc/Builder";
1313
import { toNano } from "../utils/convert";
1414
import { MessageRelaxed } from "./MessageRelaxed";
1515
import { Message } from "./Message";
16+
import { StateInit } from "./StateInit";
1617

1718
export function internal(src: {
1819
to: Address | string,
1920
value: bigint | string,
2021
bounce?: Maybe<boolean>,
21-
init?: Maybe<{ code?: Maybe<Cell>, data?: Maybe<Cell> }>,
22+
init?: Maybe<StateInit>,
2223
body?: Maybe<Cell | string>
2324
}): MessageRelaxed {
2425

@@ -68,14 +69,14 @@ export function internal(src: {
6869
createdAt: 0,
6970
createdLt: 0n
7071
},
71-
init: src.init ? { code: src.init.code, data: src.init.data } : undefined,
72+
init: src.init ?? undefined,
7273
body: body
7374
};
7475
}
7576

7677
export function external(src: {
7778
to: Address | string,
78-
init?: Maybe<{ code?: Maybe<Cell>, data?: Maybe<Cell> }>,
79+
init?: Maybe<StateInit>,
7980
body?: Maybe<Cell>
8081
}): Message {
8182

@@ -95,7 +96,7 @@ export function external(src: {
9596
dest: to,
9697
importFee: 0n
9798
},
98-
init: src.init ? { code: src.init.code, data: src.init.data } : undefined,
99+
init: src.init ?? undefined,
99100
body: src.body || Cell.EMPTY
100101
};
101102
}

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -6899,4 +6899,4 @@ __metadata:
68996899
resolution: "yocto-queue@npm:0.1.0"
69006900
checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700
69016901
languageName: node
6902-
linkType: hard
6902+
linkType: hard

0 commit comments

Comments
 (0)