mint WORKING

This commit is contained in:
dr-frmr 2024-08-09 17:57:55 +03:00
parent 8f81279535
commit 6b47043ffd
No known key found for this signature in database
4 changed files with 11 additions and 28 deletions

View File

@ -10,9 +10,6 @@ import KinodeHome from "./pages/KinodeHome"
import ImportKeyfile from "./pages/ImportKeyfile"; import ImportKeyfile from "./pages/ImportKeyfile";
import { UnencryptedIdentity } from "./lib/types"; import { UnencryptedIdentity } from "./lib/types";
import Header from "./components/Header"; import Header from "./components/Header";
import { bytesToHex } from "viem";
function App() { function App() {
const params = useParams() const params = useParams()
@ -38,8 +35,6 @@ function App() {
const openConnect = () => setConnectOpen(true) const openConnect = () => setConnectOpen(true)
const closeConnect = () => setConnectOpen(false) const closeConnect = () => setConnectOpen(false)
const commitSecret = bytesToHex(crypto.getRandomValues(new Uint8Array(32)))
useEffect(() => setAppSizeOnLoad( useEffect(() => setAppSizeOnLoad(
(window.performance.getEntriesByType('navigation') as any)[0].transferSize (window.performance.getEntriesByType('navigation') as any)[0].transferSize
), []); ), []);
@ -100,7 +95,6 @@ function App() {
tcp_port, setTcpPort, tcp_port, setTcpPort,
routers, setRouters, routers, setRouters,
nodeChainId, nodeChainId,
commitSecret,
} }
return ( return (

View File

@ -23,7 +23,6 @@ export interface PageProps {
setPw: React.Dispatch<React.SetStateAction<string>>, setPw: React.Dispatch<React.SetStateAction<string>>,
appSizeOnLoad: number, appSizeOnLoad: number,
nodeChainId: string, nodeChainId: string,
commitSecret: `0x${string}`,
} }
export type NetworkingInfo = { export type NetworkingInfo = {

View File

@ -23,7 +23,6 @@ function CommitDotOsName({
setWsPort, setWsPort,
setTcpPort, setTcpPort,
setRouters, setRouters,
commitSecret,
}: RegisterOsNameProps) { }: RegisterOsNameProps) {
let { address } = useAccount(); let { address } = useAccount();
let navigate = useNavigate(); let navigate = useNavigate();
@ -62,18 +61,18 @@ function CommitDotOsName({
return return
} }
console.log("committing to .os name: ", name) console.log("committing to .os name: ", name)
const commitSecret = keccak256(stringToHex(name))
const commit = keccak256(
encodeAbiParameters(
parseAbiParameters('bytes32, bytes32'),
[keccak256(stringToHex(name)), commitSecret]
)
)
writeContract({ writeContract({
abi: dotOsAbi, abi: dotOsAbi,
address: DOTOS, address: DOTOS,
functionName: 'commit', functionName: 'commit',
args: [ args: [commit],
keccak256(
encodeAbiParameters(
parseAbiParameters('bytes memory, bytes32'),
[keccak256(stringToHex(name)), commitSecret]
)
)
],
gas: 1000000n, gas: 1000000n,
}) })

View File

@ -6,7 +6,7 @@ import { PageProps } from "../lib/types";
import { useAccount, useWaitForTransactionReceipt, useSendTransaction } from "wagmi"; import { useAccount, useWaitForTransactionReceipt, useSendTransaction } from "wagmi";
import { useConnectModal, useAddRecentTransaction } from "@rainbow-me/rainbowkit" import { useConnectModal, useAddRecentTransaction } from "@rainbow-me/rainbowkit"
import { dotOsAbi, generateNetworkingKeys, KINO_ACCOUNT_IMPL, DOTOS } from "../abis"; import { dotOsAbi, generateNetworkingKeys, KINO_ACCOUNT_IMPL, DOTOS } from "../abis";
import { encodePacked, parseAbi, encodeFunctionData, stringToHex } from "viem"; import { encodePacked, encodeFunctionData, stringToHex, keccak256 } from "viem";
interface RegisterOsNameProps extends PageProps { } interface RegisterOsNameProps extends PageProps { }
@ -18,7 +18,6 @@ function MintDotOsName({
setWsPort, setWsPort,
setTcpPort, setTcpPort,
setRouters, setRouters,
commitSecret,
}: RegisterOsNameProps) { }: RegisterOsNameProps) {
let { address } = useAccount(); let { address } = useAccount();
let navigate = useNavigate(); let navigate = useNavigate();
@ -70,13 +69,10 @@ function MintDotOsName({
// strip .os suffix // strip .os suffix
const name = knsName.replace(/\.os$/, ''); const name = knsName.replace(/\.os$/, '');
const commitSecret = keccak256(stringToHex(name))
const abi = parseAbi([
'function mint(address,bytes,bytes,bytes,address,bytes32)',
])
const data = encodeFunctionData({ const data = encodeFunctionData({
abi, abi: dotOsAbi,
functionName: 'mint', functionName: 'mint',
args: [ args: [
address, address,
@ -88,8 +84,6 @@ function MintDotOsName({
], ],
}) })
console.log("data: ", data)
// use data to write to contract -- do NOT use writeContract // use data to write to contract -- do NOT use writeContract
// writeContract will NOT generate the correct selector for some reason // writeContract will NOT generate the correct selector for some reason
// probably THEIR bug.. no abi works // probably THEIR bug.. no abi works
@ -99,11 +93,8 @@ function MintDotOsName({
data: data, data: data,
gas: 1000000n, gas: 1000000n,
}) })
console.log('Transaction sent?')
// You might want to add some state management here to track the transaction
} catch (error) { } catch (error) {
console.error('Failed to send transaction:', error) console.error('Failed to send transaction:', error)
// Handle the error appropriately, maybe set an error state
} }
}, [direct, address, sendTransaction, setNetworkingKey, setIpAddress, setWsPort, setTcpPort, setRouters, openConnectModal]) }, [direct, address, sendTransaction, setNetworkingKey, setIpAddress, setWsPort, setTcpPort, setRouters, openConnectModal])