-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(utxo-bin): add address subcommand
- Loading branch information
Showing
10 changed files
with
128 additions
and
97 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,76 @@ | ||
import * as utxolib from '@bitgo/utxo-lib'; | ||
import { CommandModule } from 'yargs'; | ||
|
||
import { getNetworkOptionsDemand, keyOptions, KeyOptions } from '../../args'; | ||
import { | ||
formatAddressTree, | ||
formatFixedScriptAddress, | ||
generateFixedScriptAddress, | ||
getFixedScriptAddressPlaceholderDescription, | ||
getRange, | ||
parseIndexRange, | ||
} from '../../generateAddress'; | ||
|
||
type IndexLimitOptions = { | ||
index?: string[]; | ||
limit?: number; | ||
}; | ||
|
||
const indexLimitOptions = { | ||
index: { | ||
type: 'string', | ||
array: true, | ||
description: 'Address index. Can be given as a range (e.g. 0-99). Takes precedence over --limit.', | ||
}, | ||
limit: { | ||
type: 'number', | ||
description: 'Alias for --index with range starting at 0 to limit-1.', | ||
default: 100, | ||
}, | ||
} as const; | ||
|
||
function getIndexRangeFromArgv(argv: IndexLimitOptions): number[] { | ||
if (argv.index) { | ||
return parseIndexRange(argv.index); | ||
} | ||
if (argv.limit) { | ||
return getRange(0, argv.limit - 1); | ||
} | ||
throw new Error(`no index or limit`); | ||
} | ||
|
||
type ArgsGenerateAddressFixedScript = KeyOptions & | ||
IndexLimitOptions & { | ||
network: utxolib.Network; | ||
chain?: number[]; | ||
format: string; | ||
}; | ||
|
||
export const cmdGenerateFixedScript: CommandModule<unknown, ArgsGenerateAddressFixedScript> = { | ||
command: 'fromFixedScript', | ||
describe: 'generate bitgo fixed-script addresses', | ||
builder(b) { | ||
return b | ||
.options(getNetworkOptionsDemand('bitcoin')) | ||
.options(keyOptions) | ||
.option('format', { | ||
type: 'string', | ||
default: '%p0\t%a', | ||
description: `Format string.\nPlaceholders:\n${getFixedScriptAddressPlaceholderDescription()}`, | ||
}) | ||
.option('chain', { type: 'number', array: true, description: 'Address chain' }) | ||
.options(indexLimitOptions); | ||
}, | ||
handler(argv): void { | ||
for (const address of generateFixedScriptAddress({ | ||
...argv, | ||
index: getIndexRangeFromArgv(argv), | ||
})) { | ||
if (argv.format === 'tree') { | ||
console.log(formatAddressTree(address)); | ||
} else { | ||
console.log(formatFixedScriptAddress(address, argv.format)); | ||
} | ||
} | ||
}, | ||
}; |
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,15 @@ | ||
import { CommandModule } from 'yargs'; | ||
|
||
import { cmdGenerateFixedScript } from './cmdGenerate'; | ||
import { cmdParse } from './cmdParse'; | ||
|
||
export const cmdAddress: CommandModule<unknown, unknown> = { | ||
command: 'address <command>', | ||
describe: 'address commands', | ||
builder(b) { | ||
return b.strict().command(cmdGenerateFixedScript).command(cmdParse).demandCommand(); | ||
}, | ||
handler() { | ||
// do nothing | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from './cmdParseTx'; | ||
export * from './cmdParseAddress'; | ||
export * from './cmdAddress'; | ||
export * from './cmdParseScript'; | ||
export * from './cmdGenerateAddress'; | ||
export * from './cmdBip32'; |
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
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