Skip to content

Commit

Permalink
Merge pull request #9 from DECENTfoundation/feature/processd-trx-id
Browse files Browse the repository at this point in the history
add id val to processed trx from api
  • Loading branch information
vanderian authored Nov 26, 2018
2 parents 9cda919 + 1140468 commit 29f0ed4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package ch.decent.sdk.model

import ch.decent.sdk.crypto.Sha256Hash
import ch.decent.sdk.net.serialization.ByteSerializable
import ch.decent.sdk.net.serialization.bytes
import ch.decent.sdk.utils.hex
import com.google.common.primitives.Bytes
import com.google.gson.JsonArray
import com.google.gson.annotations.SerializedName
import org.threeten.bp.LocalDateTime
import org.threeten.bp.ZoneOffset

data class ProcessedTransaction(
@SerializedName("signatures") val signatures: List<String>,
Expand All @@ -12,4 +18,14 @@ data class ProcessedTransaction(
@SerializedName("ref_block_num") val refBlockNum: Int,
@SerializedName("ref_block_prefix") val refBlockPrefix: Long,
@SerializedName("operation_results") val opResults: List<JsonArray>
)
) : ByteSerializable {
override val bytes: ByteArray
get() = Bytes.concat(
BlockData(refBlockNum, refBlockPrefix, expiration.toEpochSecond(ZoneOffset.UTC)).bytes,
operations.bytes(),
byteArrayOf(0) //extensions
)

val id: String
get() = Sha256Hash.hash(bytes).take(20).toByteArray().hex()
}
1 change: 0 additions & 1 deletion library/src/test/java/ch/decent/sdk/api/OperationsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.junit.After
import org.junit.Before
import org.junit.Test
import org.slf4j.LoggerFactory
import java.lang.IllegalArgumentException
import java.math.BigInteger

class OperationsTest {
Expand Down
5 changes: 2 additions & 3 deletions library/src/test/java/ch/decent/sdk/api/TransactionApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ class TransactionApiTest(channel: Channel) : BaseApiTest(channel) {

}

// transaction_history_plugin not loaded ?
@Ignore
@Test fun `should get a transaction by ID`() {
val test = api.transactionApi.getTransaction("a9e89715f18f0bb0595b012720a10700000000000022230000000000020160e3160000000000000102c03f8e840c1699fd7808c2bb858e249c688c5be8acf0a0c1c484ab0cfb27f0a802e0ced80260630f641f61f6d6959f32b5c43b1a38be55666b98abfe8bafcc556b002ea2558d64350a204bc2a1ee670302ceddb897c2d351fa0496ff089c934e35e030f8ae4f3f9397a70000011f140e5744bcef282147ef3f0bab8df46f49704a99046d6ea5db37ab3113e0f45935fd94af7b33189ad34fa1666ab7e54aa127d725e2018fb6b68771aacef54c41")
val test = api.transactionApi.getTransaction("322d451fb1dc9b3ec6bc521395f4547a8b62eb3f")
.subscribeOn(Schedulers.newThread())
.test()

test.awaitTerminalEvent()
test.assertComplete()
.assertNoErrors()
.assertValue { it.id == "322d451fb1dc9b3ec6bc521395f4547a8b62eb3f"}

}

Expand Down

0 comments on commit 29f0ed4

Please sign in to comment.