Skip to content

Commit

Permalink
fix base64
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Oct 19, 2024
1 parent 02cf2c1 commit 1f99225
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ data class RawMessageEntity(
json.optString("stateInit"),
json.optString("payload")
) {
if (payload.base64() != payloadValue) {
/*if (payload.base64() != payloadValue) {
throw IllegalStateException("Payload is not equal")
}
}*/
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.tonapps.blockchain.ton.extensions

import io.ktor.util.encodeBase64
import org.json.JSONObject
import org.ton.bitstring.BitString
import org.ton.boc.BagOfCells
import org.ton.cell.Cell
import org.ton.cell.CellSlice
import org.ton.crypto.hex
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

@OptIn(ExperimentalEncodingApi::class)
fun String.toBoc(): BagOfCells {
/*if (startsWith("{")) { // oh fuck....
return toBocFromJSBuffer()
}*/
return try {
/*val bytes = Base64.Default.Mime.decode(this)
return BagOfCells(bytes)*/
val fixedBoc = this.replace("-", "+")
.replace("_", "/")
BagOfCells(fixedBoc.base64())
Expand Down Expand Up @@ -50,8 +54,11 @@ fun Cell.toByteArray(): ByteArray {
return BagOfCells(this).toByteArray()
}

@OptIn(ExperimentalEncodingApi::class)
fun Cell.base64(): String {
return toByteArray().encodeBase64()
/*val bytes = toByteArray()
return Base64.Default.Mime.encode(bytes)*/
return org.ton.crypto.base64(toByteArray())
}

fun Cell.hex(): String {
Expand Down

0 comments on commit 1f99225

Please sign in to comment.