Skip to content

Commit

Permalink
[Solana]: Improve TransactionDecoder API (#3723)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
satoshiotomakan committed Mar 12, 2024
1 parent 81ffb17 commit b050875
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linux-ci-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ jobs:
./tools/release-size compare --before previous/release-report.json --current release-report.json > report-diff.md
- name: Create or Update Comment
if: github.event_name == 'pull_request'
uses: edumserrano/find-create-or-update-comment@v2
with:
issue-number: ${{ github.event.pull_request.number }}
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ENV CXX=/usr/bin/clang++-14
RUN wget "https://sh.rustup.rs" -O rustup.sh \
&& sh rustup.sh -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN rustup default nightly-2024-02-09
RUN cargo install --force cbindgen \
&& rustup target add wasm32-unknown-emscripten

Expand Down
6 changes: 2 additions & 4 deletions rust/chains/tw_solana/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ impl SolanaCompiler {
input: Proto::SigningInput<'_>,
) -> SigningResult<Proto::PreSigningOutput<'static>> {
let builder = MessageBuilder::new(input);
let signers = builder.signers()?;
let unsigned_msg = builder.build()?;

let data_to_sign = TxSigner::preimage_versioned(&unsigned_msg)?;

let signers: Vec<_> = signers
.iter()
let signers: Vec<_> = unsigned_msg
.signers()
.map(|addr| Cow::from(addr.to_string().into_bytes()))
.collect();

Expand Down
16 changes: 0 additions & 16 deletions rust/chains/tw_solana/src/modules/message_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@ impl<'a> MessageBuilder<'a> {
Ok(signing_keys)
}

pub fn signers(&self) -> SigningResult<Vec<SolanaAddress>> {
let mut signers = Vec::default();
if !self.input.fee_payer.is_empty() {
signers.push(SolanaAddress::from_str(self.input.fee_payer.as_ref())?);
}

signers.push(self.signer_address()?);

// Consider matching other transaction types if they may contain other private keys.
if let ProtoTransactionType::create_nonce_account(ref nonce) = self.input.transaction_type {
signers.push(SolanaAddress::from_str(nonce.nonce_account.as_ref())?);
}

Ok(signers)
}

pub fn external_signatures(&self) -> SigningResult<PubkeySignatureMap> {
match self.input.raw_message {
Some(ref raw_message) => RawMessageBuilder::external_signatures(raw_message),
Expand Down
10 changes: 10 additions & 0 deletions rust/chains/tw_solana/src/transaction/versioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ impl VersionedMessage {
}
}

pub fn signers(&self) -> impl Iterator<Item = &SolanaAddress> {
let signatures_count = self.num_required_signatures();
match self {
VersionedMessage::Legacy(legacy) => &legacy.account_keys,
VersionedMessage::V0(v0) => &v0.account_keys,
}
.iter()
.take(signatures_count)
}

pub fn recent_blockhash(&self) -> Blockhash {
match self {
VersionedMessage::Legacy(legacy) => Blockhash::with_bytes(legacy.recent_blockhash),
Expand Down
2 changes: 0 additions & 2 deletions rust/tw_any_coin/tests/chains/solana/solana_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ fn test_solana_decode_transaction_update_blockhash_preimage_hash_and_compile() {
// Step 3. Pre-image hash the transaction.

let input = Proto::SigningInput {
// There is no matching pubkey in the transaction account keys.
sender: SENDER_PUBLIC_KEY.into(),
raw_message: Some(decoded_tx),
tx_encoding: Proto::Encoding::Base64,
..Proto::SigningInput::default()
Expand Down
4 changes: 2 additions & 2 deletions tests/chains/Firo/TransactionCompilerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
//
// Copyright © 2017 Trust Wallet.

#include "Coin.h"
#include "HexCoding.h"
#include "PublicKey.h"
#include "TransactionCompiler.h"

#include "proto/Bitcoin.pb.h"
#include "proto/TransactionCompiler.pb.h"

#include <TrustWalletCore/TWAnySigner.h>
#include <TrustWalletCore/TWBitcoinSigHashType.h>
#include <TrustWalletCore/TWCoinType.h>

#include "Bitcoin/Script.h"
#include "Bitcoin/TransactionPlan.h"

#include "TestUtilities.h"
#include <gtest/gtest.h>
Expand Down
2 changes: 1 addition & 1 deletion tools/release-size
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def compare_sizes(args):
print("## Binary size comparison")
print()
for target, current_kb in current_json.items():
before_kb = before_json.get(target, 0)
before_kb = before_json.get(target, current_kb)
display_target(target, before_kb, current_kb)
print()

Expand Down

0 comments on commit b050875

Please sign in to comment.