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

CCP Red Dragon/Turret Whitelist Example + Smart Gate Corp Whitelist #52

Draft
wants to merge 22 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 21 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
6 changes: 4 additions & 2 deletions smart-gate/packages/contracts/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ PLAYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f
RPC_URL="http://127.0.0.1:8545"
CHAIN_ID=31337


# SMART GATE CONFIG
# Copy this info from in game smart gate
SOURCE_GATE_ID=34818344039668088032259299209624217066809194721387714788472158182502870248994

# Copy this info from in game smart gate
DESTINATION_GATE_ID=67387866010353549996346280963079126762450299713900890730943797543376801696007
DESTINATION_GATE_ID=67387866010353549996346280963079126762450299713900890730943797543376801696007

# Allowed corp
WHITELISTED_CORP_ID=3434306
9 changes: 8 additions & 1 deletion smart-gate/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "test",
namespace: "dapp_dev2",
tables: {
GateAccess: {
schema: {
smartObjectId: "uint256",
corp: "uint256"
},
key: ["smartObjectId"],
}
},
});
6 changes: 5 additions & 1 deletion smart-gate/packages/contracts/script/CanJump.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ contract CanJump is Script {
uint256 sourceGateId = vm.envUint("SOURCE_GATE_ID");
uint256 destinationGateId = vm.envUint("DESTINATION_GATE_ID");

console.log(smartGate.canJump(11111, sourceGateId, destinationGateId));
console.log("-------------------\nTESTING INCORRECT CORP");
console.log("Can Jump:", smartGate.canJump(1234, sourceGateId, destinationGateId));

console.log("-------------------\nTESTING CORRECT CORP");
console.log("Can Jump:", smartGate.canJump(666666666, sourceGateId, destinationGateId));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we bring the character id from .env ?


vm.stopBroadcast();
}
Expand Down
7 changes: 7 additions & 0 deletions smart-gate/packages/contracts/script/ConfigureSmartGate.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Utils } from "../src/systems/Utils.sol";
import { Utils as SmartGateUtils } from "@eveworld/world/src/modules/smart-gate/Utils.sol";
import { SmartGateLib } from "@eveworld/world/src/modules/smart-gate/SmartGateLib.sol";
import { FRONTIER_WORLD_DEPLOYMENT_NAMESPACE } from "@eveworld/common-constants/src/constants.sol";
import { GateAccess } from "../src/codegen/tables/GateAccess.sol";

