File tree 4 files changed +23
-2
lines changed
4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
6
6
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
7
7
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
+
8
14
## [ 0.51.0] - 2023-08-17
9
15
10
16
## Added
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @ton/core" ,
3
- "version" : " 0.51 .0" ,
3
+ "version" : " 0.52 .0" ,
4
4
"main" : " dist/index.js" ,
5
5
"repository" : " https://github.com/ton-org/ton-core.git" ,
6
6
"author" :
" Whales Corp. <[email protected] >" ,
Original file line number Diff line number Diff line change @@ -19,6 +19,15 @@ describe('Transaction', () => {
19
19
const cell2 = beginCell ( ) . store ( storeTransaction ( tx ) ) . endCell ( ) ;
20
20
expect ( cell . equals ( cell2 ) ) . toBe ( true ) ;
21
21
} ) ;
22
+ it ( 'should parse transaction and hash' , ( ) => {
23
+ // Source: https://explorer.toncoin.org/transaction?account=EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N<=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
+ } ) ;
22
31
it ( 'should parse tick/tock transactions' , ( ) => {
23
32
// Source: https://explorer.toncoin.org/transaction?account=Ef80UXx731GHxVr0-LYf3DIViMerdo3uJLAG3ykQZFjXz2kW<=23019612000003&hash=36c7dbbb0cc6bf250e1265064c6c85751f8c838bea7caa58a9e62db03ea5d004
24
33
const boc = 'te6cckECBgEAATIAA69zRRfHvfUYfFWvT4th/cMhWIx6t2je4ksAbfKRBkWNfPAAAU76vLzwNWZ7xZALK0LgKzOhLytPsuTA0xeefgUOOoutURmfnnowAAFO+ry88BYZJ8ZwABQIAQIDAAEgAIJylqTCiKw1AYPxh8CsC3VDbY7yFlU0TmTCts3A0+5em+JY4alwBNV+0DtCbXo8QiEQ9DmV3wfpinUd6ThveMbXjwIFMDA0BAUAnkJmTmJaAAAAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaWAAAACWAAAABAAGAAAAAAAFGa6E8XuPiyICapdf9V8asZ/eSnaHRNIXjfpju1M+EHpAkCa8Fcsu4Q==' ;
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
import { beginCell , Builder } from "../boc/Builder" ;
10
+ import { Cell } from '../boc/Cell' ;
10
11
import { Slice } from "../boc/Slice" ;
11
12
import { Dictionary } from "../dict/Dictionary" ;
12
13
import { Maybe } from "../utils/maybe" ;
@@ -39,9 +40,12 @@ export type Transaction = {
39
40
totalFees : CurrencyCollection ,
40
41
stateUpdate : HashUpdate ,
41
42
description : TransactionDescription ,
43
+ raw : Cell ,
44
+ hash : ( ) => Buffer ,
42
45
} ;
43
46
44
- export function loadTransaction ( slice : Slice ) {
47
+ export function loadTransaction ( slice : Slice ) : Transaction {
48
+ let raw = slice . asCell ( ) ;
45
49
46
50
if ( slice . loadUint ( 4 ) !== 0x07 ) {
47
51
throw Error ( 'Invalid data' ) ;
@@ -79,6 +83,8 @@ export function loadTransaction(slice: Slice) {
79
83
totalFees,
80
84
stateUpdate,
81
85
description,
86
+ raw,
87
+ hash : ( ) => raw . hash ( ) ,
82
88
} ;
83
89
}
84
90
You can’t perform that action at this time.
0 commit comments