Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/escrow envio #9

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
15 changes: 15 additions & 0 deletions packages/backend/ninja/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 2,
"builds": [
{
"src": "./src/index.ts",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "./src/index.ts"
}
]
}
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"];
Loading
Loading