Skip to content

Commit

Permalink
Merge branch 'master' into s/ton-mnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Sep 9, 2024
2 parents e22de4c + d88a263 commit 7640110
Show file tree
Hide file tree
Showing 102 changed files with 1,968 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TestTheOpenNetworkSigner {
val privateKey = PrivateKey("c38f49de2fb13223a9e7d37d5d0ffbdd89a5eb7c8b0ee4d1c299f2cefe7dc4a0".toHexByteArray())

val transfer = TheOpenNetwork.Transfer.newBuilder()
.setWalletVersion(TheOpenNetwork.WalletVersion.WALLET_V4_R2)
.setDest("EQBm--PFwDv1yCeS-QTJ-L8oiUpqo9IT1BwgVptlSq3ts90Q")
.setAmount(10)
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
Expand All @@ -37,6 +36,7 @@ class TestTheOpenNetworkSigner {
.addMessages(transfer)
.setSequenceNumber(6)
.setExpireAt(1671132440)
.setWalletVersion(TheOpenNetwork.WalletVersion.WALLET_V4_R2)
.build()

val output = AnySigner.sign(input, CoinType.TON, SigningOutput.parser())
Expand All @@ -59,7 +59,6 @@ class TestTheOpenNetworkSigner {
.build()

val transfer = TheOpenNetwork.Transfer.newBuilder()
.setWalletVersion(TheOpenNetwork.WalletVersion.WALLET_V4_R2)
.setDest("EQBiaD8PO1NwfbxSkwbcNT9rXDjqhiIvXWymNO-edV0H5lja")
.setAmount(100 * 1000 * 1000)
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
Expand All @@ -72,6 +71,7 @@ class TestTheOpenNetworkSigner {
.addMessages(transfer)
.setSequenceNumber(1)
.setExpireAt(1787693046)
.setWalletVersion(TheOpenNetwork.WalletVersion.WALLET_V4_R2)
.build()

val output = AnySigner.sign(input, CoinType.TON, SigningOutput.parser())
Expand Down Expand Up @@ -103,7 +103,6 @@ class TestTheOpenNetworkSigner {
.build()

val transfer = TheOpenNetwork.Transfer.newBuilder()
.setWalletVersion(TheOpenNetwork.WalletVersion.WALLET_V4_R2)
.setDest(dogeChatbotDeployingAddress)
// 0.069 TON
.setAmount(69_000_000)
Expand All @@ -116,6 +115,7 @@ class TestTheOpenNetworkSigner {
.addMessages(transfer)
.setSequenceNumber(4)
.setExpireAt(1721939714)
.setWalletVersion(TheOpenNetwork.WalletVersion.WALLET_V4_R2)
.build()

val output = AnySigner.sign(input, CoinType.TON, SigningOutput.parser())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestLiquidStaking {
stake = LiquidStaking.Stake.newBuilder().apply {
amount = "1000000000000000000"
asset = LiquidStaking.Asset.newBuilder().apply {
stakingToken = LiquidStaking.Coin.MATIC
stakingToken = LiquidStaking.Coin.POL
}.build()
}.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tw_coin_entry::modules::json_signer::NoJsonSigner;
use tw_coin_entry::modules::message_signer::NoMessageSigner;
use tw_coin_entry::modules::plan_builder::NoPlanBuilder;
use tw_coin_entry::modules::transaction_decoder::NoTransactionDecoder;
use tw_coin_entry::modules::transaction_util::NoTransactionUtil;
use tw_coin_entry::modules::wallet_connector::NoWalletConnector;
use tw_coin_entry::prefix::NoPrefix;
use tw_keypair::tw::PublicKey;
Expand All @@ -35,6 +36,7 @@ impl CoinEntry for {BLOCKCHAIN}Entry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = NoTransactionUtil;

#[inline]
fn parse_address(
Expand Down
2 changes: 1 addition & 1 deletion docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ This list is generated from [./registry.json](../registry.json)
| 889 | Viction | VIC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/viction/info/logo.png" width="32" /> | <https://www.viction.xyz/> |
| 899 | eCash | XEC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ecash/info/logo.png" width="32" /> | <https://e.cash> |
| 931 | THORChain | RUNE | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/thorchain/info/logo.png" width="32" /> | <https://thorchain.org> |
| 966 | Polygon | MATIC | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png" width="32" /> | <https://polygon.technology> |
| 966 | Polygon | POL | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygon/info/logo.png" width="32" /> | <https://polygon.technology> |
| 996 | OKX Chain | OKT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/okc/info/logo.png" width="32" /> | <https://www.okx.com/okc> |
| 999 | Bitcoin Diamond | BCD | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/bitcoindiamond/info/logo.png" width="32" /> | <https://www.bitcoindiamond.org> |
| 1001 | ThunderCore | TT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/thundertoken/info/logo.png" width="32" /> | <https://thundercore.com> |
Expand Down
24 changes: 24 additions & 0 deletions include/TrustWalletCore/TWTransactionUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.

#pragma once

#include "TWBase.h"
#include "TWCoinType.h"
#include "TWData.h"

TW_EXTERN_C_BEGIN

TW_EXPORT_STRUCT
struct TWTransactionUtil;

/// Calculate the TX hash of a transaction.
///
/// \param coin coin type.
/// \param encodedTx encoded transaction data.
/// \return The TX hash of a transaction, If the input is invalid or the chain is unsupported, null is returned.
TW_EXPORT_STATIC_METHOD
TWString* _Nullable TWTransactionUtilCalcTxHash(enum TWCoinType coinType, TWString* _Nonnull encodedTx);

TW_EXTERN_C_END
19 changes: 7 additions & 12 deletions protobuf-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
#
# Copyright © 2017 Trust Wallet.

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(TrustWalletCoreProtobufPlugin)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if ("$ENV{PREFIX}" STREQUAL "")
if("$ENV{PREFIX}" STREQUAL "")
set(PREFIX "${CMAKE_SOURCE_DIR}/../build/local")
else()
set(PREFIX "$ENV{PREFIX}")
endif()

include_directories(${PREFIX}/include)
link_directories(${PREFIX}/lib)
find_package(Protobuf CONFIG REQUIRED PATH ${PREFIX}/lib/pkgconfig)

find_package(Protobuf REQUIRED PATH ${PREFIX}/lib/pkgconfig)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(protoc-gen-c-typedef c_typedef.cc)
target_link_libraries(protoc-gen-c-typedef protobuf::libprotobuf protobuf::libprotoc)

add_executable(protoc-gen-c-typedef c_typedef.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(protoc-gen-c-typedef protobuf -lprotoc -pthread)

add_executable(protoc-gen-swift-typealias swift_typealias.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(protoc-gen-swift-typealias protobuf -lprotoc -pthread)
add_executable(protoc-gen-swift-typealias swift_typealias.cc)
target_link_libraries(protoc-gen-swift-typealias protobuf::libprotobuf protobuf::libprotoc)

install(TARGETS protoc-gen-c-typedef protoc-gen-swift-typealias DESTINATION bin)
2 changes: 1 addition & 1 deletion protobuf-plugin/c_typedef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Generator : public compiler::CodeGenerator {
return "TW" + proto_file.substr(0, index) + "Proto.h";
}

bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, std::string* error) const {
std::unique_ptr<io::ZeroCopyOutputStream> output(generator_context->Open(GetOutputFilename(file->name())));
io::Printer printer(output.get(), '$');

Expand Down
2 changes: 1 addition & 1 deletion protobuf-plugin/swift_typealias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Generator : public compiler::CodeGenerator {
return proto_file.substr(0, index) + "+Proto.swift";
}

bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, std::string* error) const {
std::unique_ptr<io::ZeroCopyOutputStream> output(generator_context->Open(GetOutputFilename(file->name())));
io::Printer printer(output.get(), '$');

Expand Down
6 changes: 3 additions & 3 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -3108,7 +3108,7 @@
"id": "polygon",
"name": "Polygon",
"coinId": 966,
"symbol": "MATIC",
"symbol": "POL",
"decimals": 18,
"blockchain": "Ethereum",
"derivation": [
Expand All @@ -3129,9 +3129,9 @@
},
"info": {
"url": "https://polygon.technology",
"source": "https://github.com/maticnetwork/contracts",
"source": "https://github.com/maticnetwork",
"rpc": "https://polygon-rpc.com",
"documentation": "https://eth.wiki/json-rpc/API"
"documentation": "https://docs.polygon.technology"
}
},
{
Expand Down
7 changes: 7 additions & 0 deletions rust/chains/tw_aptos/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::address::Address;
use crate::compiler::Compiler;
use crate::modules::transaction_util::AptosTransactionUtil;
use crate::signer::Signer;
use std::str::FromStr;
use tw_coin_entry::coin_context::CoinContext;
Expand Down Expand Up @@ -35,6 +36,7 @@ impl CoinEntry for AptosEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = AptosTransactionUtil;

#[inline]
fn parse_address(
Expand Down Expand Up @@ -102,4 +104,9 @@ impl CoinEntry for AptosEntry {
fn message_signer(&self) -> Option<Self::MessageSigner> {
None
}

#[inline]
fn transaction_util(&self) -> Option<Self::TransactionUtil> {
Some(AptosTransactionUtil)
}
}
1 change: 1 addition & 0 deletions rust/chains/tw_aptos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod nft;

pub mod compiler;
pub mod liquid_staking;
pub mod modules;
pub mod signer;
pub mod transaction;
pub mod transaction_builder;
Expand Down
5 changes: 5 additions & 0 deletions rust/chains/tw_aptos/src/modules/mod.rs
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;
35 changes: 35 additions & 0 deletions rust/chains/tw_aptos/src/modules/transaction_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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::sha3::sha3_256;

pub struct AptosTransactionUtil;

impl TransactionUtil for AptosTransactionUtil {
fn calc_tx_hash(&self, coin: &dyn CoinContext, encoded_tx: &str) -> SigningResult<String> {
Self::calc_tx_hash_impl(coin, encoded_tx)
}
}

impl AptosTransactionUtil {
fn calc_tx_hash_impl(_coin: &dyn CoinContext, encoded_tx: &str) -> SigningResult<String> {
let txn_bytes = hex::decode(encoded_tx).map_err(|_| SigningErrorType::Error_input_parse)?;

// See: https://github.com/aptos-labs/aptos-ts-sdk/blob/f54cac824a41e41dea09c7a6916858a8604dc901/src/api/transaction.ts#L118
let prefix = sha3_256("APTOS::Transaction".as_bytes());

let mut hash_message = Vec::new();
hash_message.extend_from_slice(&prefix);
// 0 is the index of the enum `Transaction`, see: https://github.com/aptos-labs/aptos-core/blob/6a130c1cca274a5cfdb4a65b441cd5fe61b6c15b/types/src/transaction/mod.rs#L1939
hash_message.push(0);
hash_message.extend_from_slice(&txn_bytes);

let tx_hash = sha3_256(&hash_message);
Ok(hex::encode(tx_hash, true))
}
}
2 changes: 2 additions & 0 deletions rust/chains/tw_binance/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tw_coin_entry::modules::json_signer::NoJsonSigner;
use tw_coin_entry::modules::message_signer::NoMessageSigner;
use tw_coin_entry::modules::plan_builder::NoPlanBuilder;
use tw_coin_entry::modules::transaction_decoder::NoTransactionDecoder;
use tw_coin_entry::modules::transaction_util::NoTransactionUtil;
use tw_keypair::tw::PublicKey;
use tw_proto::Binance::Proto;
use tw_proto::TxCompiler::Proto as CompilerProto;
Expand All @@ -35,6 +36,7 @@ impl CoinEntry for BinanceEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = BinanceWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = NoTransactionUtil;

#[inline]
fn parse_address(
Expand Down
7 changes: 7 additions & 0 deletions rust/chains/tw_cosmos/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use tw_cosmos_sdk::address::{Address, Bech32Prefix};
use tw_cosmos_sdk::context::StandardCosmosContext;
use tw_cosmos_sdk::modules::compiler::tw_compiler::TWTransactionCompiler;
use tw_cosmos_sdk::modules::signer::tw_signer::TWSigner;
use tw_cosmos_sdk::modules::transaction_util::CosmosTransactionUtil;
use tw_keypair::tw;
use tw_proto::Cosmos::Proto;
use tw_proto::TxCompiler::Proto as CompilerProto;
Expand All @@ -35,6 +36,7 @@ impl CoinEntry for CosmosEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = CosmosTransactionUtil<StandardCosmosContext>;

#[inline]
fn parse_address(
Expand Down Expand Up @@ -95,4 +97,9 @@ impl CoinEntry for CosmosEntry {
public_keys,
)
}

#[inline]
fn transaction_util(&self) -> Option<Self::TransactionUtil> {
Some(CosmosTransactionUtil::<StandardCosmosContext>::default())
}
}
7 changes: 7 additions & 0 deletions rust/chains/tw_ethereum/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use tw_evm::evm_entry::EvmEntry;
use tw_evm::modules::compiler::Compiler;
use tw_evm::modules::message_signer::EthMessageSigner;
use tw_evm::modules::signer::Signer;
use tw_evm::modules::transaction_util::EvmTransactionUtil;
use tw_keypair::tw::PublicKey;
use tw_proto::Ethereum::Proto;
use tw_proto::TxCompiler::Proto as CompilerProto;
Expand All @@ -37,6 +38,7 @@ impl CoinEntry for EthereumEntry {
type MessageSigner = EthMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = EvmTransactionUtil;

#[inline]
fn parse_address(
Expand Down Expand Up @@ -100,6 +102,11 @@ impl CoinEntry for EthereumEntry {
fn message_signer(&self) -> Option<Self::MessageSigner> {
Some(EthMessageSigner)
}

#[inline]
fn transaction_util(&self) -> Option<Self::TransactionUtil> {
Some(EvmTransactionUtil)
}
}

impl EvmEntry for EthereumEntry {
Expand Down
2 changes: 2 additions & 0 deletions rust/chains/tw_greenfield/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tw_coin_entry::modules::json_signer::NoJsonSigner;
use tw_coin_entry::modules::message_signer::NoMessageSigner;
use tw_coin_entry::modules::plan_builder::NoPlanBuilder;
use tw_coin_entry::modules::transaction_decoder::NoTransactionDecoder;
use tw_coin_entry::modules::transaction_util::NoTransactionUtil;
use tw_coin_entry::modules::wallet_connector::NoWalletConnector;
use tw_coin_entry::prefix::NoPrefix;
use tw_keypair::tw::PublicKey;
Expand All @@ -35,6 +36,7 @@ impl CoinEntry for GreenfieldEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = NoTransactionUtil;

#[inline]
fn parse_address(
Expand Down
3 changes: 2 additions & 1 deletion rust/chains/tw_internet_computer/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::str::FromStr;

use tw_coin_entry::modules::transaction_decoder::NoTransactionDecoder;
use tw_coin_entry::modules::transaction_util::NoTransactionUtil;
use tw_coin_entry::{
coin_context::CoinContext,
coin_entry::CoinEntry,
Expand All @@ -16,7 +17,6 @@ use tw_coin_entry::{
prefix::NoPrefix,
signing_output_error,
};

use tw_proto::{
Common::Proto::SigningError as CommonError, InternetComputer::Proto,
TxCompiler::Proto as CompilerProto,
Expand All @@ -39,6 +39,7 @@ impl CoinEntry for InternetComputerEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = NoTransactionUtil;

#[inline]
fn parse_address(
Expand Down
2 changes: 2 additions & 0 deletions rust/chains/tw_native_evmos/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use tw_coin_entry::modules::json_signer::NoJsonSigner;
use tw_coin_entry::modules::message_signer::NoMessageSigner;
use tw_coin_entry::modules::plan_builder::NoPlanBuilder;
use tw_coin_entry::modules::transaction_decoder::NoTransactionDecoder;
use tw_coin_entry::modules::transaction_util::NoTransactionUtil;
use tw_coin_entry::modules::wallet_connector::NoWalletConnector;
use tw_cosmos_sdk::address::{Address, Bech32Prefix};
use tw_cosmos_sdk::modules::compiler::tw_compiler::TWTransactionCompiler;
Expand All @@ -35,6 +36,7 @@ impl CoinEntry for NativeEvmosEntry {
type MessageSigner = NoMessageSigner;
type WalletConnector = NoWalletConnector;
type TransactionDecoder = NoTransactionDecoder;
type TransactionUtil = NoTransactionUtil;

#[inline]
fn parse_address(
Expand Down
Loading

0 comments on commit 7640110

Please sign in to comment.