Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #49 from fioprotocol/feature/Multiple-transaction-…
Browse files Browse the repository at this point in the history
…error-fiosdk-kotlin-master-01152020

fix issue when multiple tx per block and calling getBlock.
  • Loading branch information
ericbutz authored Jan 25, 2021
2 parents ff5c4c9 + c950f38 commit 098fc72
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DevSdkTests
{
this.setupTestVariables()


println("testGenericActions: SUF Conversion Test")
Log.i(this.logTag,"testGenericActions: SUF Conversion Test")

Expand Down Expand Up @@ -482,6 +483,34 @@ class DevSdkTests
throw AssertionError("Get Account Call Failed for Alice: " + generalException.message)
}

/*
This test was used to verify the getblock was working properly when
multiple tx are in a block. To test this we performed one off testing
on test net, and visually verified the results, This test was run in isolation.
all other tests were disabled (commented out)
This test is left here in case it is useful for any other purposes later.
println("testGenericActions: Test getBlock")
Log.i(this.logTag,"testGenericActions: Test getBlock")
try
{
//this block is on test net and has multiple tx inside it.
val response = this.aliceFioSdk!!.getBlock("45844121")
// this gets a normal block. val response = this.aliceFioSdk!!.getBlock("2500")
print ("get block response " + response.toJson())
}
catch (e: FIOError)
{
throw AssertionError("Get Block Call Failed for Alice: " + e.toJson())
}
catch (generalException: Exception)
{
throw AssertionError("Get Block Call Failed for Alice: " + generalException.message)
}
*/

println("testGenericActions: End Test for Generic Actions")
Log.i(this.logTag,"testGenericActions: End Test for Generic Actions")
}
Expand Down Expand Up @@ -1106,6 +1135,7 @@ class DevSdkTests
}



}

private fun registerFioNameForUser(fioSdk:FIOSDK, fioAddress:String) {
Expand Down
32 changes: 32 additions & 0 deletions fiosdk/src/main/java/fiofoundation/io/fiosdk/FIOSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,38 @@ class FIOSDK(private var privateKey: String, var publicKey: String,var technolog
}
}


/**
* Get the block info for the specified block.
*
* @param blocknumorid block number, or id of specific block.
* @return [GetBlockResponse]
*
* @throws [FIOError]
*/
@Throws(FIOError::class)
fun getBlock(blocknumorid:String): GetBlockResponse
{
try
{
if(blocknumorid =="")
throw FIOError("Invalid Block info")

val request:GetBlockRequest =
GetBlockRequest(blocknumorid)

return this.networkProvider.getBlock(request)
}
catch(getFeeError: GetFeeError)
{
throw FIOError(getFeeError.message!!,getFeeError)
}
catch(e:Exception)
{
throw FIOError(e.message!!,e)
}
}

/**
* Compute and return fee amount for New Funds Request
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,30 @@ open class Transaction(
@SerializedName("delay_sec") var delaySec: BigInteger?,
@SerializedName("context_free_actions") var contextFreeActions: ArrayList<IAction>?,
@SerializedName("actions") var actions: ArrayList<IAction>,
@SerializedName("transaction_extensions") var transactionExtensions: ArrayList<String>?):Serializable
@SerializedName("transaction_extensions") var transactionExtensions: ArrayList<String>?):Serializable


class TransactionResp(
@SerializedName("expiration") var expiration: String,
@SerializedName("ref_block_num") var refBlockNum: BigInteger?,
@SerializedName("ref_block_prefix") var refBlockPrefix: BigInteger?,
@SerializedName("max_net_usage_words") var maxNetUsageWords: BigInteger?,
@SerializedName("max_cpu_usage_ms") var maxCpuUsageMs: BigInteger?,
@SerializedName("delay_sec") var delaySec: BigInteger?,
@Transient var contextFreeActions: ArrayList<IAction>?,
@Transient var actions: ArrayList<IAction>,
@SerializedName("transaction_extensions") var transactionExtensions: ArrayList<String>?):Serializable

public class TxItem( @SerializedName("status") var status: String,
@SerializedName("cpu_usage_us") var cpuUsageUs: BigInteger?,
@SerializedName("net_usage_words") var netUsageWords: BigInteger?,
@SerializedName("trx") var trx: Trx?):Serializable

public class Trx (@SerializedName("id") var id: String,
@SerializedName("signatures") var signatures: ArrayList<String>?,
@SerializedName("compression") var compression: String,
@SerializedName("packed_context_free_data") var packedContextFreeData: String,
@SerializedName("context_free_data") var contextFreeData: ArrayList<IAction>?,
@SerializedName("packed_trx") var packedTrx: String,
@SerializedName("transaction") var transaction: TransactionResp):Serializable

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package fiofoundation.io.fiosdk.models.fionetworkprovider.response

import com.google.gson.annotations.SerializedName
import fiofoundation.io.fiosdk.models.fionetworkprovider.TxItem
import java.math.BigInteger


class GetBlockResponse: FIOResponse(){

val id: String? = null
val producer: String? = null
val confirmed: BigInteger? = null
val previous: String? = null
val transactions: List<String>? = null
val transactions: List<TxItem>? = null
val timestamp: String? = null

@SerializedName("action_mroot")
Expand Down

0 comments on commit 098fc72

Please sign in to comment.