contract ConfigureSmartGate is Script {
using SmartGateUtils for bytes14;
Expand All @@ -34,6 +35,12 @@ contract ConfigureSmartGate is Script {
//This function can only be called by the owner of the smart turret
smartGate.configureSmartGate(smartGateId, systemId);

//Get the whitelisted corp
uint256 corpID = vm.envUint("WHITELISTED_CORP_ID");

//Set the MUD table for the corp whitelist
GateAccess.set(smartGateId, corpID);

vm.stopBroadcast();
}
}
7 changes: 4 additions & 3 deletions smart-gate/packages/contracts/script/MockData.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ contract MockData is Script {
//Create a smart character
if (CharactersByAddressTable.get(player) == 0) {
smartCharacter.createCharacter(
666666666,
player,
3434306,
666666666, //Character ID
player, // Character Address
34343061, // Corp ID
CharacterEntityRecord({ typeId: 123, itemId: 234, volume: 100 }),
EntityRecordOffchainTableData({ name: "characterName", dappURL: "noURL", description: "." }),
""
);
}

//Anchor both smart gates
anchorFuelAndOnline(sourceGateId, player);
anchorFuelAndOnline(destinationGateId, player);

Expand Down
16 changes: 15 additions & 1 deletion smart-gate/packages/contracts/src/systems/SmartGateSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.
import { System } from "@latticexyz/world/src/System.sol";
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";

import { CharactersTable } from "@eveworld/world/src/codegen/tables/CharactersTable.sol";
import { GateAccess } from "../codegen/tables/GateAccess.sol";

/**
* @dev This contract is an example for implementing logic to a smart gate
*/
contract SmartGateSystem is System {
function canJump(uint256 characterId, uint256 sourceGateId, uint256 destinationGateId) public view returns (bool) {
return false;
//Get the allowed corp
uint256 allowedCorp = GateAccess.get(sourceGateId);

//Get the character corp
uint256 characterCorp = CharactersTable.getCorpId(characterId);

//If the corp is the same, allow jumps
if(allowedCorp == characterCorp){
return true;
} else{
return false;
}
}
}
2 changes: 1 addition & 1 deletion smart-gate/packages/contracts/src/systems/constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
pragma solidity >=0.8.21;

// make sure this matches mud.config.ts namespace
bytes14 constant SMART_GATE_DEPLOYMENT_NAMESPACE = "test";
bytes14 constant SMART_GATE_DEPLOYMENT_NAMESPACE = "dapp_dev2";

bytes16 constant SMART_GATE_SYSTEM_NAME = "SmartGateSystem";
22 changes: 22 additions & 0 deletions smart-turret/packages/client/.env
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
VITE_CHAIN_ID=31337

# This .env file is for demonstration purposes only.
#
# This should usually be excluded via .gitignore and the env vars attached to
# your deployment environment, but we're including this here for ease of local
# development. Please do not commit changes to this file!
#
# Enable debug logs for MUD CLI
DEBUG=mud:*
#
# Anvil default private key:
VITE_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
VITE_WORLD_ADDRESS=0x8a791620dd6260079bf849dc5567adc3f2fdc318
VITE_PLAYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

#Local RPC
VITE_RPC_URL="http://127.0.0.1:8545"


# SMART TURRET CONFIG
# Copy this info from in game smart turret
VITE_SMART_TURRET_ID=9640513001323359261895106592991319872122110296371423549860904054745193604808
2 changes: 1 addition & 1 deletion smart-turret/packages/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>a minimal MUD client</title>
<title>Turret Whitelist</title>
</head>
<body>
<div id="react-root"></div>
Expand Down
19 changes: 14 additions & 5 deletions smart-turret/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,40 @@
"type": "module",
"scripts": {
"build": "vite build",
"dev": "wait-port localhost:8545 && vite",
"dev": "vite",
"preview": "vite preview",
"test": "tsc --noEmit"
},
"dependencies": {
"@eveworld/types": "^0.0.5",
"@eveworld/ui-components": "^0.0.6",
"@eveworld/utils": "^0.0.5",
"@latticexyz/common": "2.2.9",
"@latticexyz/faucet": "2.2.9",
"@latticexyz/dev-tools": "2.2.9",
"@latticexyz/react": "2.2.9",
"@latticexyz/schema-type": "2.2.9",
"@latticexyz/store-sync": "2.2.9",
"@latticexyz/utils": "2.2.9",
"@latticexyz/world": "2.2.9",
"@mui/material": "^5.16.3",
"contracts": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rxjs": "7.5.5",
"tailwindcss": "^3.4.12",
"viem": "2.21.6"
},
"devDependencies": {
"@types/react": "18.2.22",
"@types/react-dom": "18.2.7",
"@vitejs/plugin-react": "^3.1.0",
"autoprefixer": "^10.4.20",
"eslint-plugin-react": "7.31.11",
"eslint-plugin-react-hooks": "4.6.0",
"vite": "^4.2.1",
"wait-port": "^1.0.4"
"postcss": "^8.4.47",
"vite": "^4.5.5",
"vite-plugin-svgr": "3.3.0",
"wait-port": "^1.1.0"
}
}
6 changes: 6 additions & 0 deletions smart-turret/packages/client/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
167 changes: 150 additions & 17 deletions smart-turret/packages/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,154 @@
//Import packages
import { useMUD } from "./MUDContext";
import React, { useEffect, useState, useRef } from "react";

const styleUnset = { all: "unset" } as const;
//Import EVE Frontier Packages
import { EveButton, EveInput, EveScroll } from "@eveworld/ui-components";

//Import CSS
import "./styles.css";
import "./styles-ui.css";

