Skip to content

Commit dc22838

Browse files
authored
Merge pull request #729 from soramitsu/staging
staging
2 parents c19725f + 17ebed8 commit dc22838

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
buildscript {
22
ext {
33
// App version
4-
versionName = '2.0.12'
5-
versionCode = 73
4+
versionName = '2.0.13'
5+
versionCode = 74
66

77
// SDK and tools
88
compileSdkVersion = 31

common/src/main/java/jp/co/soramitsu/common/data/network/runtime/calls/FeeCalculationRequest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package jp.co.soramitsu.common.data.network.runtime.calls
33
import jp.co.soramitsu.fearless_utils.wsrpc.request.runtime.RuntimeRequest
44

55
class FeeCalculationRequest(extrinsicInHex: String) : RuntimeRequest(
6-
method = "payment_queryInfo",
6+
method = "payment_queryFeeDetails",
77
params = listOf(extrinsicInHex)
88
)

common/src/main/java/jp/co/soramitsu/common/data/network/runtime/model/FeeResponse.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package jp.co.soramitsu.common.data.network.runtime.model
22

33
import java.math.BigInteger
4+
import jp.co.soramitsu.fearless_utils.extensions.fromHex
5+
import jp.co.soramitsu.fearless_utils.extensions.fromUnsignedBytes
6+
import jp.co.soramitsu.fearless_utils.extensions.requireHexPrefix
47

58
// todo there were a field which caused an errors:
69
// val weight: Long
@@ -11,6 +14,33 @@ import java.math.BigInteger
1114
// "class":"normal",
1215
// "partialFee":"15407544760"
1316
// }
17+
1418
class FeeResponse(
15-
val partialFee: BigInteger
19+
val inclusionFee: InclusionFee
1620
)
21+
22+
class InclusionFee(
23+
private val baseFee: String?,
24+
private val lenFee: String?,
25+
private val adjustedWeightFee: String?,
26+
) {
27+
val sum: BigInteger
28+
get() = baseFee.decodeBigInt() + lenFee.decodeBigInt() + adjustedWeightFee.decodeBigInt()
29+
30+
private fun String?.decodeBigInt(): BigInteger {
31+
// because substrate returns hexes with different length:
32+
// 0x3b9aca00
33+
// 0x3486ced00
34+
// 0xb320334
35+
if (this == null) return BigInteger.ZERO
36+
return if (this.length.isEven.not()) {
37+
val withoutPrefix = removePrefix("0x")
38+
"0$withoutPrefix".requireHexPrefix()
39+
} else {
40+
this
41+
}.fromHex().fromUnsignedBytes()
42+
}
43+
44+
private val Int.isEven: Boolean
45+
get() = this % 2 == 0
46+
}

common/src/main/java/jp/co/soramitsu/common/utils/NumberFormatters.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package jp.co.soramitsu.common.utils
22

33
import android.content.Context
44
import android.text.format.DateUtils
5+
import android.util.Log
56
import java.math.BigDecimal
67
import java.math.RoundingMode
78
import java.text.DecimalFormat
@@ -83,7 +84,13 @@ fun Long.formatDaysSinceEpoch(context: Context): String? {
8384
val currentDays = System.currentTimeMillis().daysFromMillis()
8485
val diff = currentDays - this
8586

86-
if (diff < 0) throw IllegalArgumentException("Past date should be less than current")
87+
if (diff < 0) {
88+
Log.e(
89+
"jp.co.soramitsu.common.utils.NumberFormattersKt.formatDaysSinceEpoch",
90+
"Error: diff < 0: ",
91+
IllegalArgumentException("Past date should be less than current")
92+
)
93+
}
8794

8895
return when (diff) {
8996
0L -> context.getString(R.string.today)

runtime/src/main/java/jp/co/soramitsu/runtime/network/rpc/RpcCalls.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class RpcCalls(
110110

111111
val feeResponse = socketFor(chainId).executeAsync(request, mapper = pojo<FeeResponse>().nonNull())
112112

113-
return feeResponse.partialFee
113+
return feeResponse.inclusionFee.sum
114114
}
115115

116116
suspend fun submitExtrinsic(chainId: ChainId, extrinsic: String): String {

0 commit comments

Comments
 (0)