-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exercise contracts migrating all owned plots
- Loading branch information
1 parent
49228f6
commit 45a777a
Showing
4 changed files
with
234 additions
and
189 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const fs = require("fs"); | ||
const { ethers } = require("ethers"); | ||
|
||
function readPlotData(jsonFilePath, account) { | ||
try { | ||
// Read the JSON file | ||
const jsonData = JSON.parse(fs.readFileSync(jsonFilePath, "utf8")); | ||
|
||
// Convert the input address to checksummed format | ||
const checksummedAccount = ethers.utils.getAddress(account); | ||
|
||
// Find the data for the specified account | ||
const accountData = jsonData.find( | ||
(data) => ethers.utils.getAddress(data[0]) === checksummedAccount | ||
); | ||
|
||
if (!accountData) { | ||
console.error(`No plot data found for account: ${checksummedAccount}`); | ||
return "0x"; | ||
} | ||
|
||
const plotIds = accountData[1]; | ||
const amounts = accountData[2]; | ||
|
||
// Encode the data | ||
const encodedData = ethers.utils.defaultAbiCoder.encode( | ||
["uint256[]", "uint256[]"], | ||
[plotIds, amounts] | ||
); | ||
|
||
return encodedData; | ||
} catch (error) { | ||
console.error(`Error reading plot data: ${error.message}`); | ||
return "0x"; | ||
} | ||
} | ||
|
||
// Get command line arguments | ||
const args = process.argv.slice(2); | ||
const jsonFilePath = args[0]; | ||
const account = args[1]; | ||
|
||
// Run the function and output the result | ||
const encodedData = readPlotData(jsonFilePath, account); | ||
console.log(encodedData); |
File renamed without changes.
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,40 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
function getProofForAccount(jsonFilePath, account) { | ||
try { | ||
// Read the JSON file | ||
const jsonData = JSON.parse(fs.readFileSync(jsonFilePath, "utf8")); | ||
|
||
// Create a new object with lowercased keys | ||
const lowercaseProofs = Object.keys(jsonData.proofs).reduce((acc, key) => { | ||
acc[key.toLowerCase()] = jsonData.proofs[key]; | ||
return acc; | ||
}, {}); | ||
|
||
// Convert the input account to lowercase | ||
const lowercaseAccount = account.toLowerCase(); | ||
|
||
// Check if the lowercased account exists in the proofs object | ||
if (lowercaseProofs.hasOwnProperty(lowercaseAccount)) { | ||
const proof = lowercaseProofs[lowercaseAccount]; | ||
|
||
// Convert the proof array to a single packed string without '0x' prefixes | ||
return proof.map((element) => element.slice(2)).join(""); | ||
} else { | ||
return "NO_PROOF_FOUND"; | ||
} | ||
} catch (error) { | ||
console.error(`Error reading proof data: ${error.message}`); | ||
return "ERROR_READING_PROOF"; | ||
} | ||
} | ||
|
||
// Get the command line arguments | ||
const args = process.argv.slice(2); | ||
const jsonFilePath = args[0]; | ||
const account = args[1]; | ||
|
||
// Run the function and output the result | ||
const proof = getProofForAccount(jsonFilePath, account); | ||
console.log(proof); |
Oops, something went wrong.