-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli,world): move helper functions into world package, add ge…
…tWorldAbi (#3012)
- Loading branch information
Showing
10 changed files
with
112 additions
and
24 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
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 @@ | ||
import { Hex } from "viem"; | ||
|
||
export type WorldFunction = { | ||
readonly signature: string; | ||
readonly selector: Hex; | ||
readonly systemId: Hex; | ||
readonly systemFunctionSignature: string; | ||
readonly systemFunctionSelector: Hex; | ||
}; |
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,10 @@ | ||
import createDebug from "debug"; | ||
|
||
export const debug = createDebug("mud:world"); | ||
export const error = createDebug("mud:world"); | ||
|
||
// Pipe debug output to stdout instead of stderr | ||
debug.log = console.debug.bind(console); | ||
|
||
// Pipe error output to stderr | ||
error.log = console.error.bind(console); |
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 { AbiItem, parseAbiItem } from "viem"; | ||
|
||
export function functionSignatureToAbiItem(functionSignature: string): AbiItem { | ||
const formattedSignature = `function ${functionSignature}`; | ||
return parseAbiItem(formattedSignature); | ||
} |
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,27 @@ | ||
import { Client, Abi, Address, getAddress } from "viem"; | ||
import IBaseWorldAbi from "../out/IBaseWorld.sol/IBaseWorld.abi.json"; | ||
import { functionSignatureToAbiItem } from "./functionSignatureToAbiItem"; | ||
import { getFunctions } from "./getFunctions"; | ||
|
||
export async function getWorldAbi({ | ||
client, | ||
worldAddress, | ||
fromBlock, | ||
toBlock, | ||
}: { | ||
readonly client: Client; | ||
readonly worldAddress: Address; | ||
readonly fromBlock: bigint; | ||
readonly toBlock: bigint; | ||
}): Promise<Abi> { | ||
const worldFunctions = await getFunctions({ | ||
client, | ||
worldAddress: getAddress(worldAddress), | ||
fromBlock, | ||
toBlock, | ||
}); | ||
const worldFunctionsAbi = worldFunctions.map((func) => functionSignatureToAbiItem(func.signature)); | ||
const abi = [...IBaseWorldAbi, ...worldFunctionsAbi]; | ||
|
||
return abi; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.