2022-02-22 08:25:42 +00:00
|
|
|
const { ethers } = require("hardhat")
|
|
|
|
const { keccak256, defaultAbiCoder } = ethers.utils
|
|
|
|
|
|
|
|
function requestId(request) {
|
2022-04-06 12:26:56 +00:00
|
|
|
const Ask = "tuple(uint256, uint256, uint256, uint256)"
|
2022-07-20 08:36:22 +00:00
|
|
|
const Erasure = "tuple(uint64, uint64)"
|
2022-04-07 13:44:56 +00:00
|
|
|
const PoR = "tuple(bytes, bytes, bytes)"
|
2022-04-06 12:26:56 +00:00
|
|
|
const Content = "tuple(string, " + Erasure + ", " + PoR + ")"
|
|
|
|
const Request =
|
|
|
|
"tuple(address, " + Ask + ", " + Content + ", uint256, bytes32)"
|
|
|
|
return keccak256(defaultAbiCoder.encode([Request], requestToArray(request)))
|
2022-02-22 08:25:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 12:26:56 +00:00
|
|
|
function askToArray(ask) {
|
2022-06-13 11:19:33 +00:00
|
|
|
return [ask.size, ask.duration, ask.proofProbability, ask.reward]
|
2022-04-06 12:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function erasureToArray(erasure) {
|
2022-07-20 08:36:22 +00:00
|
|
|
return [erasure.totalChunks, erasure.totalNodes]
|
2022-04-06 12:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function porToArray(por) {
|
|
|
|
return [por.u, por.publicKey, por.name]
|
|
|
|
}
|
|
|
|
|
|
|
|
function contentToArray(content) {
|
|
|
|
return [content.cid, erasureToArray(content.erasure), porToArray(content.por)]
|
|
|
|
}
|
|
|
|
|
2022-02-22 08:25:42 +00:00
|
|
|
function requestToArray(request) {
|
|
|
|
return [
|
2022-04-06 12:26:56 +00:00
|
|
|
[
|
|
|
|
request.client,
|
|
|
|
askToArray(request.ask),
|
|
|
|
contentToArray(request.content),
|
|
|
|
request.expiry,
|
|
|
|
request.nonce,
|
|
|
|
],
|
2022-02-22 08:25:42 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:33:54 +00:00
|
|
|
function slotId(slot) {
|
|
|
|
const types = "tuple(bytes32, uint256)"
|
|
|
|
const values = [slot.request, slot.index]
|
|
|
|
const encoding = defaultAbiCoder.encode([types], [values])
|
|
|
|
return keccak256(encoding)
|
|
|
|
}
|
|
|
|
|
2022-04-06 12:26:56 +00:00
|
|
|
module.exports = {
|
|
|
|
requestId,
|
2022-07-19 09:33:54 +00:00
|
|
|
slotId,
|
2022-04-06 12:26:56 +00:00
|
|
|
requestToArray,
|
|
|
|
askToArray,
|
|
|
|
}
|