Skip to content

Commit 60b3602

Browse files
committed
Merge branch 'ton-core-main'
2 parents 8492b65 + 6624036 commit 60b3602

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.52.0] - 2023-08-24
9+
10+
## Added
11+
- `Transaction.raw` field contains raw transaction cell
12+
- `Transaction.hash` function computes hash of raw transaction cell
13+
814
## [0.51.0] - 2023-08-17
915

1016
## Added

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ton/core",
3-
"version": "0.51.0",
3+
"version": "0.52.0",
44
"main": "dist/index.js",
55
"repository": "https://github.com/ton-org/ton-core.git",
66
"author": "Whales Corp. <[email protected]>",

src/types/Transaction.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ describe('Transaction', () => {
1919
const cell2 = beginCell().store(storeTransaction(tx)).endCell();
2020
expect(cell.equals(cell2)).toBe(true);
2121
});
22+
it('should parse transaction and hash', () => {
23+
// Source: https://explorer.toncoin.org/transaction?account=EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N&lt=22901965000001&hash=E9FB666FD65E2D70479C5A2C2EC412AD08D68FCDF57676B3BAA34AADA3C95DB8
24+
const boc = 'te6cckECCgEAAlMAA7V4Pf1VLmNym0cvy8yMRevMZpFwJVi2jsdSfhukA6DzGoAAAU1Ed9DUFmPJqTvOirSq2SKzYQ5GyQgvd9+38bqLQeGJ8YYrkwEwAAFNRGeacBYYzLegADRpVFhoAQIDAgHgBAUAgnKs+GZiNansGUYB+rKGLa25KuWgzm0WaeC5p+NLonoeFBg7+If0w+KZtCRH5Mx+9HCC8Pihk1IvrTPyRowEaTRLAg8MQMYZbXqEQAgJAd+IAQe/qqXMblNo5fl5kYi9eYzSLgSrFtHY6k/DdIB0HmNQB3H/g30bYqz72JAcnKJjRhgkmca92JLgIBGap3csfDt4Jk4S1186lCTQKuGZLHb97aw106oJRO8jslWF11AnUCFNTRi7DGZdIAAAAIAcBgEB3wcAdEIACasmTDZcDR+1HcxuZZBHXmDDvLMcX2Eijok8WCLyCyEwSMJzlQAAAAAAAAAAAAAAAAAAAAAAAAAAvUgBB7+qpcxuU2jl+XmRiL15jNIuBKsW0djqT8N0gHQeY1EABNWTJhsuBo/ajuY3MsgjrzBh3lmOL7CRR0SeLBF5BZCYJGE5yoAABhRYYAAAKaiO+hqEwxmW9AAAAABAAJ1BdkMTiAAAAAAAAAAAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAG/Jh6EgTBRYQAAAAAAAAgAAAAAAA4SB9Dp1g8lBEAkVf+gygVyC7sUl7wdSG9SEX3iBd2MqQFAXjC98i7E=';
25+
const cell = Cell.fromBoc(Buffer.from(boc, 'base64'))[0];
26+
const tx = loadTransaction(cell.beginParse());
27+
28+
expect(tx.hash().toString('hex')).toEqual(cell.hash().toString('hex'));
29+
expect(tx.raw.equals(cell)).toBe(true);
30+
});
2231
it('should parse tick/tock transactions', () => {
2332
// Source: https://explorer.toncoin.org/transaction?account=Ef80UXx731GHxVr0-LYf3DIViMerdo3uJLAG3ykQZFjXz2kW&lt=23019612000003&hash=36c7dbbb0cc6bf250e1265064c6c85751f8c838bea7caa58a9e62db03ea5d004
2433
const boc = 'te6cckECBgEAATIAA69zRRfHvfUYfFWvT4th/cMhWIx6t2je4ksAbfKRBkWNfPAAAU76vLzwNWZ7xZALK0LgKzOhLytPsuTA0xeefgUOOoutURmfnnowAAFO+ry88BYZJ8ZwABQIAQIDAAEgAIJylqTCiKw1AYPxh8CsC3VDbY7yFlU0TmTCts3A0+5em+JY4alwBNV+0DtCbXo8QiEQ9DmV3wfpinUd6ThveMbXjwIFMDA0BAUAnkJmTmJaAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaWAAAACWAAAABAAGAAAAAAAFGa6E8XuPiyICapdf9V8asZ/eSnaHRNIXjfpju1M+EHpAkCa8Fcsu4Q==';

src/types/Transaction.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { beginCell, Builder } from "../boc/Builder";
10+
import { Cell } from '../boc/Cell';
1011
import { Slice } from "../boc/Slice";
1112
import { Dictionary } from "../dict/Dictionary";
1213
import { Maybe } from "../utils/maybe";
@@ -39,9 +40,12 @@ export type Transaction = {
3940
totalFees: CurrencyCollection,
4041
stateUpdate: HashUpdate,
4142
description: TransactionDescription,
43+
raw: Cell,
44+
hash: () => Buffer,
4245
};
4346

44-
export function loadTransaction(slice: Slice) {
47+
export function loadTransaction(slice: Slice): Transaction {
48+
let raw = slice.asCell();
4549

4650
if (slice.loadUint(4) !== 0x07) {
4751
throw Error('Invalid data');
@@ -79,6 +83,8 @@ export function loadTransaction(slice: Slice) {
7983
totalFees,
8084
stateUpdate,
8185
description,
86+
raw,
87+
hash: () => raw.hash(),
8288
};
8389
}
8490

0 commit comments

Comments
 (0)