Skip to content

Commit

Permalink
fixup! feat(connect): implement ethereum rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl committed Oct 21, 2024
1 parent 324e9c4 commit a854667
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { AbstractMethod } from '../../../core/AbstractMethod';
import { validateParams } from '../../common/paramsValidator';
import { ERRORS } from '../../../constants';
import { CoinInfo, EthereumCall as EthereumCallSchema } from '../../../types';
import { initBlockchain, isBackendSupported } from '../../../backend/BlockchainLink';
import { getCoinInfo } from '../../../data/coinInfo';
import { AbstractMethod, Payload } from '../core/AbstractMethod';
import { validateParams } from './common/paramsValidator';
import { ERRORS } from '../constants';
import { CoinInfo } from '../types';
import { initBlockchain, isBackendSupported } from '../backend/BlockchainLink';
import { getCoinInfo } from '../data/coinInfo';

type Params = {
coinInfo: CoinInfo;
identity?: string;
request: EthereumCallSchema;
request: Omit<Payload<'blockchainEvmRpcCall'>, 'method' | 'coin'>;
};

export default class EthereumCall extends AbstractMethod<'ethereumCall', Params> {
export default class BlockchainEvmRpcCall extends AbstractMethod<'blockchainEvmRpcCall', Params> {
init() {
this.useDevice = false;
this.useUi = false;
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class EthereumCall extends AbstractMethod<'ethereumCall', Params>
}

get info() {
return 'Ethereum call';
return 'Blockchain Evm Rpc Call';
}

async run() {
Expand All @@ -56,7 +56,7 @@ export default class EthereumCall extends AbstractMethod<'ethereumCall', Params>
postMessage,
this.params.identity,
);
const response = await backend.ethereumCall(this.params.request);
const response = await backend.rpcCall(this.params.request);

return response;
}
Expand Down
1 change: 0 additions & 1 deletion packages/connect/src/api/ethereum/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export { default as ethereumSignMessage } from './ethereumSignMessage';
export { default as ethereumSignTransaction } from './ethereumSignTransaction';
export { default as ethereumSignTypedData } from './ethereumSignTypedData';
export { default as ethereumVerifyMessage } from './ethereumVerifyMessage';
export { default as ethereumCall } from './ethereumCall';
1 change: 1 addition & 0 deletions packages/connect/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { default as blockchainDisconnect } from './blockchainDisconnect';
export { default as blockchainEstimateFee } from './blockchainEstimateFee';
export { default as blockchainGetAccountBalanceHistory } from './blockchainGetAccountBalanceHistory';
export { default as blockchainGetCurrentFiatRates } from './blockchainGetCurrentFiatRates';
export { default as blockchainEvmRpcCall } from './blockchainEvmRpcCall';
export { default as blockchainGetFiatRatesForTimestamps } from './blockchainGetFiatRatesForTimestamps';
export { default as blockchainGetTransactions } from './blockchainGetTransactions';
export { default as blockchainSetCustomBackend } from './blockchainSetCustomBackend';
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/backend/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ export class Blockchain {
return this.link.getAccountUtxo(descriptor);
}

ethereumCall(params: BlockchainLinkParams<'ethereumCall'>) {
return this.link.ethereumCall(params);
rpcCall(params: BlockchainLinkParams<'rpcCall'>) {
return this.link.rpcCall(params);
}

async estimateFee(request: Parameters<typeof this.link.estimateFee>[0]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/connect/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const factory = ({
blockchainGetCurrentFiatRates: params =>
call({ ...params, method: 'blockchainGetCurrentFiatRates' }),

blockchainEvmRpcCall: params => call({ ...params, method: 'blockchainEvmRpcCall' }),

blockchainGetFiatRatesForTimestamps: params =>
call({ ...params, method: 'blockchainGetFiatRatesForTimestamps' }),

Expand Down Expand Up @@ -125,8 +127,6 @@ export const factory = ({

ethereumVerifyMessage: params => call({ ...params, method: 'ethereumVerifyMessage' }),

ethereumCall: params => call({ ...params, method: 'ethereumCall' }),

getAccountDescriptor: params => call({ ...params, method: 'getAccountDescriptor' }),

getAccountInfo: params => call({ ...params, method: 'getAccountInfo' }),
Expand Down
6 changes: 6 additions & 0 deletions packages/connect/src/types/api/blockchainEvmRpcCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BlockchainLinkParams, BlockchainLinkResponse } from '@trezor/blockchain-link';
import type { CommonParamsWithCoin, Response } from '../params';

export declare function blockchainEvmRpcCall(
params: CommonParamsWithCoin & BlockchainLinkParams<'rpcCall'>,
): Response<BlockchainLinkResponse<'rpcCall'>>;
9 changes: 0 additions & 9 deletions packages/connect/src/types/api/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,3 @@ export const EthereumVerifyMessage = Type.Object({
hex: Type.Optional(Type.Boolean()),
signature: Type.String(),
});

// ethereumCall

export type EthereumCall = Static<typeof EthereumCall>;
export const EthereumCall = Type.Object({
from: Type.String(),
to: Type.String(),
data: Type.String(),
});
6 changes: 0 additions & 6 deletions packages/connect/src/types/api/ethereumCall.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/connect/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { blockchainDisconnect } from './blockchainDisconnect';
import { blockchainEstimateFee } from './blockchainEstimateFee';
import { blockchainGetAccountBalanceHistory } from './blockchainGetAccountBalanceHistory';
import { blockchainGetCurrentFiatRates } from './blockchainGetCurrentFiatRates';
import { blockchainEvmRpcCall } from './blockchainEvmRpcCall';
import { blockchainGetFiatRatesForTimestamps } from './blockchainGetFiatRatesForTimestamps';
import { blockchainGetTransactions } from './blockchainGetTransactions';
import { blockchainSetCustomBackend } from './blockchainSetCustomBackend';
Expand Down Expand Up @@ -40,7 +41,6 @@ import { ethereumSignMessage } from './ethereumSignMessage';
import { ethereumSignTransaction } from './ethereumSignTransaction';
import { ethereumSignTypedData } from './ethereumSignTypedData';
import { ethereumVerifyMessage } from './ethereumVerifyMessage';
import { ethereumCall } from './ethereumCall';
import { firmwareUpdate } from './firmwareUpdate';
import { getAccountDescriptor } from './getAccountDescriptor';
import { getAccountInfo } from './getAccountInfo';
Expand Down Expand Up @@ -131,6 +131,8 @@ export interface TrezorConnect {
// todo: link docs
blockchainGetCurrentFiatRates: typeof blockchainGetCurrentFiatRates;

blockchainEvmRpcCall: typeof blockchainEvmRpcCall;

// todo: link docs
blockchainGetFiatRatesForTimestamps: typeof blockchainGetFiatRatesForTimestamps;

Expand Down Expand Up @@ -218,8 +220,6 @@ export interface TrezorConnect {
// https://connect.trezor.io/9/methods/ethereum/ethereumVerifyMessage/
ethereumVerifyMessage: typeof ethereumVerifyMessage;

ethereumCall: typeof ethereumCall;

// https://connect.trezor.io/9/methods/device/firmwareUpdate/
firmwareUpdate: typeof firmwareUpdate;

Expand Down

0 comments on commit a854667

Please sign in to comment.