From 1feb6858b6bc4ce751a3f5f646a2545f447d84ed Mon Sep 17 00:00:00 2001 From: Keisuke Ishigami <62370522+kei01234kei@users.noreply.github.com> Date: Thu, 15 Feb 2024 08:07:20 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20record=20=E3=82=B3=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=83=88=E3=82=A2=E3=83=89=E3=83=AC=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=20(#9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Keisuke Ishigami --- .idea/codeStyles/Project.xml | 59 +++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ package-lock.json | 20 +++---- src/app/_components/RecordFileInput.tsx | 1 + src/app/files/record/_hooks/createRecord.ts | 27 +++++++--- 5 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..932f7d1 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c9dc363..c265195 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,9 +54,9 @@ } }, "node_modules/@adraffy/ens-normalize": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", - "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==" + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz", + "integrity": "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==" }, "node_modules/@babel/code-frame": { "version": "7.22.13", @@ -1854,9 +1854,9 @@ "integrity": "sha512-x9ibmsP0ZVqzyCo1Pitbw+4b6iEXRw/r1TCy3vOUR3eKrzWLnHYZMR325BkZW2r8fnuWE/V3Fp4QZOP9qYORCw==" }, "node_modules/@recordex/smartcontract": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@recordex/smartcontract/-/smartcontract-0.1.3.tgz", - "integrity": "sha512-mlIZ5r8nNCnjbH+Hbpvm1ZptRblP+/qwsA/rmvP9afJwZpBfut9SFlV+Pn0RsLcO5gopK8DvfHOP97YeLa9/hA==", + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@recordex/smartcontract/-/smartcontract-0.1.6.tgz", + "integrity": "sha512-LwU/AvGSpCI8pLrVlxhSJfdOYl6PFu+lFeDHUkukpEXzxJYJUPxGQWVZ8rNN9sMPlQ6i3Ky0ihfGE+pRK5rY4Q==", "dependencies": { "@openzeppelin/contracts": "^5.0.0", "eslint": "^8.53.0" @@ -3593,9 +3593,9 @@ } }, "node_modules/ethers": { - "version": "6.8.1", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.8.1.tgz", - "integrity": "sha512-iEKm6zox5h1lDn6scuRWdIdFJUCGg3+/aQWu0F4K0GVyEZiktFkqrJbRjTn1FlYEPz7RKA707D6g5Kdk6j7Ljg==", + "version": "6.11.1", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.11.1.tgz", + "integrity": "sha512-mxTAE6wqJQAbp5QAe/+o+rXOID7Nw91OZXvgpjDa1r4fAbq2Nu314oEZSbjoRLacuCzs7kUC3clEvkCQowffGg==", "funding": [ { "type": "individual", @@ -3607,7 +3607,7 @@ } ], "dependencies": { - "@adraffy/ens-normalize": "1.10.0", + "@adraffy/ens-normalize": "1.10.1", "@noble/curves": "1.2.0", "@noble/hashes": "1.3.2", "@types/node": "18.15.13", diff --git a/src/app/_components/RecordFileInput.tsx b/src/app/_components/RecordFileInput.tsx index 411e21a..7f6023e 100644 --- a/src/app/_components/RecordFileInput.tsx +++ b/src/app/_components/RecordFileInput.tsx @@ -74,6 +74,7 @@ const RecordFileInput = () => { onClick={onRecordClick} disabled={!blob} > + {/*TODO ここを差分を表示する。にする*/} 記録する diff --git a/src/app/files/record/_hooks/createRecord.ts b/src/app/files/record/_hooks/createRecord.ts index 404a2e7..413f2f7 100644 --- a/src/app/files/record/_hooks/createRecord.ts +++ b/src/app/files/record/_hooks/createRecord.ts @@ -25,20 +25,33 @@ export const createRecord = async ( const signer = await provider.getSigner(); const recordFactory = Record__factory.connect( - '0xC3e4bb03b22C7DcB3715A2f973f25Ba72d9A2e37', + '0x590b51f9D972625B263eAD11417832Fcf4fc724c', signer, ); const recordContract = recordFactory.connect(signer); - // ブロックチェーンに記録されている最新のファイルハッシュ値を取得 - const fileMetaDataHistory = - await recordContract.getFileMetadataHistory(fileHash); - const newestFileHash = - fileMetaDataHistory[fileMetaDataHistory.length - 1].hash; + let recordedNewestFileHash: string; + try { + // ブロックチェーンに記録されている最新のファイルハッシュ値を取得 + const fileMetaDataHistory = await recordContract.getFileMetadataHistory( + file.name, + ); + if (fileMetaDataHistory.length === 0) { + recordedNewestFileHash = fileHash; + } else { + recordedNewestFileHash = fileMetaDataHistory[0].hash; + } + } catch (e) { + return Promise.reject( + new Error( + `recordContract.getFileMetadataHistory 関数を実行中にエラーが発生しました。: ${e}`, + ), + ); + } // ブロックチェーンにファイルのハッシュ値を記録 const addFile = await recordContract.addFile( file.name, fileHash, - newestFileHash, + recordedNewestFileHash, ); console.log( `トランザクションの送信に成功しました。network -> ${signer.provider._network.name}, transactionHash -> ${addFile.hash})`,