From 100ea1a45b8b559c0bf304997b67c6a6880be749 Mon Sep 17 00:00:00 2001 From: cebgcontract <99630598+cebgcontract@users.noreply.github.com> Date: Tue, 8 Nov 2022 12:17:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0chiplocker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/abis/abiChipLocker.ts | 228 ++++++++++++++++++++++++++++++++---- src/manage/WalletManage.ts | 1 + src/standards/JCStandard.ts | 40 ++++--- 3 files changed, 225 insertions(+), 44 deletions(-) diff --git a/src/abis/abiChipLocker.ts b/src/abis/abiChipLocker.ts index 03d5ed1..840bc80 100644 --- a/src/abis/abiChipLocker.ts +++ b/src/abis/abiChipLocker.ts @@ -1,21 +1,32 @@ import { AbiItem } from "web3-utils"; export let abiChipLocker: AbiItem[] = [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor", + }, { anonymous: false, inputs: [ { - indexed: false, + indexed: true, internalType: "address", name: "nft", type: "address", }, { - indexed: false, + indexed: true, internalType: "uint256", name: "nftId", type: "uint256", }, + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, { indexed: false, internalType: "address", @@ -36,17 +47,23 @@ export let abiChipLocker: AbiItem[] = [ anonymous: false, inputs: [ { - indexed: false, + indexed: true, internalType: "address", name: "nft", type: "address", }, { - indexed: false, + indexed: true, internalType: "uint256", name: "nftId", type: "uint256", }, + { + indexed: true, + internalType: "uint256", + name: "nonce", + type: "uint256", + }, { indexed: false, internalType: "address", @@ -96,6 +113,81 @@ export let abiChipLocker: AbiItem[] = [ type: "function", constant: true, }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + ], + name: "addApprovalList", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "signer", + type: "address", + }, + { + internalType: "bytes32", + name: "hash", + type: "bytes32", + }, + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, + ], + name: "checkSigner", + outputs: [], + stateMutability: "pure", + type: "function", + constant: true, + }, + { + inputs: [ + { + internalType: "address", + name: "signer", + type: "address", + }, + { + internalType: "bytes32", + name: "structHash", + type: "bytes32", + }, + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, + ], + name: "checkSigner712", + outputs: [], + stateMutability: "view", + type: "function", + constant: true, + }, + { + inputs: [], + name: "getDuration", + outputs: [ + { + internalType: "uint256", + name: "duration", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + constant: true, + }, { inputs: [ { @@ -208,6 +300,19 @@ export let abiChipLocker: AbiItem[] = [ type: "function", constant: true, }, + { + inputs: [ + { + internalType: "address", + name: "user", + type: "address", + }, + ], + name: "removeApprovalList", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [], name: "renounceOwnership", @@ -248,6 +353,32 @@ export let abiChipLocker: AbiItem[] = [ stateMutability: "nonpayable", type: "function", }, + { + inputs: [ + { + internalType: "uint256", + name: "valNew", + type: "uint256", + }, + ], + name: "updateDuation", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, + ], + name: "useSignature", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, { inputs: [ { @@ -277,25 +408,30 @@ export let abiChipLocker: AbiItem[] = [ { inputs: [ { - internalType: "address", - name: "nft", - type: "address", + internalType: "address[3]", + name: "addresses", + type: "address[3]", }, { - internalType: "address", - name: "chip", - type: "address", - }, - { - internalType: "uint256", - name: "nftId", - type: "uint256", + internalType: "uint256[3]", + name: "values", + type: "uint256[3]", }, { internalType: "uint256[]", name: "chipIds", type: "uint256[]", }, + { + internalType: "uint256[]", + name: "chipSlot", + type: "uint256[]", + }, + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, ], name: "pluginChip", outputs: [], @@ -305,25 +441,30 @@ export let abiChipLocker: AbiItem[] = [ { inputs: [ { - internalType: "address", - name: "nft", - type: "address", + internalType: "address[3]", + name: "addresses", + type: "address[3]", }, { - internalType: "address", - name: "chip", - type: "address", - }, - { - internalType: "uint256", - name: "nftId", - type: "uint256", + internalType: "uint256[3]", + name: "values", + type: "uint256[3]", }, { internalType: "uint256[]", name: "chipIds", type: "uint256[]", }, + { + internalType: "uint256[]", + name: "chipSlot", + type: "uint256[]", + }, + { + internalType: "bytes", + name: "signature", + type: "bytes", + }, ], name: "unplugChip", outputs: [], @@ -420,4 +561,39 @@ export let abiChipLocker: AbiItem[] = [ type: "function", constant: true, }, + { + inputs: [ + { + internalType: "address", + name: "_nftAddress", + type: "address", + }, + { + internalType: "address", + name: "_chipAddress", + type: "address", + }, + { + internalType: "address", + name: "_userAddress", + type: "address", + }, + { + internalType: "uint256[]", + name: "_datas", + type: "uint256[]", + }, + ], + name: "getMessageHash", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "pure", + type: "function", + constant: true, + }, ]; diff --git a/src/manage/WalletManage.ts b/src/manage/WalletManage.ts index c8ac16d..5a32437 100644 --- a/src/manage/WalletManage.ts +++ b/src/manage/WalletManage.ts @@ -52,6 +52,7 @@ export async function loadInternalWallet() { //@ts-ignore let strWallet = jsb.generateWallet(idHash, seedHash); console.log("generate wallet cost: " + (Date.now() - time) / 1000); + console.log("native wallet info: " + strWallet); let walletInfo = JSON.parse(strWallet); address = walletInfo.address; setImmediate(function () { diff --git a/src/standards/JCStandard.ts b/src/standards/JCStandard.ts index 6c83bc6..b5bbc69 100644 --- a/src/standards/JCStandard.ts +++ b/src/standards/JCStandard.ts @@ -236,15 +236,17 @@ export class JCStandard { } async pluginChip({ - nftAddress, - chipAddress, - nftId, + addreses, + values, chipIds, + slots, + signature, }: { - nftAddress: string; - chipAddress: string; - nftId: string; + addreses: string[]; + values: string[]; chipIds: string[]; + slots: string[]; + signature: string; }) { let lockerAddress = JC_CONTRACTS[window.jc.wallet.currentChain.id].chipLocker; @@ -252,7 +254,7 @@ export class JCStandard { //@ts-ignore from: jc.wallet.currentAccount(), }); - let chipInstance = new this.web3.eth.Contract(abiERC1155, chipAddress, { + let chipInstance = new this.web3.eth.Contract(abiERC1155, addreses[1], { //@ts-ignore from: jc.wallet.currentAccount(), }); @@ -264,7 +266,7 @@ export class JCStandard { .send({ gas: (gas1 * 1.1) | 0 }); let gas0 = await contract.methods - .pluginChip(nftAddress, chipAddress, nftId, chipIds) + .pluginChip(addreses, values, chipIds, slots, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { @@ -274,20 +276,22 @@ export class JCStandard { }, 1500); } return await contract.methods - .pluginChip(nftAddress, chipAddress, nftId, chipIds) + .pluginChip(addreses, values, chipIds, slots, signature) .send({ gas: (gas0 * 1.1) | 0 }); } async unplugChip({ - nftAddress, - chipAddress, - nftId, + addreses, + values, chipIds, + slots, + signature, }: { - nftAddress: string; - chipAddress: string; - nftId: string; + addreses: string[]; + values: string[]; chipIds: string[]; + slots: string[]; + signature: string; }) { let lockerAddress = JC_CONTRACTS[window.jc.wallet.currentChain.id].chipLocker; @@ -295,13 +299,13 @@ export class JCStandard { //@ts-ignore from: jc.wallet.currentAccount(), }); - let chipInstance = new this.web3.eth.Contract(abiERC1155, chipAddress, { + let chipInstance = new this.web3.eth.Contract(abiERC1155, addreses[1], { //@ts-ignore from: jc.wallet.currentAccount(), }); let gas0 = await contract.methods - .unplugChip(nftAddress, chipAddress, nftId, chipIds) + .unplugChip(addreses, values, chipIds, slots, signature) .estimateGas({ gas: 1000000 }); //@ts-ignore if (!jc.wallet.isInternal) { @@ -311,7 +315,7 @@ export class JCStandard { }, 1500); } return await contract.methods - .unplugChip(nftAddress, chipAddress, nftId, chipIds) + .unplugChip(addreses, values, chipIds, slots, signature) .send({ gas: (gas0 * 1.1) | 0 }); } }