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

Update old stateinit declarations to use existing StateInit type #15

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 1 deletion src/contract/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import { Address } from "../address/Address";
import { Cell } from "../boc/Cell";
import { StateInit } from "../types/StateInit";
import { Maybe } from "../utils/maybe";
import { ContractABI } from "./ContractABI";

export interface Contract {
readonly address: Address;
readonly init?: Maybe<{ code: Cell, data: Cell }>;
readonly init?: Maybe<StateInit>;
readonly abi?: Maybe<ContractABI>;
}
3 changes: 2 additions & 1 deletion src/contract/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import { Address } from "../address/Address";
import { Cell } from "../boc/Cell";
import { SendMode } from "../types/SendMode";
import { StateInit } from "../types/StateInit";
import { Maybe } from "../utils/maybe";

export type SenderArguments = {
value: bigint,
to: Address,
sendMode?: Maybe<SendMode>,
bounce?: Maybe<boolean>,
init?: Maybe<{ code?: Maybe<Cell>, data?: Maybe<Cell> }>,
init?: Maybe<StateInit>,
body?: Maybe<Cell>
}

Expand Down
7 changes: 5 additions & 2 deletions src/contract/openContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

import { Address } from "../address/Address";
import { Cell } from "../boc/Cell";
import { Dictionary } from "../dict/Dictionary";
import { StateInit } from "../types/StateInit";
import { Contract } from "./Contract";
import { ContractProvider } from "./ContractProvider";
import { SimpleLibrary } from "../types/SimpleLibrary";

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

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

// Resolve parameters
let address: Address;
let init: { code: Cell, data: Cell } | null = null;
let init: StateInit | null = null;

if (!Address.isAddress(src.address)) {
throw Error('Invalid address');
Expand Down
9 changes: 5 additions & 4 deletions src/types/_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { beginCell } from "../boc/Builder";
import { toNano } from "../utils/convert";
import { MessageRelaxed } from "./MessageRelaxed";
import { Message } from "./Message";
import { StateInit } from "./StateInit";

export function internal(src: {
to: Address | string,
value: bigint | string,
bounce?: Maybe<boolean>,
init?: Maybe<{ code?: Maybe<Cell>, data?: Maybe<Cell> }>,
init?: Maybe<StateInit>,
body?: Maybe<Cell | string>
}): MessageRelaxed {

Expand Down Expand Up @@ -68,14 +69,14 @@ export function internal(src: {
createdAt: 0,
createdLt: 0n
},
init: src.init ? { code: src.init.code, data: src.init.data } : undefined,
init: src.init ?? undefined,
body: body
};
}

export function external(src: {
to: Address | string,
init?: Maybe<{ code?: Maybe<Cell>, data?: Maybe<Cell> }>,
init?: Maybe<StateInit>,
body?: Maybe<Cell>
}): Message {

Expand All @@ -95,7 +96,7 @@ export function external(src: {
dest: to,
importFee: 0n
},
init: src.init ? { code: src.init.code, data: src.init.data } : undefined,
init: src.init ?? undefined,
body: src.body || Cell.EMPTY
};
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6899,4 +6899,4 @@ __metadata:
resolution: "yocto-queue@npm:0.1.0"
checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700
languageName: node
linkType: hard
linkType: hard