2022-02-22 08:25:42 +00:00
|
|
|
const { ethers } = require("hardhat")
|
|
|
|
const { keccak256, defaultAbiCoder } = ethers.utils
|
|
|
|
|
|
|
|
function requestId(request) {
|
2022-08-24 05:30:55 +00:00
|
|
|
const Ask = "tuple(int64, uint256, uint256, uint256, uint256, int64)"
|
2022-07-20 08:44:22 +00:00
|
|
|
const Erasure = "tuple(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-08-02 09:41:49 +00:00
|
|
|
return [
|
|
|
|
ask.slots,
|
|
|
|
ask.slotSize,
|
|
|
|
ask.duration,
|
|
|
|
ask.proofProbability,
|
|
|
|
ask.reward,
|
2022-08-24 05:30:55 +00:00
|
|
|
ask.maxSlotLoss,
|
2022-08-02 09:41:49 +00:00
|
|
|
]
|
2022-04-06 12:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function erasureToArray(erasure) {
|
2022-07-20 08:44:22 +00:00
|
|
|
return [erasure.totalChunks]
|
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,
|
|
|
|
}
|