From 7f7359df43db4cc956e28f45cf137a01a2619341 Mon Sep 17 00:00:00 2001 From: Dan Volkov Date: Fri, 13 Sep 2024 11:32:00 +0400 Subject: [PATCH 1/6] feat: allow "is" as a prefix for the contract methods --- CHANGELOG.md | 5 +++++ src/contract/openContract.ts | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e41a7d..59956a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +## Added +- Methods, prefixed with "is" in the contract classes are now wrapped like "send"/"get" + ## [0.57.0] - 2024-08-16 ## Added - More flexible merkle proof generation (thx @akifoq) diff --git a/src/contract/openContract.ts b/src/contract/openContract.ts index 1d15f5f..a803a55 100644 --- a/src/contract/openContract.ts +++ b/src/contract/openContract.ts @@ -8,14 +8,12 @@ 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 = { - [P in keyof F]: P extends `${'get' | 'send'}${string}` + [P in keyof F]: P extends `${'get' | 'send' | 'is'}${string}` ? (F[P] extends (x: ContractProvider, ...args: infer P) => infer R ? (...args: P) => R : never) : F[P]; } From d1c6a78c411438c1a60446ebfdb98344461e46f7 Mon Sep 17 00:00:00 2001 From: Dan Volkov Date: Fri, 13 Sep 2024 11:37:49 +0400 Subject: [PATCH 2/6] Release 0.58.0 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59956a7..85ef494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.58.0] - 2024-09-13 ## Added - Methods, prefixed with "is" in the contract classes are now wrapped like "send"/"get" diff --git a/package.json b/package.json index ab69269..ad1788f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ton/core", - "version": "0.57.0", + "version": "0.58.0", "main": "dist/index.js", "repository": "https://github.com/ton-org/ton-core.git", "author": "Whales Corp. ", From 2b23bada50787ad01dd326b87a9ed415c5ef7ee5 Mon Sep 17 00:00:00 2001 From: Dan Volkov Date: Fri, 13 Sep 2024 11:41:02 +0400 Subject: [PATCH 3/6] fix: contract proxy method discovery --- src/contract/openContract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contract/openContract.ts b/src/contract/openContract.ts index a803a55..103129c 100644 --- a/src/contract/openContract.ts +++ b/src/contract/openContract.ts @@ -45,7 +45,7 @@ export function openContract(src: T, factory: (params: { add return new Proxy(src as any, { get(target, prop) { const value = target[prop]; - if (typeof prop === 'string' && (prop.startsWith('get') || prop.startsWith('send'))) { + if (typeof prop === 'string' && (prop.startsWith('get') || prop.startsWith('send') || prop.startsWith('is'))) { if (typeof value === 'function') { return (...args: any[]) => value.apply(target, [executor, ...args]); } From ea32eb6439f93bdace19c085d828eda5e66b602c Mon Sep 17 00:00:00 2001 From: Dan Volkov Date: Fri, 13 Sep 2024 11:41:40 +0400 Subject: [PATCH 4/6] chore: changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ef494..75825a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +## Fixed +- Contract proxy method discovery + ## [0.58.0] - 2024-09-13 ## Added From 8d6a6a0e5c1998d379aac61cebb9d7ec8cf4068e Mon Sep 17 00:00:00 2001 From: Dan Volkov Date: Fri, 13 Sep 2024 11:43:19 +0400 Subject: [PATCH 5/6] Release 0.58.1 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75825a6..55a5fd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.58.1] - 2024-09-13 ## Fixed - Contract proxy method discovery diff --git a/package.json b/package.json index ad1788f..953cae7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ton/core", - "version": "0.58.0", + "version": "0.58.1", "main": "dist/index.js", "repository": "https://github.com/ton-org/ton-core.git", "author": "Whales Corp. ", From 68e1b7c2c95135a6d0960737127848e713c15f92 Mon Sep 17 00:00:00 2001 From: krigga <25533192+krigga@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:43:32 +0300 Subject: [PATCH 6/6] feat: Cell.fromHex --- src/boc/Cell.ts | 14 +++++++++++++- src/boc/cell/serialization.spec.ts | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/boc/Cell.ts b/src/boc/Cell.ts index 3b75e47..88e7ce5 100644 --- a/src/boc/Cell.ts +++ b/src/boc/Cell.ts @@ -34,7 +34,7 @@ export class Cell { } /** - * Helper class that deserializes a single cell from BOC in base64 + * Helper function that deserializes a single cell from BOC in base64 * @param src source string */ static fromBase64(src: string): Cell { @@ -45,6 +45,18 @@ export class Cell { return parsed[0]; } + /** + * Helper function that deserializes a single cell from BOC in hex + * @param src source string + */ + static fromHex(src: string): Cell { + let parsed = Cell.fromBoc(Buffer.from(src, 'hex')); + if (parsed.length !== 1) { + throw new Error("Deserialized more than one cell"); + } + return parsed[0]; + } + // Public properties readonly type: CellType; readonly bits: BitString; diff --git a/src/boc/cell/serialization.spec.ts b/src/boc/cell/serialization.spec.ts index 11e3361..d0e2f39 100644 --- a/src/boc/cell/serialization.spec.ts +++ b/src/boc/cell/serialization.spec.ts @@ -241,5 +241,10 @@ describe('boc', () => { expect(cell.toString()).toBe('x{000000E4}\n x{00000539}\n x{0000053A}'); expect(serialized).toBe('b5ee9c7281010301001400080e140208000000e4010200080000053900080000053a'); }); + + it('should deserialize cell from hex', () => { + let cell = Cell.fromHex('b5ee9c7241010201000d00010800000001010008000000027d4b3cf8'); + expect(cell.toString()).toBe('x{00000001}\n x{00000002}'); + }); });