Skip to content

Commit 5ac84c0

Browse files
committed
0.4.1
1 parent 550c89b commit 5ac84c0

File tree

82 files changed

+1441
-1358
lines changed

Some content is hidden

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

82 files changed

+1441
-1358
lines changed

bitstring/src/ByteBackedBitString.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public open class ByteBackedBitString protected constructor(
4545
if (augment && (size % 8 != 0)) {
4646
appendAugmentTag(bytes, size)
4747
} else {
48-
bytes.copyOf()
48+
bytes.copyOf((size + 7) ushr 3)
4949
}
5050

5151
override fun toBooleanArray(): BooleanArray = toList().toBooleanArray()

block-tlb/src/Account.kt

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,86 @@
1-
@file:Suppress("OPT_IN_USAGE")
2-
31
package org.ton.block
42

5-
import kotlinx.serialization.json.JsonClassDiscriminator
6-
import org.ton.tlb.TlbCombinator
7-
import org.ton.tlb.TlbObject
8-
import org.ton.tlb.providers.TlbCombinatorProvider
3+
import org.ton.cell.CellBuilder
4+
import org.ton.cell.CellSlice
5+
import org.ton.cell.invoke
6+
import org.ton.tlb.*
7+
import org.ton.tlb.TlbConstructor
8+
9+
/**
10+
* Existing account data.
11+
*/
12+
public data class Account(
13+
/**
14+
* Account address.
15+
*/
16+
val address: MsgAddressInt,
17+
18+
/**
19+
* Storage statistics.
20+
*/
21+
val storageStat: StorageInfo,
22+
23+
/**
24+
* Logical time after the last transaction execution.
25+
*/
26+
val lastTransLt: Long,
27+
28+
/**
29+
* Account balance for all currencies.
30+
*/
31+
val balance: CurrencyCollection,
32+
33+
/**
34+
* Account state.
35+
*/
36+
val state: AccountState
37+
) {
38+
public companion object : TlbCodec<Account?> by AccountInfoTlbConstructor.asNullable()
939

10-
@JsonClassDiscriminator("@type")
40+
@Deprecated("Use fields lastTransLt, balance, state instead")
41+
val storage: AccountStorage // storage : AccountStorage
42+
get() = AccountStorage(lastTransLt.toULong(), balance, state)
1143

12-
public sealed interface Account : TlbObject {
13-
public companion object : TlbCombinatorProvider<Account> by AccountTlbCombinator
44+
@Deprecated("Use address instead", ReplaceWith("address"))
45+
val addr: MsgAddressInt
46+
get() = address
47+
48+
val isActive: Boolean get() = storage.state is AccountActive
49+
val isFrozen: Boolean get() = storage.state is AccountFrozen
50+
val isUninit: Boolean get() = storage.state is AccountUninit
1451
}
1552

16-
private object AccountTlbCombinator : TlbCombinator<Account>(
17-
Account::class,
18-
AccountNone::class to AccountNone,
19-
AccountInfo::class to AccountInfo
20-
)
53+
public val Account?.balance: CurrencyCollection
54+
get() = this?.balance ?: CurrencyCollection.ZERO
55+
56+
public val Account?.accountLastTransLt: Long
57+
get() = this?.lastTransLt ?: 0
58+
59+
public val Account?.status: AccountStatus
60+
get() = this?.state?.status ?: AccountStatus.NONEXIST
61+
62+
private object AccountInfoTlbConstructor : TlbConstructor<Account>(
63+
schema = "account\$1 addr:MsgAddressInt storage_stat:StorageInfo storage:AccountStorage = Account;"
64+
) {
65+
override fun storeTlb(
66+
cellBuilder: CellBuilder,
67+
value: Account
68+
) = cellBuilder {
69+
storeTlb(MsgAddressInt, value.addr)
70+
storeTlb(StorageInfo, value.storageStat)
71+
storeULong(value.lastTransLt.toULong())
72+
storeTlb(CurrencyCollection, value.balance)
73+
storeTlb(AccountState, value.state)
74+
}
75+
76+
override fun loadTlb(
77+
cellSlice: CellSlice
78+
): Account = cellSlice {
79+
val addr = loadTlb(MsgAddressInt)
80+
val storageStat = loadTlb(StorageInfo)
81+
val lastTransLt = loadULong().toLong()
82+
val balance = loadTlb(CurrencyCollection)
83+
val state = loadTlb(AccountState)
84+
Account(addr, storageStat, lastTransLt, balance, state)
85+
}
86+
}

block-tlb/src/AccountActive.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public value class AccountActive(
1919
@get:JvmName("value")
2020
public val value: StateInit
2121
) : AccountState {
22+
override val status: AccountStatus get() = AccountStatus.ACTIVE
23+
2224
override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter {
2325
return printer.type("account_active") {
2426
value.print(printer)

block-tlb/src/AccountFrozen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public data class AccountFrozen(
2121
require(stateHash.size == 256) { "stateHash must be 256 bits long" }
2222
}
2323

24+
override val status: AccountStatus get() = AccountStatus.FROZEN
25+
2426
override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter = printer.type("account_frozen") {
2527
printer.field("state_hash", stateHash)
2628
}

block-tlb/src/AccountInfo.kt

Lines changed: 0 additions & 72 deletions
This file was deleted.

block-tlb/src/AccountNone.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.

block-tlb/src/AccountState.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import org.ton.tlb.providers.TlbCombinatorProvider
1010

1111
@JsonClassDiscriminator("@type")
1212
public sealed interface AccountState : TlbObject {
13+
/**
14+
* Account status.
15+
*/
16+
public val status: AccountStatus
17+
1318
public companion object : TlbCombinatorProvider<AccountState> by AccountStateTlbCombinator
1419
}
1520

block-tlb/src/AccountStorage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlin.jvm.JvmName
1111

1212
@SerialName("account_storage")
1313

14+
@Deprecated("Use fields from Account instead")
1415
public data class AccountStorage(
1516
@SerialName("last_trans_lt")
1617
@get:JvmName("lastTransLt")

block-tlb/src/AccountUninit.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import org.ton.tlb.providers.TlbConstructorProvider
1010

1111
@SerialName("account_uninit")
1212
public object AccountUninit : AccountState, TlbConstructorProvider<AccountUninit> by AccountUninitTlbConstructor {
13+
override val status: AccountStatus get() = AccountStatus.UNINIT
14+
1315
override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter {
1416
return printer.type("account_uninit")
1517
}

block-tlb/src/TrActionPhase.kt renamed to block-tlb/src/ActionPhase.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import org.ton.tlb.providers.TlbConstructorProvider
1616

1717
@SerialName("tr_phase_action")
1818

19-
public data class TrActionPhase(
19+
public data class ActionPhase(
2020
val success: Boolean,
2121
val valid: Boolean,
2222
@SerialName("no_funds") val noFunds: Boolean,
@@ -57,10 +57,10 @@ public data class TrActionPhase(
5757

5858
override fun toString(): String = print().toString()
5959

60-
public companion object : TlbConstructorProvider<TrActionPhase> by TrActionPhaseTlbConstructor
60+
public companion object : TlbConstructorProvider<ActionPhase> by TrActionPhaseTlbConstructor
6161
}
6262

63-
private object TrActionPhaseTlbConstructor : TlbConstructor<TrActionPhase>(
63+
private object TrActionPhaseTlbConstructor : TlbConstructor<ActionPhase>(
6464
schema = "tr_phase_action\$_ success:Bool valid:Bool no_funds:Bool " +
6565
"status_change:AccStatusChange " +
6666
"total_fwd_fees:(Maybe Coins) total_action_fees:(Maybe Coins) " +
@@ -74,7 +74,7 @@ private object TrActionPhaseTlbConstructor : TlbConstructor<TrActionPhase>(
7474

7575
override fun storeTlb(
7676
cellBuilder: CellBuilder,
77-
value: TrActionPhase
77+
value: ActionPhase
7878
) = cellBuilder {
7979
storeBit(value.success)
8080
storeBit(value.valid)
@@ -94,7 +94,7 @@ private object TrActionPhaseTlbConstructor : TlbConstructor<TrActionPhase>(
9494

9595
override fun loadTlb(
9696
cellSlice: CellSlice
97-
): TrActionPhase = cellSlice {
97+
): ActionPhase = cellSlice {
9898
val success = loadBit()
9999
val valid = loadBit()
100100
val noFunds = loadBit()
@@ -109,7 +109,7 @@ private object TrActionPhaseTlbConstructor : TlbConstructor<TrActionPhase>(
109109
val msgCreated = loadUInt(16).toInt()
110110
val actionListHash = loadBits(256)
111111
val totMsgSize = loadTlb(StorageUsedShort)
112-
TrActionPhase(
112+
ActionPhase(
113113
success,
114114
valid,
115115
noFunds,

0 commit comments

Comments
 (0)