Skip to content

Commit b050875

Browse files
[Solana]: Improve TransactionDecoder API (#3723)
* [Solana]: Do not require to provide a sender address if `RawMessage` specified * [CI] Trigger CI * [CI]: Fix Docker and check-binary-sizes * [CI]: Fix Docker build * [CI]: Fix Docker build №2
1 parent 81ffb17 commit b050875

File tree

8 files changed

+17
-25
lines changed

8 files changed

+17
-25
lines changed

.github/workflows/linux-ci-rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ jobs:
152152
./tools/release-size compare --before previous/release-report.json --current release-report.json > report-diff.md
153153
154154
- name: Create or Update Comment
155+
if: github.event_name == 'pull_request'
155156
uses: edumserrano/find-create-or-update-comment@v2
156157
with:
157158
issue-number: ${{ github.event.pull_request.number }}

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ENV CXX=/usr/bin/clang++-14
3838
RUN wget "https://sh.rustup.rs" -O rustup.sh \
3939
&& sh rustup.sh -y
4040
ENV PATH="/root/.cargo/bin:${PATH}"
41+
RUN rustup default nightly-2024-02-09
4142
RUN cargo install --force cbindgen \
4243
&& rustup target add wasm32-unknown-emscripten
4344

rust/chains/tw_solana/src/compiler.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ impl SolanaCompiler {
3535
input: Proto::SigningInput<'_>,
3636
) -> SigningResult<Proto::PreSigningOutput<'static>> {
3737
let builder = MessageBuilder::new(input);
38-
let signers = builder.signers()?;
3938
let unsigned_msg = builder.build()?;
40-
4139
let data_to_sign = TxSigner::preimage_versioned(&unsigned_msg)?;
4240

43-
let signers: Vec<_> = signers
44-
.iter()
41+
let signers: Vec<_> = unsigned_msg
42+
.signers()
4543
.map(|addr| Cow::from(addr.to_string().into_bytes()))
4644
.collect();
4745

rust/chains/tw_solana/src/modules/message_builder.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,6 @@ impl<'a> MessageBuilder<'a> {
5757
Ok(signing_keys)
5858
}
5959

60-
pub fn signers(&self) -> SigningResult<Vec<SolanaAddress>> {
61-
let mut signers = Vec::default();
62-
if !self.input.fee_payer.is_empty() {
63-
signers.push(SolanaAddress::from_str(self.input.fee_payer.as_ref())?);
64-
}
65-
66-
signers.push(self.signer_address()?);
67-
68-
// Consider matching other transaction types if they may contain other private keys.
69-
if let ProtoTransactionType::create_nonce_account(ref nonce) = self.input.transaction_type {
70-
signers.push(SolanaAddress::from_str(nonce.nonce_account.as_ref())?);
71-
}
72-
73-
Ok(signers)
74-
}
75-
7660
pub fn external_signatures(&self) -> SigningResult<PubkeySignatureMap> {
7761
match self.input.raw_message {
7862
Some(ref raw_message) => RawMessageBuilder::external_signatures(raw_message),

rust/chains/tw_solana/src/transaction/versioned.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ impl VersionedMessage {
6565
}
6666
}
6767

68+
pub fn signers(&self) -> impl Iterator<Item = &SolanaAddress> {
69+
let signatures_count = self.num_required_signatures();
70+
match self {
71+
VersionedMessage::Legacy(legacy) => &legacy.account_keys,
72+
VersionedMessage::V0(v0) => &v0.account_keys,
73+
}
74+
.iter()
75+
.take(signatures_count)
76+
}
77+
6878
pub fn recent_blockhash(&self) -> Blockhash {
6979
match self {
7080
VersionedMessage::Legacy(legacy) => Blockhash::with_bytes(legacy.recent_blockhash),

rust/tw_any_coin/tests/chains/solana/solana_transaction.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,6 @@ fn test_solana_decode_transaction_update_blockhash_preimage_hash_and_compile() {
302302
// Step 3. Pre-image hash the transaction.
303303

304304
let input = Proto::SigningInput {
305-
// There is no matching pubkey in the transaction account keys.
306-
sender: SENDER_PUBLIC_KEY.into(),
307305
raw_message: Some(decoded_tx),
308306
tx_encoding: Proto::Encoding::Base64,
309307
..Proto::SigningInput::default()

tests/chains/Firo/TransactionCompilerTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
//
33
// Copyright © 2017 Trust Wallet.
44

5-
#include "Coin.h"
65
#include "HexCoding.h"
76
#include "PublicKey.h"
87
#include "TransactionCompiler.h"
98

109
#include "proto/Bitcoin.pb.h"
1110
#include "proto/TransactionCompiler.pb.h"
1211

12+
#include <TrustWalletCore/TWAnySigner.h>
13+
#include <TrustWalletCore/TWBitcoinSigHashType.h>
1314
#include <TrustWalletCore/TWCoinType.h>
1415

1516
#include "Bitcoin/Script.h"
16-
#include "Bitcoin/TransactionPlan.h"
1717

1818
#include "TestUtilities.h"
1919
#include <gtest/gtest.h>

tools/release-size

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def compare_sizes(args):
5454
print("## Binary size comparison")
5555
print()
5656
for target, current_kb in current_json.items():
57-
before_kb = before_json.get(target, 0)
57+
before_kb = before_json.get(target, current_kb)
5858
display_target(target, before_kb, current_kb)
5959
print()
6060

0 commit comments

Comments
 (0)