//Import components
import WhitelistEntry from './components/WhitelistEntry'
import AppContainer from './components/AppContainer'
import Title from './components/Title'
import ContentContainer from './components/ContentContainer'
import Section from './components/Section'

export const App = () => {
const {
network: { tables, useStore }
} = useMUD();

const tasks = useStore((state) => {
const records = Object.values(state.getRecords(tables.Tasks));
records.sort((a, b) => Number(a.value.createdAt - b.value.createdAt));
return records;
});

return (
<>

</>
);
};
const {
systemCalls: {
getWhitelist,
addToWhitelist,
removeFromWhitelist
},
} = useMUD();

//Character name input value
const characterNameInputRef = useRef(0);

//Pre-populate the UI list
const [whitelist, setWhitelist] = useState(<WhitelistEntry id={"LOADING...."}></WhitelistEntry>);
const [addErrorVar, setAddErrorVar] = useState("");

//Edit character name
const handleEdit = (
refString: React.MutableRefObject<number>,
eventString: number
): void => {
refString.current = eventString;
};

//Initial load
useEffect(() => {
setTimeout(function(){
fetchWhitelist(null);
}, 1000)
}, [])

//Remove from the whitelist
const remove = async (id) => {
const whitelist = await removeFromWhitelist(id);

loadWhitelist(whitelist);
}

//Fetch the whitelist data
async function fetchWhitelist(event){
if(event) event.preventDefault();
const whitelist = await getWhitelist();
loadWhitelist(whitelist);
}

//Load the whitelist UI
async function loadWhitelist(result){
if(result == null) return;

var newArray = result.whitelist.map((value) => <WhitelistEntry key={value.toString()} id={value.toString()} handleClick={remove}>{value}</WhitelistEntry>)
setWhitelist(newArray);
}

//Add to the whitelist
async function addToWhitelistButton (){
//Check there is a name
if(characterNameInputRef.current == ""){
setAddErrorVar("- NO INPUT");
return;
}

//Fetch the world API data
const response = await fetch(`https://blockchain-gateway-nova.nursery.reitnorf.com/smartcharacters`);
const data = await response.json();

var address = null;

//Check to see if the address exists
for(var i = 0; i < data.length; i++){
if(data[i].name == characterNameInputRef.current){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you go by characterId address instead of name ? Or possibly enter characterName or characterId or characterAddress

address = data[i].address;
}
}

//If an address wasn't found, exit
if(address == null){
setAddErrorVar("- CHARACTER NOT FOUND");
return;
}

//Clear the error message
setAddErrorVar("");

//Add to whitelist
const whitelist = await addToWhitelist(address);

//Load whitelist if not null
if(whitelist != null) loadWhitelist(whitelist);
}

return (
<AppContainer>
<Title>
SMART TURRET WHITELISTING
</Title>
<ContentContainer>
<Section>
<div className="grid grid-cols-1 rows-2 gap-1">
<EveInput
inputType="string"
defaultValue=""
fieldName={`Character Name ${addErrorVar}`}
onChange={(str) => handleEdit(characterNameInputRef, str as number)}
/>
<EveButton
typeClass="primary"
onClick={addToWhitelistButton}
className="primary-sm">
Add to Whitelist
</EveButton>
</div>
</Section>
<Section>
<EveButton
typeClass="primary"
onClick={(event) => fetchWhitelist(event)}
className="primary-sm">
Fetch Whitelist
</EveButton>
</Section>
<Section>
<div className="w-full items-center py-1">
Whitelist
</div>

<EveScroll
maxHeight="200px"
classStyles="h-full"
>
{whitelist}
</EveScroll>
</Section>
</ContentContainer>
</AppContainer>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions smart-turret/packages/client/src/components/AppContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

const AppContainer = ({children}) => {
return(
<div className="bg-crude-5 w-screen min-h-screen">
<div className="flex flex-col align-center max-w-[560px] mx-auto pb-6 min-h-screen h-full">
{children}
</div>
</div>
)
}

export default AppContainer;
Loading