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

[Polkadot]: Refactor Polkadot to support any Substrate chain #3261

Merged
merged 8 commits into from
Jun 28, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,48 @@ class TestPolkadotSigner {
val expected = "0xd10184008361bd08ddca5fda28b5e2aa84dc2621de566e23e089e555a42194c3eaf2da7900c891ba102db672e378945d74cf7f399226a76b43cab502436971599255451597fc2599902e4b62c7ce85ecc3f653c693fef3232be620984b5bb5bcecbbd7b209d50318001a02080706070207004d446617"
assertEquals(encoded, expected)
}

@Test
fun PolkadotTransactionAcalaSigning() {
val transferCallIndices = Polkadot.CallIndices.newBuilder().apply {
custom = Polkadot.CustomCallIndices.newBuilder().apply {
moduleIndex = 0x0a
methodIndex = 0x00
}.build()
}

val call = Polkadot.Balance.Transfer.newBuilder().apply {
value = "0xe8d4a51000".toHexBytesInByteString() // 1 ACA
toAddress = "25Qqz3ARAvnZbahGZUzV3xpP1bB3eRrupEprK7f2FNbHbvsz"
callIndices = transferCallIndices.build()
}

val acalaGenesisHashStr = "0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c".toHexBytesInByteString()
val acalaNetworkSs58Prefix = 10

val input = Polkadot.SigningInput.newBuilder().apply {
genesisHash = acalaGenesisHashStr
blockHash = "0x707ffa05b7dc6cdb6356bd8bd51ff20b2757c3214a76277516080a10f1bc7537".toHexBytesInByteString()
nonce = 0
specVersion = 2170
network = acalaNetworkSs58Prefix
transactionVersion = 2
privateKey = "9066aa168c379a403becb235c15e7129c133c244e56a757ab07bc369288bcab0".toHexBytesInByteString()
era = Polkadot.Era.newBuilder().apply {
blockNumber = 3893613
period = 64
}.build()
balanceCall = Polkadot.Balance.newBuilder().apply {
transfer = call.build()
}.build()
multiAddress = true
}

val output = AnySigner.sign(input.build(), POLKADOT, SigningOutput.parser())
val encoded = Numeric.toHexString(output.encoded.toByteArray())

// https://acala.subscan.io/extrinsic/3893620-3
val expected = "0x41028400e9590e4d99264a14a85e21e69537e4a64f66a875d38cb8f76b305f41fabe24a900dd54466dffd1e3c80b76013e9459fbdcd17805bd5fdbca0961a643bad1cbd2b7fe005c62c51c18b67f31eb9e61b187a911952fee172ef18402d07c703eec3100d50200000a0000c8c602ded977c56076ae38d98026fa669ca10d6a2b5a0bfc4086ae7668ed1c60070010a5d4e8"
assertEquals(encoded, expected)
}
}
48 changes: 0 additions & 48 deletions include/TrustWalletCore/TWSubstrateAddress.h

This file was deleted.

26 changes: 0 additions & 26 deletions include/TrustWalletCore/TWSubstrateSigner.h

This file was deleted.

2 changes: 2 additions & 0 deletions rust/tw_proto/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub unsafe extern "C" fn polkadot_test_signing_input() -> CByteArrayResult {
let balance = BalanceEnum::transfer(proto::mod_Balance::Transfer {
to_address: Cow::from(to_address),
value: Cow::Borrowed(&value),
memo: Cow::default(),
call_indices: None,
});
let signing_input = proto::SigningInput {
block_hash: Cow::Owned(block_hash),
Expand Down
2 changes: 1 addition & 1 deletion samples/kmp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.trustwallet:wallet-core-kotlin:3.2.0")
implementation("com.trustwallet:wallet-core-kotlin:3.2.1")
}
}
val commonTest by getting {
Expand Down
3 changes: 3 additions & 0 deletions src/Polkadot/Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Address: public SS58Address {
/// Initializes a Polkadot address with a string representation.
explicit Address(const std::string& string): SS58Address(string, TWSS58AddressTypePolkadot) {}

/// Initializes a Polkadot address with a string representation.
explicit Address(const std::string& string, uint32_t ss58Prefix): SS58Address(string, ss58Prefix) {}

/// Initializes a Polkadot address with a public key.
explicit Address(const PublicKey& publicKey): SS58Address(publicKey, TWSS58AddressTypePolkadot) {}
/// Initializes a Polkadot address with a public key and a given ss58Prefix.
Expand Down
Loading