Skip to content

Commit

Permalink
chore: record コントラクトアドレスを修正しました (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Keisuke Ishigami <[email protected]>
  • Loading branch information
kei01234kei and kei01234kei authored Feb 14, 2024
1 parent 39467c1 commit 1feb685
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 17 deletions.
59 changes: 59 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/app/_components/RecordFileInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const RecordFileInput = () => {
onClick={onRecordClick}
disabled={!blob}
>
{/*TODO ここを差分を表示する。にする*/}
記録する
</Button>
</Stack>
Expand Down
27 changes: 20 additions & 7 deletions src/app/files/record/_hooks/createRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`,
Expand Down

0 comments on commit 1feb685

Please sign in to comment.