GitHub Repository
You can find the Adventure Layer Slither at the following link:Adventure Layer ECS - Adventure Layer Slither.
The core modules of the Adventure Layer Slither are as follows.
1. Binding Independent Private Keys to Different Wallet Accounts
The Adventure Layer Slither allows binding independent private key accounts to different wallet accounts. Here’s how it works:-
Private Key Generation and Storage:
Inmud/util.ts, thegeneratePrivateKeyandprivateKeyToAccountfunctions are used to generate a private key and convert it into account information. The private key can be stored in local storage for future use. -
Private Key Validation:
Also inmud/util.ts, theassertPrivateKeyfunction is employed to validate the private key, ensuring it is in hexadecimal format and can successfully extract the corresponding address.
Relevant Code Snippet
2. AGL Table Structure
Inmud.config.ts, multiple AGL tables are defined, including:
- Users
- GameCodeToGameState
- UserToOthersPositions
- UserToOwnPositions
- UserToSnakeDeque
- Balance
- UserAccountMapping
Code Snippet
3. Main Contracts
IWorld.sol
This interface integrates all systems and associated function selectors that are dynamically registered in the World during deployment.BalanceSystem.sol
This contract handles balance-related operations for the game, including starting a game, querying balances, setting game fees, and managing player balances.UsersSystem.sol
This contract manages user-related operations, such as retrieving user data, starting a game, adding users, and generating random numbers.4.Heartbeat Mechanism Implementation
-
Contract Task Management:
- The
ManageContractTaskfunction is used to start or stop the polling tasks for the contract, managing these tasks throughcontractMap.
- The
-
Heartbeat Mechanism:
- The
startPollingfunction uses the ABI of theadventureHeatbeatfunction to package data and periodically send transactions via a timer. - The transaction sending is implemented by constructing, signing, and submitting the transaction.
- The
-
Concurrency Control:
- The use of
sync.Mutexensures that the transaction sending is thread-safe.
- The use of
-
Periodic Invocation:
- The periodic invocation is implemented through
time.Sleep(task.Interval), whereIntervalis the time interval in milliseconds.
- The periodic invocation is implemented through
adventureHeatbeat function can be regularly called at specified time intervals, thus achieving the heartbeat function. Each call may trigger random refreshes of food in the game, among other operations.
