Skip to content

Commit

Permalink
Better error reporting in deposit script
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Sep 2, 2023
1 parent 1344800 commit e18a494
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@openzeppelin/contracts": "^4.3.2",
"@truffle/hdwallet-provider": "^1.4.2",
"dotenv": "^10.0.0",
"dotenv": "^16.3.1",
"truffle": "^5.4.3",
"web3": "^1.6.0"
},
Expand Down
20 changes: 18 additions & 2 deletions scripts/deposit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const Web3 = require('web3')

const path = require('path')
const { abi } = require('../build/contracts/IERC677.json')
const { abi: depositABI } = require('../build/contracts/IDepositContract.json')

require('dotenv').config({ path: path.resolve(__dirname, '.env') })

const {
RPC_URL,
GAS_PRICE,
Expand All @@ -19,7 +21,11 @@ const {
const web3 = new Web3(RPC_URL)
const { address } = web3.eth.accounts.wallet.add(STAKING_ACCOUNT_PRIVATE_KEY)

const depositData = require(process.argv[2])
const depositDataFilepath = process.argv[2]
if (!depositDataFilepath) {
throw Error('must provide positional argument $deposit_data_filepath')
}
const depositData = readJson(depositDataFilepath)

const batchSize = parseInt(BATCH_SIZE, 10)
const offset = parseInt(OFFSET, 10)
Expand Down Expand Up @@ -154,4 +160,14 @@ async function getPastLogs(contract, event, { fromBlock, toBlock }) {
}
}

function readJson(filepath) {
const s = fs.readFileSync(filepath)
try {
return JSON.parse(s)
} catch (e) {
e.message = `error parsing JSON string: ${e.message}\n${s}`
throw e
}
}

main()
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2543,10 +2543,10 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"

dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
dotenv@^16.3.1:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==

[email protected]:
version "2.1.0-0"
Expand Down

0 comments on commit e18a494

Please sign in to comment.