Skip to content

Commit

Permalink
error init
Browse files Browse the repository at this point in the history
  • Loading branch information
Seonghun committed Aug 31, 2023
1 parent 9ab1601 commit 520d73d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 21 deletions.
4 changes: 0 additions & 4 deletions app/src/main/java/io/kthulu/sdk/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// Setting the context
MyContext.setAppContext(this)

launch {
withContext(Dispatchers.IO) {

}
}
}
Expand Down
24 changes: 16 additions & 8 deletions app/src/main/java/io/kthulu/sdk/account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ suspend fun createAccountsAsync(
// save data arrya
var saveMainNet = JSONArray()
var jsonData = JSONObject()
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -79,6 +79,7 @@ suspend fun createAccountsAsync(
resultData

} catch(e: Exception){
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand Down Expand Up @@ -123,7 +124,7 @@ suspend fun restoreAccountAsync(
var saveMainNet = JSONArray()
var jsonData = JSONObject()
// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -190,6 +191,7 @@ suspend fun restoreAccountAsync(

resultData
} catch(e: Exception){
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -199,7 +201,7 @@ suspend fun restoreAccountAsync(
}

suspend fun getAccountInfoAsync(account: String): JSONObject = withContext(Dispatchers.IO) {
val resultArray = JSONArray()
var resultArray = JSONArray()
var jsonData = JSONObject()
val resultData = JSONObject().apply {
put("result", "FAIL")
Expand Down Expand Up @@ -234,6 +236,7 @@ suspend fun getAccountInfoAsync(account: String): JSONObject = withContext(Dispa
put("value", resultArray)
}
} catch(e: Exception){
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -252,7 +255,7 @@ suspend fun getBalanceAsync(
networkSettings(network)
val jsonData = JSONObject()
// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
val resultData = JSONObject().apply {
put("result", "FAIL")
put("value", resultArray)
Expand Down Expand Up @@ -293,6 +296,7 @@ suspend fun getBalanceAsync(
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -307,7 +311,7 @@ suspend fun getTokenInfoAsync(
networkSettings(network)
val jsonData = JSONObject()
// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
val resultData = JSONObject().apply {
put("result", "FAIL")
put("value", resultArray)
Expand Down Expand Up @@ -387,6 +391,7 @@ suspend fun getTokenInfoAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -402,7 +407,7 @@ suspend fun getTokenHistoryAsync(
limit: Int? = 1000,
page_number: Int? = 1
) : JSONObject = withContext(Dispatchers.IO) {
val resultArray = JSONArray()
var resultArray = JSONArray()
var jsonData = JSONObject()
val resultData = JSONObject().apply {
put("result", "FAIL")
Expand Down Expand Up @@ -474,6 +479,7 @@ suspend fun getTokenHistoryAsync(
dbConnector.disconnect()
resultData
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -486,7 +492,7 @@ suspend fun getTokenHistoryAsync(
suspend fun getUsersAsync(
owner: String
) : JSONObject = withContext(Dispatchers.IO) {
val resultArray = JSONArray()
var resultArray = JSONArray()
var jsonData = JSONObject()
val resultData = JSONObject().apply {
put("result", "FAIL")
Expand Down Expand Up @@ -528,6 +534,7 @@ suspend fun getUsersAsync(
dbConnector.disconnect()
resultData
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -541,7 +548,7 @@ suspend fun getTokenListAsync(
sort: String? = "DESC",
limit: Int? = 1000,
page_number: Int? = 1): JSONObject = withContext(Dispatchers.IO) {
val resultArray = JSONArray()
var resultArray = JSONArray()
var jsonData = JSONObject()
val resultData = JSONObject().apply {
put("result", "FAIL")
Expand Down Expand Up @@ -613,6 +620,7 @@ suspend fun getTokenListAsync(
dbConnector.disconnect()
resultData
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand Down
40 changes: 31 additions & 9 deletions app/src/main/java/io/kthulu/sdk/transaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ suspend fun sendTransactionAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -185,12 +185,14 @@ suspend fun sendTransactionAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -210,7 +212,7 @@ suspend fun sendTokenTransactionAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -370,12 +372,14 @@ suspend fun sendTokenTransactionAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -394,7 +398,7 @@ suspend fun deployErc20Async(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()

resultData.put("result", "FAIL")
Expand Down Expand Up @@ -512,6 +516,7 @@ suspend fun deployErc20Async(
.getString("gas")

} catch (e: Exception){
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand Down Expand Up @@ -552,12 +557,14 @@ suspend fun deployErc20Async(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -576,7 +583,7 @@ suspend fun bridgeCoinAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()

resultData.put("result", "FAIL")
Expand Down Expand Up @@ -714,12 +721,14 @@ suspend fun bridgeCoinAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -738,7 +747,7 @@ suspend fun bridgeTokenAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()

resultData.put("result", "FAIL")
Expand Down Expand Up @@ -952,12 +961,14 @@ suspend fun bridgeTokenAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -976,7 +987,7 @@ suspend fun tokenSwapAppoveAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -1094,19 +1105,22 @@ suspend fun tokenSwapAppoveAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}

} else {
resultArray = JSONArray()
jsonData.put("error", "pair not found")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -1126,7 +1140,7 @@ suspend fun coinForTokenswapAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -1247,13 +1261,15 @@ suspend fun coinForTokenswapAsync(
}

} else {
resultArray = JSONArray()
jsonData.put("error", "pair not found")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
return@withContext resultData
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -1274,7 +1290,7 @@ suspend fun tokenForTokenswapAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -1404,19 +1420,22 @@ suspend fun tokenForTokenswapAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}

} else {
resultArray = JSONArray()
jsonData.put("error", "pair not found")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand All @@ -1436,7 +1455,7 @@ suspend fun tokenForCoinswapAsync(
val jsonData = JSONObject()

// return array & object
val resultArray = JSONArray()
var resultArray = JSONArray()
var resultData = JSONObject()
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
Expand Down Expand Up @@ -1574,19 +1593,22 @@ suspend fun tokenForCoinswapAsync(
resultData.put("result", "OK")
resultData.put("value", resultArray)
} else {
resultArray = JSONArray()
jsonData.put("error", "insufficient funds")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}

} else {
resultArray = JSONArray()
jsonData.put("error", "pair not found")
resultArray.put(jsonData)
resultData.put("result", "FAIL")
resultData.put("value", resultArray)
}
} catch (e: Exception) {
resultArray = JSONArray()
jsonData.put("error", e.message)
resultArray.put(jsonData)
resultData.put("result", "FAIL")
Expand Down

0 comments on commit 520d73d

Please sign in to comment.