import { hotfixToHash , ProposalBuilder , ProposalTransactionJSON } from '@celo/governance' ; import { trimLeading0x } from '@celo/utils/lib/address' ; import { flags } from '@oclif/command' ; import { readFileSync } from 'fs-extra' ; import { BaseCommand } from '../../base' ; import { printValueMap } from '../../utils/cli' ; import { checkProposal } from '../../utils/governance' ; export default class HashHotfix extends BaseCommand { static description = 'Hash a governance hotfix specified by JSON and a salt' ; static flags = { ... BaseCommand . flags , jsonTransactions : flags . string ( { required : true , description : 'Path to json transactions of the hotfix' , } ) , force : flags . boolean ( { description : 'Skip execution check' , default : false } ) , salt : flags . string ( { required : true , description : 'Secret salt associated with hotfix' } ) , } ; static examples = [ 'hashhotfix --jsonTransactions ./transactions.json --salt 0x614dccb5ac13cba47c2430bdee7829bb8c8f3603a8ace22e7680d317b39e3658' , ] ; async run ( ) { const res = this . parse ( HashHotfix ) ; const jsonString = readFileSync ( res . flags . jsonTransactions ) . toString ( ) ; const jsonTransactions = JSON . parse ( jsonString ) ; const builder = new ProposalBuilder ( this . kit ) ; jsonTransactions . forEach ( ( tx ) => builder . addJsonTx ( tx ) ) ; const hotfix = await builder . build ( ) ; if ( ! res . flags . force ) { const ok = await checkProposal ( hotfix , this . kit ) ; if ( ! ok ) { return ; } } const saltBuff = Buffer . from ( trimLeading0x ( res . flags . salt ) , 'hex' ) ; console . log ( `salt: ${ res . flags . salt }, buf: ${ saltBuff . toString ( 'hex' ) }` ) ; const hash = hotfixToHash ( this . kit , hotfix , saltBuff ) ; printValueMap ( { hash : '0x' + hash . toString ( 'hex' ) } ) ; } }