Skip to content

Commit

Permalink
Feature/generic signed extensions (#62)
Browse files Browse the repository at this point in the history
* Rework signed extensions

* Code style

* Bump versions

* Comments

* Handle nonce as struct

* Handle nonce as struct

* update image link

* change to using install workflow

* Force older version of log

* change install dep

fix spelling

push cargo toml

change location

fix syntax

remove fmt

remove semicolon from expression

remove directory switching

adding ndk

change installation action and add crago-c

fix syntax

remove cargo-c

return toolchain back

try to install libgcc

fix syntx

adding sudo

update version of image

remove toolchain

update version

return installation through action

decrease version

try to install target separatelly

fix shell

add gcc-multilib

fix syntax

change to macos

install all libraries

fix syntax

E: Unable to locate package lib32ncurses5

try to fix libgcc problem

change to stable version

adding aarch64-linux-android

* update other actions

* remove debug info

* remove additional libraries

---------

Co-authored-by: Stepan Lavrentev <lawrentievsv@gmail.com>
  • Loading branch information
valentunn and stepanLav committed Oct 15, 2023
1 parent c2c1aac commit 1122560
Show file tree
Hide file tree
Showing 28 changed files with 337 additions and 173 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ on:

jobs:
test:

runs-on: ubuntu-latest
container:
image: ghcr.io/nova-wallet/build_tools:pr-5
credentials:
username: stepanLav
password: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- name: 🔧 Install dependencies
uses: ./.github/workflows/install/

- name: Lint
run: ./gradlew ktlint

Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Install dependencies for Android build
description: Contains all dependencies for Android build
runs:
using: "composite"
steps:
- name: ☕️ Install Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
cache: 'gradle'

- uses: nttld/setup-ndk@v1
with:
ndk-version: r21d
local-cache: true

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- name: Add targets
run: |
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
rustup target add x86_64-linux-android
rustup target add aarch64-linux-android
shell: bash
21 changes: 10 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ on:
release:
types: [released]

env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/nova-wallet/build_tools:pr-5
credentials:
username: stepanLav
password: ${{ secrets.GITHUB_TOKEN }}
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

steps:
- uses: actions/checkout@v2

- name: 🔧 Install dependencies
uses: ./.github/workflows/install/

- name: Kotlin linter
run: ./gradlew ktlint

Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ on:
branches:
- "develop"

env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/nova-wallet/build_tools:pr-5
credentials:
username: stepanLav
password: ${{ secrets.GITHUB_TOKEN }}
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

steps:
- uses: actions/checkout@v2

- name: 🔧 Install dependencies
uses: ./.github/workflows/install/

- name: Kotlin linter
run: ./gradlew ktlint

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ app/*.apk
*.lock
/sr25519-java/target
/sr25519-java/.idea


# Added by cargo

/target
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.8.0'
versionName = '1.9.0'
versionCode = 1

// SDK and tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fun v13Preset(): TypePreset = typePreset {
type(Bytes)
type(BitVec)

type(Extrinsic.Default)
type(Extrinsic)

type(CallBytes) // seems to be unused in runtime
type(EraType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jp.co.soramitsu.fearless_utils.runtime.definitions.types.composite
import io.emeraldpay.polkaj.scale.ScaleCodecReader
import io.emeraldpay.polkaj.scale.ScaleCodecWriter
import jp.co.soramitsu.fearless_utils.runtime.RuntimeSnapshot
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.RuntimeType
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.Type
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.TypeReference

Expand All @@ -23,3 +24,7 @@ class Alias(alias: String, val aliasedReference: TypeReference) : Type<Any?>(ali
override val isFullyResolved: Boolean
get() = aliasedReference.isResolved()
}

fun RuntimeType<*, *>.aliasedAs(newName: String): Alias {
return Alias(newName, TypeReference(this))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jp.co.soramitsu.fearless_utils.runtime.definitions.types.composite
import io.emeraldpay.polkaj.scale.ScaleCodecReader
import io.emeraldpay.polkaj.scale.ScaleCodecWriter
import jp.co.soramitsu.fearless_utils.runtime.RuntimeSnapshot
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.RuntimeType
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.Type
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.TypeReference
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.skipAliases
Expand Down Expand Up @@ -44,3 +45,9 @@ class Struct(
override val isFullyResolved: Boolean
get() = mapping.all { (_, ref) -> ref.isResolved() }
}

fun RuntimeType<*, *>.isEmptyStruct(): Boolean {
val asStruct = skipAliases() as? Struct ?: return false

return asStruct.mapping.isEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package jp.co.soramitsu.fearless_utils.runtime.definitions.types.composite
import io.emeraldpay.polkaj.scale.ScaleCodecReader
import io.emeraldpay.polkaj.scale.ScaleCodecWriter
import jp.co.soramitsu.fearless_utils.runtime.RuntimeSnapshot
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.RuntimeType
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.Type
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.TypeReference
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.skipAliases
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.skipAliasesOrNull

class Tuple(name: String, val typeReferences: List<TypeReference>) : Type<List<*>>(name) {
Expand Down Expand Up @@ -36,3 +38,9 @@ class Tuple(name: String, val typeReferences: List<TypeReference>) : Type<List<*
override val isFullyResolved: Boolean
get() = typeReferences.all { it.isResolved() }
}

fun RuntimeType<*, *>.isEmptyTuple(): Boolean {
val asTuple = skipAliases() as? Tuple ?: return false

return asTuple.typeReferences.isEmpty()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package jp.co.soramitsu.fearless_utils.runtime.definitions.types.generics

import jp.co.soramitsu.fearless_utils.runtime.definitions.types.primitives.Compact
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.primitives.u32
import jp.co.soramitsu.fearless_utils.runtime.metadata.SignedExtensionMetadata
import jp.co.soramitsu.fearless_utils.runtime.metadata.SignedExtensionMetadata.Companion.onlyAdditional
import jp.co.soramitsu.fearless_utils.runtime.metadata.SignedExtensionMetadata.Companion.onlySigned

object DefaultSignedExtensions {

const val CHECK_MORTALITY = "CheckMortality"
const val CHECK_NONCE = "CheckNonce"
const val CHECK_TX_PAYMENT = "ChargeTransactionPayment"
const val CHECK_GENESIS = "CheckGenesis"
const val CHECK_SPEC_VERSION = "CheckSpecVersion"
const val CHECK_TX_VERSION = "CheckTxVersion"

val ALL = listOf(
SignedExtensionMetadata(CHECK_MORTALITY, type = EraType, additionalSigned = H256),
onlySigned(CHECK_NONCE, Compact("Compact<Index>")),
onlySigned(CHECK_TX_PAYMENT, Compact("Compact<u32>")),
onlyAdditional(CHECK_GENESIS, H256),
onlyAdditional(CHECK_SPEC_VERSION, u32),
onlyAdditional(CHECK_TX_VERSION, u32),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,8 @@ private val SIGNED_MASK = 0b1000_0000.toUByte()
private const val TYPE_ADDRESS = "Address"
private const val TYPE_SIGNATURE = "ExtrinsicSignature"

class Extrinsic(
val signedExtrasType: ExtrinsicPayloadExtras = SignedExtras.default
) :
RuntimeType<Extrinsic.EncodingInstance, Extrinsic.DecodedInstance>("ExtrinsicsDecoder") {

companion object {
val Default = Extrinsic()
}
@OptIn(ExperimentalUnsignedTypes::class)
object Extrinsic : RuntimeType<Extrinsic.EncodingInstance, Extrinsic.DecodedInstance>("ExtrinsicsDecoder") {

class EncodingInstance(
val signature: Signature?,
Expand Down Expand Up @@ -71,7 +65,7 @@ class Extrinsic(
Signature(
accountIdentifier = addressType(runtime).decode(scaleCodecReader, runtime),
signature = signatureType(runtime).decode(scaleCodecReader, runtime),
signedExtras = signedExtrasType.decode(scaleCodecReader, runtime)
signedExtras = SignedExtras.decode(scaleCodecReader, runtime)
)
} else {
null
Expand Down Expand Up @@ -113,7 +107,7 @@ class Extrinsic(

val addressBytes = addressType(runtime).bytes(runtime, signature.accountIdentifier)
val signatureBytes = signatureType(runtime).bytes(runtime, signature.signature)
val signedExtrasBytes = signedExtrasType.bytes(runtime, signature.signedExtras)
val signedExtrasBytes = SignedExtras.bytes(runtime, signature.signedExtras)

addressBytes + signatureBytes + signedExtrasBytes
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jp.co.soramitsu.fearless_utils.runtime.definitions.types.generics

import jp.co.soramitsu.fearless_utils.encrypt.EncryptionType
import jp.co.soramitsu.fearless_utils.runtime.definitions.types.composite.DictEnum
import jp.co.soramitsu.fearless_utils.runtime.extrinsic.SignedExtension

class MultiSignature(val encryptionType: EncryptionType, val value: ByteArray)

Expand All @@ -16,17 +15,6 @@ fun Extrinsic.Signature.tryExtractMultiSignature(): MultiSignature? {
return MultiSignature(encryptionType, value)
}

fun Extrinsic.Companion.create(customSignedExtensions: Collection<SignedExtension>): Extrinsic {
val customSignedExtensionTypes = customSignedExtensions.associateBy(
keySelector = { it.name },
valueTransform = { it.type }
)

val allSignedExtensions = SignedExtras.default.extras + customSignedExtensionTypes

return Extrinsic(ExtrinsicPayloadExtras(allSignedExtensions))
}

private val EncryptionType.multiSignatureName
get() = rawName.capitalize()

Expand Down
Loading

0 comments on commit 1122560

Please sign in to comment.