-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation check for Debug endpoints and eth_sendTransaction endp…
…oint (#570) * fix: change a little bit debug rpc output endpoints * fix: typo
- Loading branch information
1 parent
bafa919
commit bf215d8
Showing
12 changed files
with
196 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { type TraceReturnType } from '@vechain/vechain-sdk-network/src/thor-client/debug'; | ||
import { type TracerNameRPC, type TracerReturnTypeRPC } from './types'; | ||
|
||
/** | ||
* Output formatter for RPC debug endpoints: | ||
* * debug_traceTransaction | ||
* * debug_traceCall | ||
* It converts our endpoint calls output to the RPC standard output. | ||
* | ||
* @param tracerName - Tracer name used for the debug endpoint. | ||
* @param debugDetails - Debug details to be formatted. | ||
*/ | ||
function formatToRPCStandard<TDebugType extends TracerNameRPC>( | ||
tracerName: TDebugType, | ||
debugDetails: TraceReturnType<TDebugType> | ||
): TracerReturnTypeRPC<'call'> | TracerReturnTypeRPC<'prestate'> { | ||
if (tracerName === 'call') { | ||
return { | ||
...(debugDetails as TraceReturnType<'call'>), | ||
|
||
// Empty revert reason | ||
revertReason: '' | ||
} satisfies TracerReturnTypeRPC<'call'>; | ||
} | ||
|
||
return Object.fromEntries( | ||
Object.entries(debugDetails as TraceReturnType<'prestate'>).map( | ||
([key, value]) => { | ||
const valueWithoutEnergy = { | ||
balance: value.balance, | ||
code: value.code, | ||
storage: value.storage | ||
} satisfies Omit< | ||
{ | ||
balance: string; | ||
energy: string; | ||
code?: string; | ||
storage?: Record<string, string>; | ||
}, | ||
'energy' | ||
>; | ||
|
||
return [key, { ...valueWithoutEnergy, nonce: 0 }]; | ||
} | ||
) | ||
) satisfies TracerReturnTypeRPC<'prestate'>; | ||
} | ||
|
||
export { formatToRPCStandard }; |
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,8 @@ | ||
import { formatToRPCStandard } from './formatter'; | ||
|
||
export * from './formatter'; | ||
export * from './types.d'; | ||
|
||
export const debugFormatter = { | ||
formatToRPCStandard | ||
}; |
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,58 @@ | ||
import { type TraceReturnType } from '@vechain/vechain-sdk-network/src/thor-client/debug'; | ||
|
||
/** | ||
* Return type for the following RPC endpoints: | ||
* * debug_traceTransaction | ||
* * debug_traceCall | ||
*/ | ||
type TracerReturnTypeRPC<TracerNameType extends TracerNamesRPC> = | ||
TracerNameType extends 'call' ? CallTracerRPC : PrestateTracerRPC; | ||
|
||
/** | ||
* Available tracers for the RPC standard. | ||
*/ | ||
type TracerNameRPC = 'call' | 'prestate'; | ||
|
||
/** | ||
* The return type of the 'call' tracer for the RPC standard. | ||
*/ | ||
type CallTracerRPC = TraceReturnType<'call'> & { | ||
/** | ||
* Same of the 'call' tracer of vechain, | ||
* BUT with the addition of the revertReason field. | ||
* | ||
* @note This is not part of the vechain's 'call' tracer. | ||
* For this reason, it will have a default value of ''. | ||
*/ | ||
revertReason?: ''; | ||
}; | ||
|
||
/** | ||
* The return type of the 'prestate' tracer for the RPC standard. | ||
*/ | ||
type PrestateTracerRPC = Record< | ||
string, | ||
{ | ||
balance: string; | ||
code?: string; | ||
storage?: Record<string, string>; | ||
|
||
/** | ||
* Same of the 'prestate' tracer of vechain, | ||
* BUT with the addition of the nonce field. | ||
* This field substitutes the 'energy' field | ||
* of the vechain's 'prestate' tracer. | ||
* | ||
* @note This is not part of the vechain's 'prestate' tracer. | ||
* For this reason, it will have a default value of 0. | ||
*/ | ||
nonce: 0; | ||
} | ||
>; | ||
|
||
export type { | ||
TracerReturnTypeRPC, | ||
TracerNameRPC, | ||
CallTracerRPC, | ||
PrestateTracerRPC | ||
}; |
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
2 changes: 2 additions & 0 deletions
2
packages/provider/src/utils/rpc-mapper/methods-map/methods/debug_traceTransaction/index.ts
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,2 @@ | ||
export * from './debug_traceTransaction'; | ||
export * from './types.d'; |
11 changes: 11 additions & 0 deletions
11
packages/provider/src/utils/rpc-mapper/methods-map/methods/debug_traceTransaction/types.d.ts
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,11 @@ | ||
/** | ||
* Type for trace options | ||
*/ | ||
interface TraceOptionsRPC { | ||
tracer: 'callTracer' | 'prestateTracer'; | ||
tracerConfig?: { onlyTopCall?: boolean }; | ||
// Not supported yet | ||
timeout?: string; | ||
} | ||
|
||
export type { TraceOptionsRPC }; |
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
Oops, something went wrong.
bf215d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test Coverage
Summary