Skip to content

Commit

Permalink
Merge pull request #77 from novasamatech/develop
Browse files Browse the repository at this point in the history
v.11.2
  • Loading branch information
valentunn authored Feb 16, 2024
2 parents 327044a + 1982c52 commit 4580580
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
// App version
versionName = '1.11.1'
versionName = '1.11.2'
versionCode = 1

// SDK and tools
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package jp.co.soramitsu.fearless_utils.runtime.extrinsic

enum class BatchMode {

/**
* Execute all calls until finding an uncessffull one
*/
BATCH,

/**
* Either execute all calls succeffuly or revert whole batch if at least one call was uncescessfull
*/
BATCH_ALL,

/**
* Execute all successfull calls even if there was some unsuccessfull ones in between them
*/
FORCE_BATCH
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class ExtrinsicBuilder(
}

suspend fun build(
useBatchAll: Boolean = false
batchMode: BatchMode = BatchMode.BATCH
): String {
val call = maybeWrapInBatch(useBatchAll)
val call = maybeWrapInBatch(batchMode)

return build(CallRepresentation.Instance(call))
}
Expand All @@ -115,9 +115,9 @@ class ExtrinsicBuilder(
}

suspend fun buildSignature(
useBatchAll: Boolean = false
batchMode: BatchMode = BatchMode.BATCH
): String {
val call = maybeWrapInBatch(useBatchAll)
val call = maybeWrapInBatch(batchMode)

return buildSignature(CallRepresentation.Instance(call))
}
Expand Down Expand Up @@ -164,11 +164,11 @@ class ExtrinsicBuilder(
return signatureType.toHexUntyped(runtime, multiSignature)
}

private fun maybeWrapInBatch(useBatchAll: Boolean): GenericCall.Instance {
private fun maybeWrapInBatch(batchMode: BatchMode): GenericCall.Instance {
return if (calls.size == 1) {
calls.first()
} else {
wrapInBatch(useBatchAll)
wrapInBatch(batchMode)
}
}

Expand Down Expand Up @@ -204,9 +204,14 @@ class ExtrinsicBuilder(
return default + custom
}

private fun wrapInBatch(useBatchAll: Boolean): GenericCall.Instance {
private fun wrapInBatch(batchMode: BatchMode): GenericCall.Instance {
val batchModule = runtime.metadata.module("Utility")
val batchFunctionName = if (useBatchAll) "batch_all" else "batch"

val batchFunctionName = when (batchMode) {
BatchMode.BATCH -> "batch"
BatchMode.BATCH_ALL -> "batch_all"
BatchMode.FORCE_BATCH -> "force_batch"
}
val batchFunction = batchModule.call(batchFunctionName)

return GenericCall.Instance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ExtrinsicBuilderTest {
)
}

val encoded = extrinsicBuilder.build(useBatchAll = true)
val encoded = extrinsicBuilder.build(batchMode = BatchMode.BATCH_ALL)
val decoded = Extrinsic.fromHex(runtime, encoded)

assertEquals(decoded.call.function.name, "batch_all")
Expand All @@ -145,7 +145,7 @@ class ExtrinsicBuilderTest {
)
}

val encoded = extrinsicBuilder.build(useBatchAll = true)
val encoded = extrinsicBuilder.build(batchMode = BatchMode.BATCH_ALL)

assertEquals(BIG_TRANSACTION, encoded)
}
Expand Down

0 comments on commit 4580580

Please sign in to comment.