-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: convert-address command & unknown address option
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 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
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,26 @@ | ||
import { Command, OptionValues } from 'commander'; | ||
import { substrateAddressToEvmAddress, evmAddressToSubstrateAddress } from '../lib/evm/address'; | ||
import { ValidatedAddress, unknownAddressOption } from './options'; | ||
|
||
export function makeConvertAddressCommand() { | ||
const cmd = new Command('convert-address'); | ||
cmd.description('Get the associated EVM/Substrate address for a Substrate or EVM account'); | ||
cmd.addOption(unknownAddressOption.makeOptionMandatory()); | ||
cmd.action(convertAddressAction); | ||
return cmd; | ||
} | ||
|
||
function convertAddressAction (options: OptionValues) | ||
{ | ||
const address = options.address as ValidatedAddress; | ||
const type = address.type; | ||
if (type === 'EVM') { | ||
console.log(`AssociatedSubstrate address: ${evmAddressToSubstrateAddress(address.address)}`); | ||
} else if (type === 'Substrate') { | ||
console.log(`Associated EVM address: ${substrateAddressToEvmAddress(address.address)}`); | ||
} else { | ||
console.error('Invalid address type'); | ||
process.exit(1); | ||
} | ||
process.exit(0); | ||
} |
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