Skip to content

Commit

Permalink
escrowMapping contract update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanX21 committed Sep 7, 2024
1 parent 16cdc31 commit 7a8d6eb
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 958 deletions.
10 changes: 10 additions & 0 deletions packages/backend/ninja/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# flyctl launch added from .gitignore
**/*.sqlite
**/node_modules
**/build
**/bun.lockb
**/stackr_build
**/.env
**/dist
**/.vercel
fly.toml
4 changes: 2 additions & 2 deletions packages/backend/ninja/deployment.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"appId": 101,
"appInbox": "0xaf4a15008892e5Ca30B04A70891834c38d4b88b6",
"appId": 110,
"appInbox": "0x0d5aFA71F688B480469D9686C9C946910C804535",
"chainId": 11155111
}
46 changes: 46 additions & 0 deletions packages/hardhat/contracts/EscrowMapping.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract EscrowGameMapping {
address public owner;

// Mapping from EscrowId (uint256) to GameId (bytes32)
mapping(uint256 => bytes32) public escrowToGame;

// Event to log the mapping creation
event MappingCreated(uint256 indexed escrowId, bytes32 indexed gameId);

// Modifier to restrict function access to the owner
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}

// Constructor to set the contract deployer as the initial owner
constructor() {
owner = msg.sender;
}

// Function to transfer ownership to a new address (only callable by the current owner)
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner is the zero address");
owner = newOwner;
}

// Function to create a new mapping between EscrowId and GameId
function createMapping(uint256 escrowId, bytes32 gameId) public onlyOwner {
// Ensure that the EscrowId is not already mapped
require(escrowToGame[escrowId] == bytes32(0), "EscrowId is already mapped to a GameId.");

// Create the mapping
escrowToGame[escrowId] = gameId;

// Emit the event
emit MappingCreated(escrowId, gameId);
}

// Function to retrieve the GameId for a given EscrowId
function getGameId(uint256 escrowId) public view returns (bytes32) {
return escrowToGame[escrowId];
}
}
31 changes: 31 additions & 0 deletions packages/hardhat/deploy/03_deploy_escrow_mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { Contract } from "ethers";

/**
* Deploys a contract named "EscrowGameMapping" using the deployer account
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployEscrowGameMapping: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

// Deploy the contract
await deploy("EscrowGameMapping", {
from: deployer,
args: [], // No constructor arguments
log: true,
autoMine: true,
});

// Get the deployed contract to interact with it after deploying.
const escrowGameMapping: Contract = await hre.ethers.getContract<Contract>("EscrowGameMapping", deployer);
console.log("🥷🏻 Deployed", await escrowGameMapping.getAddress());
};

export default deployEscrowGameMapping;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags EscrowGameMapping
deployEscrowGameMapping.tags = ["EscrowGameMapping"];
File renamed without changes.
Loading

0 comments on commit 7a8d6eb

Please sign in to comment.