-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ee0f23
commit 9c22599
Showing
10 changed files
with
186 additions
and
5 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 |
---|---|---|
|
@@ -36,3 +36,6 @@ false/* | |
*.sh | ||
|
||
largest1k | ||
|
||
bun.lockb | ||
node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,9 @@ | ||
# Example: Invoking Heimdall via TypeScript | ||
|
||
This TypeScript script demonstrates how to use the `heimdall` CLI tool to decode calldata via TypeScript. It provides a simple class structure to define arguments and manage the decode process, with support for customizing various decode options. | ||
|
||
_Note: This is just an example for the decode module, but a similar approach will work for all heimdall modules._ | ||
|
||
## Overview | ||
|
||
The script utilizes the `heimdall decode` command to decode a target. For ease of use, the script abstracts the command-line interface of `heimdall` into a TS class, allowing users to easily call the decode process in their TS projects. |
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,103 @@ | ||
import { execSync } from 'child_process'; | ||
import * as fs from 'fs'; | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
|
||
interface DecodeArgsOptions { | ||
target: string; | ||
rpc_url?: string; | ||
default?: boolean; | ||
skip_resolving?: boolean; | ||
raw?: boolean; | ||
} | ||
|
||
class DecodeArgs { | ||
public target: string; | ||
public rpc_url: string; | ||
public default: boolean; | ||
public skip_resolving: boolean; | ||
public raw: boolean; | ||
|
||
constructor( | ||
target: string, | ||
rpc_url: string = "", | ||
useDefault: boolean = false, | ||
skip_resolving: boolean = false, | ||
raw: boolean = false | ||
) { | ||
this.target = target; | ||
this.rpc_url = rpc_url; | ||
this.default = useDefault; | ||
this.skip_resolving = skip_resolving; | ||
this.raw = raw; | ||
} | ||
} | ||
|
||
class Decoder { | ||
private args: DecodeArgs; | ||
|
||
constructor(args: DecodeArgs) { | ||
this.args = args; | ||
} | ||
|
||
public decode(): any | null { | ||
try { | ||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'decoder-')); | ||
|
||
const command = ['decode', this.args.target, ]; | ||
|
||
if (this.args.rpc_url) { | ||
command.push('--rpc-url', this.args.rpc_url); | ||
} | ||
if (this.args.default) { | ||
command.push('--default'); | ||
} | ||
if (this.args.skip_resolving) { | ||
command.push('--skip-resolving'); | ||
} | ||
if (this.args.raw) { | ||
command.push('--raw'); | ||
} | ||
|
||
// Execute heimdall command | ||
execSync(`heimdall ${command.join(' ')}`, { stdio: 'inherit' }); | ||
|
||
// Here you would read and parse the output from `tempDir` | ||
// For now, we return null since the original code doesn't show the parsing step. | ||
return null; | ||
} catch (e) { | ||
console.error("Error: ", e); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
function isHeimdallInstalled(): boolean { | ||
try { | ||
execSync('which heimdall', { stdio: 'pipe' }); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
function main() { | ||
if (!isHeimdallInstalled()) { | ||
console.log("heimdall does not seem to be installed on your system."); | ||
console.log("please install heimdall before running this script."); | ||
return; | ||
} | ||
|
||
const args = new DecodeArgs( | ||
"0x000000000000000000000000008dfede2ef0e61578c3bba84a7ed4b9d25795c30000000000000000000000000000000000000001431e0fae6d7217caa00000000000000000000000000000000000000000000000000000000000000000002710fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc7c0000000000000000000000000000000000000000000000a6af776004abf4e612ad000000000000000000000000000000000000000000000000000000012a05f20000000000000000000000000000000000000000000000000000000000000111700000000000000000000000001c5f545f5b46f76e440fa02dabf88fdc0b10851a00000000000000000000000000000000000000000000000000000002540be400", | ||
"", | ||
false, | ||
false, | ||
true | ||
); | ||
|
||
const decoded = new Decoder(args).decode(); | ||
console.log("Decoded Result:", decoded); | ||
} | ||
|
||
main(); |
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,16 @@ | ||
{ | ||
"name": "heimdall-ts", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"decode": "tsx index.ts" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/node": "^20.0.0", | ||
"ts-node": "^10.9.2", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.5.4" | ||
} | ||
} |