diff --git a/.github/workflows/codegen-v2.yml b/.github/workflows/codegen-v2.yml index 504467782405..8438d788d56c 100644 --- a/.github/workflows/codegen-v2.yml +++ b/.github/workflows/codegen-v2.yml @@ -12,7 +12,7 @@ env: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index db3513b2a175..336faa4ce81b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,7 +11,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v3 - name: Lint Dockerfile diff --git a/.github/workflows/linux-ci-rust.yml b/.github/workflows/linux-ci-rust.yml index 36d3e57931a4..7e0889e824af 100644 --- a/.github/workflows/linux-ci-rust.yml +++ b/.github/workflows/linux-ci-rust.yml @@ -20,7 +20,7 @@ jobs: permissions: contents: read checks: write - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 @@ -61,7 +61,7 @@ jobs: # Run Rust tests in WASM. test-wasm: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/linux-ci-sonarcloud.yml b/.github/workflows/linux-ci-sonarcloud.yml index 775486d741af..83fa3b4f2163 100644 --- a/.github/workflows/linux-ci-sonarcloud.yml +++ b/.github/workflows/linux-ci-sonarcloud.yml @@ -13,7 +13,7 @@ concurrency: jobs: build: if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.fork == false - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/linux-ci.yml b/.github/workflows/linux-ci.yml index 653fbf0c135a..1062e02dacb7 100644 --- a/.github/workflows/linux-ci.yml +++ b/.github/workflows/linux-ci.yml @@ -12,13 +12,13 @@ concurrency: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 - name: Install system dependencies run: | - tools/install-sys-dependencies-linux ci + tools/install-sys-dependencies-linux tools/install-rust-dependencies - name: Cache internal dependencies id: internal_cache diff --git a/.github/workflows/linux-sampleapp-ci.yml b/.github/workflows/linux-sampleapp-ci.yml index da1aa11656bc..a8c0dbe15da1 100644 --- a/.github/workflows/linux-sampleapp-ci.yml +++ b/.github/workflows/linux-sampleapp-ci.yml @@ -12,13 +12,13 @@ concurrency: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 - name: Install system dependencies run: | - tools/install-sys-dependencies-linux ci + tools/install-sys-dependencies-linux tools/install-rust-dependencies - name: Cache internal dependencies id: internal_cache @@ -61,13 +61,6 @@ jobs: env: CC: /usr/bin/clang CXX: /usr/bin/clang++ - - name: Build, run, and test devconsole.ts - run: | - cd samples/typescript/devconsole.ts - npm install - npm run build - echo -e "help() \n .exit" | npm run start - npm run test - name: Install Go env: GO_VERSION: 1.19 diff --git a/.github/workflows/wasm-ci.yml b/.github/workflows/wasm-ci.yml index da063d565bee..d68b0dcb39db 100644 --- a/.github/workflows/wasm-ci.yml +++ b/.github/workflows/wasm-ci.yml @@ -12,7 +12,7 @@ concurrency: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 if: github.event.pull_request.draft == false steps: - uses: actions/checkout@v3 diff --git a/Package.swift b/Package.swift index 38e74510f2ff..7e933efe93dc 100644 --- a/Package.swift +++ b/Package.swift @@ -12,13 +12,13 @@ let package = Package( targets: [ .binaryTarget( name: "WalletCore", - url: "https://github.com/trustwallet/wallet-core/releases/download/4.0.33/WalletCore.xcframework.zip", - checksum: "2fb8b833047b9697bba6ade66a9bdeede622b2fe0fb7a9b90cb9edb4651ec866" + url: "https://github.com/trustwallet/wallet-core/releases/download/4.1.12/WalletCore.xcframework.zip", + checksum: "1632bbbab1c6a588689eec77a24e1468d9a6746968652cf0a7e669e996c3d24d" ), .binaryTarget( name: "SwiftProtobuf", - url: "https://github.com/trustwallet/wallet-core/releases/download/4.0.33/SwiftProtobuf.xcframework.zip", - checksum: "05557735dd607c5a369dc378eb3f299504b880614ef13f136a028ecd320b0e4d" + url: "https://github.com/trustwallet/wallet-core/releases/download/4.1.12/SwiftProtobuf.xcframework.zip", + checksum: "33d80c20428c9db4fcf99d1272ba19655f7c6ee7e5b1809fa8a7e7d4aa1b222b" ) ] ) diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt index 9064a873e7c7..f99db4e987c2 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt @@ -154,5 +154,6 @@ class CoinAddressDerivationTests { TIA -> assertEquals("celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7", address) NATIVEZETACHAIN -> assertEquals("zeta13u6g7vqgw074mgmf2ze2cadzvkz9snlwywj304", address) DYDX -> assertEquals("dydx142j9u5eaduzd7faumygud6ruhdwme98qeayaky", address) + PACTUS -> assertEquals("pc1r7ys2g5a4xc2qtm0t4q987m4mvs57w5g0v4pvzg", address) } } diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/bitcoincash/TestBitcoinCashSigning.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/bitcoincash/TestBitcoinCashSigning.kt new file mode 100644 index 000000000000..2c826c0bd4f4 --- /dev/null +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/bitcoincash/TestBitcoinCashSigning.kt @@ -0,0 +1,81 @@ +package com.trustwallet.core.app.blockchains.bitcoincash + +import com.trustwallet.core.app.utils.Numeric +import com.trustwallet.core.app.utils.toHexBytesInByteString +import org.junit.Assert.assertEquals +import org.junit.Test +import wallet.core.java.AnySigner +import wallet.core.jni.BitcoinSigHashType +import wallet.core.jni.CoinType +import wallet.core.jni.proto.Bitcoin +import wallet.core.jni.proto.BitcoinV2 +import wallet.core.jni.proto.Common.SigningError + +class TestBitcoinCashSigning { + + init { + System.loadLibrary("TrustWalletCore") + } + + @Test + fun testSignV2P2PKH() { + val privateKey = "7fdafb9db5bc501f2096e7d13d331dc7a75d9594af3d251313ba8b6200f4e384".toHexBytesInByteString() + + val utxo1 = BitcoinV2.Input.newBuilder().apply { + outPoint = BitcoinV2.OutPoint.newBuilder().apply { + hash = "e28c2b955293159898e34c6840d99bf4d390e2ee1c6f606939f18ee1e2000d05".toHexBytesInByteString() + vout = 2 + }.build() + value = 5151 + sighashType = BitcoinSigHashType.ALL.value() + BitcoinSigHashType.FORK.value() + receiverAddress = "bitcoincash:qzhlrcrcne07x94h99thved2pgzdtv8ccujjy73xya" + } + + val out1 = BitcoinV2.Output.newBuilder().apply { + value = 600 + // Legacy address + toAddress = "1Bp9U1ogV3A14FMvKbRJms7ctyso4Z4Tcx" + } + val changeOutputExplicit = BitcoinV2.Output.newBuilder().apply { + value = 4325 + // Legacy address + toAddress = "qz0q3xmg38sr94rw8wg45vujah7kzma3cskxymnw06" + } + + val builder = BitcoinV2.TransactionBuilder.newBuilder() + .setVersion(BitcoinV2.TransactionVersion.V1) + .addInputs(utxo1) + .addOutputs(out1) + .addOutputs(changeOutputExplicit) + .setInputSelector(BitcoinV2.InputSelector.UseAll) + .setFixedDustThreshold(546) + .build() + + val input = BitcoinV2.SigningInput.newBuilder() + .addPrivateKeys(privateKey) + .setBuilder(builder) + .setChainInfo(BitcoinV2.ChainInfo.newBuilder().apply { + p2PkhPrefix = 0 + p2ShPrefix = 5 + hrp = "bitcoincash" + }) + .build() + + val legacyInput = Bitcoin.SigningInput.newBuilder() + .setSigningV2(input) + // `CoinType` must be set to be handled correctly. + .setCoinType(CoinType.BITCOINCASH.value()) + .build() + + val outputLegacy = AnySigner.sign(legacyInput, CoinType.BITCOINCASH, Bitcoin.SigningOutput.parser()) + assertEquals(outputLegacy.error, SigningError.OK) + assert(outputLegacy.hasSigningResultV2()) + + val output = outputLegacy.signingResultV2 + assertEquals(output.error, SigningError.OK) + assertEquals( + Numeric.toHexString(output.encoded.toByteArray()), + "0x0100000001e28c2b955293159898e34c6840d99bf4d390e2ee1c6f606939f18ee1e2000d05020000006b483045022100b70d158b43cbcded60e6977e93f9a84966bc0cec6f2dfd1463d1223a90563f0d02207548d081069de570a494d0967ba388ff02641d91cadb060587ead95a98d4e3534121038eab72ec78e639d02758e7860cdec018b49498c307791f785aa3019622f4ea5bffffffff0258020000000000001976a914769bdff96a02f9135a1d19b749db6a78fe07dc9088ace5100000000000001976a9149e089b6889e032d46e3b915a3392edfd616fb1c488ac00000000" + ) + } +} diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusAddress.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusAddress.kt new file mode 100644 index 000000000000..b58b068b8590 --- /dev/null +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusAddress.kt @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright © 2017 Trust Wallet. + +package com.trustwallet.core.app.blockchains.pactus + +import com.trustwallet.core.app.utils.toHex +import com.trustwallet.core.app.utils.toHexByteArray +import org.junit.Assert.assertEquals +import org.junit.Test +import wallet.core.jni.* + +class TestPactusAddress { + + init { + System.loadLibrary("TrustWalletCore") + } + + @Test + fun testAddress() { + val key = PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray()) + val pubkey = key.publicKeyEd25519 + val address = AnyAddress(pubkey, CoinType.PACTUS) + val expected = AnyAddress("pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr", CoinType.PACTUS) + + assertEquals(pubkey.data().toHex(), "0x95794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa") + assertEquals(address.description(), expected.description()) + } +} diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt new file mode 100644 index 000000000000..2cbaaf9635e0 --- /dev/null +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/pactus/TestPactusSigner.kt @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright © 2017 Trust Wallet. + +package com.trustwallet.core.app.blockchains.pactus + +import com.google.protobuf.ByteString +import com.trustwallet.core.app.utils.toHexByteArray +import org.junit.Assert.assertEquals +import org.junit.Test +import wallet.core.jni.PrivateKey +import wallet.core.java.AnySigner +import wallet.core.jni.CoinType +import wallet.core.jni.CoinType.PACTUS +import wallet.core.jni.proto.Pactus +import wallet.core.jni.proto.Pactus.SigningOutput +import com.trustwallet.core.app.utils.Numeric +import org.junit.Assert.assertArrayEquals + +class TestPactusSigner { + + init { + System.loadLibrary("TrustWalletCore") + } + + @Test + fun testPactusTransactionSigning() { + val signingInput = Pactus.SigningInput.newBuilder() + signingInput.apply { + privateKey = ByteString.copyFrom(PrivateKey("4e51f1f3721f644ac7a193be7f5e7b8c2abaa3467871daf4eacb5d3af080e5d6".toHexByteArray()).data()) + transaction = Pactus.TransactionMessage.newBuilder().apply { + lockTime = 0x00030201 + fee = 1000 + memo = "test" + transfer = Pactus.TransferPayload.newBuilder().apply { + sender = "pc1rwzvr8rstdqypr80ag3t6hqrtnss9nwymcxy3lr" + receiver = "pc1r0g22ufzn8qtw0742dmfglnw73e260hep0k3yra" + amount = 20000 + }.build() + }.build() + } + + val output = AnySigner.sign(signingInput.build(), PACTUS, SigningOutput.parser()) + + assertEquals( + "0x34cd4656a98f7eb996e83efdc384cefbe3a9c52dca79a99245b4eacc0b0b4311", + Numeric.toHexString(output.transactionId.toByteArray()) + ) + + assertEquals( + "0x50ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd09", + Numeric.toHexString(output.signature.toByteArray()) + ) + + assertEquals( + "0x000101020300e807047465737401037098338e0b6808119dfd4457ab806b9c2059b89b037a14ae24533816e7faaa6ed28fcdde8e55a7df21a09c0150ac25c7125271489b0cd230549257c93fb8c6265f2914a988ba7b81c1bc47fff027412dd59447867911035ff69742d171060a1f132ac38b95acc6e39ec0bd0995794161374b22c696dabb98e93f6ca9300b22f3b904921fbf560bb72145f4fa", + Numeric.toHexString(output.signedTransactionData.toByteArray()) + ) + } +} diff --git a/codegen-v2/src/codegen/rust/templates/blockchain_crate/entry.rs b/codegen-v2/src/codegen/rust/templates/blockchain_crate/entry.rs index 9b1194bbb688..e26b696fa59d 100644 --- a/codegen-v2/src/codegen/rust/templates/blockchain_crate/entry.rs +++ b/codegen-v2/src/codegen/rust/templates/blockchain_crate/entry.rs @@ -49,11 +49,7 @@ impl CoinEntry for {BLOCKCHAIN}Entry { } #[inline] - fn parse_address_unchecked( - &self, - _coin: &dyn CoinContext, - address: &str, - ) -> AddressResult { + fn parse_address_unchecked(&self, address: &str) -> AddressResult { {BLOCKCHAIN}Address::from_str(address) } diff --git a/codegen/lib/code_generator.rb b/codegen/lib/code_generator.rb index 087a75b34c2f..d1fcf3881afd 100644 --- a/codegen/lib/code_generator.rb +++ b/codegen/lib/code_generator.rb @@ -136,7 +136,7 @@ def render_kotlin_jni_c def render(file, locals = {}) @locals = locals path = File.expand_path(file, File.join(File.dirname(__FILE__), 'templates')) - template = ERB.new(File.read(path), nil, '-') + template = ERB.new(File.read(path), trim_mode: '-') template.result(binding) end diff --git a/docs/registry.md b/docs/registry.md index 7606e14a45bd..a5045889d198 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -99,6 +99,7 @@ This list is generated from [./registry.json](../registry.json) | 14001 | WAX | WAXP | | | | 18000 | Meter | MTR | | | | 19167 | Flux | FLUX | | | +| 21888 | Pactus | PAC | | | | 52752 | Celo | CELO | | | | 59144 | Linea | ETH | | | | 81457 | Blast | ETH | | | diff --git a/include/TrustWalletCore/TWBlockchain.h b/include/TrustWalletCore/TWBlockchain.h index faf4c575c1b1..eeb2f7444746 100644 --- a/include/TrustWalletCore/TWBlockchain.h +++ b/include/TrustWalletCore/TWBlockchain.h @@ -65,6 +65,8 @@ enum TWBlockchain { TWBlockchainInternetComputer = 52, TWBlockchainNativeEvmos = 53, // Cosmos TWBlockchainNativeInjective = 54, // Cosmos + TWBlockchainBitcoinCash = 55, + TWBlockchainPactus = 56, }; TW_EXTERN_C_END diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index 388bd270334e..9d2f10e36c93 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -186,6 +186,7 @@ enum TWCoinType { TWCoinTypeBlast = 81457, TWCoinTypeBounceBit = 6001, TWCoinTypeZkLinkNova = 810180, + TWCoinTypePactus = 21888, // end_of_tw_coin_type_marker_do_not_modify }; diff --git a/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt b/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt index c3d3dbf05270..959fd4821eb0 100644 --- a/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt +++ b/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt @@ -147,5 +147,6 @@ class CoinAddressDerivationTests { Tia -> "celestia142j9u5eaduzd7faumygud6ruhdwme98qpwmfv7" NativeZetaChain -> "zeta13u6g7vqgw074mgmf2ze2cadzvkz9snlwywj304" Dydx -> "dydx142j9u5eaduzd7faumygud6ruhdwme98qeayaky" + Pactus -> "pc1r7ys2g5a4xc2qtm0t4q987m4mvs57w5g0v4pvzg" } } diff --git a/registry.json b/registry.json index 1bb8123783af..2c9d8f410df1 100644 --- a/registry.json +++ b/registry.json @@ -1453,7 +1453,7 @@ "coinId": 145, "symbol": "BCH", "decimals": 8, - "blockchain": "Bitcoin", + "blockchain": "BitcoinCash", "derivation": [ { "path": "m/44'/145'/0'/0/0", @@ -3667,7 +3667,7 @@ "coinId": 899, "symbol": "XEC", "decimals": 2, - "blockchain": "Bitcoin", + "blockchain": "BitcoinCash", "derivation": [ { "path": "m/44'/899'/0'/0/0", @@ -4781,5 +4781,32 @@ "rpc": "https://rpc.zklink.io", "documentation": "https://docs.zklink.io" } + }, + { + "id": "pactus", + "name": "Pactus", + "coinId": 21888, + "symbol": "PAC", + "decimals": 9, + "blockchain": "Pactus", + "derivation": [ + { + "path": "m/44'/21888'/3'/0'" + } + ], + "curve": "ed25519", + "publicKeyType": "ed25519", + "hrp": "pc", + "explorer": { + "url": "https://pacviewer.com", + "txPath": "/transaction/", + "accountPath": "/address/" + }, + "info": { + "url": "https://pactus.org", + "source": "https://github.com/pactus-project/pactus", + "rpc": "https://docs.pactus.org/api/http", + "documentation": "https://docs.pactus.org" + } } ] diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 108bb84e1e00..e12cf3ea3759 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1800,6 +1800,21 @@ dependencies = [ "tw_utxo", ] +[[package]] +name = "tw_bitcoincash" +version = "0.1.0" +dependencies = [ + "tw_bitcoin", + "tw_coin_entry", + "tw_encoding", + "tw_hash", + "tw_keypair", + "tw_memory", + "tw_misc", + "tw_proto", + "tw_utxo", +] + [[package]] name = "tw_coin_entry" version = "0.1.0" @@ -1829,6 +1844,7 @@ dependencies = [ "tw_aptos", "tw_binance", "tw_bitcoin", + "tw_bitcoincash", "tw_coin_entry", "tw_cosmos", "tw_ethereum", @@ -1841,6 +1857,7 @@ dependencies = [ "tw_misc", "tw_native_evmos", "tw_native_injective", + "tw_pactus", "tw_ronin", "tw_solana", "tw_sui", @@ -2062,6 +2079,20 @@ dependencies = [ "tw_memory", ] +[[package]] +name = "tw_pactus" +version = "0.1.0" +dependencies = [ + "bech32", + "byteorder", + "tw_coin_entry", + "tw_encoding", + "tw_hash", + "tw_keypair", + "tw_memory", + "tw_proto", +] + [[package]] name = "tw_proto" version = "0.1.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ca41fb6099d5..692beec26920 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -3,12 +3,14 @@ members = [ "chains/tw_aptos", "chains/tw_binance", "chains/tw_bitcoin", + "chains/tw_bitcoincash", "chains/tw_cosmos", "chains/tw_ethereum", "chains/tw_greenfield", "chains/tw_internet_computer", "chains/tw_native_evmos", "chains/tw_native_injective", + "chains/tw_pactus", "chains/tw_ronin", "chains/tw_solana", "chains/tw_sui", diff --git a/rust/chains/tw_aptos/src/entry.rs b/rust/chains/tw_aptos/src/entry.rs index f9a46c55049f..e2ef01a6e2fe 100644 --- a/rust/chains/tw_aptos/src/entry.rs +++ b/rust/chains/tw_aptos/src/entry.rs @@ -49,11 +49,7 @@ impl CoinEntry for AptosEntry { } #[inline] - fn parse_address_unchecked( - &self, - _coin: &dyn CoinContext, - address: &str, - ) -> AddressResult { + fn parse_address_unchecked(&self, address: &str) -> AddressResult { Address::from_str(address) } diff --git a/rust/chains/tw_aptos/src/transaction_payload.rs b/rust/chains/tw_aptos/src/transaction_payload.rs index aa1c74d02dac..d0105bc949d8 100644 --- a/rust/chains/tw_aptos/src/transaction_payload.rs +++ b/rust/chains/tw_aptos/src/transaction_payload.rs @@ -109,10 +109,7 @@ fn serialize_argument(arg: &TransactionArgument) -> EncodingResult { TransactionArgument::U256(v) => bcs::encode(v), TransactionArgument::U8Vector(v) => bcs::encode(v), TransactionArgument::Bool(v) => bcs::encode(v), - TransactionArgument::Address(v) => { - let serialized_v = bcs::encode(v)?; - bcs::encode(&serialized_v) - }, + TransactionArgument::Address(v) => bcs::encode(v), } } @@ -220,6 +217,10 @@ mod tests { let v = EntryFunction::try_from(payload_value.clone()).unwrap(); assert_eq!(payload_value, v.to_json()); + + let tp = TransactionPayload::EntryFunction(v); + let serialized = bcs::encode(&tp).unwrap(); + assert_eq!(hex::encode(serialized, false), "02c23c3b70956ce8d88fb18ad9ed3b463fe873cb045db3f6d2e2fb15b9aab71d500349464f0772656c65617365030748e0e3958d42b8d452c9199d4a221d0d1b15d14655787453dbe77208ced9051705636f696e730442555344000748e0e3958d42b8d452c9199d4a221d0d1b15d14655787453dbe77208ced9051705636f696e730344414900079936836587ca33240d3d3f91844651b16cb07802faf5e34514ed6f78580deb0a0575696e7473025531000120c95db29a67a848940829b3df6119b5e67b788ff0248676e4484c7c6f29c0f5e6"); } #[test] @@ -255,7 +256,8 @@ mod tests { ); let tp = TransactionPayload::EntryFunction(entry); let serialized = bcs::encode(&tp).unwrap(); - assert_eq!(hex::encode(serialized, false), "02000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220eeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b08e803000000000000"); + let expected_serialized = "02000000000000000000000000000000000000000000000000000000000000000104636f696e087472616e73666572010700000000000000000000000000000000000000000000000000000000000000010a6170746f735f636f696e094170746f73436f696e000220eeff357ea5c1a4e7bc11b2b17ff2dc2dcca69750bfef1e1ebcaccf8c8018175b08e803000000000000"; + assert_eq!(hex::encode(serialized, false), expected_serialized); let payload_value: Value = json!({ "function": "0x1::coin::transfer", "type": "entry_function_payload", @@ -263,5 +265,12 @@ mod tests { "type_arguments": ["0x1::aptos_coin::AptosCoin"] }); assert_eq!(tp.to_json(), payload_value); + + // Rebuild a new EntryFunction object from the JSON above + let v = EntryFunction::try_from(payload_value.clone()).unwrap(); + let tp = TransactionPayload::EntryFunction(v); + // Serialize the new EntryFunction object and compare with the expected serialized value + let serialized = bcs::encode(&tp).unwrap(); + assert_eq!(hex::encode(serialized, false), expected_serialized); } } diff --git a/rust/chains/tw_binance/src/entry.rs b/rust/chains/tw_binance/src/entry.rs index 55930473d53a..6552c0e6bd0c 100644 --- a/rust/chains/tw_binance/src/entry.rs +++ b/rust/chains/tw_binance/src/entry.rs @@ -49,11 +49,7 @@ impl CoinEntry for BinanceEntry { } #[inline] - fn parse_address_unchecked( - &self, - _coin: &dyn CoinContext, - address: &str, - ) -> AddressResult { + fn parse_address_unchecked(&self, address: &str) -> AddressResult { BinanceAddress::from_str(address) } diff --git a/rust/chains/tw_bitcoin/src/context.rs b/rust/chains/tw_bitcoin/src/context.rs new file mode 100644 index 000000000000..8ecdd4f8e553 --- /dev/null +++ b/rust/chains/tw_bitcoin/src/context.rs @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright © 2017 Trust Wallet. + +use tw_coin_entry::error::prelude::SigningResult; +use tw_utxo::address::standard_bitcoin::StandardBitcoinAddress; +use tw_utxo::context::{AddressPrefixes, UtxoContext}; +use tw_utxo::script::Script; + +#[derive(Default)] +pub struct StandardBitcoinContext; + +impl UtxoContext for StandardBitcoinContext { + type Address = StandardBitcoinAddress; + + fn addr_to_script_pubkey( + addr: &Self::Address, + prefixes: AddressPrefixes, + ) -> SigningResult