-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support calculating the TX hash of a Substrate transaction
- Loading branch information
Showing
8 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
pub mod transaction_util; |
27 changes: 27 additions & 0 deletions
27
rust/frameworks/tw_substrate/src/modules/transaction_util.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Copyright © 2017 Trust Wallet. | ||
|
||
use tw_coin_entry::coin_context::CoinContext; | ||
use tw_coin_entry::error::prelude::*; | ||
use tw_coin_entry::modules::transaction_util::TransactionUtil; | ||
use tw_encoding::hex; | ||
use tw_hash::blake2::blake2_b; | ||
|
||
pub struct SubstrateTransactionUtil; | ||
|
||
impl TransactionUtil for SubstrateTransactionUtil { | ||
fn calc_tx_hash(&self, coin: &dyn CoinContext, encoded_tx: &str) -> SigningResult<String> { | ||
Self::calc_tx_hash_impl(coin, encoded_tx) | ||
} | ||
} | ||
|
||
impl SubstrateTransactionUtil { | ||
fn calc_tx_hash_impl(_coin: &dyn CoinContext, encoded_tx: &str) -> SigningResult<String> { | ||
let tx_bytes = hex::decode(encoded_tx).map_err(|_| SigningErrorType::Error_input_parse)?; | ||
|
||
let tx_hash = blake2_b(&tx_bytes, 32).map_err(|_| SigningErrorType::Error_internal)?; | ||
|
||
Ok(hex::encode(&tx_hash, true)) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters