Skip to content

Commit

Permalink
初步完成abi填写。
Browse files Browse the repository at this point in the history
  • Loading branch information
Glacier-Luo committed Mar 25, 2023
1 parent b77d308 commit 9c17bac
Show file tree
Hide file tree
Showing 6 changed files with 2,739 additions and 1,746 deletions.
1 change: 1 addition & 0 deletions packages/core-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"monaco-editor": "^0.35.0",
"postcss": "8",
"react-hook-form": "^7.43.7",
"semver": "^7.3.8",
"solive-compiler": "workspace:0.0.1-alpha",
"solive-provider": "workspace:^0.0.1",
"solive-solc": "workspace:0.0.1-aplha"
Expand Down
71 changes: 67 additions & 4 deletions packages/core-dev/src/components/FooterConsole/CallBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,78 @@
import {TabPanel} from "@material-tailwind/react";
import { TabPanel, Select, Option, Input, Button } from "@material-tailwind/react";
import { useState } from "react";
import { ethers, ContractInterface } from 'ethers';

import {useEditor} from "../../editor/editorContext";
import { useEditor } from "../../editor/editorContext";

interface dataObj {
[key: string]: any
}

const abitest = [{ "inputs": [{ "internalType": "string", "name": "revealingURI_", "type": "string" }, { "internalType": "address", "name": "cucpContractAddress_", "type": "address" }, { "internalType": "address", "name": "maintainerAddress_", "type": "address" }, { "internalType": "string", "name": "provenance_", "type": "string" }], "stateMutability": "nonpayable", "type": "constructor" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "approved", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "Approval", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "operator", "type": "address" }, { "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" }], "name": "ApprovalForAll", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "bool", "name": "isBrewingAllowed", "type": "bool" }], "name": "BrewingAllowedFlagChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "BrewingInterrupted", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, { "indexed": true, "internalType": "address", "name": "account", "type": "address" }], "name": "BrewingStarted", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, { "indexed": true, "internalType": "address", "name": "account", "type": "address" }], "name": "BrewingStopped", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "BrewingTokenTransfered", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "contractAddress", "type": "address" }], "name": "CUCPContractAddressChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "cucpTokenId", "type": "uint256" }, { "indexed": true, "internalType": "uint256", "name": "cheersUpTokenId", "type": "uint256" }], "name": "CheersUpRevealed", "type": "event" }, { "anonymous": false, "inputs": [], "name": "ContractSealed", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Deposit", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "maintainer", "type": "address" }], "name": "MaintainerAddressChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], "name": "Paused", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "string", "name": "procenance", "type": "string" }], "name": "ProvenanceUpdated", "type": "event" }, { "anonymous": false, "inputs": [{ "components": [{ "internalType": "uint256", "name": "startTime", "type": "uint256" }, { "internalType": "uint256", "name": "endTime", "type": "uint256" }, { "internalType": "uint256", "name": "price", "type": "uint256" }, { "internalType": "address", "name": "beneficiary", "type": "address" }], "indexed": false, "internalType": "struct CheersUp.RefundConfig", "name": "config", "type": "tuple" }], "name": "RefundConfigChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "Refunded", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "string", "name": "uri", "type": "string" }], "name": "RevealingURIChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, { "indexed": false, "internalType": "bytes32", "name": "tokenHash", "type": "bytes32" }], "name": "TokenHashSet", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "Transfer", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], "name": "Unpaused", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Withdraw", "type": "event" }, { "inputs": [], "name": "MAX_TOKEN", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "approve", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], "name": "balanceOf", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bytes", "name": "data_", "type": "bytes" }], "name": "base58", "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "internalType": "uint256[]", "name": "tokenIds_", "type": "uint256[]" }, { "internalType": "bytes32[]", "name": "tokenHashes_", "type": "bytes32[]" }], "name": "batchSetTokenHash", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256[]", "name": "tokenIds_", "type": "uint256[]" }], "name": "burn", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "bytes32", "name": "sha256Hash_", "type": "bytes32" }], "name": "cidv0", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "pure", "type": "function" }, { "inputs": [], "name": "contractSealed", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "cucpContractAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "deposit", "outputs": [], "stateMutability": "payable", "type": "function" }, { "inputs": [], "name": "emergencyPause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "getApproved", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "tokenId_", "type": "uint256" }], "name": "getTokenBrewingStatus", "outputs": [{ "internalType": "bool", "name": "isBrewing_", "type": "bool" }, { "internalType": "uint256", "name": "current_", "type": "uint256" }, { "internalType": "uint256", "name": "total_", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256[]", "name": "tokenIds_", "type": "uint256[]" }], "name": "interruptTokenBrewing", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "operator", "type": "address" }], "name": "isApprovedForAll", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "isBrewingAllowed", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "isRefundEnabled", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "maintainerAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "address_", "type": "address" }, { "internalType": "uint256", "name": "cucpTokenId_", "type": "uint256" }], "name": "mint", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "name", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "owner", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "ownerOf", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "paused", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "provenance", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "tokenId_", "type": "uint256" }], "name": "refund", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "refundConfig", "outputs": [{ "internalType": "uint256", "name": "startTime", "type": "uint256" }, { "internalType": "uint256", "name": "endTime", "type": "uint256" }, { "internalType": "uint256", "name": "price", "type": "uint256" }, { "internalType": "address", "name": "beneficiary", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "revealingURI", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "from", "type": "address" }, { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "safeTransferFrom", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "from", "type": "address" }, { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, { "internalType": "bytes", "name": "_data", "type": "bytes" }], "name": "safeTransferFrom", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "from_", "type": "address" }, { "internalType": "address", "name": "to_", "type": "address" }, { "internalType": "uint256", "name": "tokenId_", "type": "uint256" }], "name": "safeTransferWhileBrewing", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "sealContract", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "operator", "type": "address" }, { "internalType": "bool", "name": "approved", "type": "bool" }], "name": "setApprovalForAll", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "address_", "type": "address" }], "name": "setCUCPContractAddress", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "bool", "name": "isBrewingAllowed_", "type": "bool" }], "name": "setIsBrewingAllowed", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "maintainerAddress_", "type": "address" }], "name": "setMaintainerAddress", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "string", "name": "provenance_", "type": "string" }], "name": "setProvenance", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "uint256", "name": "startTime", "type": "uint256" }, { "internalType": "uint256", "name": "endTime", "type": "uint256" }, { "internalType": "uint256", "name": "price", "type": "uint256" }, { "internalType": "address", "name": "beneficiary", "type": "address" }], "internalType": "struct CheersUp.RefundConfig", "name": "config_", "type": "tuple" }], "name": "setRefundConfig", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "string", "name": "revealingURI_", "type": "string" }], "name": "setRevealingURI", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256[]", "name": "tokenIds_", "type": "uint256[]" }, { "internalType": "bool", "name": "state_", "type": "bool" }], "name": "setTokenBrewingState", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "tokenId_", "type": "uint256" }, { "internalType": "bytes32", "name": "tokenHash_", "type": "bytes32" }], "name": "setTokenHash", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }], "name": "supportsInterface", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "symbol", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "tokenURI", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalMinted", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "from", "type": "address" }, { "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "tokenId", "type": "uint256" }], "name": "transferFrom", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "unpause", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "withdraw", "outputs": [], "stateMutability": "nonpayable", "type": "function" }]

const CallBlock = () => {
const {id} = useEditor();
const { id, state, vmProviderRef } = useEditor();
const [abiItem, setAbiItem] = useState('')
const [params, setParams] = useState({})

const contractInfo = state.compliedContract || {};
const abi = contractInfo.abi || [];

console.log(abi);

const abiOption = (abiJson: any) => {
if (!(abiJson instanceof Array)) return ''
return abiJson.filter(item => {return item.type !== 'constructor'}).map((v: any, k: any) => {
return <Option
key={id + k}
className="text-black"
value={JSON.stringify(v)}>
({v.stateMutability === 'pure' || v.stateMutability === 'view' ? 'Read' : 'Write'}){v.name ? v.name : v.type}
</Option>
})
}

const handleInputsChange = (data: any) => {
const newParam: dataObj = {}
newParam[data.target.name] = data.target.value
setParams((prev) => {
return { ...prev, ...newParam }
})
}

const displayInputs = (item: any) => {
if (item === '') return ''
return JSON.parse(item).inputs.map((v: any, k: any) => {
return <Input key={id + v.name} name={v.name} label={`${v.name}(${v.internalType})`} onChange={handleInputsChange} />
})
}

const handleChange = (value: any) => {
setAbiItem(value)
setParams({})
}

const handleExecute = async () => {
const a = JSON.parse(abiItem)
console.log(abiItem)
console.log(params)
// vmProviderRef.current.provider;
const signer = await vmProviderRef.current.getSigner(contractInfo?.signerAddress)
const contact = new ethers.Contract(contractInfo?.address, abi, signer);
const result = await contact[a.name](...Object.values(params || []));
console.log(result);
}

return (
<div>
<TabPanel className="text-white" key={id + "_tabPanel_call"} value="call">
测试CallBlock
<Select label="Select function" value={abiItem} onChange={handleChange}>
{abiOption(abi)}
</Select>
<div className="mt-6 flex flex-col space-y-4">
{displayInputs(abiItem)}
<Button disabled={abiItem === ''} onClick={handleExecute}>Execute</Button>
</div>
</TabPanel>
</div>
)
Expand Down
6 changes: 3 additions & 3 deletions packages/core-dev/src/components/FooterConsole/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ const FooterConsole = () => {
id={id + "_tabs"}
value={selectedTab}
onChange={(value: string) => console.log(value)}
className={`bg-[#0f172a] rounded-b-lg`}
className={`bg-[#0f172a] rounded-b-lg !overflow-visible`}
>
<TabsHeader>
{data.map(({ label, value }) => (
<Tab
key={id + "_tab_" + value}
className={value === selectedTab ? '' : 'text-white'}
className={value === selectedTab ? 'z-0' : 'text-white'}
value={value}
onClick={() => setSelectedTab(value)}
>
{label}
</Tab>
))}
</TabsHeader>
<TabsBody animate={animation}>
<TabsBody animate={animation} className="!overflow-visible">
<CallBlock />
<ConsoleBlock />
</TabsBody>
Expand Down
2 changes: 1 addition & 1 deletion packages/core-dev/src/components/TopBar/Deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Deploy = () => {
actions.updateCompilerContract({
name: selectedContract!,
address: contract.address,
abi: contract.interface.format(),
abi: abi,
signerAddress: '0x5B38Da6a701c568545dCfcB03FcB875f56beddC4',
});
setDeployContractAddress(contract.address);
Expand Down
Loading

0 comments on commit 9c17bac

Please sign in to comment.