forked from trezor/trezor-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connect): implement ethereum rpc call
- Loading branch information
Showing
7 changed files
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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'; | ||
|
||
type Params = { | ||
coinInfo: CoinInfo; | ||
identity?: string; | ||
request: EthereumCallSchema; | ||
}; | ||
|
||
export default class EthereumCall extends AbstractMethod<'ethereumCall', Params> { | ||
init() { | ||
this.useDevice = false; | ||
this.useUi = false; | ||
|
||
const { payload } = this; | ||
|
||
// validate incoming parameters | ||
validateParams(payload, [ | ||
{ name: 'coin', type: 'string', required: true }, | ||
{ name: 'identity', type: 'string' }, | ||
{ name: 'from', type: 'string' }, | ||
{ name: 'to', type: 'string', required: true }, | ||
{ name: 'data', type: 'string', required: true }, | ||
]); | ||
|
||
const coinInfo = getCoinInfo(payload.coin); | ||
|
||
if (!coinInfo) { | ||
throw ERRORS.TypedError('Method_UnknownCoin'); | ||
} | ||
// validate backend | ||
isBackendSupported(coinInfo); | ||
|
||
this.params = { | ||
coinInfo, | ||
identity: payload.identity, | ||
request: { | ||
from: payload.from, | ||
to: payload.to, | ||
data: payload.data, | ||
}, | ||
}; | ||
} | ||
|
||
get info() { | ||
return 'Ethereum call'; | ||
} | ||
|
||
async run() { | ||
const backend = await initBlockchain( | ||
this.params.coinInfo, | ||
postMessage, | ||
this.params.identity, | ||
); | ||
const response = await backend.ethereumCall(this.params.request); | ||
|
||
return response; | ||
} | ||
} |
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
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,6 @@ | ||
import type { CommonParamsWithCoin, Params, Response } from '../params'; | ||
import type { EthereumCall } from './ethereum'; | ||
|
||
export declare function ethereumCall( | ||
params: CommonParamsWithCoin & Params<EthereumCall>, | ||
): Response<{ data: string }>; |
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