Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
;(async () => {
const kit = newKitFromWeb3(web3)
const account = await importAndUnlockAccount(web3, keystorePath)
const from = account.address
const accountContract = await kit.contracts.getAccounts()
const isAccount = await accountContract.isAccount(from)
if (!isAccount) {
// register
await displaySendTx('register', accountContract.createAccount(), { from: from })
// set name
const accountName: string = process.env.NAME || `account-${account.address}`
await delay(1000)
await displaySendTx('setName', accountContract.setName(accountName), { from: from })
// set encryption key
const publicKey = add0x(generatePublicKeyFromPrivateKey(account.privateKey.slice(2)))
const registerDataEncryptionKeyTx = accountContract.setAccountDataEncryptionKey(
publicKey as any
)
await displaySendTx('encryption', registerDataEncryptionKeyTx, { from: from })
}
console.log(account)
})()
const from = account.address
const accountContract = await kit.contracts.getAccounts()
const isAccount = await accountContract.isAccount(from)
if (!isAccount) {
// register
await displaySendTx('register', accountContract.createAccount(), { from: from })
// set name
const accountName: string = process.env.NAME || `account-${account.address}`
await delay(1000)
await displaySendTx('setName', accountContract.setName(accountName), { from: from })
// set encryption key
const publicKey = add0x(generatePublicKeyFromPrivateKey(account.privateKey.slice(2)))
const registerDataEncryptionKeyTx = accountContract.setAccountDataEncryptionKey(
publicKey as any
)
await displaySendTx('encryption', registerDataEncryptionKeyTx, { from: from })
}
console.log(account)
})()
;(async () => {
const kit = newKitFromWeb3(web3)
const account = await importAndUnlockAccount(web3, keystorePath)
const from = account.address
const accountContract = await kit.contracts.getAccounts()
const isAccount = await accountContract.isAccount(from)
if (!isAccount) {
// register
await displaySendTx('register', accountContract.createAccount(), { from: from })
// set name
const accountName: string = process.env.NAME || `account-${account.address}`
await delay(1000)
await displaySendTx('setName', accountContract.setName(accountName), { from: from })
// set encryption key
const publicKey = add0x(generatePublicKeyFromPrivateKey(account.privateKey.slice(2)))
const registerDataEncryptionKeyTx = accountContract.setAccountDataEncryptionKey(
publicKey as any
)
await displaySendTx('encryption', registerDataEncryptionKeyTx, { from: from })
}
console.log(account)
})()
const from = account.address
const pubkey = getPublicKeysData(account.privateKey)
const validatorContract = await kit.contracts.getValidators()
if (!(await validatorContract.isValidator(from))) {
await lockGoldIfNeeded(web3, from)
await delay(1000)
console.log(pubkey)
const txRegisterVal = validatorContract.registerValidator(pubkey as any)
await displaySendTx('registerValidator', txRegisterVal, { from: from })
await delay(1000)
}
const me = await validatorContract.getValidator(from)
console.log('affiliation', validatorGroup)
if (me.affiliation === '0x0000000000000000000000000000000000000000') {
const txAffiliate = validatorContract.affiliate(validatorGroup)
await displaySendTx('affiliate', txAffiliate, { from: from })
}
console.log(await validatorContract.getValidator(from))
})()
;(async () => {
const kit = newKitFromWeb3(web3)
const account = await importAndUnlockAccount(web3, keystorePath)
const from = account.address
const pubkey = getPublicKeysData(account.privateKey)
const validatorContract = await kit.contracts.getValidators()
if (!(await validatorContract.isValidator(from))) {
await lockGoldIfNeeded(web3, from)
await delay(1000)
console.log(pubkey)
const txRegisterVal = validatorContract.registerValidator(pubkey as any)
await displaySendTx('registerValidator', txRegisterVal, { from: from })
await delay(1000)
}
const me = await validatorContract.getValidator(from)
console.log('affiliation', validatorGroup)
if (me.affiliation === '0x0000000000000000000000000000000000000000') {
const txAffiliate = validatorContract.affiliate(validatorGroup)
await displaySendTx('affiliate', txAffiliate, { from: from })
}
console.log(await validatorContract.getValidator(from))
})()
;(async () => {
const kit = newKitFromWeb3(web3)
const account = await importAndUnlockAccount(web3, keystorePath)
const from = account.address
const validatorContract = await kit.contracts.getValidators()
console.log(await validatorContract.isValidatorGroup(from))
if (!(await validatorContract.isValidatorGroup(from))) {
await lockGoldIfNeeded(web3, from)
await delay(1000)
const txRegisterVG = await validatorContract.registerValidatorGroup(new BigNumber(0.1))
await displaySendTx('registerValidatorGroup', txRegisterVG, { from: from })
}
})()
export async function lockGoldIfNeeded(web3: Web3, from: string) {
const minLockedGold = new BigNumber(20000000000000000000000)
const kit = newKitFromWeb3(web3)
const lockedGoldContract = await kit.contracts.getLockedGold()
const nonvotingGold = await lockedGoldContract.getAccountNonvotingLockedGold(from)
if (nonvotingGold.lt(minLockedGold)) {
const txLock = lockedGoldContract.lock()
await displaySendTx('lock', txLock, {
from: from,
value: minLockedGold.toString(),
})
}
}