-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from lambdaclass/recover-pubdata
Recovering Pubdata from Turing Avail DA
- Loading branch information
Showing
7 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ account.json | |
.vscode/ | ||
venv/ | ||
logs/ | ||
pubdata/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"tasks": { | ||
"validium": "deno run --allow-read --allow-net --allow-env main.ts", | ||
"test": "deno test --allow-net --allow-read --allow-env tests.ts" | ||
"test": "deno test --allow-net --allow-read --allow-env tests.ts", | ||
"get-pubdata": "deno run --allow-write --allow-read --allow-net --allow-env get_pubdata.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { getPubdata } from "./validium.ts"; | ||
|
||
await getPubdata(Deno.args[0], Deno.args[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,13 @@ import { | |
assertEquals, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts"; | ||
import { ProofData, submitDataAndVerify, verifyProof } from "./validium.ts"; | ||
import { | ||
getPubdata, | ||
ProofData, | ||
submitDataAndVerify, | ||
SubmitDataHash, | ||
verifyProof, | ||
} from "./validium.ts"; | ||
import { pubdataTest } from "./pubdata_test.ts"; | ||
|
||
const env = await load(); | ||
|
@@ -63,11 +69,33 @@ Deno.test("verifyBlobLeaf function should return expected result", async () => { | |
assertEquals(isVerified, expectedValue); | ||
}); | ||
|
||
const resultHashes: SubmitDataHash[] = []; | ||
let isSubmitDataAndVerifyDone = false; | ||
|
||
Deno.test({ | ||
name: "submitDataAndVerify", | ||
async fn() { | ||
for (const batch of pubdataTest) { | ||
await submitDataAndVerify(batch); | ||
resultHashes.push(await submitDataAndVerify(batch)); | ||
} | ||
console.log(resultHashes); | ||
isSubmitDataAndVerifyDone = true; | ||
}, | ||
sanitizeOps: false, | ||
sanitizeResources: false, | ||
}); | ||
|
||
Deno.test({ | ||
name: "getPubdata function should return expected pubdata", | ||
async fn() { | ||
while (!isSubmitDataAndVerifyDone) { | ||
await new Promise((resolve) => setTimeout(resolve, 100)); | ||
} | ||
let index = 0; | ||
for (const hash of resultHashes) { | ||
const result = await getPubdata(hash.txHash, hash.blockHash); | ||
assertEquals(result, pubdataTest[index]); | ||
index++; | ||
} | ||
}, | ||
sanitizeOps: false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ import { ethers } from "npm:[email protected]"; | |
import { load } from "https://deno.land/[email protected]/dotenv/mod.ts"; | ||
import ABI from "./abi/availbridge.json" with { type: "json" }; | ||
import { KeyringPair } from "https://deno.land/x/[email protected]/keyring/types.ts"; | ||
import { createAccount, initializeAvailApi } from "./helpers.ts"; | ||
import { createAccount, initializeAvailApi, writeJson } from "./helpers.ts"; | ||
import { H256 } from "https://deno.land/x/[email protected]/types/interfaces/types.ts"; | ||
|
||
const env = await load(); | ||
|
||
|
@@ -41,6 +42,11 @@ interface SubmitDataResult extends ISubmittableResult { | |
blockNumber: string; | ||
} | ||
|
||
export interface SubmitDataHash { | ||
txHash: string; | ||
blockHash: string; | ||
} | ||
|
||
/** | ||
* Submitting data to Avail as a transaction. | ||
* | ||
|
@@ -167,4 +173,30 @@ export async function submitDataAndVerify(data: string) { | |
} | ||
await proofAndVerify(result); | ||
await availApi.disconnect(); | ||
const submitDataHash: SubmitDataHash = { | ||
txHash: result.txHash.toHex(), | ||
blockHash: (result.status.asFinalized as H256).toHex(), | ||
}; | ||
return submitDataHash; | ||
} | ||
|
||
export async function getPubdata( | ||
tx_hash: string, | ||
block_hash: string, | ||
): Promise<string> { | ||
const availApi = await initializeAvailApi(AVAIL_RPC); | ||
const block = await availApi.rpc.chain.getBlock(block_hash); | ||
const tx = block.block.extrinsics.find((tx) => tx.hash.toHex() == tx_hash); | ||
if (tx == undefined) { | ||
console.log("Failed to find the Submit Data transaction"); | ||
Deno.exit(1); | ||
} | ||
console.log(tx.toHuman()); | ||
const dataHex = tx.method.args.map((a) => a.toString()).join(", "); | ||
// Data retrieved from the extrinsic data | ||
console.log(`submitted data: ${dataHex}`); | ||
const fileName = `./pubdata/${tx_hash}.json`; | ||
console.log(writeJson(fileName, dataHex)); | ||
await availApi.disconnect(); | ||
return dataHex; | ||
} |