Skip to content

Commit 192c55c

Browse files
authored
0.4.0 (#125)
- New dictionary API - Full extra-currency support - CellBuilder/CellSlice optimizations - CellContext API - MessageLayout API
1 parent f0502a1 commit 192c55c

File tree

227 files changed

+3177
-901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+3177
-901
lines changed

.github/workflows/release.yml

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
name: Release
2-
on:
3-
push:
4-
branches:
5-
- main
6-
7-
jobs:
8-
build:
9-
if: "!contains(github.event.commits[0].message, '[skip ci]')"
10-
strategy:
11-
matrix:
12-
include:
13-
- os: macos-latest
14-
gradle_args: assemble publishIosX64PublicationToSonatypeRepository
15-
- os: macos-latest
16-
gradle_args: assemble publishIosArm64PublicationToSonatypeRepository
17-
- os: macos-latest
18-
gradle_args: assemble publishIosSimulatorArm64PublicationToSonatypeRepository
19-
- os: macos-latest
20-
gradle_args: assemble publishTvosX64PublicationToSonatypeRepository
21-
- os: macos-latest
22-
gradle_args: assemble publishTvosArm64PublicationToSonatypeRepository
23-
- os: macos-latest
24-
gradle_args: assemble publishTvosSimulatorArm64PublicationToSonatypeRepository
25-
- os: macos-latest
26-
gradle_args: assemble publishWatchosArm32PublicationToSonatypeRepository
27-
- os: macos-latest
28-
gradle_args: assemble publishWatchosArm64PublicationToSonatypeRepository
29-
- os: macos-latest
30-
gradle_args: assemble publishWatchosX64PublicationToSonatypeRepository
31-
- os: macos-latest
32-
gradle_args: assemble publishWatchosSimulatorArm64PublicationToSonatypeRepository
33-
- os: macos-latest
34-
gradle_args: assemble publishMacosX64PublicationToSonatypeRepository
35-
- os: macos-latest
36-
gradle_args: assemble publishMacosArm64PublicationToSonatypeRepository
37-
- os: ubuntu-latest
38-
gradle_args: assemble publishKotlinMultiplatformPublicationToSonatypeRepository publishJvmPublicationToSonatypeRepository publishLinuxX64PublicationToSonatypeRepository publishLinuxArm64PublicationToSonatypeRepository publishMingwX64PublicationToSonatypeRepository
39-
40-
runs-on: ${{ matrix.os }}
41-
steps:
42-
- name: Checkout project sources
43-
uses: actions/checkout@v3
44-
- uses: actions/setup-java@v3
45-
with:
46-
distribution: liberica
47-
java-version: 8
48-
- name: Build using gradle
49-
uses: gradle/gradle-build-action@v2
50-
with:
51-
arguments: ${{ matrix.gradle_args }}
52-
env:
53-
SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
54-
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
55-
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
56-
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1+
#name: Release
2+
#on:
3+
# push:
4+
# branches:
5+
# - main
6+
#
7+
#jobs:
8+
# build:
9+
# if: "!contains(github.event.commits[0].message, '[skip ci]')"
10+
# strategy:
11+
# matrix:
12+
# include:
13+
# - os: macos-latest
14+
# gradle_args: assemble publishIosX64PublicationToSonatypeRepository
15+
# - os: macos-latest
16+
# gradle_args: assemble publishIosArm64PublicationToSonatypeRepository
17+
# - os: macos-latest
18+
# gradle_args: assemble publishIosSimulatorArm64PublicationToSonatypeRepository
19+
# - os: macos-latest
20+
# gradle_args: assemble publishTvosX64PublicationToSonatypeRepository
21+
# - os: macos-latest
22+
# gradle_args: assemble publishTvosArm64PublicationToSonatypeRepository
23+
# - os: macos-latest
24+
# gradle_args: assemble publishTvosSimulatorArm64PublicationToSonatypeRepository
25+
# - os: macos-latest
26+
# gradle_args: assemble publishWatchosArm32PublicationToSonatypeRepository
27+
# - os: macos-latest
28+
# gradle_args: assemble publishWatchosArm64PublicationToSonatypeRepository
29+
# - os: macos-latest
30+
# gradle_args: assemble publishWatchosX64PublicationToSonatypeRepository
31+
# - os: macos-latest
32+
# gradle_args: assemble publishWatchosSimulatorArm64PublicationToSonatypeRepository
33+
# - os: macos-latest
34+
# gradle_args: assemble publishMacosX64PublicationToSonatypeRepository
35+
# - os: macos-latest
36+
# gradle_args: assemble publishMacosArm64PublicationToSonatypeRepository
37+
# - os: ubuntu-latest
38+
# gradle_args: assemble publishKotlinMultiplatformPublicationToSonatypeRepository publishJvmPublicationToSonatypeRepository publishLinuxX64PublicationToSonatypeRepository publishLinuxArm64PublicationToSonatypeRepository publishMingwX64PublicationToSonatypeRepository
39+
#
40+
# runs-on: ${{ matrix.os }}
41+
# steps:
42+
# - name: Checkout project sources
43+
# uses: actions/checkout@v3
44+
# - uses: actions/setup-java@v3
45+
# with:
46+
# distribution: liberica
47+
# java-version: 8
48+
# - name: Build using gradle
49+
# uses: gradle/gradle-build-action@v2
50+
# with:
51+
# arguments: ${{ matrix.gradle_args }}
52+
# env:
53+
# SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }}
54+
# SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
55+
# OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
56+
# OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
57+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ local.properties
2828

2929
# Ignore Gradle build output directory
3030
build
31+
32+
.jreleaser/config.toml

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010

1111
### Core components
1212

13-
* `org.ton:ton-kotlin-tvm:0.3.1` - TVM Primitives (Cells, BOC, etc.)
14-
* `org.ton:ton-kotlin-crypto:0.3.1` - Crypto primitives for TON (ED25519, SHA, etc.)
15-
* `org.ton:ton-kotlin-adnl:0.3.1` - ADNL (Abstract Datagram Network Layer) TON Network implementation
13+
* `org.ton.kotlin:ton-kotlin-tvm:0.4.0` - TVM Primitives (Cells, BOC, etc.)
14+
* `org.ton.kotlin:ton-kotlin-crypto:0.4.0` - Crypto primitives for TON (ED25519, SHA, etc.)
15+
* `org.ton.kotlin:ton-kotlin-adnl:0.4.0` - ADNL (Abstract Datagram Network Layer) TON Network implementation
1616

1717
### API Interfaces
1818

19-
* `org.ton:ton-kotlin-contract:0.3.1` - Smart-contracts API interface
20-
* `org.ton:ton-kotlin-liteclient:0.3.1` - Lite-client API implementation
19+
* `org.ton.kotlin:ton-kotlin-contract:0.4.0` - Smart-contracts API interface
20+
* `org.ton.kotlin:ton-kotlin-liteclient:0.4.0` - Lite-client API implementation
2121

2222
### TL-B (TL-Binary)
2323

24-
* `org.ton:ton-kotlin-tlb:0.3.1` - TON TL-B (TL-Binary) serialization/deserialization
25-
* `org.ton:ton-kotlin-block-tlb:0.3.1` - Pre-generated TL-B schemas for TON Blockchain
26-
* `org.ton:ton-kotlin-hashmap-tlb:0.3.1` - Pre-generated TL-B schemas for TON Hashmap (also known as Dictionary)
24+
* `org.ton.kotlin:ton-kotlin-tlb:0.4.0` - TON TL-B (TL-Binary) serialization/deserialization
25+
* `org.ton.kotlin:ton-kotlin-block-tlb:0.4.0` - Pre-generated TL-B schemas for TON Blockchain
26+
* `org.ton.kotlin:ton-kotlin-hashmap-tlb:0.4.0` - Pre-generated TL-B schemas for TON Hashmap (also known as Dictionary)
2727

2828
## Documentation
2929

3030
https://github.com/andreypfau/ton-kotlin/wiki/TON-Kotlin-documentation
3131

3232
<!-- Badges -->
3333

34-
[maven-central]: https://central.sonatype.com/artifact/org.ton/ton-kotlin-tvm/0.3.1
34+
[maven-central]: https://central.sonatype.com/artifact/org.ton/ton-kotlin-tvm/0.4.0
3535

3636
[license]: LICENSE
3737

bitstring/src/BitString.kt

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public inline fun BitString(size: Int): BitString = BitString.of(size)
1414
public inline fun BitString(vararg bits: Boolean): BitString = BitString.of(*bits)
1515
public inline fun BitString(bits: Iterable<Boolean>): BitString = BitString.of(bits)
1616
public inline fun BitString(bits: Collection<Boolean>): BitString = BitString.of(bits)
17-
public inline fun BitString(hex: String): BitString = BitString.of(hex)
17+
public inline fun BitString(hex: String): BitString = BitString.parse(hex)
1818

1919
public inline fun Iterable<Boolean>.toBitString(): BitString = BitString(this)
2020
public inline fun BooleanArray.toBitString(): BitString = BitString(*this)
@@ -27,13 +27,14 @@ public interface BitString : Iterable<Boolean>, Comparable<BitString> {
2727
public operator fun get(index: Int): Boolean
2828
public fun getOrNull(index: Int): Boolean?
2929

30+
public fun countLeadingBits(fromIndex: Int = 0, toIndex: Int = size, bit: Boolean): Int
31+
3032
public operator fun plus(bit: Boolean): BitString =
3133
plus(booleanArrayOf(bit))
3234

3335
public operator fun plus(bits: BooleanArray): BitString =
3436
plus(bits.asIterable())
3537

36-
3738
public operator fun plus(bits: Collection<Boolean>): BitString =
3839
plus(bits.asIterable())
3940

@@ -61,8 +62,17 @@ public interface BitString : Iterable<Boolean>, Comparable<BitString> {
6162
public fun commonSuffixWith(other: BitString): BitString =
6263
binary(toBinary().commonSuffixWith(other.toBinary()))
6364

64-
public fun slice(indices: IntRange): BitString = slice(indices.first, indices.last)
65+
@Deprecated("use substring(indices) instead", ReplaceWith("substring(indices)"))
66+
public fun slice(indices: IntRange): BitString = substring(indices.first, indices.last)
67+
68+
@Deprecated("use substring(startIndex, endIndex) instead", ReplaceWith("substring(startIndex, endIndex)"))
6569
public fun slice(startIndex: Int, endIndex: Int = size): BitString =
70+
substring(startIndex, endIndex)
71+
72+
public fun substring(range: IntRange): BitString =
73+
substring(range.first, range.last)
74+
75+
public fun substring(startIndex: Int, endIndex: Int = size): BitString =
6676
binary(toBinary().substring(startIndex, endIndex))
6777

6878
public infix fun xor(other: BitString): BitString
@@ -81,6 +91,18 @@ public interface BitString : Iterable<Boolean>, Comparable<BitString> {
8191

8292
public fun toHexString(): String
8393

94+
public fun copyInto(
95+
destination: MutableBitString,
96+
destinationOffset: Int = 0,
97+
startIndex: Int = 0,
98+
endIndex: Int = size
99+
) {
100+
val length = endIndex - startIndex
101+
for (i in 0 until length) {
102+
destination[destinationOffset + i] = this[startIndex + i]
103+
}
104+
}
105+
84106
public companion object {
85107
@JvmStatic
86108
public fun empty(): BitString = EmptyBitString
@@ -132,12 +154,16 @@ public interface BitString : Iterable<Boolean>, Comparable<BitString> {
132154
}
133155

134156
@JvmStatic
135-
public fun of(hex: String): BitString {
136-
if (hex.isEmpty()) return empty()
157+
@Deprecated("use parse(hex) instead", replaceWith = ReplaceWith("parse(hex)"))
158+
public fun of(hex: String): BitString = parse(hex)
159+
160+
@JvmStatic
161+
public fun parse(source: CharSequence): BitString {
162+
if (source.isEmpty()) return empty()
137163
// True if bit string doesn't contain mod 4 number of bits
138-
val incomplete = hex.isNotEmpty() && hex.last() == '_'
164+
val incomplete = source.isNotEmpty() && source.last() == '_'
139165

140-
val bits = hex.asSequence()
166+
val bits = source.asSequence()
141167
.takeWhile { it != '_' } // consume entire hexadecimal string, except for `_`
142168
.map { char ->
143169
char.digitToInt(16)

bitstring/src/ByteBackedBitString.kt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public open class ByteBackedBitString protected constructor(
2222
override fun getOrNull(index: Int): Boolean? =
2323
if (index in 0..size) get(bytes, index) else null
2424

25+
override fun countLeadingBits(fromIndex: Int, toIndex: Int, bit: Boolean): Int {
26+
return countLeadingBits(bytes, fromIndex, toIndex - fromIndex, bit)
27+
}
28+
2529
override fun plus(bits: BitString): BitString = toMutableBitString().plus(bits)
2630
override fun plus(bytes: ByteArray): BitString = toMutableBitString().plus(bytes)
2731
override fun plus(bytes: ByteArray, bits: Int): BitString = toMutableBitString().plus(bytes, bits)
@@ -84,6 +88,13 @@ public open class ByteBackedBitString protected constructor(
8488
}
8589
}
8690

91+
override fun copyInto(destination: MutableBitString, destinationOffset: Int, startIndex: Int, endIndex: Int) {
92+
if (destination !is ByteBackedBitString) {
93+
return super.copyInto(destination, destinationOffset, startIndex, endIndex)
94+
}
95+
bitsCopy(destination.bytes, destinationOffset, bytes, startIndex, endIndex - startIndex)
96+
}
97+
8798
override fun toString(): String = "x{${toHexString()}}"
8899

89100
override fun toHexString(): String {
@@ -218,3 +229,117 @@ private fun appendAugmentTag(data: ByteArray, bits: Int): ByteArray {
218229
return newData
219230
}
220231
}
232+
233+
internal fun bitsCopy(dest: ByteArray, toIndex: Int, src: ByteArray, fromIndex: Int, bitCount: Int) {
234+
if (bitCount <= 0) return
235+
236+
var srcOffset = fromIndex shr 3
237+
var destOffset = toIndex shr 3
238+
val fromOffset = fromIndex and 7
239+
val toOffset = toIndex and 7
240+
241+
var remainingBits = bitCount
242+
val bitCountTotal = bitCount + fromOffset
243+
244+
if (fromOffset == toOffset) {
245+
if (bitCountTotal < 8) {
246+
val mask = ((-0x100 ushr bitCountTotal) and (0xff ushr toOffset))
247+
dest[destOffset] = ((dest[destOffset].toInt() and mask.inv()) or (src[srcOffset].toInt() and mask)).toByte()
248+
return
249+
}
250+
251+
val bytesToCopy = bitCountTotal shr 3
252+
if (toOffset == 0) {
253+
src.copyInto(dest, destOffset, srcOffset, srcOffset + bytesToCopy)
254+
} else {
255+
val mask = (0xff ushr toOffset)
256+
dest[destOffset] = ((dest[destOffset].toInt() and mask.inv()) or (src[srcOffset].toInt() and mask)).toByte()
257+
src.copyInto(dest, destOffset + 1, srcOffset + 1, srcOffset + bytesToCopy)
258+
}
259+
260+
if (bitCountTotal and 7 != 0) {
261+
val mask = (-0x100 ushr (bitCountTotal and 7))
262+
dest[destOffset + bytesToCopy] =
263+
((dest[destOffset + bytesToCopy].toInt() and mask.inv()) or (src[srcOffset + bytesToCopy].toInt() and mask)).toByte()
264+
}
265+
} else {
266+
var bitsInAcc = toOffset
267+
var accumulator = if (bitsInAcc != 0) dest[destOffset].toLong() ushr (8 - bitsInAcc) else 0L
268+
269+
if (bitCountTotal < 8) {
270+
accumulator = accumulator shl remainingBits
271+
accumulator =
272+
accumulator or ((src[srcOffset].toLong() and (0xffL ushr fromOffset)) ushr (8 - bitCountTotal))
273+
bitsInAcc += remainingBits
274+
} else {
275+
val leadingBits = 8 - fromOffset
276+
accumulator = (accumulator shl leadingBits)
277+
accumulator = accumulator or (src[srcOffset++].toLong() and (0xffL ushr fromOffset))
278+
bitsInAcc += leadingBits
279+
remainingBits -= leadingBits
280+
281+
while (remainingBits >= 8) {
282+
accumulator = accumulator shl 8
283+
accumulator = accumulator or (src[srcOffset++].toLong() and 0xffL)
284+
dest[destOffset++] = (accumulator ushr bitsInAcc).toByte()
285+
remainingBits -= 8
286+
}
287+
288+
if (remainingBits > 0) {
289+
accumulator =
290+
(accumulator shl remainingBits) or ((src[srcOffset].toLong() and 0xff) ushr (8 - remainingBits))
291+
bitsInAcc += remainingBits
292+
}
293+
}
294+
295+
while (bitsInAcc >= 8) {
296+
bitsInAcc -= 8
297+
dest[destOffset++] = (accumulator ushr bitsInAcc).toByte()
298+
}
299+
300+
if (bitsInAcc > 0) {
301+
dest[destOffset] =
302+
((dest[destOffset].toInt() and (0xff ushr bitsInAcc)) or (accumulator.toInt() shl (8 - bitsInAcc))).toByte()
303+
}
304+
}
305+
}
306+
307+
internal fun countLeadingBits(
308+
array: ByteArray,
309+
offset: Int,
310+
bitCount: Int,
311+
bit: Boolean
312+
): Int {
313+
if (bitCount == 0) return 0
314+
315+
val xorVal = if (bit) -1 else 0
316+
var index = offset ushr 3
317+
val bitOffset = offset and 7
318+
var reminder = bitCount
319+
320+
if (bitOffset != 0) {
321+
val v = ((array[index++].toInt() and 0xFF) xor xorVal) shl (24 + bitOffset)
322+
val c = v.countLeadingZeroBits()
323+
val remainingBits = 8 - bitOffset
324+
if (c < remainingBits || bitCount <= remainingBits) {
325+
return min(c, bitCount)
326+
}
327+
reminder -= remainingBits
328+
}
329+
330+
while (reminder >= 8) {
331+
val v = ((array[index++].toInt() xor xorVal) and 0xFF) shl 24
332+
if (v != 0) {
333+
return bitCount - reminder + v.countLeadingZeroBits()
334+
}
335+
reminder -= 8
336+
}
337+
338+
if (reminder > 0) {
339+
val v = (((array[index].toInt() xor xorVal) and 0xFF) shl 24).countLeadingZeroBits()
340+
if (v < reminder) {
341+
return bitCount - reminder + v
342+
}
343+
}
344+
return bitCount
345+
}

bitstring/src/ByteBackedMutableBitString.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public open class ByteBackedMutableBitString(
99
override var bytes: ByteArray,
1010
override var size: Int
1111
) : ByteBackedBitString(size, bytes), MutableBitString {
12+
public constructor(size: Int) : this(ByteArray((size + 7) ushr 3), size)
13+
1214
override operator fun set(index: Int, bit: Int) {
1315
set(index, bit != 0)
1416
}

0 commit comments

Comments
 (0)