Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v.11.2 #77

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading