diff --git a/packages/blockchain-link-types/src/blockbook.ts b/packages/blockchain-link-types/src/blockbook.ts index 5ea2ab45c131..edc292574b66 100644 --- a/packages/blockchain-link-types/src/blockbook.ts +++ b/packages/blockchain-link-types/src/blockbook.ts @@ -6,6 +6,7 @@ import type { GetFiatRatesForTimestampsParams, GetFiatRatesTickersListParams, EstimateFeeParams, + EthereumCallParams, AccountInfoParams, } from './params'; import type { AccountBalanceHistory, FiatRatesBySymbol, TokenStandard } from './common'; @@ -210,6 +211,7 @@ declare function FSend( params: GetFiatRatesForTimestampsParams, ): Promise; declare function FSend(method: 'estimateFee', params: EstimateFeeParams): Promise; +declare function FSend(method: 'rpcCall', params: EthereumCallParams): Promise<{ data: string }>; declare function FSend( method: 'subscribeAddresses', params: { addresses: string[] }, diff --git a/packages/blockchain-link-types/src/constants/messages.ts b/packages/blockchain-link-types/src/constants/messages.ts index 7b3ba7305d4e..b8ba014ff013 100644 --- a/packages/blockchain-link-types/src/constants/messages.ts +++ b/packages/blockchain-link-types/src/constants/messages.ts @@ -14,6 +14,7 @@ export const GET_ACCOUNT_UTXO = 'm_get_account_utxo'; export const GET_TRANSACTION = 'm_get_transaction'; export const GET_TRANSACTION_HEX = 'm_get_transaction_hex'; export const ESTIMATE_FEE = 'm_estimate_fee'; +export const ETHEREUM_CALL = 'm_ethereum_call'; export const SUBSCRIBE = 'm_subscribe'; export const UNSUBSCRIBE = 'm_unsubscribe'; export const PUSH_TRANSACTION = 'm_push_tx'; diff --git a/packages/blockchain-link-types/src/constants/responses.ts b/packages/blockchain-link-types/src/constants/responses.ts index 313b58f16dec..4ed4887edbaa 100644 --- a/packages/blockchain-link-types/src/constants/responses.ts +++ b/packages/blockchain-link-types/src/constants/responses.ts @@ -13,6 +13,7 @@ export const GET_ACCOUNT_BALANCE_HISTORY = 'r_get_account_balance_history'; export const GET_TRANSACTION = 'r_get_transaction'; export const GET_TRANSACTION_HEX = 'r_get_transaction_hex'; export const ESTIMATE_FEE = 'r_estimate_fee'; +export const ETHEREUM_CALL = 'r_ethereum_call'; export const SUBSCRIBE = 'r_subscribe'; export const UNSUBSCRIBE = 'r_unsubscribe'; export const PUSH_TRANSACTION = 'r_push_tx'; diff --git a/packages/blockchain-link-types/src/messages.ts b/packages/blockchain-link-types/src/messages.ts index 64d09f7e67aa..5cad21570eff 100644 --- a/packages/blockchain-link-types/src/messages.ts +++ b/packages/blockchain-link-types/src/messages.ts @@ -6,6 +6,7 @@ import type { GetFiatRatesForTimestampsParams, GetFiatRatesTickersListParams, EstimateFeeParams, + EthereumCallParams, AccountInfoParams, } from './params'; @@ -77,6 +78,11 @@ export interface EstimateFee { payload: EstimateFeeParams; } +export interface EthereumCall { + type: typeof MESSAGES.ETHEREUM_CALL; + payload: EthereumCallParams; +} + export interface Subscribe { type: typeof MESSAGES.SUBSCRIBE; payload: @@ -144,6 +150,7 @@ export type Message = | ChannelMessage | ChannelMessage | ChannelMessage + | ChannelMessage | ChannelMessage | ChannelMessage | ChannelMessage; diff --git a/packages/blockchain-link-types/src/params.ts b/packages/blockchain-link-types/src/params.ts index a5bbf4428436..3995feddf501 100644 --- a/packages/blockchain-link-types/src/params.ts +++ b/packages/blockchain-link-types/src/params.ts @@ -35,6 +35,12 @@ export interface EstimateFeeParams { }; } +export interface EthereumCallParams { + from: string; + to: string; + data: string; +} + export interface AccountInfoParams { descriptor: string; // address or xpub details?: 'basic' | 'tokens' | 'tokenBalances' | 'txids' | 'txs'; // depth, default: 'basic' diff --git a/packages/blockchain-link-types/src/responses.ts b/packages/blockchain-link-types/src/responses.ts index 5a88dbedf0f9..a59c51f6e182 100644 --- a/packages/blockchain-link-types/src/responses.ts +++ b/packages/blockchain-link-types/src/responses.ts @@ -101,6 +101,13 @@ export interface EstimateFee { }[]; } +export interface EthereumCall { + type: typeof RESPONSES.ETHEREUM_CALL; + payload: { + data: string; + }; +} + export interface Subscribe { type: typeof RESPONSES.SUBSCRIBE; payload: { subscribed: boolean }; @@ -173,6 +180,7 @@ export type Response = | ChannelMessage | ChannelMessage | ChannelMessage + | ChannelMessage | ChannelMessage | ChannelMessage | ChannelMessage diff --git a/packages/blockchain-link/src/index.ts b/packages/blockchain-link/src/index.ts index 407483353c51..70067ee37d06 100644 --- a/packages/blockchain-link/src/index.ts +++ b/packages/blockchain-link/src/index.ts @@ -229,6 +229,15 @@ class BlockchainLink extends TypedEmitter { }); } + ethereumCall( + payload: MessageTypes.EthereumCall['payload'], + ): Promise { + return this.sendMessage({ + type: MESSAGES.ETHEREUM_CALL, + payload, + }); + } + /** * Subscribe for live changes in * - blockchain i.e new blocks mined. diff --git a/packages/blockchain-link/src/workers/blockbook/index.ts b/packages/blockchain-link/src/workers/blockbook/index.ts index 58c1b428265f..4830ef6c5098 100644 --- a/packages/blockchain-link/src/workers/blockbook/index.ts +++ b/packages/blockchain-link/src/workers/blockbook/index.ts @@ -163,6 +163,16 @@ const estimateFee = async (request: Request) => { } as const; }; +const ethereumCall = async (request: Request) => { + const api = await request.connect(); + const resp = await api.ethereumCall(request.payload); + + return { + type: RESPONSES.ETHEREUM_CALL, + payload: resp, + } as const; +}; + const onNewBlock = ({ post }: Context, event: BlockNotification) => { post({ id: -1, @@ -417,6 +427,8 @@ const onRequest = (request: Request) => { return getFiatRatesTickersList(request); case MESSAGES.ESTIMATE_FEE: return estimateFee(request); + case MESSAGES.ETHEREUM_CALL: + return ethereumCall(request); case MESSAGES.PUSH_TRANSACTION: return pushTransaction(request); case MESSAGES.SUBSCRIBE: diff --git a/packages/blockchain-link/src/workers/blockbook/websocket.ts b/packages/blockchain-link/src/workers/blockbook/websocket.ts index bfa6862946f5..aad9ed1b8d4e 100644 --- a/packages/blockchain-link/src/workers/blockbook/websocket.ts +++ b/packages/blockchain-link/src/workers/blockbook/websocket.ts @@ -18,6 +18,7 @@ import type { AccountInfoParams, EstimateFeeParams, AccountBalanceHistoryParams, + EthereumCallParams, } from '@trezor/blockchain-link-types/src/params'; import { BaseWebsocket } from '../baseWebsocket'; @@ -126,6 +127,10 @@ export class BlockbookAPI extends BaseWebsocket { return this.send('estimateFee', payload); } + ethereumCall(payload: EthereumCallParams) { + return this.send('rpcCall', payload); + } + getCurrentFiatRates(payload: GetCurrentFiatRates['payload']) { return this.send('getCurrentFiatRates', payload); }