Skip to content

Commit

Permalink
feat(contracts): 🎸update contract so its possible to control minters
Browse files Browse the repository at this point in the history
  • Loading branch information
markogracin committed Dec 17, 2024
1 parent f45ea6b commit 2e60d59
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 11 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
94 changes: 92 additions & 2 deletions contracts/artifacts/contracts/NFTContract.sol/NFTContract.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/fdd9c5e1222ec4644fba7d05a6b0a6ea.json"
"buildInfo": "../../../build-info/e0d27f44f97abb5534e508a66a390154.json"
}
37 changes: 36 additions & 1 deletion contracts/contracts/NFTContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,55 @@ import "./utils/KeyHelper.sol";
contract NFTContract is ExpiryHelper, KeyHelper, HederaTokenService {
address public owner;

// Mapping to track authorized minters
mapping(address => bool) public authorizedMinters;

// Mapping to track which wallet can claim which NFT serial number
mapping(int64 => address) public nftClaimRights;
// Mapping to track if an NFT has been claimed
mapping(int64 => bool) public claimed;

// Events
event MinterAdded(address indexed minter);
event MinterRemoved(address indexed minter);

constructor() {
owner = msg.sender;
// Make the owner an authorized minter by default
authorizedMinters[msg.sender] = true;
}

modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call this function");
_;
}

modifier onlyMinter() {
require(authorizedMinters[msg.sender], "Only authorized minters can call this function");
_;
}

// Function to add a new minter
function addMinter(address minter) external onlyOwner {
require(minter != address(0), "Invalid minter address");
require(!authorizedMinters[minter], "Address is already a minter");
authorizedMinters[minter] = true;
emit MinterAdded(minter);
}

// Function to remove a minter
function removeMinter(address minter) external onlyOwner {
require(minter != owner, "Cannot remove owner as minter");
require(authorizedMinters[minter], "Address is not a minter");
authorizedMinters[minter] = false;
emit MinterRemoved(minter);
}

// Function to check if an address is an authorized minter
function isMinter(address account) external view returns (bool) {
return authorizedMinters[account];
}

function createNft(
string memory name,
string memory symbol,
Expand Down Expand Up @@ -57,7 +92,7 @@ contract NFTContract is ExpiryHelper, KeyHelper, HederaTokenService {
address token,
bytes[] memory metadata,
address allowedClaimer
) external onlyOwner returns(int64) {
) external onlyMinter returns(int64) {
(int response, , int64[] memory serial) = HederaTokenService.mintToken(token, 0, metadata);

if(response != HederaResponseCodes.SUCCESS){
Expand Down
57 changes: 57 additions & 0 deletions contracts/scripts/minter/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
AccountId,
ContractExecuteTransaction,
ContractFunctionParameters,
ContractId,
Hbar,
} from "@hashgraph/sdk";
import { clientSetup } from "../client";

// Get command line arguments
const [contractId, minterId] = process.argv.slice(2);

if (!contractId || !minterId) {
console.error("Missing required arguments");
console.error("Usage: npx ts-node addMinter.ts <contractId> <minterId>");
console.error("Example: npx ts-node addMinter.ts 0.0.123456 0.0.789101");
process.exit(1);
}

const addMinter = async () => {
try {
// Create client and set operator
const client = clientSetup();

console.log("\n----- Adding New Minter -----");
console.log(`Contract ID: ${contractId}`);
console.log(`Minter ID: ${minterId}`);

// Convert IDs to correct format
const contractIdObj = ContractId.fromString(contractId);
const minterIdObj = AccountId.fromString(minterId);
const minterAddress = minterIdObj.toSolidityAddress();

// Create and execute the transaction
const addMinterTx = new ContractExecuteTransaction()
.setContractId(contractIdObj)
.setGas(1000000)
.setMaxTransactionFee(new Hbar(20))
.setFunction(
"addMinter",
new ContractFunctionParameters().addAddress(minterAddress),
);

const txResponse = await addMinterTx.execute(client);
const receipt = await txResponse.getReceipt(client);

console.log("\nMinter added successfully!");
console.log("Transaction ID:", txResponse.transactionId.toString());

client.close();
} catch (error) {
console.error("Error adding minter:", error);
throw error;
}
};

addMinter();
56 changes: 56 additions & 0 deletions contracts/scripts/minter/remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
AccountId,
ContractExecuteTransaction,
ContractFunctionParameters,
ContractId,
Hbar,
} from "@hashgraph/sdk";
import { clientSetup } from "../client";

// Get command line arguments
const [contractId, minterId] = process.argv.slice(2);

if (!contractId || !minterId) {
console.error("Missing required arguments");
console.error("Usage: npx ts-node removeMinter.ts <contractId> <minterId>");
console.error("Example: npx ts-node removeMinter.ts 0.0.123456 0.0.789101");
process.exit(1);
}

const removeMinter = async () => {
try {
const client = clientSetup();

console.log("\n----- Removing Minter -----");
console.log(`Contract ID: ${contractId}`);
console.log(`Minter ID: ${minterId}`);

// Convert IDs to correct format
const contractIdObj = ContractId.fromString(contractId);
const minterIdObj = AccountId.fromString(minterId);
const minterAddress = minterIdObj.toSolidityAddress();

// Create and execute the transaction
const removeMinterTx = new ContractExecuteTransaction()
.setContractId(contractIdObj)
.setGas(1000000)
.setMaxTransactionFee(new Hbar(20))
.setFunction(
"removeMinter",
new ContractFunctionParameters().addAddress(minterAddress),
);

const txResponse = await removeMinterTx.execute(client);
const receipt = await txResponse.getReceipt(client);

console.log("\nMinter removed successfully!");
console.log("Transaction ID:", txResponse.transactionId.toString());

client.close();
} catch (error) {
console.error("Error removing minter:", error);
throw error;
}
};

removeMinter();

0 comments on commit 2e60d59

Please sign in to comment.