Skip to content

Commit

Permalink
blocks struct refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: andreypfau <[email protected]>
  • Loading branch information
andreypfau committed Feb 17, 2025
1 parent 29b1b1d commit 98f3d7d
Show file tree
Hide file tree
Showing 81 changed files with 2,084 additions and 1,528 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions bitstring/src/BitString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface BitString : Iterable<Boolean>, Comparable<BitString> {
public fun plus(bytes: ByteArray, bits: Int): BitString

public fun toByteArray(augment: Boolean = false): ByteArray
public fun toByteString(): ByteString = ByteString(*toByteArray())
public fun toBooleanArray(): BooleanArray
public fun toMutableBitString(): MutableBitString
public fun toBitString(): BitString = this
Expand Down
7 changes: 6 additions & 1 deletion bitstring/src/ByteBackedBitString.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ton.bitstring

import kotlinx.io.bytestring.ByteString
import org.ton.bitstring.exception.BitStringUnderflowException
import kotlin.experimental.and
import kotlin.experimental.or
Expand Down Expand Up @@ -48,12 +49,16 @@ public open class ByteBackedBitString protected constructor(
bytes.copyOf((size + 7) ushr 3)
}

override fun toByteString(): ByteString {
return ByteString(*toByteArray())
}

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

override fun toMutableBitString(): MutableBitString =
ByteBackedMutableBitString.of(bytes.copyOf((size + 7) ushr 3), size)

override fun toBitString(): BitString = ByteBackedBitString(size, bytes.copyOf((size + 7) ushr 3))
override fun toBitString(): ByteBackedBitString = ByteBackedBitString(size, bytes.copyOf((size + 7) ushr 3))

override fun iterator(): Iterator<Boolean> = BitStringIterator(this)

Expand Down
2 changes: 2 additions & 0 deletions bitstring/src/EmptyBitString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ internal object EmptyBitString : BitString {

override fun toHexString(): String = ""

override fun isEmpty(): Boolean = true

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null) return false
Expand Down
31 changes: 11 additions & 20 deletions block-tlb/src/AccountActive.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package org.ton.block
import kotlinx.serialization.SerialName
import org.ton.cell.CellBuilder
import org.ton.cell.CellSlice
import org.ton.cell.invoke
import org.ton.kotlin.account.StateInit
import org.ton.kotlin.cell.CellContext
import org.ton.tlb.TlbConstructor
import org.ton.tlb.TlbPrettyPrinter
import org.ton.tlb.loadTlb
import org.ton.tlb.providers.TlbConstructorProvider
import org.ton.tlb.storeTlb
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmName

Expand All @@ -21,31 +19,24 @@ public value class AccountActive(
) : AccountState {
override val status: AccountStatus get() = AccountStatus.ACTIVE

override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter {
return printer.type("account_active") {
value.print(printer)
}
}

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

public companion object : TlbConstructorProvider<AccountActive> by AccountActiveTlbConstructor
}

private object AccountActiveTlbConstructor : TlbConstructor<AccountActive>(
schema = "account_active\$1 _:StateInit = AccountState;"
) {
override fun storeTlb(
cellBuilder: CellBuilder,
value: AccountActive
) = cellBuilder {
storeTlb(StateInit, value.value)
builder: CellBuilder,
value: AccountActive,
context: CellContext
) {
StateInit.storeTlb(builder, value.value, context)
}

override fun loadTlb(
cellSlice: CellSlice
): AccountActive = cellSlice {
val init = loadTlb(StateInit)
AccountActive(init)
slice: CellSlice, context: CellContext
): AccountActive {
val init = StateInit.loadTlb(slice, context)
return AccountActive(init)
}
}
67 changes: 0 additions & 67 deletions block-tlb/src/AccountBlock.kt

This file was deleted.

7 changes: 0 additions & 7 deletions block-tlb/src/AccountFrozen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.ton.cell.CellBuilder
import org.ton.cell.CellSlice
import org.ton.cell.invoke
import org.ton.tlb.TlbConstructor
import org.ton.tlb.TlbPrettyPrinter
import org.ton.tlb.providers.TlbConstructorProvider
import kotlin.jvm.JvmName

Expand All @@ -23,12 +22,6 @@ public data class AccountFrozen(

override val status: AccountStatus get() = AccountStatus.FROZEN

override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter = printer.type("account_frozen") {
printer.field("state_hash", stateHash)
}

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

public companion object : TlbConstructorProvider<AccountFrozen> by AccountFrozenTlbConstructor
}

Expand Down
3 changes: 1 addition & 2 deletions block-tlb/src/AccountState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ package org.ton.block

import kotlinx.serialization.json.JsonClassDiscriminator
import org.ton.tlb.TlbCombinator
import org.ton.tlb.TlbObject
import org.ton.tlb.providers.TlbCombinatorProvider


@JsonClassDiscriminator("@type")
public sealed interface AccountState : TlbObject {
public sealed interface AccountState {
/**
* Account status.
*/
Expand Down
7 changes: 0 additions & 7 deletions block-tlb/src/AccountUninit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ import kotlinx.serialization.SerialName
import org.ton.cell.CellBuilder
import org.ton.cell.CellSlice
import org.ton.tlb.TlbConstructor
import org.ton.tlb.TlbPrettyPrinter
import org.ton.tlb.providers.TlbConstructorProvider


@SerialName("account_uninit")
public object AccountUninit : AccountState, TlbConstructorProvider<AccountUninit> by AccountUninitTlbConstructor {
override val status: AccountStatus get() = AccountStatus.UNINIT

override fun print(printer: TlbPrettyPrinter): TlbPrettyPrinter {
return printer.type("account_uninit")
}

override fun toString(): String = print().toString()
}

private object AccountUninitTlbConstructor : TlbConstructor<AccountUninit>(
Expand Down
63 changes: 0 additions & 63 deletions block-tlb/src/AddrExtern.kt

This file was deleted.

16 changes: 2 additions & 14 deletions block-tlb/src/AddrNone.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package org.ton.block

import kotlinx.serialization.SerialName
import org.ton.cell.CellBuilder
import org.ton.cell.CellSlice
import org.ton.kotlin.cell.CellSize
import org.ton.tlb.TlbConstructor
import org.ton.tlb.TlbPrettyPrinter
import org.ton.tlb.providers.TlbConstructorProvider

@SerialName("addr_none")

public object AddrNone : MsgAddressExt, TlbConstructorProvider<AddrNone> by AddrNoneTlbConstructor {
override val cellSize: CellSize = CellSize(2, 0)

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

override fun print(tlbPrettyPrinter: TlbPrettyPrinter): TlbPrettyPrinter = tlbPrettyPrinter {
type("addr_none")
}
}
@Deprecated("Use ExtAddr? instead", ReplaceWith("AddrInternal?"))
public object AddrNone : TlbConstructorProvider<AddrNone> by AddrNoneTlbConstructor

private object AddrNoneTlbConstructor : TlbConstructor<AddrNone>(
schema = "addr_none\$00 = MsgAddressExt;"
Expand Down
Loading

0 comments on commit 98f3d7d

Please sign in to comment.